![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2005 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: ssChordIntersector.h,v $ $Revision: 1.6 $ $State: Exp $ 00007 ******************************************************************************/ 00008 #ifndef ssChordIntersector_H_ 00009 #define ssChordIntersector_H_ 00010 00011 #include <vlutil/vlConfig.h> 00012 #include <vlutil/vlPrint.h> 00013 00014 #include "geometry/spatialSubdivision.h" 00015 #include "geometry/ssFunctor.h" 00016 #include "geometry/ssExtentIntersector.h" 00017 00018 #include "geometry/chord.h" 00019 #include "geometry/point.h" 00020 #include "geometry/plane.h" 00021 #include "geometry/tdbextent.h" 00022 00023 00025 // Note: Must use this macro to get around issues with VC 6.0 vs .Net/gcc. 00026 // 6.0 complains if you use the typename qualifier outside of a class definition, 00027 // but it is incorrect to not specify that the cell type is a type when using it 00028 // as a template parameter. 00030 #ifdef DtSPATIAL_SUB_CELL_TYPE 00031 #undef DtSPATIAL_SUB_CELL_TYPE 00032 #endif 00033 00034 #if _MSC_VER == 1200 // Visual Studio 6.0 00035 #define DtSPATIAL_SUB_CELL_TYPE DtSpatialSubdivision< T >::DtSpatialSubCellType 00036 #else 00037 #define DtSPATIAL_SUB_CELL_TYPE typename DtSpatialSubdivision< T >::DtSpatialSubCellType 00038 #endif 00039 00040 00041 00042 // 00043 // The DtSsChordIntersector is *solely* responsible for intersecting a DtChord and a 00044 // DtSpatialSubdivision together. It does not know what to do with the intersection 00045 // results, nor does it rely on the specific contents of the spatial subdivision. 00046 // 00047 // This is one of the basic SS intersection classes provided by the toolkit. 00048 // 00049 template <typename T> 00050 class DtSsChordIntersector 00051 { 00052 public: 00053 00054 // Constructor 00055 DtSsChordIntersector(); 00056 00057 // Destructor 00058 virtual ~DtSsChordIntersector(); 00059 00060 // Intersects the specified chord and spatial subdivision together. 00061 // @returns A boolean indicating whether or not the chord intersected the 00062 // spatial subdivision at all. 00063 // @note Technically, this returns true if the chord's @b extent intersects 00064 // the spatial subdivision at all. It does not do a true mathematical 00065 // intersection of the chord and the SS. 00066 virtual bool intersect(const DtChord& chord, DtSpatialSubdivision< T >& spatialSubdivision) const; 00067 00068 // Intersects the specified chord and spatial subdivision together. Applies 00069 // the functor to the intersection results, in order, until the functor 00070 // is done processing (returns true). 00071 // 00072 // @returns A boolean indicating whether or not the chord intersected the 00073 // spatial subdivision or not. Has nothing to do with the functor's success 00074 // or failure in its own processing. 00075 // 00076 // @note Unlike the above intersection function, this function only returns 00077 // true if the chord intersected the SS, not just the chord's extent. And the 00078 // functor is applied to the cells in the SS in the order that the chord intersects 00079 // them. 00080 // 00081 virtual bool intersect(const DtChord& chord, 00082 DtSpatialSubdivision< T >& spatialSubdivision, 00083 DtSsFunctor<const DtChord, DtSPATIAL_SUB_CELL_TYPE >& functor) const; 00084 00085 protected: 00086 00087 // Trims the specified chord to the spatial subdivision. 00088 bool trimChordToSubdivision(const DtChord& chord, 00089 const DtSpatialSubdivision<T>& spatialSubdivision, 00090 int xIndexStart, int yIndexStart, int zIndexStart, 00091 int xIndexEnd, int yIndexEnd, int zIndexEnd, 00092 double& tMin, double& tMax) const; 00093 00094 // A utility function used when trimming the chord to the spatial subdivision. 00095 // Given the specified chord, the specified starting/ending indices - in a single 00096 // dimension, the min and max planes in that dimension, and the actual starting 00097 // and ending indices, it computes the minimum and maximum time along the chord 00098 // in the specified dimension (basically when along the chord it intersects 00099 // the min and max planes. 00100 // 00101 // @returns a boolean indicating whether or not any part of the chord is inside 00102 // the specified planes. If the chord lies before the minPlane or after the maxPlane, 00103 // then the function returns false. 00104 bool trimChordInSingleDimension(const DtChord& chord, 00105 int minIndex, int maxIndex, DtPlane& minPlane, DtPlane& maxPlane, 00106 int indexStart, int indexEnd, double& tMin, double& tMax) const; 00107 00108 // Performs a recursive intersection of the chord with the spatial subdivision, 00109 // starting in the specified cell. Intersects the chord with the initial cell, 00110 // and then, if the functor is not done processing, creates a new chord from the 00111 // intersection point of the chord and the cell wall, and the endpoint of the 00112 // chord, and continues traversing/intersecting with that chord until no more 00113 // of the chord lies in the spatial subdivision or is entirely contained within 00114 // a single cell. 00115 // 00116 //@returns A boolean indicating whether or not the intersection succeeded or not. 00117 bool intersectStartingIn(const DtChord& chord, 00118 DtSpatialSubdivision< T >& spatialSubdivision, 00119 int xIndexStart, int yIndexStart, int zIndexStart, 00120 int xIndexEnd, int yIndexEnd, int zIndexEnd, 00121 DtSsFunctor<const DtChord, DtSPATIAL_SUB_CELL_TYPE >& functor) const; 00122 00123 // A utility function used in determining chord traversal in the x, y, z dimensions. 00124 // If the start is greater than the end, then we are traversing backwards in 00125 // the dimension. If the start is less than the end, then we are traversing 00126 // forwards in the dimension. 00127 // Specifically if the 00128 // start < end, then direction = 1 00129 // start > end, then direction = -1 00130 // start == end, then direction = 0 00131 int getRelativeDirection(int start, int end) const; 00132 00133 // A utility function used in determining chord traversal. This function 00134 // determines the nearest time along the chord until it intersects a cell wall 00135 // in the spatial subdivision, given the starting indices and the directions 00136 // of traversal in the different dimensions. 00137 void determineDirectionOfTraversal(const DtChord& chord, 00138 DtSpatialSubdivision<T>& spatialSubdivision, 00139 double& nearestTime, double& cellTime, int* offsetToNext, 00140 int xDir, int yDir, int zDir, 00141 int xIndexStart, int yIndexStart, int zIndexStart) const; 00142 00143 private: 00144 // Copy constructor & Assignment operator - not implemented 00145 DtSsChordIntersector(const DtSsChordIntersector& orig); 00146 DtSsChordIntersector& operator=(const DtSsChordIntersector& orig); 00147 00148 }; 00149 00150 #define SSCHORDINTERSECTOR_HEADER 00151 #include "geometry/ssChordIntersector.inl" 00152 #undef SSCHORDINTERSECTOR_HEADER 00153 00154 #ifdef DtSPATIAL_SUB_CELL_TYPE 00155 #undef DtSPATIAL_SUB_CELL_TYPE 00156 #endif 00157 00158 #endif