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