VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
terrainDatabase.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2003 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: terrainDb.h,v $ $Revision: 1.87 $ $State: Exp $
7 *******************************************************************************/
8 #ifndef terrainDatabase_H_
9 #define terrainDatabase_H_
10 
11 //
12 // \file terrainDb.h
13 // \brief Contains the DtTerrainDatabase class declarationn, as well as the DtTerrainFileVersionNumber and other related declarations and definitions.
14 //
15 
16 #include "gdb/gdbDefines.h"
17 #include "gdb/gdbNode.h"
18 #include "gdb/fileNode.h"
19 #include "tdbutil/serializable.h"
20 #include "terrainCS/coordSystem.h"
22 #include "gdb/surfaceManager.h"
24 #include "gdb/vertexManager.h"
26 #include "geometry/surface.h"
27 #include <vlutil/vlFilename.h>
28 #include <vlutil/vlConfig.h>
29 #include <vector>
30 #include <assert.h>
31 
32 class DtList;
33 class DtPoint;
34 class DtExtent;
35 class DtChord;
36 class DtChordBundle;
39 class DtColor;
40 class DtMemoryManager;
42 class DtAllTypesPolygon;
43 class DtGroup;
47 class DtPolygonIndirect;
48 class DtTriangleIndirect;
49 class DtVectorNetwork;
51 class DtPlane;
54 
56 {
59 };
60 
62 {
65 };
66 
67 // Terrain database file version number:
68 // 100: initial version
69 // 201: DtFileNodes added
70 // 202: Spatial indexes and optional data flags added
71 // 203: Vector network added
72 // 204: Reorganization of data - forced new format
73 // 205: Refactored vector data format completely.
74 // 206: Changed from using spatial index to using spatial subdivision.
75 // 207: Added map datum to coordinate system node and scale factor to utm node
76 // 209: Removed spatial subdivision. It now works with opcode. It only stores triangles.
77 // 210: Added back in spatial subdivision and added new terrain intersection method integer
79 
80 // Optional data flags
81 // These are bitfield values (they must be a power of 2). Only add new values
82 // on the end of the list, regardless of what order they are written in!
83 typedef enum
84 {
85  OPT_FEATURES = 0x00000001,
89 
91 
92 // A mask of the currently defined optional data bitfield values
94 
95 //
96 // These callback function types are defined so this library
97 // doesn't have to know about the GUI system but can still call
98 // GUI functions which update a ProgressMeterDialogBoxClass
99 //
100 // The calling GUI code does this:
101 //
102 // static ProgressMeterDialogBoxClass *p = 0;
103 // static wxFrame *me = 0;
104 // void prog_start_fcn(char *label, int range) { p = new ProgressMeterDialogBoxClass(me, "label", range); }
105 // void prog_incremental_fcn(int increment) { p->DidSomeMore(increment); }
106 // void prog_set_value_fcn(int value) { p->SetValue(value); }
107 // void prog_end_fcn(void) { delete(p); }
108 //
109 //
110 // The called, time-intensive tdb functions call these like:
111 //
112 // void load_db(progressCallbackStartFunction *prog_start_fcnp,
113 // progressCallbackSetValueFunction *prog_set_value_fcnp,
114 // progressCallbackIncrementalProgressFunction *prog_incremental_fcnp,
115 // progressCallbackEndFunction *prog_end_fcnp)
116 // {
117 // (*prog_start_fcnp)("Loading database", 10000);
118 //
119 // for (int i=0; i<10000; i++)
120 // {
121 // (*prog_set_value_fcnp)(i); // This, or...
122 // (*prog_incremental_fcnp)(1); // this.
123 // }
124 // (*prog_end_fcnp)();
125 // }
126 //
127 // Or, if you can live with the restrictions, inherit CanPopUpProgressMeter
128 // class.
129 //
130 
131 typedef void progressCallbackStartFunction(const char* label, int range);
132 typedef void progressCallbackSetValueFunction(int value);
136 
137 // class DtTerrainDatabase:
138 //
139 // DtTerrainDatabase represents an entire database in GDB format. It
140 // represents the terrain skin, geometrical features over the skin and a
141 // vector network. The database can be written out to, and read from, a file.
142 
143 
144 //
145 // DtTerrainDatabase represents an entire database in GDB format. It
146 // represents the terrain skin, geometrical features over the skin and a
147 // vector network. The database can be written out to, and read from, a file.
149 {
150 public:
151  // default constructor
153 
154  // destructor
155  virtual ~DtTerrainDatabase();
156 
157 private:
158  // copy constructor - unimplemented
160 
161  // assignment operator - unimplemented
162  DtTerrainDatabase& operator=(const DtTerrainDatabase& orig);
163 
164 public:
165 
166  // Initialization function - must be called before ANY other member
167  // function.
168  // Override this to function to add new member data types in derived
169  // terrain databases.
170  virtual bool init();
171 
172  // Sets the terrain intersector to be used for the terrain. Pass a filled
173  // out descriptor for the intersector that is desired. If you want the intersector
174  // to be used after making this call, make initIntersector call right after()
175  virtual bool setIntersector(const DtTerrainIntersectorDescriptor* intersectorDescriptor);
176 
177  // Sets the terrain intersector directly. Usually, you should use the
178  // setIntersector() call, and use the descriptor, but if you want to set
179  // a custom intersector class, it can be done with this call.
180  // \note DtTerrainDatabase takes ownership of this pointer, and will delete
181  // the intersector when done with it.
182  virtual bool setIntersectorManually(DtTerrainIntersector* intersector);
183 
184  // \return A pointer to a intersector descriptor that the DtTerrainDatabase
185  // determines to be the best for the current terrain.
186  // \note The caller is responsible for deleting this descriptor.
187  // \note This does not this this intersector to the terrain. Call setIntersector()
188  // with the return value of this method to change the intersector.
189  virtual DtTerrainIntersectorDescriptor* autoChooseIntersector() const;
190 
191  // Initializes the terrain polygon intersector.
192  // This <b>must</b> be called after all the polygons are added to the
193  // terrain and before the terrain is used for intersection calls.
194  virtual bool initIntersector();
195 
196  // File name associated with database.
197  virtual const DtFilename& fileName() const;
198  virtual void setFileName(const DtFilename& arg);
199 
200  // \return the type of file this database was loaded from.
201  // For example, if this terrainDatabase was loaded from a
202  // .gdb file, it will return "gdb". If it was loaded from a
203  // shape file, it will return "shape".
204  virtual DtString dataType() const;
205  virtual void setDataType(const DtString& newDataType);
206 
207  // \return the version number of the file from which
208  // this database was loaded. For example, if it was loaded
209  // from a gdb file from version 203 it would return 203.
210  // Only non-zero if applicable.
211  virtual unsigned int versionNumber() const;
212  virtual void setVersionNumber(unsigned int versionNumber);
213 
214 
215  //-------------------------------------------------------
216  // Coordinate system
217  //-------------------------------------------------------
218 
219  // Coordinate system type of the database.
220  virtual CS_Type coordinateSystemType() const;
221 
222  // Coordinate system associated with the database.
223  virtual Coordinate_System* coordinateSystem();
224  virtual const Coordinate_System* coordinateSystem() const;
225 
226  // Sets both the coordinate system and coordinate system type
227  // of the database.
228  virtual void setCoordinateSystem(Coordinate_System* coordSys);
229 
230  // Change the coordinate system from the current coordinate system
231  // to the one specified. Will transform all appropriate elements
232  // of the terrain database, including all geometry, into the new CS.
233  // Requires that the terrainDatabase currently have a coordinate system.
234  // and that the terrain be loaded.
235  //
236  // If allowReflect is true, allows the coordinate system to be translated to the
237  // same coordinate system. This can be used to project a database to a new location
238  // If transformVectorNetwork is true, also attempts to transform vector network, if
239  // possible (not all transformations are allowed).
240  virtual bool transformCoordinateSystem(Coordinate_System* newCoordSys, bool allowReflect = false,
241  DtVectorNetworkTransformFlag transformVectorNetwork = TransformYes);
242 
243  // Applies the specified transform to the terrain database.
244  // \return false if the transformation fails for any reason.
245  // A side affect of performing the transformation is that all coordinate
246  // system nodes in the terrain will be applied to their children and
247  // removed. May result in a much larger GDB as new vertices will be created
248  // for previously shared vertices.
249  virtual bool applyTransform(const DtHomogeneousTransformMatrix& matrix,
250  bool createNewVertices);
251 
252  //-------------------------------------------------------
253  // Creating and accessing nodes and features
254  //-------------------------------------------------------
255  // \return a pointer to the group node that encompasses all of
256  // the terrain skin.
257  virtual DtGroup* terrain();
258  virtual const DtGroup* terrain() const;
259  virtual bool setTerrain(DtGroup* newTerrain);
260 
261  // \return a pointer to the group node that encompasses all of
262  // the terrain features.
263  virtual DtGroup* features();
264  virtual const DtGroup* features() const;
265  virtual bool setFeatures(DtGroup* newFeatures);
266 
267  // get the number of features in the terrain database.
268  virtual int featureCount() const;
269 
270  virtual DtVertexManager* vertexManager();
271  virtual const DtVertexManager* vertexManager() const;
272 
273  virtual DtSurfaceManager* surfaceManager();
274  virtual const DtSurfaceManager* surfaceManager() const;
275 
276  virtual DtVectorNetwork* vectorNetwork();
277  virtual const DtVectorNetwork* vectorNetwork() const;
278  virtual void setVectorNetwork(DtVectorNetwork* newVectorNetwork);
279 
280  // Create nodes based on the type. Types are defined in gdbNode.h. The
281  // terrain database will allocate memory using its memory manager for
282  // efficiency.
283  // Use of this function is highly discouraged in favor of the direct node
284  // creation functions provided below.
285  virtual DtGdbNode* newNode(DtGdbNode::DtGdbNodeType type);
286 
288  // Create particular node types.
290 
291  // Asks the TerrainDatabase to create a new instance of a polygon node
292  // with the specified vertices, surface and parent. If the parent is
293  // not specified, then it adds the new polygon as a child to the root
294  // terrain group node.
295  // If addToStart is specified, it adds the child to the start of
296  // the parent (or terrain) node.
297  virtual bool createPolygon(const std::vector<DtVertex>& vertices,
298  DtSurface& surface,
299  DtGroup* const parent = 0,
300  bool addToStart = false);
301 
302  // Asks the TerrainDatabase to create a new instance of a polygon node
303  // with the specified vertexIDs, surfaceID and parent. If the parent is
304  // not specified, then it adds the new polygon as a child to the root
305  // terrain group node.
306  // If addToStart is specified, it adds the child to the start of
307  // the parent (or terrain) node.
308  virtual bool createPolygon(const std::vector<DtVertexID>& vertexIDList,
309  DtSurfaceID surfID,
310  DtGroup* const parent = 0,
311  bool addToStart = false);
312 
313  // Asks the TerrainDatabase to create a new instance of a triangle node
314  // with the specified vertices, surface and parent. If the parent is
315  // not specified, then it adds the new group as a child to the root
316  // terrain group node.
317  // If addToStart is specified, it adds the child to the start of
318  // the parent (or terrain) node.
319  virtual DtTriangleIndirect* createTriangle(const DtPoint& vert1,
320  const DtPoint& vert2,
321  const DtPoint& vert3,
322  const DtSurface& surface,
323  DtGroup* const parent = 0,
324  bool addToStart = false);
325 
326  // Asks the TerrainDatabase to create a new instance of a triangle node
327  // with the specified vertex IDs, surface ID and parent. If the parent is
328  // not specified, then it adds the new group as a child to the root
329  // terrain group node.
330  // If addToStart is specified, it adds the child to the start of
331  // the parent (or terrain) node.
332  virtual DtTriangleIndirect* createTriangle(const int vert0ID,
333  const int vert1ID,
334  const int vert2ID,
335  const DtSurfaceID surfID,
336  DtGroup* const parent = 0,
337  bool addToStart = false);
338 
339  // If the parent is specified, then it adds the new group as a child to
340  // that parent group. Otherwise, it just adds it to the top level terrain.
341  virtual DtGroup* createGroup(DtGroup* parent = 0) const;
342 
343  // Add/remove nodes from a terrain database. Note that the DtTerrainDatabase
344  // will assume responsibility for deleting the memory associated with nodes
345  // added to the database (regardless of whether or not the memory was allocated
346  // in the client by calling new or by call DtTerrainDatabase::newNode()).
347  virtual bool addNode(DtGdbNode *node, DtGroup *parent);
348  virtual bool addNodeToStart(DtGdbNode *node, DtGroup *parent);
349 
350  virtual bool addTerrainNode(DtGdbNode *node, DtGroup *parent = 0);
351  virtual bool addTerrainNodeToStart(DtGdbNode *node, DtGroup *parent = 0);
352  virtual bool removeTerrainNode(DtGdbNode *node, DtGdbNode *parent = 0);
353 
354  virtual bool addFeatureNode(DtGdbNode *node, DtGroup *parent = 0);
355  virtual bool addFeatureNodeToStart(DtGdbNode *node, DtGroup *parent = 0);
356  virtual bool removeFeatureNode(DtGdbNode *node, DtGdbNode *parent = 0);
357 
358  //-------------------------------------------------------
359  // Database extent
360  //-------------------------------------------------------
361 
362  // Forces the entire terrain database to recompute extents. This includes all
363  // child nodes (groups, etc).
364  virtual void recomputeExtent() const;
365 
366  // \return the extent of the database.
367  virtual void getExtent(DtExtent& extent) const;
368 
369 
370  //-------------------------------------------------------
371  // VectorNetwork Operations
372  //-------------------------------------------------------
373  virtual bool planarizeVectorNetwork(DtReal tolerance, unsigned int excessiveEdgeCount);
374 
375  // Clips the vector network to the specified extent.
376  virtual bool clipVectorNetwork(const DtPoint& southWestPoint,
377  const DtPoint& northEastPoint);
378 
379  // Clips the vector network to the correct extent of the terrain data
380  virtual bool clipVectorNetwork();
381 
382  // Get and set the vector network tool.
383  // Allows the user to create their own derived vectorNetworkTool
384  // and have the TerrainDatabase use it.
385  // @note Deletes any existing vector network tool.
386  virtual const DtVectorNetworkTool* vectorNetworkTool() const;
387  virtual DtVectorNetworkTool* vectorNetworkTool();
388  virtual void setVectorNetworkTool(DtVectorNetworkTool* vectorNetworkTool);
389 
390 
391  //-------------------------------------------------------
392  // Intersection routines
393  //-------------------------------------------------------
394 
395  // Functions for finding the height of the terrain at a specified location.
396  // Takes a location, in either local (DB) coordinates
397  // or a latitude and longitude, and the returns the altitude of the
398  // terrain at the specified location if possible. If no intersection
399  // with terrain was found at the specified location, 0 is returned.
400  //
401  // \note
402  // 1 - These functions *only* intersect terrain polygons - no
403  // feature data.
404  //
405  // 2 - The intersection is defined to be the topmost intersection with
406  // the terrain. Thus if there are multiple levels of terrain polygons,
407  // the highest intersection will be returned as the height.
408  virtual double terrainHeight(const DtPoint& localLocation) const;
409  virtual double terrainHeight(const DtVector& localLocation) const;
410  virtual double terrainHeight(double lat, double lon) const;
411 
412  // Similar to above functions, but return a boolean signifying whether or
413  // not an intersection with the terrain was found or not. If not,
414  // the height is set to 0 and false is returned. If so, true is returned
415  // and the height parameter is set to the height of the terrain.
416  virtual bool terrainHeight(const DtPoint& localLocation, double& height) const;
417  virtual bool terrainHeight(const DtVector& localLocation, double& height) const;
418  virtual bool terrainHeight(double lat, double lon, double& height) const;
419 
420  // Functions for determining the height of the terrain at a specified location,
421  // AND the soil type of the terrain polygon intersected at that location.
422  //
423  // Return Values:
424  // These functions return true if an intersection occurred, If so, they also set the
425  // height to be the height of the intersection point and the soilType to be the
426  // soilType associated with the intersected polygon.
427  //
428  // They return false if no intersection occurred. If so, they also set the height
429  // to 0 and the soilType to "DtSurface::undefinedSoilType"
430  //
431  // \note
432  // 1 - These functions to NOT intersect vector or geometric feature data - they are
433  // intended for finding the "ground" height.
434  // 2 - These functions determine the *topmost* intersection with the terrain. Thus
435  // if there are multiple levels of terrain, the highest intersection point will
436  // be returned as the height.
437  // In order to get the closest intersection points with terrain (and possibly features
438  // data, use the closestIntersection() functions below.
439  virtual bool terrainHeightAndSoilType(const DtVector& localLocation, double& height, DtSoilType& soilType) const;
440  virtual bool terrainHeightAndSoilType(double lat, double lon, double& height, DtSoilType& soilType) const;
441 
442  // Functions for determining the height of the terrain at a specified location,
443  // AND additional data from the intersection with terrain polygon intersected at that location.
444  //
445  // Return Values:
446  // These functions return true if an intersection occurred, If so, they also set the
447  // height to be the height of the intersection point and the intersection record
448  // to the data returned from the intersection with the terrain at that point.
449  //
450  // They return false if no intersection occurred. If so, they also set the height
451  // to 0 and the soilType to "DtSurface::undefinedSoilType"
452  //
453  // @note
454  // 1 - These functions to NOT intersect vector or geometric feature data - they are
455  // intended for finding the "ground" height.
456  // 2 - These functions determine the *topmost* intersection with the terrain. Thus
457  // if there are multiple levels of terrain, the highest intersection point will
458  // be returned as the height.
459  // In order to get the closest intersection points with terrain (and possibly features
460  // data, use the closestIntersection() functions below.
461  // 3 - The amount of data returned in the intersection record will be determined by the
462  // Intersection Record Type flag that is passed into the call.
463  virtual bool terrainHeightAndIntersection(const DtVector& localLocation, double& height,
466 
467  // Similar to the terrainHeight functions above.
468  // Function to determine the closest intersection to a specified location,
469  // either in local (DB) coordinates or in lat/lon. The closest intersection
470  // is defined as the closest intersection in the down or up direction from
471  // location. Thus if there are multiple terrain levels, it will not necessarily
472  // return an intersection with the topmost as the terrainHeight functions do.
473  //
474  // \note Unlike the terrainHeight functions, if the vectorNetworkRecord and
475  // vectorNetworkIntersectionRecord are non-NULL, it will computes an
476  // intersection with the vector network and return the best intersection as
477  // defined by the metrics in the vectorNetworkRecord.
478  //
479  // Return Values:
480  // True if any intersection, vector data or terrain, is found.
481  // If a vector data intersection is found, then the vecNetworkIntersectionRecord
482  // is set appropriately.
483  // If at least one terrain intersection is found, the intersectionPoint
484  // parameter is set to the *closest* intersection point.
485  //
486  // \return A boolean indication whether or not an intersection has been found.
487  //
488  virtual bool closestIntersection(const DtVector& localLocation,
489  DtPoint& intersectionPoint,
490  DtVectorNetworkRecord* vectorNetworkRecord = 0,
491  DtVectorNetworkIntersectionRecord* vecNetworkIntersectionRecord = 0) const;
492 
493  // Same as above function, but accepts location in lat/lon.
494  virtual bool closestIntersection(double lat,
495  double lon,
496  DtPoint& intersectionPoint,
497  DtVectorNetworkRecord* vectorNetworkRecord = 0,
498  DtVectorNetworkIntersectionRecord* vecNetworkIntersectionRecord = 0) const;
499 
500  // Same as above function, but returns the entire intersection record,
501  // and not just the intersection point.
502  virtual bool closestIntersection(const DtVector& localLocation,
505  DtVectorNetworkRecord* vectorDatarecord = 0,
506  DtVectorNetworkIntersectionRecord* vectorIntersectionRecord = 0) const;
507 
508  // Same as above function, but accepts location in lat/lon.
509  virtual bool closestIntersection(double lat,
510  double lon,
513  DtVectorNetworkRecord* vectorDatarecord = 0,
514  DtVectorNetworkIntersectionRecord* vectorIntersectionRecord = 0) const;
515 
516  virtual bool closestIntersection(const DtList& localLocationList,
517  DtList& recordList,
518  int& numIntersections,
520  DtVectorNetworkRecord *vectorDatarecord = 0,
521  DtList *vectorList = 0) const;
522 
523  // Calculates the first terrain intersection point along a chord given in
524  // Database Coordinates.
525  virtual bool intersect(
526  const DtChord& chord,
527  DtPoint& intersectionPoint,
528  double& intersectionTime,
529  DtVectorNetworkRecord *record = 0,
530  DtVectorNetworkIntersectionRecord *intersectionRecord = 0) const;
531 
532  // Returns complete intersection information about the first terrain
533  // intersection point along a chord given in Database Coordinates.
534  // The irtFlag value specifies which data should be calculated and returned
535  // for each intersection point.
536  virtual bool intersect(
537  const DtChord& chord,
540  DtVectorNetworkRecord *vectorDatarecord = 0,
541  DtVectorNetworkIntersectionRecord *vectorIntersectionRecord = 0) const;
542 
543  // \return True if the specified sphere intersects with any terrain polygons.
544  // If irtFlag is IRT_IPOLYGON or higher, a list of all the intersected
545  // polygons is returned inside the record.
546  virtual bool intersect(const DtSphere& sphere,
549 
550  // Computes the list of all intersections of a chord (in Database
551  // Coordinates) with the terrain database. Returns a list of
552  // DtChordIntersectionRecords. Returns false if no intersections exist.
553  // The irtFlag value specifies which data should be calculated and returned
554  // for each intersection point.
555  // Note that passing an irtFlag value of IRT_NO_DATA will probably never
556  // return more than one intersection.
557  virtual bool allIntersectsAlongChord(
558  const DtChord& chord,
561  DtVectorNetworkRecord *vectorDatarecord = 0,
562  DtList *vectorList = 0) const;
563 
564  // Returns complete intersection information about the first terrain
565  // intersection points along each of a list of DtChords given in Database
566  // Coordinates. The returned record list is a DtList of
567  // DtChordIntersectionRecords (one for each chord) each of which must be
568  // created and deleted by the caller. The irtFlag value specifies which
569  // data should be calculated and returned for each intersection point.
570  //
571  // numTerrainIntersections and numVectorNetworkIntersections are set to the
572  // numbers of chords that intersected each respectively.
573  //
574  // Returns true if any chord intersected the terrain (or vector network if specified).
575  // Returns false otherwise.
576  //
577  virtual bool intersectList(
578  const DtList& chordList,
579  DtList& recordList,
580  int& numTerrainIntersections,
581  int& numVectorNetworkIntersections,
583  DtVectorNetworkRecord *vectorDatarecord = 0,
584  DtList *vectorList = 0) const;
585 
586  // Computes the list of all intersections of each of a list of chords (in
587  // Database Coordinates) with the terrain database. Returns data in a
588  // DtList of DtChordIntersectionRecordLists, which the caller is
589  // responsible for creating and deleting.
590  //
591  // Parameters:
592  // numTerrainIntersections and numVectorNetworkIntersections are set to the
593  // numbers of chords that intersected each respectively.
594  // irtFlag - specifies which data should be calculated and returned
595  // for each intersection point.
596  //
597  // \note passing an irtFlag value of IRT_NO_DATA will probably never return
598  // more than one intersection per chord.
599  //
600  // Returns true if any chord intersected the terrain (or vector network if specified).
601  // Returns false otherwise.
602  virtual bool allIntersectsAlongChordList(
603  const DtList& chordList,
604  DtList& intListList,
605  int& numTerrainIntersections,
606  int& numVectorNetworkIntersections,
608  DtVectorNetworkRecord *vectorDatarecord = 0,
609  DtList *vectorListList = 0) const;
610 
611 
613  // Vector Network Intersection Functions
615  //
616  // The following functions all intersect a chord, location,
617  // or list thereof with the vector network.
618  // The functions all:
619  // Return true if intersection(s) occurred.
620  // Return false otherwise, including when no vector data exists
621  // or if input parameters are 0
622  //
623  //
624  // Common parameters:
625  // irtFlag - All of these functions specify a flag that determines what
626  // data is requested by the intersection call. This flag specifies
627  // the type and amount of data returned.
628  // vectorRecord - the vectorRecord specifies such things as the metric(s)
629  // to use and the interest range in searching the vector data.
630  // vectorIntersectionRecord - either a single record or list of records,
631  // these hold the returned vector intersection records.
632  // When more than one is returned, they are sorted in
633  // relevance/closeness order.
634  // For example: a bridge is more relevant than a river under it.
635  //
636  // \note The user is responsible for allocating and deallocating the
637  // vectorNetworkRecord and vector intersection records.
638  // \note The vectorIntersectionRecords (or lists thereof) must be
639  // initialized properly if they are going to be reused.
640  virtual bool intersectVectorNetwork(
641  const DtChord& chord,
643  DtVectorNetworkRecord* vectorRecord,
644  DtVectorNetworkIntersectionRecord* vectorIntersectionRecord) const;
645 
646  // Parameters:
647  // vectorList - DtList of the DtVectorNetworkIntersectionRecords
648  // for the chord.
649  // \note The user is responsible for deleting the DtList and
650  // all associated items.
651  virtual bool intersectVectorNetwork(
652  const DtChord& chord,
654  DtVectorNetworkRecord* vectorRecord,
655  DtList* vectorList) const;
656 
657  //
658  // \param vectorList DtList of the best (as defined above)
659  // DtVectorNetworkIntersectionRecord
660  // for each chord in the list.
661  // \note The user is responsible for deleting the DtList and
662  // all associated items.
663  virtual bool intersectChordsWithVectorNetwork(
664  const DtList& chordList,
666  DtVectorNetworkRecord* vectorRecord,
667  DtList* vectorList) const;
668 
669  // Intersections a list of local (DB) locations with the vector network.
670  // The single best intersections, not a list, per location are put in the
671  // list of vector network intersection records.
672  //
673  // \note The user is responsible for deleting the list of
674  // DtVectorNetworkIntersectionRecords (and the records too).
675  virtual bool intersectLocationsOnVectorNetwork(
676  const DtList& localLocationList,
678  DtVectorNetworkRecord* vectorRecord,
679  DtList* vectorList) const;
680 
681  // Intersects a list of chords with the vector network.
682  // Parameters:
683  // vectorListList - list of DtVectorNetworkIntersectionRecordLists which
684  // will contain all the DtVectorNetworkIntersectionRecordLists
685  // associated with each chord. If the actual recordList is
686  // empty, then that chord intersected nothing.
687  // \note The user is responsible for allocating and deallocating the list of
688  // DtVectorNetworkIntersectionRecordsLists.
689  virtual bool allIntersectionsWithVectorNetworkAlongChordList(
690  const DtList& chordList,
692  DtVectorNetworkRecord* record,
693  DtList* vectorListList) const;
694 
695 
696  //-------------------------------------------------------
697  // Post-processing
698  //-------------------------------------------------------
699  virtual void reduce();
700 
701  // Eliminates duplicate vertices in all polygons and triangles in the
702  // terrain database.
703  // This should save memory if many vertices are shared among polygons
704  // and/or triangles, but may take a while to process.
705  virtual void eliminateDuplicateVertices(const double tol);
706 
707  // Eliminates duplicate surfaces in the terrain database.
708  virtual void eliminateDuplicateSurfaces(void);
709 
710  // Converts all three-sided polygons nodes to triangle nodes
711  //
712  // \note Does NOT triangulate polygons with more than 3 sides.
713  virtual void polygonNodesToTriangleNodes();
714 
715  // Attempts to balance the terrain node (tree structure of DtGdbNodes)
716  // according to the branching and leafing parameters specified.
717  //
718  // \note Balancing the tree is an extremely computationally expensive
719  // operation for all but the simplest terrains. Use with caution.
720  //
721  // KNOWN ISSUE: balancing the terrain *will* reorder the nodes in the
722  // tree, thus potentially causing drawing issues.
723  virtual void balanceTerrain(unsigned int branching,
724  unsigned int bushiness);
725 
726  // Returns the type of intersection model being used. Calls down to intersection model pointer
727  // to return type
728  virtual int terrainIntersectorType() const;
729 
730  //-------------------------------------------------------
731  // Miscellaneous
732  //-------------------------------------------------------
733 
734  // Try to figure out what most common terrain skin poly color is so we
735  // can clear to it.
736  virtual DtColor mostCommonTerrainSkinColorWithin(const DtExtent& e) const;
737 
738 
739  // Creates two terrain triangles formed from the specified extent. The
740  // altitude of the vertices is determined by the altitude of the left, back,
741  // bottom vertex and the right, front, upper vertex. These are used as the
742  // SW and NE vertices respectively. The altitude of the SE vertex matches
743  // the altitude of the SW vertex and the altitude of the NW vertex equals the
744  // altitude of the NE vertex.
745  //
746  // (NW) *----------* (NE)
747  // |\ |
748  // | \ |
749  // | \ |
750  // | \ |
751  // | \ |
752  // | \ |
753  // | \ |
754  // | \ |
755  // | \ |
756  // | \|
757  // (SW) *----------* (SE)
758  //
759  virtual bool setFromExtent(const DtExtent& e);
760 
762  virtual bool groundClamp(DtPoint& databaseCoord, float const offset = 0) const;
763 
764  // Terrain Modified callback registration.
765  virtual void addTerrainModifiedCallback(
766  DtTerrainModifiedCallbackFunction cb, void* userData);
767 
768  // Terrain Modified callback cancellation.
769  virtual void removeTerrainModifiedCallback(
770  DtTerrainModifiedCallbackFunction cb, void* userData);
771 
772  // Notify the terrain object (and any registered callbacks) that the
773  // terrain database has just changed somewhere.
774  virtual void terrainWasModified(const DtExtent& changedVolume);
775 
776  // \return a pointer to a memory manager class that handles
777  // allocations of a group of objects (polygons, groups, grids,
778  // features, etc.)
779  virtual DtMemoryManager* memoryMgr() const;
780 
782  // transforms to all nodes under them.
783  virtual bool collapseNodeTree();
784 
785  // Prints in the output console/log file (as verbose) the amount
786  // of memory being used by this object
787  virtual void printMemoryUsage(DtMemoryUsageDetails details=ShowDetails) const;
788 
789  virtual int sizeInBytes() const;
790 
792  virtual DtVertex highestPoint();
793 
795  virtual DtVertex lowestPoint();
796 
798  virtual int totalOfPolygons() const;
799 
804  virtual int loadExternalReferences(int level=1);
805 
807  DtTerrainIntersector* terrainIntersector() const;
808 
810  DtTerrainIntersector* terrainIntersector();
811 
812  void setOptionalDataFlag(DtTerrainFileOptionalData, bool onOff);
813  int optionalDataFlags() const;
814 
815  // While reading a GDB file, reports whether this database will contain
816  // optional data
817  bool fileHasOptionalData(DtTerrainFileOptionalData optData) const;
818 
819 public:
820 
821  // \return a newly created instance of a DtTerrainDatabase.
822  static DtTerrainDatabase* create();
823 
824 protected:
825 
826  bool calculateExtremePoints();
827 
828  bool testInvariant() const;
829 
830  // Process the modified callbacks
831  virtual void processTerrainModifiedCallbacks(const DtExtent& changedVolume);
832 
833  // Remaps the vertex and surface IDs for all nodes below the current node.
834  // Assumes that both parameters are non-null and valid.
835  virtual bool remapVertexIDs(DtGdbNode* currentNode, DtVertexID* oldIDToNewIDMap);
836  virtual bool remapSurfaceIDs(DtGdbNode* currentNode, DtSurfaceID* oldIDToNewIDMap);
837 
838  // Transform all appropriate parts of the terrain database from/to the
839  // specified coordinate system.
840  // Requires that the coordinate system be set as specified
841  // in the function title.
842  virtual bool xformCoordinateSystemTo(Coordinate_System* coordSys, DtVectorNetworkTransformFlag transformVectorNetwork);
843 
844  // Should only be used when re-projecting withing the same database to a different zone
845  virtual bool xformUTMtoUTM(Coordinate_System* coordSys, DtVectorNetworkTransformFlag transformVectorNetwork);
846 
847  virtual void xformVectorNetwork(Coordinate_System* newCoordSys, locationConversionFunction conversionFcn, const DtVector* offset=0);
848  virtual void xformVertexManager(Coordinate_System* newCoordSys, locationConversionFunction conversionFcn, const DtVector* offset=0);
849  virtual void xformTreeNodes(Coordinate_System* newCoordSys, locationConversionFunction conversionFcn, const DtVector* offset=0);
850 
851 protected:
852  DtFilename myFileName;
853 
854  // a group node encompassing all of the nodes that
855  // constitute the terrain skin.
858 
861 
862  // holds number of features in terrain database.
867 
871 
873 
875 
877  DtIntrusiveList myTerrainModifiedCallbacks;
878 
879  // Lowest and highest points in the terrain
883 
884  // Total of polygons in the terrain
886 };
887 
889 {
890  return myTotalOfTriangles;
891 }
892 
894 {
896  {
898  }
899  return myHighestPoint;
900 }
901 
903 {
905  {
907  }
908  return myLowestPoint;
909 }
910 
912 {
913  return myMemoryMgr;
914 }
915 
917 {
918  return myTerrain;
919 }
920 
921 inline const DtGroup* DtTerrainDatabase::terrain() const
922 {
923  return myTerrain;
924 }
925 
926 
928 {
929  return myFeatures;
930 }
931 
933 {
934  return myFeatures;
935 }
936 
938 {
939  return myVectorNetwork;
940 }
942 {
943  return myVectorNetwork;
944 }
945 
947 {
948  if (myCoordinateSystem)
949  {
950  return myCoordinateSystem->getCS_Type();
951  }
952  else
953  {
954  return CS_NONE;
955  }
956 }
957 
959 {
960  return myCoordinateSystem;
961 }
963 {
964  return myCoordinateSystem;
965 }
966 
968 {
969  myCoordinateSystem = coordSys;
970 }
971 
973 {
974  return myFeatureCount;
975 }
976 
978 {
979  if (onOff)
980  {
982  }
983  else
984  {
986  }
987 }
988 
989 // While reading a GDB file, reports whether this database will contain
990 // optional data
992 {
993  bool retVal = false;
994 
995  if (myOptionalDataFlagFromFile & optData)
996  {
997  return true;
998  }
999 
1000  return retVal;
1001 }
1002 
1004 {
1006 }
1007 
1009 {
1010  return myTerrainIntersector;
1011 }
1012 
1014 {
1015  return myTerrainIntersector;
1016 }
1017 
1018 #endif

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)