![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /********************************************************************* 00002 ** Copyright (c) 2000 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: triInd.h,v $ $Revision: 1.25 $ $State: Exp $ 00007 *********************************************************************/ 00008 00009 #ifndef triInd_H_ 00010 #define triInd_H_ 00011 00012 #include "gdb/gdbDefines.h" 00013 #include "gdb/baseTri.h" 00014 #include "gdb/vtxMgr.h" 00015 #include "gdb/surfMgr.h" 00016 #include "geometry/point.h" 00017 00018 #include <vlutil/vlPrint.h> 00019 #include <assert.h> 00020 00021 // forward declarations 00022 class DtSurfaceManager; 00023 class DtPolygonIndirect; 00024 00025 00026 // class DtTriangleIndirect: 00027 // 00028 // DtTriangleIndirect allows for the specification of the 00029 // vertices of a polygon as indices into a vertex Manager. 00030 00031 class DT_DLL_gdb DtTriangleIndirect : public DtBaseTriangle 00032 { 00033 public: 00034 00035 // constructor using a polygon indirect. 00036 DtTriangleIndirect(const DtPolygonIndirect* const poly); 00037 00038 // constructor with vertex IDs, vertex manager, surface manager, 00039 // and surface ID 00040 DtTriangleIndirect(DtVertexManager* const vertManager, 00041 const DtVertexID vertID0, 00042 const DtVertexID vertID1, 00043 const DtVertexID vertID2, 00044 DtSurfaceManager* const surfMgr, 00045 const DtSurfaceID surfID); 00046 00047 // destructor 00048 virtual ~DtTriangleIndirect(); 00049 00050 // copy constructor 00051 DtTriangleIndirect(const DtTriangleIndirect& orig); 00052 00053 // assignment operator 00054 DtTriangleIndirect& operator=(const DtTriangleIndirect& orig); 00055 00056 // computes the intersection of chord with polygon; returns 00057 // intersection point. 00058 virtual bool intersect(const DtChord& chord, 00059 DtPoint& intersectionPoint, 00060 double& t) const; 00061 00062 // Since this class only overrides one of the intersection functions, 00063 // specify that its using the base classes to prevent hiding. 00064 using DtBaseTriangle::intersect; 00065 using DtBaseTriangle::intersectBundle; 00066 using DtBaseTriangle::allIntersectsAlongChordBundle; 00067 00068 // returns extent of the triangle 00069 inline DtExtent extent() const; 00070 00071 // vertex accessors 00072 inline DtPoint& vertex0(); 00073 inline const DtPoint& vertex0() const; 00074 00075 inline DtPoint& vertex1(); 00076 inline const DtPoint& vertex1() const; 00077 00078 inline DtPoint& vertex2(); 00079 inline const DtPoint& vertex2() const; 00080 00081 virtual bool getVertex(DtPoint& retVal, unsigned int localIndex) const; 00082 const DtPoint& getVertex(unsigned int localIndex) const; 00083 00084 // Requires index be a valid localIndex into the list of vertex IDs. 00085 virtual DtVertexID getVertexID(unsigned int localIndex) const; 00086 00087 virtual void setVertex(unsigned int localIndex, DtVertexID vertexID); 00088 00089 // get the surface associated with the triangle 00090 virtual bool getSurface(DtSurface& s) const; 00091 const DtSurface& getSurface() const; 00092 00093 // get the surface ID associated with the triangle 00094 virtual DtSurfaceID getSurfaceID() const; 00095 00096 // set the surface associated with the triangle 00097 // If the ID is a valid surface ID, then it sets the 00098 // surface and returns true. If the ID is invalid, 00099 // the it returns false and does NOT set the surface. 00100 virtual bool setSurface(DtSurfaceID surfaceID); 00101 00102 // Sets the surface of the associated triangle. 00103 // \return A boolean indicating whether or not the surface could be set. 00104 // \note \b Implementation \b detail! - Does not add the surface if it already 00105 // exists in the surface manager. 00106 virtual bool setSurface(const DtSurface& newSurface); 00107 00108 // get the vertex Manager associated with the polygon 00109 inline virtual DtVertexManager* const vertexManager() const; 00110 00111 // get a pointer to the the surface Manager associated with the triangle 00112 inline virtual DtSurfaceManager* const surfaceManager() const; 00113 00114 // debugging aid function 00115 virtual void dump(int indentLevel) const; 00116 00117 // Applies the specified transform to its vertices. If the flag 00118 // is true, will create new vertices instead of modifying existing 00119 // ones. Returns false if the transformation fails for any reason. 00120 virtual bool applyTransform(const DtHomogeneousTransfMatrix& matrix, 00121 bool createNewVertices); 00122 00123 // Unsafe public functions: These functions expose the internals of 00124 // the object.They are unsafe in that, should the implementation change, 00125 // these functions are not guaranteed to stay the same. Any use of these 00126 // functions assumes the risk they will be broken by future changes to the 00127 // internals of this class 00128 00129 // default constructor 00130 DtTriangleIndirect(); 00131 00132 // constructor with vertex indices and vertex manager to 00133 // index into 00134 DtTriangleIndirect(DtVertexManager* vertMgr, 00135 const DtVertexID ind0, 00136 const DtVertexID ind1, 00137 const DtVertexID ind2); 00138 00139 // returns type of gdb node 00140 virtual DtGdbNode::DtGdbNodeType type() const; 00141 00142 // set the vertex Manager associated with the polygon 00143 // Requires that the specified vertex manager is not 0. 00144 virtual void setVertexManager(DtVertexManager* const vertManager); 00145 00146 // set the pointer to the surface Manager associated with the triangle 00147 // Requires that the specified surface manager is not 0. 00148 virtual void setSurfaceManager(DtSurfaceManager* const surfManager); 00149 00150 virtual int sizeInBytes() const; 00151 00152 protected: 00153 00154 virtual bool testInvariant() const; 00155 00156 DtSurfaceID mySurfaceID; 00157 DtSurfaceManager* mySurfaceManager; 00158 DtVertexManager* myVertexManager; 00159 DtVertexID myVertexIDs[3]; // an array of size 3 to hold the indices. 00160 }; 00161 00163 // Functions below do NOT test for invariancy 00164 // and may corrupt the triangle if not used properly 00166 inline DtPoint& DtTriangleIndirect::vertex0() 00167 { 00168 return myVertexManager->vertex(myVertexIDs[0]); 00169 } 00170 00171 inline const DtPoint& DtTriangleIndirect::vertex0() const 00172 { 00173 return myVertexManager->vertex(myVertexIDs[0]); 00174 } 00175 00176 00177 inline DtPoint& DtTriangleIndirect::vertex1() 00178 { 00179 return myVertexManager->vertex(myVertexIDs[1]); 00180 } 00181 00182 inline const DtPoint& DtTriangleIndirect::vertex1() const 00183 { 00184 return myVertexManager->vertex(myVertexIDs[1]); 00185 } 00186 00187 00188 inline DtPoint& DtTriangleIndirect::vertex2() 00189 { 00190 return myVertexManager->vertex(myVertexIDs[2]); 00191 } 00192 00193 inline const DtPoint& DtTriangleIndirect::vertex2() const 00194 { 00195 return myVertexManager->vertex(myVertexIDs[2]); 00196 } 00197 00198 inline DtExtent DtTriangleIndirect::extent() const 00199 { 00200 DtExtent expandedExtent(vertex0(), vertex1()); 00201 expandedExtent.expandToInclude(vertex2()); 00202 return expandedExtent; 00203 } 00204 00205 inline DtVertexManager* const DtTriangleIndirect::vertexManager() const 00206 { 00207 return myVertexManager; 00208 } 00209 00210 00211 inline DtSurfaceManager* const DtTriangleIndirect::surfaceManager() const 00212 { 00213 return mySurfaceManager; 00214 } 00215 00216 00217 inline DtGdbNode::DtGdbNodeType DtTriangleIndirect::type() const 00218 { 00219 return DtGdbNode::TRIANGLE_INDIRECT; 00220 } 00221 00222 inline DtVertexID DtTriangleIndirect::getVertexID(unsigned int index) const 00223 { 00224 assert(index <= 2); 00225 return myVertexIDs[index]; 00226 } 00227 00228 inline const DtPoint& DtTriangleIndirect::getVertex(unsigned int localIndex) const 00229 { 00230 return myVertexManager->vertex(myVertexIDs[localIndex]); 00231 } 00232 00233 inline DtSurfaceID DtTriangleIndirect::getSurfaceID() const 00234 { 00235 return mySurfaceID; 00236 } 00237 00238 inline void DtTriangleIndirect::setSurfaceManager(DtSurfaceManager* surfMgr) 00239 { 00240 assert(surfMgr != 0); 00241 mySurfaceManager = surfMgr; 00242 // every polygon is created with a surface type of 0 00243 // as soon as there is a surface manager, add 1 to the polygon count of this 00244 // surface 00245 mySurfaceManager->updateSurfaceTerrainElementMap(mySurfaceID, 1); 00246 } 00247 00248 inline void DtTriangleIndirect::setVertexManager(DtVertexManager* vertManager) 00249 { 00250 assert(vertManager != 0); 00251 myVertexManager = vertManager; 00252 } 00253 00254 inline void DtTriangleIndirect::setVertex(unsigned int localIndex, DtVertexID vertexIndex) 00255 { 00256 assert(localIndex <= 2); 00257 assert(myVertexManager->isValidID(vertexIndex)); 00258 if (localIndex <= 2) 00259 { 00260 myVertexIDs[localIndex] = vertexIndex; 00261 } 00262 else 00263 { 00264 DtWarn("Warning: DtTriangleIndirect::setVertex -- " 00265 "bad localIndex %d\n", localIndex); 00266 } 00267 } 00268 00269 inline const DtSurface& DtTriangleIndirect::getSurface() const 00270 { 00271 return mySurfaceManager->surface(mySurfaceID); 00272 } 00273 00274 #endif