VR-Forces 4.0.4 Class Documentation
include/gdb/ssAllIntersectionsFunctor.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2005 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: ssAllIntersectionsFunctor.h,v $ $Revision: 1.5 $ $State: Exp $
00007 *********************************************************************/
00008 #ifndef ssAllIntersectionsFunctor_H_
00009 #define ssAllIntersectionsFunctor_H_
00010 
00011 #include <vlutil/vlConfig.h> 
00012 #include "geometry/spatialSubdivision.h"
00013 #include "geometry/ssFunctor.h"
00014 
00015 #include "geometry/chrdIntRec.h"
00016 #include "gdb/gdbNode.h"
00017 #include "geometry/intRecLst.h"
00018 #include <assert.h>
00019 
00020 //
00021 // A functor intended for use with the spatial subdivision set of classes.  It's 
00022 // primary usage is to intersect the first parameter into the second.  
00023 // 
00024 // Expected usage:
00025 // When passed to the intersection objects intersection functions, this fucntor 
00026 // intersects the first item into the second one.  Used primarily for intersecting the
00027 // different spatial sorted elements into their appropriate spatial subdivisions.
00028 // For an example, see the gdbNode intersecter class.
00029 // 
00030 template <typename TypeToIntersect, typename Container>
00031 class DtSsAllIntersectionsFunctor : public DtSsFunctor<TypeToIntersect, Container>
00032 {
00033 public:
00034    // Constructor
00035    DtSsAllIntersectionsFunctor();
00036 
00037    // Destructor
00038    virtual ~DtSsAllIntersectionsFunctor();
00039 
00040 private:
00041    // not implemented
00042    DtSsAllIntersectionsFunctor(const DtSsAllIntersectionsFunctor& original);   
00043    DtSsAllIntersectionsFunctor& operator=(const DtSsAllIntersectionsFunctor& original);
00044 
00045 public:
00046    // Function operator - when applied intersects the first element with the
00047    // second element.
00048    // @param itemToIntersect The item to intersect into the second parameter.
00049    // @param container The container of elements into which to intersect the first
00050    // parameter.
00051    //
00052    // @returns Always returns false as it is never done processing - it can
00053    // always continue intersecting elements.
00054    virtual bool operator()(TypeToIntersect& itemToIntersect, Container& container);
00055 
00056    virtual DtChordIntersectRecordList* intersectionRecordContainer() const;
00057 
00058    virtual void setIntersectionRecordContainer(
00059       DtChordIntersectRecordList* newIntersectionRecordContainer);
00060 
00061    virtual DtGdbNode::DtIntersectRecordType intersectionRecordType() const;
00062 
00063    virtual void setIntersectionRecordType(
00064       DtGdbNode::DtIntersectRecordType& newIntersectionRecordType);
00065 
00066 
00067 private:
00068 
00069    DtChordIntersectRecordList*      myIntersectionRecordContainer;
00070    DtGdbNode::DtIntersectRecordType myIntersectionRecordType;
00071 };
00072 
00073 
00074 //------------------------------------------------------
00075 //  INLINE METHODS
00076 //------------------------------------------------------
00077 template <typename TypeToIntersect, typename Container>
00078 DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::DtSsAllIntersectionsFunctor()
00079 : DtSsFunctor<TypeToIntersect, Container>()
00080 , myIntersectionRecordContainer(0)
00081 , myIntersectionRecordType(DtGdbNode::IRT_IPOINT)
00082 {
00083 }
00084 
00085 
00086 template <typename TypeToIntersect, typename Container>
00087 DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::~DtSsAllIntersectionsFunctor()
00088 {
00089 }
00090 
00091 template <typename TypeToIntersect, typename Container>
00092 bool DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::operator()
00093    (TypeToIntersect& itemToIntersect, Container& containerToIntersect) 
00094 {
00095    // Use our record type to determine whether we should keep looking
00096    bool retVal = false;
00097    
00098    assert(myIntersectionRecordContainer != 0);
00099 
00100    typename Container::iterator iter = containerToIntersect.begin();
00101    typename Container::iterator endIter = containerToIntersect.end();
00102    for (; iter != endIter; ++iter)
00103    {
00104       if ((*iter)->allIntersectsAlongChord(itemToIntersect, 
00105          *myIntersectionRecordContainer, myIntersectionRecordType))
00106       {
00107          assert(myIntersectionRecordContainer->count() != 0);
00108          // Ok I found one. Is that all I'm looking for?
00109          // If our intersection record is IRT_ALL_DATA_TERRAIN or 
00110          // IRT_VECTOR_DATA_ALONG_CHORD or IRT_ALL_DATA_ALONG_CHORD
00111          // we are looking for all possible hits so keep looking even
00112          // if one interesection is found.
00113          if ( myIntersectionRecordType == 0x07 ||
00114               myIntersectionRecordType == 0x20 ||
00115               myIntersectionRecordType == 0x27)
00116          {
00117             // We should keep looking for more
00118             retVal = false;
00119          }
00120          else
00121          {
00122             // We're done, we found the intersection we were looking for
00123             retVal = true;
00124          }
00125       }
00126    }
00127 
00128    return retVal;
00129 }
00130 
00131 
00132 template <typename TypeToIntersect, typename Container>
00133 DtChordIntersectRecordList* 
00134 DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::intersectionRecordContainer() const
00135 {
00136    return myIntersectionRecordContainer;
00137 }
00138 
00139 
00140 template <typename TypeToIntersect, typename Container>
00141 void DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::
00142 setIntersectionRecordContainer(DtChordIntersectRecordList* newIntersectionRecordContainer)
00143 {
00144    assert(newIntersectionRecordContainer != 0);
00145    myIntersectionRecordContainer = newIntersectionRecordContainer;
00146 }
00147 
00148 
00149 template <typename TypeToIntersect, typename Container>
00150 DtGdbNode::DtIntersectRecordType 
00151 DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::intersectionRecordType() const
00152 {
00153    return myIntersectionRecordType;
00154 }
00155 
00156 
00157 template <typename TypeToIntersect, typename Container>
00158 void DtSsAllIntersectionsFunctor<TypeToIntersect, Container>::
00159 setIntersectionRecordType(DtGdbNode::DtIntersectRecordType& newIntersectionRecordType) 
00160 {  
00161    myIntersectionRecordType = newIntersectionRecordType;
00162 }
00163 
00164 
00165 
00166 #endif
00167 
00168 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)