![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2004 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: fileNode.h,v $ $Revision: 1.19 $ $State: Exp $ 00007 *******************************************************************************/ 00008 #ifndef fileNode_H_ 00009 #define fileNode_H_ 00010 00011 // \file fileNode.h 00012 // \brief Contains the DtFileNode class declaration. 00013 00014 #include "gdb/gdbDefines.h" 00015 #include <stdio.h> 00016 00017 #include <vlutil/vlMachineTypes.h> 00018 #include <vlutil/vlFilename.h> 00019 #include <vector> 00020 #include "geometry/tdbextent.h" 00021 #include "gdb/gdbNode.h" 00022 00023 00024 // Forward declarations 00025 class DtGroup; 00026 class DtTerrainDatabase; 00027 class DtChordBundle; 00028 class DtList; 00029 class DtPoint; 00030 class Coordinate_System; 00031 class DtTriangleIndirect; 00032 00033 00034 // 00035 // Instances of DtFileNode represent a GDB database file nested within another 00036 // GDB database file. 00037 class DT_DLL_gdb DtFileNode : public DtGdbNode 00038 { 00039 public: 00040 00041 // default constructor 00042 DtFileNode(); 00043 00044 // Extra constructor if not reading from a file. This is used so that we 00045 // can save away the coordinate system and directory of the parent database 00046 // for use when reading children later. 00047 DtFileNode(DtTerrainDatabase* parentTerrainDatabase); 00048 00049 // destructor 00050 virtual ~DtFileNode(); 00051 00052 // copy constructor 00053 DtFileNode(const DtFileNode& orig); 00054 00055 // assignment operator 00056 DtFileNode& operator=(const DtFileNode& orig); 00057 00058 // returns the type of gdb node 00059 virtual DtGdbNodeType type() const; 00060 00061 // process the polygons included in the node that fall within the input 00062 // extent, and update the color count in the colorCountRecord which is 00063 // an in-out parameter. 00064 virtual void countPolyColors(DtColorCountRecord& cr, 00065 const DtExtent& e) const; 00066 00067 // Return a pointer to the parent terrain database (0 if unknown) 00068 virtual DtTerrainDatabase* parentTerrainDatabase() const; 00069 // Set the pointer to the parent terrain database 00070 virtual void setParentTerrainDatabase(DtTerrainDatabase* arg); 00071 00072 // Returns the extent of the database (if loaded), or the alternate 00073 // representation (if not loaded). 00074 virtual DtExtent extent() const; 00075 00076 // Forces the file node to compute or recompute the extent. 00077 virtual void recomputeExtent(); 00078 00079 // if the terrain is loaded, it will transform it into the new coordinate system. 00080 virtual bool transformCoordinateSystem(Coordinate_System* newCoordSys); 00081 00082 virtual void setHomogeneousTransformMatrix(DtHomogeneousTransfMatrix transfMatrix); 00083 virtual DtHomogeneousTransfMatrix homogeneousTransfMatrix() const; 00084 00085 virtual void setCreateNewVertices(bool createNewVertices); 00086 virtual bool createNewVertices() const; 00087 00088 // redefine extent to include all components of the group 00089 virtual void expandExtent(DtExtent& e) const; 00090 virtual void setExtent(DtExtent& e); 00091 00092 // Returns the child object, either the top terrain object or the alternate 00093 // representation node. 00094 virtual DtGdbNode* child() const; 00095 00096 // Get alternative representation 00097 virtual DtGroup* alternateRep() const; 00098 // Set alternative representation 00099 virtual void setAlternateRep(DtGroup* arg); 00100 virtual void setAlternateRep(const DtGroup& arg); 00101 00102 // Build an alternate representation from the given terrain 00103 // NOTE: Uses the parent terrainDatabase to build the polygons representing 00104 // the alternate representation. Parent terrainDatabase must be valid. 00105 // This is necessary to prevent the polygons representing the terrain 00106 // from being deleted when the terrain database from which this is created is 00107 // destroyed. 00108 virtual bool makeAlternateRepFromTerrain(const DtTerrainDatabase& terrain); 00109 virtual bool makeAlternateRepFromTerrain(const DtGroup *gp); 00110 00111 // Take the given terrain as the alternate representation, the top-level 00112 // DtGdbNode is ripped out of the given terrain object and put in our 00113 // group. The File node will take over ownership of the terrain database 00114 // and will delete it when the file node is also destroyed. 00115 virtual bool takeAlternateRepTerrain(DtTerrainDatabase* terrain); 00116 00117 // Get filename 00118 virtual const DtFilename& filename() const; 00119 // Set filename 00120 virtual void setFilename(const DtFilename& arg); 00121 00122 // Get directory of parent database 00123 virtual const DtFilename& directory() const; 00124 // Set directory of parent database 00125 virtual void setDirectory(const DtFilename& arg); 00126 00127 // Get load failure flag 00128 virtual bool loadFailed() const; 00129 // Set load failure flag 00130 virtual void setLoadFailed(bool arg); 00131 00132 // Get terrain database (will be 0 if not yet loaded) 00133 virtual const DtTerrainDatabase* terrainDatabase() const; 00134 virtual DtTerrainDatabase* terrainDatabase(); 00135 00136 // Set terrain database (this also sets extents and filename) 00137 virtual void setTerrainDatabase(DtTerrainDatabase* arg); 00138 00139 // Get the coordinate system 00140 virtual Coordinate_System* coordinateSystem() const; 00141 // Set the coordinate system 00142 virtual void setCoordinateSystem(Coordinate_System* arg); 00143 00144 // Returns true iff the external terrain file has been loaded 00145 bool terrainIsLoaded() const; 00146 00147 // Load in the terrain file. 00148 // If the member homogeneous transformation is not identity, this will 00149 // apply the transform to the loaded child database and reset the member 00150 // transform to identity (as it's been applied) and myCreateNewVertices 00151 // to false. 00152 // If the child coordinate system is different from the parent's coordinate system 00153 // the child's will be converted if possible. 00154 virtual bool loadTerrain() const; 00155 00156 // Unload the terrain file. 00157 virtual bool unloadTerrain() const; 00158 00159 // Compute the intersection point of chord and the group. Note: this 00160 // forces a load of the terrain file (if possible) 00161 virtual bool intersect(const DtChord& chord, 00162 DtPoint& intersectionPoint, double& t) const; 00163 00164 // Computes the intersection of the terrain section represented by the 00165 // group components and a chord. In addition to the intersection point and 00166 // a parametric value, optionally computes and returns surface description 00167 // for the intersecting surface, and normal. Identifies the lowest level 00168 // intersecting polygon. This function will only replace the contents of 00169 // the intersection record if it finds an intersection with a smaller 00170 // intersectionTime value. 00171 virtual bool intersect(const DtChord& chord, 00172 DtChordIntersectionRecord& record, DtIntersectRecordType irtFlag) const; 00173 00174 // Computes the list of all intersections of a chord with the terrain 00175 // section represented by the group components. Adds to a list of 00176 // DtChordIntersectionRecords sorted by distance along the chord. Returns 00177 // false if no intersections exist. 00178 virtual bool allIntersectsAlongChord(const DtChord& chord, 00179 DtChordIntersectRecordList& intList, 00180 DtIntersectRecordType irtFlag) const; 00181 00182 // Computes the intersection of terrain section represented by the terrain 00183 // section represented by the group components and a bundle of chords. The 00184 // returned record list is a a DtList of DtChordIntersectionRecords (one 00185 // for each chord) each of which must be created and deleted by the caller. 00186 // The irtFlag value specifies which data should be calculated and returned 00187 // for each intersection point. The return value of this function is the 00188 // number of the chords that had any intersections with the terrain. This 00189 // function will only replace the contents of the intersection records if 00190 // it finds an intersection with a smaller intersectionTime value. 00191 virtual int intersectBundle(const DtChordBundle& chordBundle, 00192 DtList& recordList, DtIntersectRecordType irtFlag) const; 00193 00194 // Computes the list of all intersections of each of a bundle of chords 00195 // with the terrain section represented by the group components. For each 00196 // chord in the bundle, adds to a matching DtChordIntersectRecordList 00197 // sorted by distance along the chord. The caller is responsible for 00198 // creating and deleting the DtChordIntersectRecordLists in the intListList 00199 // DtList. The return value of this function is the number of the chords 00200 // that had any intersections with the terrain. Note that passing an 00201 // irtFlag value of IRT_NO_DATA will probably never return more than one 00202 // intersection per chord. 00203 virtual int allIntersectsAlongChordBundle(const DtChordBundle& chordBundle, 00204 DtList& intListList, DtIntersectRecordType irtFlag) const; 00205 00206 // Reduce the group object to eliminate redundant nodes. 00207 virtual DtGdbNode* reduce(int& numReductions); 00208 00209 // check the object to ensure it is valid. 00210 virtual bool sanityCheck() const; 00211 00212 // Prints out the contents of the object. 00213 virtual void dump(int indentLevel) const; 00214 00215 // Finds all instances of node type searchType in the tree including and 00216 // below this node in it's alternate representation. 00217 // Does NOT look in the child terrain database. 00218 virtual void allInstancesOf(const DtGdbNodeType searchType, 00219 DtFoundInstancesContainer& foundInstances, 00220 bool recurseIntoCoordSysNodes = false); 00221 00222 virtual void allInstancesOf(const DtGdbNodeType searchType, 00223 DtFoundInstancesConstContainer& foundInstances, 00224 bool recurseIntoCoordSysNodes = false) const; 00225 00226 virtual void allInstancesOf(const DtGdbNodeType searchType, 00227 DtFoundInstancesContainer& foundInstances, bool recurseIntoCoordSysNodes, 00228 DtGdbNodeEvaluationFunctor& functor); 00229 00230 virtual void allInstancesOf(const DtGdbNodeType searchType, 00231 DtFoundInstancesConstContainer& foundInstances, 00232 bool recurseIntoCoordSysNodes, DtGdbNodeEvaluationFunctor& functor) const; 00233 00234 00235 // Return the minimum terrain file version number that this Node can be 00236 // saved in. 00237 virtual DtTerrainFileVersionNumber minSaveVersion() const; 00238 00239 // Finds and removes all instances of every node type in the tree below 00240 // this node; deletes the nodes if they are not memory managed. It returns 00241 // this. 00242 virtual DtGdbNode* purgeAll(); 00243 00244 // Load in all external DtFileNode files. Returns the number of databases 00245 // that were just loaded. 00246 virtual unsigned int loadAllExternalFiles() const; 00247 00248 // Unload all external DtFileNode files. Returns the number of databases 00249 // that were unloaded. 00250 virtual unsigned int unloadAllExternalFiles() const; 00251 00252 // Find the parent (if it exists of child in the tree under the node) 00253 virtual DtGdbNode* parent(DtGdbNode *child); 00254 00255 // remove the child (if it is) from this node 00256 virtual DtGdbNode* removeChild(DtGdbNode *child); 00257 00258 // Applies the specified transform to the child terrain database. 00259 // If the database is not loaded, applies to the node's extent and 00260 // sets the member transform matrix. 00261 // Returns false if the transformation fails for any reason. 00262 virtual bool applyTransform(const DtHomogeneousTransfMatrix& matrix, 00263 bool createNewVertices); 00264 00265 virtual int sizeInBytes() const; 00266 00267 virtual void buildExtentTriangles(); 00268 00269 virtual DtGroup* extentTriangles(); 00270 00271 protected: 00272 // The child terrain object has just been created, register a 00273 // terrainModifiedCallback with it so we can pass any changes along to our 00274 // parent DtTerrainDatabase. 00275 virtual void registerChildTerrainCallbacks() const; 00276 00277 // The child terrain object is about to be unloaded, unregister the 00278 // terrainModifiedCallback. 00279 virtual void unRegisterChildTerrainCallbacks() const; 00280 00281 // Tell the parent terrain database that it was modified, either by being 00282 // loaded or by the child terrain being modified. 00283 virtual void terrainWasModified(DtTerrainDatabase* terrain, 00284 const DtExtent& changedVolume) const; 00285 00286 static void childTerrainModifiedCB(DtTerrainDatabase* terrain, 00287 const DtExtent& changedVolume, void* usrData); 00288 00289 virtual void buildExtentTriangle( const DtPoint& v0, const DtPoint& v1, const DtPoint& v2); 00290 00291 protected: 00292 DtTerrainDatabase* myParentTerrainDatabase; 00293 DtExtent myExtent; 00294 DtGroup* myAlternateRep; 00295 DtFilename myFilename; 00296 DtFilename myDirectory; 00297 DtTerrainDatabase* myTerrainDatabase; 00298 Coordinate_System* myCoordinateSystem; 00299 // Make this a group!!! 00300 DtGroup* myExtentTriangles; 00301 //typedef std::vector<DtTriangleIndirect*> DtExtentTriangles; 00302 //DtExtentTriangles myExtentTriangles; 00303 00304 // a homogeneous transform matrix that rotates, scales, and translates 00305 // the child terrain database when loaded. Applied to the extent upon 00306 // being set. 00307 DtHomogeneousTransfMatrix myHomogeneousTransformMatrix; 00308 // flag to be used in conjunction with the transformation matrix specifying 00309 // whether new vertices should be created or not. 00310 bool myCreateNewVertices; 00311 00312 bool myLoadFailed; 00313 // The following pointer is only used to temporarily hold a pointer to an 00314 // original database object from which the alternateRep was taken. 00315 DtTerrainDatabase* myAltTerrainDatabase; 00316 }; 00317 00318 #endif