VR-Forces 4.1.1 Class Documentation
fileNode.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2004 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: fileNode.h,v $ $Revision: 1.19 $ $State: Exp $
7 *******************************************************************************/
8 #ifndef fileNode_H_
9 #define fileNode_H_
10 
11 // \file fileNode.h
12 // \brief Contains the DtFileNode class declaration.
13 
14 #include "gdb/gdbDefines.h"
15 #include <stdio.h>
16 
17 #include <vlutil/vlMachineTypes.h>
18 #include <vlutil/vlFilename.h>
19 #include <vector>
20 #include "geometry/tdbextent.h"
21 #include "gdb/gdbNode.h"
22 
23 
24 // Forward declarations
25 class DtGroup;
26 class DtTerrainDatabase;
27 class DtChordBundle;
28 class DtList;
29 class DtPoint;
30 class Coordinate_System;
31 class DtTriangleIndirect;
32 
33 
34 //
35 // Instances of DtFileNode represent a GDB database file nested within another
36 // GDB database file.
38 {
39 public:
40 
41  // default constructor
42  DtFileNode();
43 
44  // Extra constructor if not reading from a file. This is used so that we
45  // can save away the coordinate system and directory of the parent database
46  // for use when reading children later.
47  DtFileNode(DtTerrainDatabase* parentTerrainDatabase);
48 
49  // destructor
50  virtual ~DtFileNode();
51 
52  // copy constructor
53  DtFileNode(const DtFileNode& orig);
54 
55  // assignment operator
56  DtFileNode& operator=(const DtFileNode& orig);
57 
58  // returns the type of gdb node
59  virtual DtGdbNodeType type() const;
60 
61  // process the polygons included in the node that fall within the input
62  // extent, and update the color count in the colorCountRecord which is
63  // an in-out parameter.
64  virtual void countPolyColors(DtColorCountRecord& cr,
65  const DtExtent& e) const;
66 
67  // Return a pointer to the parent terrain database (0 if unknown)
68  virtual DtTerrainDatabase* parentTerrainDatabase() const;
69  // Set the pointer to the parent terrain database
70  virtual void setParentTerrainDatabase(DtTerrainDatabase* arg);
71 
72  // Returns the extent of the database (if loaded), or the alternate
73  // representation (if not loaded).
74  virtual DtExtent extent() const;
75 
76  // Forces the file node to compute or recompute the extent.
77  virtual void recomputeExtent();
78 
79  // if the terrain is loaded, it will transform it into the new coordinate system.
80  virtual bool transformCoordinateSystem(Coordinate_System* newCoordSys);
81 
82  virtual void setHomogeneousTransformMatrix(DtHomogeneousTransfMatrix transfMatrix);
83  virtual DtHomogeneousTransfMatrix homogeneousTransfMatrix() const;
84 
85  virtual void setCreateNewVertices(bool createNewVertices);
86  virtual bool createNewVertices() const;
87 
88  // redefine extent to include all components of the group
89  virtual void expandExtent(DtExtent& e) const;
90  virtual void setExtent(DtExtent& e);
91 
92  // Returns the child object, either the top terrain object or the alternate
93  // representation node.
94  virtual DtGdbNode* child() const;
95 
96  // Get alternative representation
97  virtual DtGroup* alternateRep() const;
98  // Set alternative representation
99  virtual void setAlternateRep(DtGroup* arg);
100  virtual void setAlternateRep(const DtGroup& arg);
101 
102  // Build an alternate representation from the given terrain
103  // NOTE: Uses the parent terrainDatabase to build the polygons representing
104  // the alternate representation. Parent terrainDatabase must be valid.
105  // This is necessary to prevent the polygons representing the terrain
106  // from being deleted when the terrain database from which this is created is
107  // destroyed.
108  virtual bool makeAlternateRepFromTerrain(const DtTerrainDatabase& terrain);
109  virtual bool makeAlternateRepFromTerrain(const DtGroup *gp);
110 
111  // Take the given terrain as the alternate representation, the top-level
112  // DtGdbNode is ripped out of the given terrain object and put in our
113  // group. The File node will take over ownership of the terrain database
114  // and will delete it when the file node is also destroyed.
115  virtual bool takeAlternateRepTerrain(DtTerrainDatabase* terrain);
116 
117  // Get filename
118  virtual const DtFilename& filename() const;
119  // Set filename
120  virtual void setFilename(const DtFilename& arg);
121 
122  // Get directory of parent database
123  virtual const DtFilename& directory() const;
124  // Set directory of parent database
125  virtual void setDirectory(const DtFilename& arg);
126 
127  // Get load failure flag
128  virtual bool loadFailed() const;
129  // Set load failure flag
130  virtual void setLoadFailed(bool arg);
131 
132  // Get terrain database (will be 0 if not yet loaded)
133  virtual const DtTerrainDatabase* terrainDatabase() const;
134  virtual DtTerrainDatabase* terrainDatabase();
135 
136  // Set terrain database (this also sets extents and filename)
137  virtual void setTerrainDatabase(DtTerrainDatabase* arg);
138 
139  // Get the coordinate system
140  virtual Coordinate_System* coordinateSystem() const;
141  // Set the coordinate system
142  virtual void setCoordinateSystem(Coordinate_System* arg);
143 
144  // Returns true iff the external terrain file has been loaded
145  bool terrainIsLoaded() const;
146 
147  // Load in the terrain file.
148  // If the member homogeneous transformation is not identity, this will
149  // apply the transform to the loaded child database and reset the member
150  // transform to identity (as it's been applied) and myCreateNewVertices
151  // to false.
152  // If the child coordinate system is different from the parent's coordinate system
153  // the child's will be converted if possible.
154  virtual bool loadTerrain() const;
155 
156  // Unload the terrain file.
157  virtual bool unloadTerrain() const;
158 
159  // Compute the intersection point of chord and the group. Note: this
160  // forces a load of the terrain file (if possible)
161  virtual bool intersect(const DtChord& chord,
162  DtPoint& intersectionPoint, double& t) const;
163 
164  // Computes the intersection of the terrain section represented by the
165  // group components and a chord. In addition to the intersection point and
166  // a parametric value, optionally computes and returns surface description
167  // for the intersecting surface, and normal. Identifies the lowest level
168  // intersecting polygon. This function will only replace the contents of
169  // the intersection record if it finds an intersection with a smaller
170  // intersectionTime value.
171  virtual bool intersect(const DtChord& chord,
172  DtChordIntersectionRecord& record, DtIntersectRecordType irtFlag) const;
173 
174  // Computes the list of all intersections of a chord with the terrain
175  // section represented by the group components. Adds to a list of
176  // DtChordIntersectionRecords sorted by distance along the chord. Returns
177  // false if no intersections exist.
178  virtual bool allIntersectsAlongChord(const DtChord& chord,
180  DtIntersectRecordType irtFlag) const;
181 
182  // Computes the intersection of terrain section represented by the terrain
183  // section represented by the group components and a bundle of chords. The
184  // returned record list is a a DtList of DtChordIntersectionRecords (one
185  // for each chord) each of which must be created and deleted by the caller.
186  // The irtFlag value specifies which data should be calculated and returned
187  // for each intersection point. The return value of this function is the
188  // number of the chords that had any intersections with the terrain. This
189  // function will only replace the contents of the intersection records if
190  // it finds an intersection with a smaller intersectionTime value.
191  virtual int intersectBundle(const DtChordBundle& chordBundle,
192  DtList& recordList, DtIntersectRecordType irtFlag) const;
193 
194  // Computes the list of all intersections of each of a bundle of chords
195  // with the terrain section represented by the group components. For each
196  // chord in the bundle, adds to a matching DtChordIntersectRecordList
197  // sorted by distance along the chord. The caller is responsible for
198  // creating and deleting the DtChordIntersectRecordLists in the intListList
199  // DtList. The return value of this function is the number of the chords
200  // that had any intersections with the terrain. Note that passing an
201  // irtFlag value of IRT_NO_DATA will probably never return more than one
202  // intersection per chord.
203  virtual int allIntersectsAlongChordBundle(const DtChordBundle& chordBundle,
204  DtList& intListList, DtIntersectRecordType irtFlag) const;
205 
206  // Reduce the group object to eliminate redundant nodes.
207  virtual DtGdbNode* reduce(int& numReductions);
208 
209  // check the object to ensure it is valid.
210  virtual bool sanityCheck() const;
211 
212  // Prints out the contents of the object.
213  virtual void dump(int indentLevel) const;
214 
215  // Finds all instances of node type searchType in the tree including and
216  // below this node in it's alternate representation.
217  // Does NOT look in the child terrain database.
218  virtual void allInstancesOf(const DtGdbNodeType searchType,
219  DtFoundInstancesContainer& foundInstances,
220  bool recurseIntoCoordSysNodes = false);
221 
222  virtual void allInstancesOf(const DtGdbNodeType searchType,
223  DtFoundInstancesConstContainer& foundInstances,
224  bool recurseIntoCoordSysNodes = false) const;
225 
226  virtual void allInstancesOf(const DtGdbNodeType searchType,
227  DtFoundInstancesContainer& foundInstances, bool recurseIntoCoordSysNodes,
228  DtGdbNodeEvaluationFunctor& functor);
229 
230  virtual void allInstancesOf(const DtGdbNodeType searchType,
231  DtFoundInstancesConstContainer& foundInstances,
232  bool recurseIntoCoordSysNodes, DtGdbNodeEvaluationFunctor& functor) const;
233 
234 
235  // Return the minimum terrain file version number that this Node can be
236  // saved in.
238 
239  // Finds and removes all instances of every node type in the tree below
240  // this node; deletes the nodes if they are not memory managed. It returns
241  // this.
242  virtual DtGdbNode* purgeAll();
243 
244  // Load in all external DtFileNode files. Returns the number of databases
245  // that were just loaded.
246  virtual unsigned int loadAllExternalFiles() const;
247 
248  // Unload all external DtFileNode files. Returns the number of databases
249  // that were unloaded.
250  virtual unsigned int unloadAllExternalFiles() const;
251 
252  // Find the parent (if it exists of child in the tree under the node)
253  virtual DtGdbNode* parent(DtGdbNode *child);
254 
255  // remove the child (if it is) from this node
256  virtual DtGdbNode* removeChild(DtGdbNode *child);
257 
258  // Applies the specified transform to the child terrain database.
259  // If the database is not loaded, applies to the node's extent and
260  // sets the member transform matrix.
261  // Returns false if the transformation fails for any reason.
262  virtual bool applyTransform(const DtHomogeneousTransfMatrix& matrix,
263  bool createNewVertices);
264 
265 virtual int sizeInBytes() const;
266 
267  virtual void buildExtentTriangles();
268 
269  virtual DtGroup* extentTriangles();
270 
271 protected:
272  // The child terrain object has just been created, register a
273  // terrainModifiedCallback with it so we can pass any changes along to our
274  // parent DtTerrainDatabase.
275  virtual void registerChildTerrainCallbacks() const;
276 
277  // The child terrain object is about to be unloaded, unregister the
278  // terrainModifiedCallback.
279  virtual void unRegisterChildTerrainCallbacks() const;
280 
281  // Tell the parent terrain database that it was modified, either by being
282  // loaded or by the child terrain being modified.
283  virtual void terrainWasModified(DtTerrainDatabase* terrain,
284  const DtExtent& changedVolume) const;
285 
286  static void childTerrainModifiedCB(DtTerrainDatabase* terrain,
287  const DtExtent& changedVolume, void* usrData);
288 
289  virtual void buildExtentTriangle( const DtPoint& v0, const DtPoint& v1, const DtPoint& v2);
290 
291 protected:
295  DtFilename myFilename;
296  DtFilename myDirectory;
299  // Make this a group!!!
301  //typedef std::vector<DtTriangleIndirect*> DtExtentTriangles;
302  //DtExtentTriangles myExtentTriangles;
303 
304  // a homogeneous transform matrix that rotates, scales, and translates
305  // the child terrain database when loaded. Applied to the extent upon
306  // being set.
308  // flag to be used in conjunction with the transformation matrix specifying
309  // whether new vertices should be created or not.
311 
313  // The following pointer is only used to temporarily hold a pointer to an
314  // original database object from which the alternateRep was taken.
316 };
317 
318 #endif

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)