![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /********************************************************************* 00002 ** Copyright (c) 1998 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: basePoly.h,v $ $Revision: 1.26 $ $State: Exp $ 00007 *********************************************************************/ 00008 #ifndef basePoly_H_ 00009 #define basePoly_H_ 00010 00011 #include "gdb/gdbDefines.h" 00012 #include "gdb/allPoly.h" 00013 #include "geometry/plane.h" 00014 #include "geometry/tdbextent.h" 00015 #include <matrix/vlVector.h> 00016 00017 // forward declarations 00018 class DtList; 00019 class DtChordBundle; 00020 class DtSurface; 00021 class DtTerrainDatabase; 00022 00023 // class DtBasePolygon: 00024 // 00025 // DtBasePolygon is an abstract base class for representing 00026 // polygons. A polygon consists of a sequence of vertices in 00027 // counter-clockwise order. It is assumed that all the 00028 // vertices (if more than 3) are coplanar. 00029 class DT_DLL_gdb DtBasePolygon : public DtAllTypesPolygon 00030 { 00031 public: 00032 // Destructor 00033 virtual ~DtBasePolygon(); 00034 00035 protected: 00036 // Constructor is protected as this is an abstract 00037 // base class. 00038 DtBasePolygon(); 00039 00040 // Additional constructor 00041 DtBasePolygon(unsigned int numVertices); 00042 00043 // Copy constructor 00044 DtBasePolygon(const DtBasePolygon& orig); 00045 00046 // Assignment operator 00047 DtBasePolygon& operator=(const DtBasePolygon& orig); 00048 00049 public: 00050 00051 // mutator function 00052 virtual void setNumberOfVertices(unsigned int n); 00053 00054 //accessor functions 00055 virtual unsigned int numberOfVertices() const; 00056 00057 // Calls initPlaneAndExtent to force the polygon 00058 // to recompute the extent. 00059 virtual void recomputeExtent(); 00060 00061 // initialization function 00062 virtual void initPlaneAndExtent(); 00063 00064 // @return The plane through the polygon 00065 virtual DtPlane plane() const; 00066 00067 // @return The extent of polygon 00068 // @note Non-virtual to allow inlining. Very frequently called. 00069 DtExtent extent() const; 00070 00071 // returns normal to polygon 00072 virtual DtVector normal() const; 00073 00074 // for edge, plane, and normal. 00075 virtual bool getEdge(DtChord& edge, int edgeNumber) const; 00076 virtual void getPlane(DtPlane& plane) const; 00077 virtual void getNormal(DtVector& normal) const; 00078 00079 // if the polygon falls within the input 00080 // extent, update the color count in the colorCountRecord which is 00081 // an in-out parameter. 00082 virtual void countPolyColors(DtColorCountRecord& cr,const DtExtent& e) const; 00083 00084 //geometric functions 00085 00086 //redefine other extent to include all the vertices of the 00087 //polygon. 00088 virtual void expandExtent(DtExtent& otherExtent) const; 00089 00090 // computes the intersection of chord with polygon; returns 00091 // intersection point. 00092 // \param chordToTest The chord to test for intersection. 00093 // \param intersectionPoint The intersection point, if one occurred. 00094 // \param intersectionTime The time along the chord of the intersection. Only set if an intersection occured. 00095 // \return A boolean indicating whether or not an intersection occurred. 00096 virtual bool intersect(const DtChord& chordToTest, DtPoint& intersectionPoint, 00097 double& intersectionTime) const; 00098 00099 // Computes the intersection of the polygon and a chord. In addition to the 00100 // intersection point and a parametric value, optionally computes and 00101 // returns surface description for the intersecting surface, and 00102 // normal. Identifies the lowest level intersecting polygon. This function 00103 // will only replace the contents of the intersection record if it finds an 00104 // intersection with a smaller intersectionTime value. 00105 virtual bool intersect( 00106 const DtChord& chord, 00107 DtChordIntersectionRecord& record, 00108 DtIntersectRecordType irtFlag) const; 00109 00110 // Computes the intersection of terrain section represented by the polygon 00111 // and a bundle of chords. The returned record list is a a DtList of 00112 // DtChordIntersectionRecords (one for each chord) each of which must be 00113 // created and deleted by the caller. The irtFlag value specifies which 00114 // data should be calculated and returned for each intersection point. The 00115 // return value of this function is the number of the chords that had any 00116 // intersections with the terrain. This function will only replace the 00117 // contents of the intersection records if it finds an intersection with a 00118 // smaller intersectionTime value. 00119 virtual int intersectBundle( 00120 const DtChordBundle& chordBundle, 00121 DtList& recordList, 00122 DtIntersectRecordType irtFlag) const; 00123 00124 // Computes the list of all intersections of each of a bundle of chords 00125 // with the polygon. For each chord in the bundle, adds to a matching 00126 // DtChordIntersectRecordList sorted by distance along the chord. The 00127 // caller is responsible for creating and deleting the 00128 // DtChordIntersectRecordLists in the intListList DtList. The return value 00129 // of this function is the number of the chords that had any intersections 00130 // with the terrain. Note that passing an irtFlag value of IRT_NO_DATA 00131 // will probably never return more than one intersection per chord. 00132 virtual int allIntersectsAlongChordBundle( 00133 const DtChordBundle& chordBundle, 00134 DtList& intListList, 00135 DtIntersectRecordType irtFlag) const; 00136 00137 // \copydoc DtGdbNode::intersect(const DtSphere& sphere, 00138 // DtSphereIntersectionRecord& record, DtIntersectRecordType irtFlag) 00139 virtual bool intersect(const DtSphere& sphere, DtSphereIntersectionRecord& record, 00140 DtIntersectRecordType irtFlag) const; 00141 00142 //accessor functions 00143 virtual bool getVertex(DtPoint& retVal, unsigned int i) const = 0; 00144 virtual const DtPoint& getVertex(unsigned int i) const = 0; 00145 virtual bool getSurface(DtSurface& s) const = 0; 00146 virtual const DtSurface& getSurface() const = 0; 00147 virtual bool setSurface(const DtSurface& newSurface) = 0; 00148 00149 // determine if a given point is inside the polygon. 00150 virtual bool pointInPolygon(const DtPoint& point) const; 00151 00152 // Finds the point on the specified chord that is closest to this 00153 // polygon, and returns it in closestPoint. 00154 // \return Distance squared to the found point. 00155 // If cutoffDistance is specified (> 0), the first point found within 00156 // this distance will be returned, even if it is not the closest point. 00157 // This may cut down significantly on the calculation when the actual 00158 // closest point is not required. 00159 virtual double closestPointOnChordToPolygon(const DtChord& chord, 00160 DtPoint& closestPoint, double cutoffDistance = 0.) const; 00161 00162 // determine the minimum and maximum z-values among the 00163 // vertices in the polygon. 00164 virtual double minZ() const; 00165 virtual double maxZ() const; 00166 00167 // KLUDGE -- have different max # of verts per type of poly -- JM 00168 virtual bool isFull() const = 0; 00169 00170 virtual int sizeInBytes() const = 0; 00171 00172 protected: 00173 bool testInvariant() const; 00174 00175 // compute twice the area of the triangle formed by a, b, c, 00176 // as the magnitude of the cross product (b-a)X(c-a). 00177 virtual double computeTwiceArea( 00178 const DtPoint& a, 00179 const DtPoint& b, 00180 const DtPoint& c) const; 00181 00182 protected: 00183 00184 unsigned int myNumberOfVertices; 00185 bool myInitialized; // used to determine if plane and extent have 00186 // been computed. 00187 DtPlane myPlane; 00188 DtExtent myExtent; 00189 }; 00190 00191 inline double DtBasePolygon::minZ() const 00192 { 00193 return myExtent.minZ(); 00194 } 00195 00196 inline double DtBasePolygon::maxZ() const 00197 { 00198 return myExtent.maxZ(); 00199 } 00200 00201 inline unsigned int DtBasePolygon::numberOfVertices() const 00202 { 00203 return myNumberOfVertices; 00204 } 00205 00206 inline void DtBasePolygon::setNumberOfVertices(unsigned int n) 00207 { 00208 myNumberOfVertices = n; 00209 } 00210 00211 inline DtPlane DtBasePolygon::plane() const 00212 { 00213 return myPlane; 00214 } 00215 00216 inline DtExtent DtBasePolygon::extent() const 00217 { 00218 return myExtent; 00219 } 00220 00221 inline DtVector DtBasePolygon::normal() const 00222 { 00223 return plane().normal(); 00224 } 00225 00226 #endif