![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /********************************************************************* 00002 ** Copyright (c) 1999 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: group.h,v $ $Revision: 1.24 $ $State: Exp $ 00007 *********************************************************************/ 00008 00009 #ifndef group_H_ 00010 #define group_H_ 00011 00012 #include "gdb/gdbDefines.h" 00013 #include "gdb/gdbNode.h" 00014 #include "geometry/tdbextent.h" 00015 #include "geometry/matrix4x4.h" 00016 #include <vlutil/vlConfig.h> 00017 #include <list> 00018 #include <vector> 00019 #include <set> 00020 00021 // forward declarations 00022 class DtChordBundle; 00023 00024 // class DtGroup: 00025 // 00026 // DtGroup represents a container of DtGdbNodes. 00027 // 00028 class DT_DLL_gdb DtGroup : public DtGdbNode 00029 { 00030 public: 00031 00032 typedef std::vector<DtGdbNode*> DtGroupChildren; 00033 typedef const std::vector<DtGdbNode*> DtConstGroupChildren; 00034 typedef std::vector<DtGdbNode*>::iterator DtGroupChildrenIter; 00035 typedef std::vector<DtGdbNode*>::const_iterator DtGroupChildrenConstIter; 00036 00037 // default constructor 00038 DtGroup(); 00039 00040 // destructor 00041 virtual ~DtGroup(); 00042 00043 // copy constructor 00044 DtGroup(const DtGroup& orig); 00045 00046 // assignment operator 00047 DtGroup& operator=(const DtGroup& orig); 00048 00049 // returns the type of gdb node 00050 virtual DtGdbNodeType type() const; 00051 00052 // Non-virtual to allow inlining. Very frequently called. 00053 // Returns the extent of the group 00054 DtExtent extent() const; 00055 00056 // returns the group's child nodes. 00057 virtual DtGroupChildren& children(); 00058 virtual DtConstGroupChildren& children() const; 00059 00060 // process the polygons included in the node that fall within the input 00061 // extent, and update the color count in the colorCountRecord which is 00062 // an in-out parameter. 00063 virtual void countPolyColors(DtColorCountRecord& cr,const DtExtent& e) const; 00064 00065 // redefine extent to include all components of the group 00066 virtual void expandExtent(DtExtent& extent) const; 00067 00068 // Forces all children to recalculate their extents, and then recomputes 00069 // the extent for the group using the new extents 00070 virtual void recomputeExtent(); 00071 00072 // compute the intersection point of chord and the group. 00073 virtual bool intersect(const DtChord& chord, 00074 DtPoint& intersectionPoint, double& t) const; 00075 00076 // Computes the intersection of the terrain section represented by the 00077 // group components and a chord. In addition to the intersection point and 00078 // a parametric value, optionally computes and returns surface description 00079 // for the intersecting surface, and normal. Identifies the lowest level 00080 // intersecting polygon. This function will only replace the contents of 00081 // the intersection record if it finds an intersection with a smaller 00082 // intersectionTime value. 00083 virtual bool intersect(const DtChord& chord, 00084 DtChordIntersectionRecord& record, DtIntersectRecordType irtFlag) const; 00085 00086 // Tests for intersection between the terrain represented by this node 00087 // and the specified sphere. 00088 // \return True if an intersection occurs. 00089 // \note irtFlag is ignored for now. 00090 virtual bool intersect(const DtSphere& sphere, DtSphereIntersectionRecord& record, 00091 DtIntersectRecordType irtFlag) const; 00092 00093 // Computes the list of all intersections of a chord with the terrain 00094 // section represented by the group components. Adds to a list of 00095 // DtChordIntersectionRecords sorted by distance along the chord. Returns 00096 // false if no intersections exist. 00097 virtual bool allIntersectsAlongChord(const DtChord& chord, 00098 DtChordIntersectRecordList& intList, 00099 DtIntersectRecordType irtFlag) const; 00100 00101 // Computes the intersection of terrain section represented by the group 00102 // components and a bundle of chords. The 00103 // returned record list is a a DtList of DtChordIntersectionRecords (one 00104 // for each chord) each of which must be created and deleted by the caller. 00105 // The irtFlag value specifies which data should be calculated and returned 00106 // for each intersection point. The return value of this function is the 00107 // number of the chords that had any intersections with the terrain. This 00108 // function will only replace the contents of the intersection records if 00109 // it finds an intersection with a smaller intersectionTime value. 00110 virtual int intersectBundle(const DtChordBundle& chordBundle, 00111 DtList& recordList, DtIntersectRecordType irtFlag) const; 00112 00113 // Computes the list of all intersections of each of a bundle of chords 00114 // with the terrain section represented by the group components. For each 00115 // chord in the bundle, adds to a matching DtChordIntersectRecordList 00116 // sorted by distance along the chord. The caller is responsible for 00117 // creating and deleting the DtChordIntersectRecordLists in the intListList 00118 // DtList. The return value of this function is the number of the chords 00119 // that had any intersections with the terrain. Note that passing an 00120 // irtFlag value of IRT_NO_DATA will probably never return more than one 00121 // intersection per chord. 00122 virtual int allIntersectsAlongChordBundle(const DtChordBundle& chordBundle, 00123 DtList& intListList, DtIntersectRecordType irtFlag) const; 00124 00125 // add a node to the group 00126 // If for some reason, it cannot add the child due to lack of memory, it 00127 // throws a std::bad_alloc exception 00128 // \throws std::bad_alloc 00129 virtual void addChild(DtGdbNode* newNode); 00130 virtual void addChildIfNonNull(DtGdbNode* newNode); 00131 virtual void addChildToStart(DtGdbNode* newNode); 00132 00133 // collapses any coordinate system nodes below this node 00134 // matrix is the transform matrix to apply to children of the node 00135 // - contains transformation necessary to go from child coords all 00136 // the way back out to world coordinates 00137 virtual bool applyTransform(const DtHomogeneousTransfMatrix& matrix, 00138 bool createNewVertices); 00139 00140 // Reconstitute the group after each child is reduced, eliminating 00141 // child nodes that reduce to null. 00142 virtual void reduceChildren(int& numReductions); 00143 00144 // reduce the group object to eliminate redundant nodes. 00145 virtual DtGdbNode* reduce(int& numReductions); 00146 00147 // check the object to ensure it is valid. 00148 virtual bool sanityCheck() const; 00149 00150 // prints out the contents of the object 00151 virtual void dump(int indentLevel) const; 00152 00153 // Return the minimum terrain file version number that this Node can be 00154 // saved in. 00155 virtual DtTerrainFileVersionNumber minSaveVersion() const; 00156 00157 // Finds all instances of node type searchType in the tree including and 00158 // below this node. 00159 virtual void allInstancesOf(const DtGdbNodeType searchType, 00160 DtFoundInstancesContainer& foundInstances, 00161 bool recurseIntoCoordSysNodes = false); 00162 00163 virtual void allInstancesOf(const DtGdbNodeType searchType, 00164 DtFoundInstancesConstContainer& foundInstances, 00165 bool recurseIntoCoordSysNodes = false) const; 00166 00167 virtual void allInstancesOf(const DtGdbNodeType searchType, 00168 DtFoundInstancesContainer& foundInstances, bool recurseIntoCoordSysNodes, 00169 DtGdbNodeEvaluationFunctor& functor); 00170 00171 virtual void allInstancesOf(const DtGdbNodeType searchType, 00172 DtFoundInstancesConstContainer& foundInstances, bool recurseIntoCoordSysNodes, 00173 DtGdbNodeEvaluationFunctor& functor) const; 00174 00175 // Finds and removes all instances of node type searchType in the tree 00176 // below this node. 00177 virtual void purgeAllInstancesOf(const DtGdbNodeType searchType); 00178 00179 // Finds and removes all instances of every node type in the tree below 00180 // this node; deletes the nodes if they are not memory managed. It returns 00181 // this. 00182 virtual DtGdbNode* purgeAll(); 00183 00184 //Finds and replaces all three-sided polygons with triangles 00185 //in the tree below this node. 00186 virtual void polygonToTriangle(DtMemoryManager* memMgr, 00187 unsigned int& numIndConverted, unsigned int& numIndTotal); 00188 00189 // Load in all external DtFileNode files. Returns the number of databases 00190 // that were just loaded. 00191 virtual unsigned int loadAllExternalFiles() const; 00192 00193 // Unload all external DtFileNode files. Returns the number of databases 00194 // that were unloaded. 00195 virtual unsigned int unloadAllExternalFiles() const; 00196 00197 // This method returns a balanced-tree. branching is the maximum 00198 // branching factor, and bushiness is the number of leaves in the last 00199 // group. This function leaves the old tree intact. 00200 virtual DtGroup* balanced(unsigned int branching, unsigned int bushiness); 00201 00202 // This method returns a balanced-tree. branching is the maximum 00203 // branching factor, and bushiness is the number of leaves in the last 00204 // group. This function purges the groups in the old tree. 00205 virtual DtGroup* balancedAndPurged(unsigned int branching, unsigned int bushiness); 00206 00207 // Find the parent (if it exists of child in the tree under the node) 00208 virtual DtGdbNode* parent(DtGdbNode *child); 00209 00210 // remove the child (if it is) from this node 00211 virtual DtGdbNode* removeChild(DtGdbNode *child); 00212 00213 virtual void computeExtent(); 00214 00215 virtual int sizeInBytes() const; 00216 00217 protected: 00218 00219 // Deletes a node iff it is not memory managed. 00220 virtual void purge(DtGdbNode* node); 00221 00222 virtual void dumpComponents(int indentLevel) const; 00223 00224 virtual void reduceChildrenAux(DtGroupChildren& nodesToBeReduced, 00225 std::list<DtGdbNode*>& nodesAlreadyReduced, 00226 int& numReductions); 00227 00228 protected: 00229 00230 DtExtent myExtent; 00231 DtGroupChildren myNodes; 00232 }; 00233 00234 inline DtGdbNode::DtGdbNodeType DtGroup::type() const 00235 { 00236 return DtGdbNode::GROUP; 00237 } 00238 00239 inline DtExtent DtGroup::extent() const 00240 { 00241 return myExtent; 00242 } 00243 00244 inline DtGroup::DtGroupChildren& DtGroup::children() 00245 { 00246 return myNodes; 00247 } 00248 00249 inline DtGroup::DtConstGroupChildren& DtGroup::children() const 00250 { 00251 return myNodes; 00252 } 00253 00254 #endif 00255