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

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)