![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /********************************************************************* 00002 ** Copyright (c) 2005 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: ssClosestIntersectionFunctor.h,v $ $Revision: 1.5 $ $State: Exp $ 00007 *********************************************************************/ 00008 #ifndef ssClosestIntersectionFunctor_H_ 00009 #define ssClosestIntersectionFunctor_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 <assert.h> 00018 00019 // 00020 // A functor intended for use with the spatial subdivision set of classes. It's 00021 // primary usage is to intersect the first parameter into the second. Results 00022 // of the intersection are reported in the record type specified in the third 00023 // template parameter. 00024 // 00025 // Expected usage: 00026 // When passed to the intersection objects intersection functions, this fucntor 00027 // intersects the first item into the second one. Used primarily for intersecting the 00028 // different spatial sorted elements into their appropriate spatial subdivisions. 00029 // For an example, see the gdbNode intersecter class. 00030 // 00031 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00032 class DtSsClosestIntersectionFunctor : public DtSsFunctor<TypeToIntersect, Container> 00033 { 00034 public: 00035 // Constructor 00036 DtSsClosestIntersectionFunctor(); 00037 00038 // Destructor 00039 virtual ~DtSsClosestIntersectionFunctor(); 00040 00041 private: 00042 // not implemented 00043 DtSsClosestIntersectionFunctor(const DtSsClosestIntersectionFunctor& original); 00044 DtSsClosestIntersectionFunctor& operator=(const DtSsClosestIntersectionFunctor& original); 00045 00046 public: 00047 // Function operator - when applied intersects the first element with the 00048 // second element. 00049 // @param itemToIntersect The item to intersect into the second parameter. 00050 // @param container The container of elements into which to intersect the first 00051 // parameter. 00052 // 00053 // @returns Always returns false as it is never done processing - it can 00054 // always continue intersecting elements. 00055 virtual bool operator()(TypeToIntersect& itemToIntersect, Container& container); 00056 00057 virtual T_IntersectionRecordType* intersectionRecord() const; 00058 00059 virtual void setIntersectionRecord(T_IntersectionRecordType* newIntersectionRecord); 00060 00061 virtual DtGdbNode::DtIntersectRecordType intersectionRecordType() const; 00062 00063 virtual void setIntersectionRecordType( 00064 DtGdbNode::DtIntersectRecordType& newIntersectionRecordType); 00065 00066 00067 private: 00068 00069 T_IntersectionRecordType* myIntersectionRecord; 00070 DtGdbNode::DtIntersectRecordType myIntersectionRecordType; 00071 }; 00072 00073 00074 //------------------------------------------------------ 00075 // INLINE METHODS 00076 //------------------------------------------------------ 00077 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00078 DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>::DtSsClosestIntersectionFunctor() 00079 : DtSsFunctor<TypeToIntersect, Container>() 00080 , myIntersectionRecord(0) 00081 , myIntersectionRecordType(DtGdbNode::IRT_IPOINT) 00082 { 00083 } 00084 00085 00086 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00087 DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>::~DtSsClosestIntersectionFunctor() 00088 { 00089 } 00090 00091 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00092 bool DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>::operator() 00093 (TypeToIntersect& itemToIntersect, Container& containerToIntersect) 00094 { 00095 bool retVal = false; 00096 00097 assert(myIntersectionRecord != 0); 00098 00099 typename Container::iterator iter = containerToIntersect.begin(); 00100 typename Container::iterator endIter = containerToIntersect.end(); 00101 for (; iter != endIter; ++iter) 00102 { 00103 if ((*iter)->intersect(itemToIntersect, *myIntersectionRecord, myIntersectionRecordType)) 00104 { 00105 assert(myIntersectionRecord->intersectionFound()); 00106 retVal = true; 00107 } 00108 } 00109 00110 return retVal; 00111 } 00112 00113 00114 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00115 T_IntersectionRecordType* 00116 DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>::intersectionRecord() const 00117 { 00118 return myIntersectionRecord; 00119 } 00120 00121 00122 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00123 void DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>:: 00124 setIntersectionRecord(T_IntersectionRecordType* newIntersectionRecord) 00125 { 00126 assert(newIntersectionRecord != 0); 00127 myIntersectionRecord = newIntersectionRecord; 00128 } 00129 00130 00131 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00132 DtGdbNode::DtIntersectRecordType 00133 DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>::intersectionRecordType() const 00134 { 00135 return myIntersectionRecordType; 00136 } 00137 00138 template <typename TypeToIntersect, typename Container, typename T_IntersectionRecordType> 00139 void DtSsClosestIntersectionFunctor<TypeToIntersect, Container, T_IntersectionRecordType>:: 00140 setIntersectionRecordType(DtGdbNode::DtIntersectRecordType& newIntersectionRecordType) 00141 { 00142 myIntersectionRecordType = newIntersectionRecordType; 00143 } 00144 00145 #endif 00146 00147