![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2008 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: opcodeTerrainIntersectorImpl.h,v $ $Revision: 1.5 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00011 00012 #ifndef opcodeTerrainIntersectorImpl_h 00013 #define opcodeTerrainIntersectorImpl_h 00014 00015 #define BAN_OPCODE_AUTOLINK 00016 00017 #include "Opcode.h" 00018 #include <vector> 00019 #include "gdb/triInd.h" 00020 #include <vlutil/vlMutex.h> 00021 00022 // Enable this to create a log of all the chord intersection calls that 00023 // are made though this interface. 00024 // The resulting file can be used in the terrainPerformance test program. 00025 //#define LOG_INTERSECTIONS 00026 00027 #ifdef LOG_INTERSECTIONS 00028 #include <list> 00029 #include "geometry/chord.h" 00030 #endif 00031 00032 00033 class DtTerrainDatabase; 00034 class DtPoint; 00035 class DtGdbNode; 00036 class DtChordIntersectionRecord; 00037 class DtChord; 00038 class DtSphere; 00039 class DtFileNode; 00040 00041 class DT_DLL_gdb DtOpcodeTerrainIntersectorImpl 00042 { 00043 public: 00044 DtOpcodeTerrainIntersectorImpl(); 00045 virtual ~DtOpcodeTerrainIntersectorImpl(); 00046 00047 // Builds the opcode model based on this terrain. The terrain 00048 // must triangularized before this is done. 00049 virtual bool initFromGdb(DtTerrainDatabase* terrain); 00050 00051 // \return A text string specifying the initialization state of the interface. 00052 // This will contain error text if initFromGdb() fails. 00053 virtual DtString initStateText() const; 00054 00055 // \return The number of bytes used by the opcode interface and model. 00056 virtual unsigned int memoryUsage() const; 00057 00058 // \return Information about the first intersection of the specified Chord. 00059 virtual bool chordIntersect(const DtChord& chord, 00060 DtChordIntersectionRecord& record, 00061 DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN) const; 00062 00063 virtual bool allIntersectsAlongChord(const DtChord& chord, 00064 DtChordIntersectRecordList& intList, 00065 DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN, 00066 const DtFileNode* visitedFileNode = 0) const; 00067 00068 virtual bool sphereIntersect(const DtSphere& sphere, DtSphereIntersectionRecord& record, 00069 DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN) const; 00070 00071 protected: 00072 typedef std::pair<DtChordIntersectionRecord*, DtOpcodeTerrainIntersectorImpl*> RecordMeshPair; 00073 00074 virtual bool makeOpcodeTriangleIndex(DtGdbNode* node); 00075 00076 // \throws std::bad_alloc if there is not enough memory 00077 virtual void makeIndexedTriangleArray(); 00078 00079 // Returns the list of file nodes that intersects with the chord 00080 virtual bool intersectAnyFileNode(const DtChord& chord, std::vector<DtFileNode*>& vec) const; 00081 00082 // Returns the list of file nodes whose extent intersects with the sphere's extent 00083 // or contain the sphere's center. 00084 virtual bool intersectAnyFileNode(const DtSphere& sphere, std::vector<DtFileNode*>& vec) const; 00085 00086 // \brief Used to insert items inside a map in order 00087 virtual bool lessDistance(const Opcode::CollisionFace& c1, const Opcode::CollisionFace& c2); 00088 00089 protected: 00090 00091 typedef std::vector<DtTriangleIndirect*> TriangleIndexType; 00092 00093 IndexedTriangle* myIndexedTriangleArray; 00094 TriangleIndexType myTriangleIndex; 00095 unsigned int myNumberOfVertices; 00096 unsigned int myNumberOfTriangles; 00097 Opcode::Model myOpcodeModel; 00098 00099 Opcode::OPCODECREATE myOPC; 00100 Opcode::MeshInterface myMeshInterface; 00101 DtString myInitStateText; 00102 00103 #ifdef LOG_INTERSECTIONS 00104 typedef std::list<std::pair<DtChord, DtGdbNode::DtIntersectRecordType> > DtIntersectionHistoryList; 00105 mutable DtIntersectionHistoryList myIntersectionHistory; 00106 mutable bool myIntersectionHistoryStarted; 00107 00108 void writeIntersectionHistory() const; 00109 void addIntersectionHistory(const DtChord& chord, DtGdbNode::DtIntersectRecordType irtFlag) const; 00110 #endif 00111 00112 // Since OPCODE is not thread safe, use this mutex to protect 00113 // against multiple threads inside the intersection methods. 00114 mutable DtMutex myIntersectMutex; 00115 DtTerrainDatabase* myTerrainDb; 00116 std::vector<DtFileNode*> myFileNodes; 00117 }; 00118 00119 #endif