VR-Forces 4.0.4 Class Documentation
include/gdb/terrainDb.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2003 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: terrainDb.h,v $ $Revision: 1.87 $ $State: Exp $
00007 *******************************************************************************/
00008 #ifndef terrainDb_H_
00009 #define terrainDb_H_
00010 
00011 //
00012 // \file terrainDb.h
00013 // \brief Contains the DtTerrainDatabase class declarationn, as well as the DtTerrainFileVersionNumber and other related declarations and definitions.
00014 //
00015 
00016 #include "gdb/gdbDefines.h"
00017 #include "gdb/gdbNode.h"
00018 #include "gdb/fileNode.h"
00019 #include "tdbutil/serializ.h"
00020 #include "terrainCS/coordSystem.h"
00021 #include "gdb/terModCbInfo.h"
00022 #include "gdb/surfMgr.h"
00023 #include "gdb/specMgr.h"
00024 #include "gdb/vtxMgr.h"
00025 #include "geometry/matrix4x4.h"
00026 #include "geometry/surface.h"
00027 #include <vlutil/vlFilename.h>
00028 #include <vlutil/vlConfig.h>
00029 #include <vector>
00030 #include <assert.h>
00031 
00032 class DtList;
00033 class DtPoint;
00034 class DtExtent;
00035 class DtChord;
00036 class DtChordBundle;
00037 class DtChordIntersectionRecord;
00038 class DtChordIntersectRecordList;
00039 class DtColor;
00040 class DtMemoryManager;
00041 class DtBaseCoordinateSystem;
00042 class DtAllTypesPolygon;
00043 class DtGroup;
00044 class DtVectorNetworkRecord;
00045 class DtVectorNetworkIntersectionRecord;
00046 class DtTerrainInitializer;
00047 class DtPolygonIndirect;
00048 class DtTriangleIndirect;
00049 class DtVectorNetwork;
00050 class DtVectorNetworkTool;
00051 class DtPlane;
00052 class DtTerrainIntersector;
00053 class DtTerrainIntersectorDescriptor;
00054 
00055 enum DtMemoryUsageDetails
00056 {
00057    ShowDetails = 1,
00058    ShowSizeOnly
00059 };
00060 
00061 enum DtVectorNetworkTransformFlag
00062 {
00063    TransformYes = 1,
00064    TransformNo   
00065 };
00066 
00067 // Terrain database file version number:
00068 // 100:  initial version
00069 // 201:  DtFileNodes added
00070 // 202:  Spatial indexes and optional data flags added
00071 // 203:  Vector network added
00072 // 204:  Reorganization of data - forced new format
00073 // 205:  Refactored vector data format completely.
00074 // 206:  Changed from using spatial index to using spatial subdivision.
00075 // 207:  Added map datum to coordinate system node and scale factor to utm node
00076 // 209:  Removed spatial subdivision. It now works with opcode. It only stores triangles.
00077 // 210:  Added back in spatial subdivision and added new terrain intersection method integer
00078 static const DtTerrainFileVersionNumber CURRENT_TDB_FILE_FORMAT_VERSION = TDB_210_VERSION;
00079 
00080 // Optional data flags
00081 // These are bitfield values (they must be a power of 2).  Only add new values
00082 // on the end of the list, regardless of what order they are written in!
00083 typedef enum
00084 {
00085    OPT_FEATURES =             0x00000001,
00086    OPT_SPATIAL_SUBDIVISION =  0x00000002,
00087    OPT_EXPORTED_BY_3D_GUI  =  0x00000004
00088 } DtTerrainFileOptionalData;
00089 
00090 static const DtTerrainFileOptionalData CURRENT_TDB_MAX_OPTIONAL_DATA = OPT_EXPORTED_BY_3D_GUI;
00091 
00092 // A mask of the currently defined optional data bitfield values
00093 static const unsigned int OPT_FLAGS_MASK = (CURRENT_TDB_MAX_OPTIONAL_DATA*CURRENT_TDB_MAX_OPTIONAL_DATA)-1;
00094 
00095 //
00096 // These callback function types are defined so this library
00097 // doesn't have to know about the GUI system but can still call
00098 // GUI functions which update a ProgressMeterDialogBoxClass
00099 //
00100 // The calling GUI code does this:
00101 //
00102 // static ProgressMeterDialogBoxClass *p = 0;
00103 // static wxFrame *me = 0;
00104 // void prog_start_fcn(char *label, int range) { p = new ProgressMeterDialogBoxClass(me, "label", range); }
00105 // void prog_incremental_fcn(int increment) { p->DidSomeMore(increment); }
00106 // void prog_set_value_fcn(int value) { p->SetValue(value); }
00107 // void prog_end_fcn(void) { delete(p); }
00108 //
00109 //
00110 // The called, time-intensive tdb functions call these like:
00111 //
00112 // void load_db(progressCallbackStartFunction *prog_start_fcnp,
00113 //        progressCallbackSetValueFunction *prog_set_value_fcnp,
00114 //        progressCallbackIncrementalProgressFunction *prog_incremental_fcnp,
00115 //        progressCallbackEndFunction *prog_end_fcnp)
00116 // {
00117 //    (*prog_start_fcnp)("Loading database", 10000);
00118 //
00119 //    for (int i=0; i<10000; i++)
00120 //      {
00121 //     (*prog_set_value_fcnp)(i); // This, or...
00122 //        (*prog_incremental_fcnp)(1); // this. 
00123 //      }
00124 //    (*prog_end_fcnp)();
00125 // }  
00126 //
00127 // Or, if you can live with the restrictions, inherit CanPopUpProgressMeter
00128 // class.
00129 //
00130 
00131 typedef void progressCallbackStartFunction(const char* label, int range);
00132 typedef void progressCallbackSetValueFunction(int value);
00133 typedef void progressCallbackIncrementalProgressFunction(int increment);
00134 typedef void progressCallbackEndFunction();
00135 typedef void (*locationConversionFunction)(Coordinate_System* csFrom, Coordinate_System* csTo, DtPoint& in, DtPoint& out, const DtVector* offset);
00136 
00137 // class DtTerrainDatabase:
00138 //
00139 // DtTerrainDatabase represents an entire database in GDB format.  It 
00140 // represents the terrain skin, geometrical features over the skin and a 
00141 // vector network.  The database can be written out to, and read from, a file.
00142 
00143 
00144 //
00145 // DtTerrainDatabase represents an entire database in GDB format.  It 
00146 // represents the terrain skin, geometrical features over the skin and a 
00147 // vector network.  The database can be written out to, and read from, a file.
00148 class DT_DLL_gdb DtTerrainDatabase
00149 {
00150 public:
00151    // default constructor
00152    DtTerrainDatabase();
00153 
00154    // destructor
00155    virtual ~DtTerrainDatabase();
00156 
00157 private:
00158    // copy constructor - unimplemented
00159    DtTerrainDatabase(const DtTerrainDatabase& orig);
00160 
00161    // assignment operator - unimplemented
00162    DtTerrainDatabase& operator=(const DtTerrainDatabase& orig);
00163 
00164 public:
00165       
00166    // Initialization function - must be called before ANY other member 
00167    // function.
00168    // Override this to function to add new member data types in derived 
00169    // terrain databases.
00170    virtual bool init();
00171 
00172    // Sets the terrain intersector to be used for the terrain.  Pass a filled
00173    // out descriptor for the intersector that is desired.  If you want the intersector
00174    // to be used after making this call, make initIntersector call right after()
00175    virtual bool setIntersector(const DtTerrainIntersectorDescriptor* intersectorDescriptor);
00176 
00177    // Sets the terrain intersector directly.  Usually, you should use the 
00178    // setIntersector() call, and use the descriptor, but if you want to set
00179    // a custom intersector class, it can be done with this call.
00180    // \note DtTerrainDatabase takes ownership of this pointer, and will delete
00181    // the intersector when done with it.
00182    virtual bool setIntersectorManually(DtTerrainIntersector* intersector);
00183 
00184    // \return A pointer to a intersector descriptor that the DtTerrainDatabase
00185    // determines to be the best for the current terrain.
00186    // \note The caller is responsible for deleting this descriptor.
00187    // \note This does not this this intersector to the terrain.  Call setIntersector()
00188    // with the return value of this method to change the intersector.
00189    virtual DtTerrainIntersectorDescriptor* autoChooseIntersector() const;
00190 
00191    // Initializes the terrain polygon intersector.
00192    // This <b>must</b> be called after all the polygons are added to the
00193    // terrain and before the terrain is used for intersection calls.
00194    virtual bool initIntersector();
00195 
00196    // File name associated with database.
00197    virtual const DtFilename& fileName() const;
00198    virtual void setFileName(const DtFilename& arg);
00199 
00200    // \return the type of file this database was loaded from.
00201    // For example, if this terrainDatabase was loaded from a 
00202    // .gdb file, it will return "gdb".  If it was loaded from a 
00203    // shape file, it will return "shape".
00204    virtual DtString dataType() const;
00205    virtual void setDataType(const DtString& newDataType);
00206 
00207    // \return the version number of the file from which 
00208    // this database was loaded.  For example, if it was loaded
00209    // from a gdb file from version 203 it would return 203.  
00210    // Only non-zero if applicable.
00211    virtual unsigned int versionNumber() const;
00212    virtual void setVersionNumber(unsigned int versionNumber);
00213 
00214 
00215    //-------------------------------------------------------
00216    // Coordinate system
00217    //-------------------------------------------------------
00218 
00219    // Coordinate system type of the database.
00220    virtual CS_Type coordinateSystemType() const;
00221 
00222    // Coordinate system associated with the database.
00223    virtual Coordinate_System* coordinateSystem();
00224    virtual const Coordinate_System* coordinateSystem() const;
00225 
00226    // Sets both the coordinate system and coordinate system type
00227    // of the database.
00228    virtual void setCoordinateSystem(Coordinate_System* coordSys);
00229 
00230    // Change the coordinate system from the current coordinate system
00231    // to the one specified.  Will transform all appropriate elements
00232    // of the terrain database, including all geometry, into the new CS.
00233    // Requires that the terrainDatabase currently have a coordinate system.
00234    // and that the terrain be loaded.
00235    //
00236    // If allowReflect is true, allows the coordinate system to be translated to the
00237    // same coordinate system.  This can be used to project a database to a new location
00238    // If transformVectorNetwork is true, also attempts to transform vector network, if
00239    // possible (not all transformations are allowed).
00240    virtual bool transformCoordinateSystem(Coordinate_System* newCoordSys, bool allowReflect = false, 
00241       DtVectorNetworkTransformFlag transformVectorNetwork = TransformYes);
00242 
00243    // Applies the specified transform to the terrain database.
00244    // \return false if the transformation fails for any reason.
00245    // A side affect of performing the transformation is that all coordinate 
00246    // system nodes in the terrain will be applied to their children and 
00247    // removed.  May result in a much larger GDB as new vertices will be created
00248    // for previously shared vertices.
00249    virtual bool applyTransform(const DtHomogeneousTransfMatrix& matrix,
00250                                bool createNewVertices);
00251 
00252    //-------------------------------------------------------
00253    // Creating and accessing nodes and features
00254    //-------------------------------------------------------
00255    // \return a pointer to the group node that encompasses all of
00256    // the terrain skin.
00257    virtual DtGroup* terrain();
00258    virtual const DtGroup* terrain() const;
00259    virtual bool setTerrain(DtGroup* newTerrain);
00260 
00261    // \return a pointer to the group node that encompasses all of
00262    // the terrain features.
00263    virtual DtGroup* features();
00264    virtual const DtGroup* features() const;
00265    virtual bool setFeatures(DtGroup* newFeatures);
00266 
00267    // get the number of features in the terrain database.
00268    virtual int featureCount() const;
00269 
00270    virtual DtVertexManager* vertexManager();
00271    virtual const DtVertexManager* vertexManager() const;
00272 
00273    virtual DtSurfaceManager* surfaceManager();
00274    virtual const DtSurfaceManager* surfaceManager() const;
00275 
00276    virtual DtVectorNetwork* vectorNetwork();
00277    virtual const DtVectorNetwork* vectorNetwork() const;
00278    virtual void setVectorNetwork(DtVectorNetwork* newVectorNetwork);
00279 
00280    // Create nodes based on the type.  Types are defined in gdbNode.h.  The 
00281    // terrain database will allocate memory using its memory manager for 
00282    // efficiency.  
00283    // Use of this function is highly discouraged in favor of the direct node 
00284    // creation functions provided below.  
00285    virtual DtGdbNode* newNode(DtGdbNode::DtGdbNodeType type);
00286 
00288    // Create particular node types.
00290 
00291    // Asks the TerrainDatabase to create a new instance of a polygon node
00292    // with the specified vertices, surface and parent.  If the parent is 
00293    // not specified, then it adds the new polygon as a child to the root 
00294    // terrain group node.
00295    // If addToStart is specified, it adds the child to the start of
00296    // the parent (or terrain) node.
00297    virtual bool createPolygon(const std::vector<DtVertex>& vertices,
00298                                             DtSurface& surface,
00299                                             DtGroup* const parent = 0,
00300                                             bool addToStart = false);
00301 
00302    // Asks the TerrainDatabase to create a new instance of a polygon node
00303    // with the specified vertexIDs, surfaceID and parent.  If the parent is 
00304    // not specified, then it adds the new polygon as a child to the root 
00305    // terrain group node.
00306    // If addToStart is specified, it adds the child to the start of
00307    // the parent (or terrain) node.
00308    virtual bool createPolygon(const std::vector<DtVertexID>& vertexIDList,
00309                                             DtSurfaceID surfID,       
00310                                             DtGroup* const parent = 0,
00311                                             bool addToStart = false);
00312 
00313    // Asks the TerrainDatabase to create a new instance of a triangle node 
00314    // with the specified vertices, surface and parent.  If the parent is 
00315    // not specified, then it adds the new group as a child to the root 
00316    // terrain group node.
00317    // If addToStart is specified, it adds the child to the start of
00318    // the parent (or terrain) node.
00319    virtual DtTriangleIndirect* createTriangle(const DtPoint& vert1, 
00320                                               const DtPoint& vert2,
00321                                               const DtPoint& vert3,
00322                                               const DtSurface& surface,
00323                                               DtGroup* const parent = 0,
00324                                               bool addToStart = false);
00325 
00326    // Asks the TerrainDatabase to create a new instance of a triangle node 
00327    // with the specified vertex IDs, surface ID and parent.  If the parent is 
00328    // not specified, then it adds the new group as a child to the root
00329    // terrain group node.
00330    // If addToStart is specified, it adds the child to the start of
00331    // the parent (or terrain) node.
00332    virtual DtTriangleIndirect* createTriangle(const int vert0ID, 
00333                                               const int vert1ID, 
00334                                               const int vert2ID,
00335                                               const DtSurfaceID surfID,
00336                                               DtGroup* const parent = 0,
00337                                               bool addToStart = false);
00338 
00339    // If the parent is specified, then it adds the new group as a child to 
00340    // that parent group.  Otherwise, it just adds it to the top level terrain.
00341    virtual DtGroup* createGroup(DtGroup* parent = 0) const;
00342 
00343    // Add/remove nodes from a terrain database.  Note that the DtTerrainDatabase
00344    // will assume responsibility for deleting the memory associated with nodes
00345    // added to the database (regardless of whether or not the memory was allocated
00346    // in the client by calling new or by call DtTerrainDatabase::newNode()).
00347    virtual bool addNode(DtGdbNode *node, DtGroup *parent);
00348    virtual bool addNodeToStart(DtGdbNode *node, DtGroup *parent);
00349 
00350    virtual bool addTerrainNode(DtGdbNode *node, DtGroup *parent = 0);
00351    virtual bool addTerrainNodeToStart(DtGdbNode *node, DtGroup *parent = 0);
00352    virtual bool removeTerrainNode(DtGdbNode *node, DtGdbNode *parent = 0);
00353    
00354    virtual bool addFeatureNode(DtGdbNode *node, DtGroup *parent = 0);
00355    virtual bool addFeatureNodeToStart(DtGdbNode *node, DtGroup *parent = 0);
00356    virtual bool removeFeatureNode(DtGdbNode *node, DtGdbNode *parent = 0);
00357 
00358    //-------------------------------------------------------
00359    // Database extent
00360    //-------------------------------------------------------
00361 
00362    // Forces the entire terrain database to recompute extents.  This includes all
00363    // child nodes (groups, etc).
00364    virtual void recomputeExtent() const;
00365 
00366    // \return the extent of the database.
00367    virtual void getExtent(DtExtent& extent) const;
00368 
00369 
00370    //-------------------------------------------------------
00371    // VectorNetwork Operations
00372    //-------------------------------------------------------
00373    virtual bool planarizeVectorNetwork(DtReal tolerance, unsigned int excessiveEdgeCount);
00374 
00375    // Clips the vector network to the specified extent.
00376    virtual bool clipVectorNetwork(const DtPoint& southWestPoint,
00377                                   const DtPoint& northEastPoint);
00378 
00379    // Clips the vector network to the correct extent of the terrain data
00380    virtual bool clipVectorNetwork();
00381 
00382    // Get and set the vector network tool.
00383    // Allows the user to create their own derived vectorNetworkTool
00384    // and have the TerrainDatabase use it.
00385    // @note Deletes any existing vector network tool.
00386    virtual const DtVectorNetworkTool* vectorNetworkTool() const;
00387    virtual DtVectorNetworkTool* vectorNetworkTool();
00388    virtual void setVectorNetworkTool(DtVectorNetworkTool* vectorNetworkTool);
00389 
00390 
00391    //-------------------------------------------------------
00392    // Intersection routines
00393    //-------------------------------------------------------
00394 
00395    // Functions for finding the height of the terrain at a specified location.
00396    // Takes a location, in either local (DB) coordinates
00397    // or a latitude and longitude, and the returns the altitude of the 
00398    // terrain at the specified location if possible. If no intersection 
00399    // with terrain was found at the specified location, 0 is returned.
00400    // 
00401    // \note
00402    // 1 - These functions *only* intersect terrain polygons - no 
00403    //     feature data.  
00404    //
00405    // 2 - The intersection is defined to be the topmost intersection with 
00406    //     the terrain.  Thus if there are multiple levels of terrain polygons,
00407    //     the highest intersection will be returned as the height. 
00408    virtual double terrainHeight(const DtPoint& localLocation) const;
00409    virtual double terrainHeight(const DtVector& localLocation) const;
00410    virtual double terrainHeight(double lat, double lon) const;
00411 
00412    // Similar to above functions, but return a boolean signifying whether or
00413    // not an intersection with the terrain was found or not.  If not,
00414    // the height is set to 0 and false is returned.  If so, true is returned
00415    // and the height parameter is set to the height of the terrain.
00416    virtual bool terrainHeight(const DtPoint& localLocation, double& height) const;
00417    virtual bool terrainHeight(const DtVector& localLocation, double& height) const;
00418    virtual bool terrainHeight(double lat, double lon, double& height) const;
00419 
00420    // Functions for determining the height of the terrain at a specified location, 
00421    // AND the soil type of the terrain polygon intersected at that location.
00422    // 
00423    // Return Values:
00424    // These functions return true if an intersection occurred, If so, they also set the
00425    // height to be the height of the intersection point and the soilType to be the 
00426    // soilType associated with the intersected polygon.
00427    //
00428    // They return false if no intersection occurred.  If so, they also set the height 
00429    // to 0 and the soilType to "DtSurface::undefinedSoilType"
00430    //
00431    // \note
00432    // 1 - These functions to NOT intersect vector or geometric feature data - they are
00433    //     intended for finding the "ground" height.
00434    // 2 - These functions determine the *topmost* intersection with the terrain.  Thus
00435    //     if there are multiple levels of terrain, the highest intersection point will
00436    //     be returned as the height. 
00437    //     In order to get the closest intersection points with terrain (and possibly features
00438    //     data, use the closestIntersection() functions below.
00439    virtual bool terrainHeightAndSoilType(const DtVector& localLocation, double& height, DtSoilType& soilType) const;
00440    virtual bool terrainHeightAndSoilType(double lat, double lon, double& height, DtSoilType& soilType) const;
00441 
00442    // Functions for determining the height of the terrain at a specified location, 
00443    // AND additional data from the intersection with terrain polygon intersected at that location.
00444    // 
00445    // Return Values:
00446    // These functions return true if an intersection occurred, If so, they also set the
00447    // height to be the height of the intersection point and the intersection record
00448    // to the data returned from the intersection with the terrain at that point.
00449    //
00450    // They return false if no intersection occurred.  If so, they also set the height 
00451    // to 0 and the soilType to "DtSurface::undefinedSoilType"
00452    //
00453    // @note
00454    // 1 - These functions to NOT intersect vector or geometric feature data - they are
00455    //     intended for finding the "ground" height.
00456    // 2 - These functions determine the *topmost* intersection with the terrain.  Thus
00457    //     if there are multiple levels of terrain, the highest intersection point will
00458    //     be returned as the height. 
00459    //     In order to get the closest intersection points with terrain (and possibly features
00460    //     data, use the closestIntersection() functions below.
00461    // 3 - The amount of data returned in the intersection record will be determined by the
00462    //     Intersection Record Type flag that is passed into the call.
00463    virtual bool terrainHeightAndIntersection(const DtVector& localLocation, double& height,
00464       DtChordIntersectionRecord& record,
00465       DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN) const;
00466 
00467    // Similar to the terrainHeight functions above.
00468    // Function to determine the closest intersection to a specified location, 
00469    // either in local (DB) coordinates or in lat/lon.  The closest intersection 
00470    // is defined as the closest intersection in the down or up direction from
00471    // location.  Thus if there are multiple terrain levels, it will not necessarily
00472    // return an intersection with the topmost as the terrainHeight functions do.
00473    // 
00474    // \note  Unlike the terrainHeight functions, if the vectorNetworkRecord and 
00475    // vectorNetworkIntersectionRecord are non-NULL, it will computes an 
00476    // intersection with the vector network and return the best intersection as 
00477    // defined by the metrics in the vectorNetworkRecord.
00478    //
00479    // Return Values:
00480    // True if any intersection, vector data or terrain, is found.  
00481    // If a vector data intersection is found,  then the vecNetworkIntersectionRecord
00482    // is set appropriately.  
00483    // If at least one terrain intersection is found, the intersectionPoint 
00484    // parameter is set to the *closest* intersection point.  
00485    //
00486    // \return A boolean indication whether or not an intersection has been found.
00487    // 
00488    virtual bool closestIntersection(const DtVector& localLocation, 
00489                                     DtPoint& intersectionPoint,
00490                                     DtVectorNetworkRecord* vectorNetworkRecord = 0, 
00491                                     DtVectorNetworkIntersectionRecord* vecNetworkIntersectionRecord = 0) const;
00492 
00493    // Same as above function, but accepts location in lat/lon.
00494    virtual bool closestIntersection(double lat, 
00495                                     double lon, 
00496                                     DtPoint& intersectionPoint,
00497                                     DtVectorNetworkRecord* vectorNetworkRecord = 0, 
00498                                     DtVectorNetworkIntersectionRecord* vecNetworkIntersectionRecord = 0) const;
00499 
00500    // Same as above function, but returns the entire intersection record, 
00501    // and not just the intersection point.
00502    virtual bool closestIntersection(const DtVector& localLocation, 
00503                                     DtChordIntersectionRecord& record,
00504                                     DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,
00505                                     DtVectorNetworkRecord* vectorDatarecord = 0, 
00506                                     DtVectorNetworkIntersectionRecord* vectorIntersectionRecord = 0) const;
00507 
00508    // Same as above function, but accepts location in lat/lon.
00509    virtual bool closestIntersection(double lat, 
00510                                     double lon, 
00511                                     DtChordIntersectionRecord& record,
00512                                     DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,
00513                                     DtVectorNetworkRecord* vectorDatarecord = 0, 
00514                                     DtVectorNetworkIntersectionRecord* vectorIntersectionRecord = 0) const;
00515 
00516    virtual bool closestIntersection(const DtList& localLocationList, 
00517                                     DtList& recordList,
00518                                     int& numIntersections,
00519                                     DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,      
00520                                     DtVectorNetworkRecord *vectorDatarecord = 0, 
00521                                     DtList *vectorList = 0) const;
00522 
00523    // Calculates the first terrain intersection point along a chord given in
00524    // Database Coordinates.
00525    virtual bool intersect(
00526       const DtChord& chord, 
00527       DtPoint& intersectionPoint, 
00528       double& intersectionTime,
00529       DtVectorNetworkRecord *record = 0, 
00530       DtVectorNetworkIntersectionRecord *intersectionRecord = 0) const;
00531     
00532    // Returns complete intersection information about the first terrain
00533    // intersection point along a chord given in Database Coordinates.
00534    // The irtFlag value specifies which data should be calculated and returned
00535    // for each intersection point.
00536    virtual bool intersect(
00537       const DtChord& chord, 
00538       DtChordIntersectionRecord& record,
00539       DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,
00540       DtVectorNetworkRecord *vectorDatarecord = 0, 
00541       DtVectorNetworkIntersectionRecord *vectorIntersectionRecord = 0) const;
00542 
00543    // \return True if the specified sphere intersects with any terrain polygons.
00544    // If irtFlag is IRT_IPOLYGON or higher, a list of all the intersected 
00545    // polygons is returned inside the record.
00546    virtual bool intersect(const DtSphere& sphere,
00547       DtSphereIntersectionRecord& record,
00548       DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN) const;
00549 
00550    // Computes the list of all intersections of a chord (in Database
00551    // Coordinates) with the terrain database. Returns a list of
00552    // DtChordIntersectionRecords. Returns false if no intersections exist.
00553    // The irtFlag value specifies which data should be calculated and returned
00554    // for each intersection point.
00555    // Note that passing an irtFlag value of IRT_NO_DATA will probably never
00556    // return more than one intersection.
00557    virtual bool allIntersectsAlongChord(
00558       const DtChord& chord,
00559       DtChordIntersectRecordList& intList,
00560       DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,
00561       DtVectorNetworkRecord *vectorDatarecord = 0, 
00562       DtList *vectorList = 0) const;
00563     
00564    // Returns complete intersection information about the first terrain
00565    // intersection points along each of a list of DtChords given in Database
00566    // Coordinates.  The returned record list is a DtList of
00567    // DtChordIntersectionRecords (one for each chord) each of which must be
00568    // created and deleted by the caller.  The irtFlag value specifies which
00569    // data should be calculated and returned for each intersection point.  
00570    //
00571    // numTerrainIntersections and numVectorNetworkIntersections are set to the
00572    // numbers of chords that intersected each respectively.
00573    // 
00574    // Returns true if any chord intersected the terrain (or vector network if specified).
00575    // Returns false otherwise.
00576    // 
00577    virtual bool intersectList(
00578       const DtList& chordList, 
00579       DtList& recordList,
00580       int& numTerrainIntersections,
00581       int& numVectorNetworkIntersections,
00582       DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,
00583       DtVectorNetworkRecord *vectorDatarecord = 0, 
00584       DtList *vectorList = 0) const;
00585 
00586    // Computes the list of all intersections of each of a list of chords (in
00587    // Database Coordinates) with the terrain database. Returns data in a
00588    // DtList of DtChordIntersectionRecordLists, which the caller is
00589    // responsible for creating and deleting.  
00590    // 
00591    // Parameters: 
00592    // numTerrainIntersections and numVectorNetworkIntersections are set to the
00593    // numbers of chords that intersected each respectively.
00594    // irtFlag  - specifies which data should be calculated and returned 
00595    //            for each intersection point.  
00596    //
00597    // \note  passing an irtFlag value of IRT_NO_DATA will probably never return
00598    // more than one intersection per chord.
00599    // 
00600    // Returns true if any chord intersected the terrain (or vector network if specified).
00601    // Returns false otherwise.
00602    virtual bool allIntersectsAlongChordList(
00603       const DtList& chordList,
00604       DtList& intListList,         
00605       int& numTerrainIntersections,
00606       int& numVectorNetworkIntersections,
00607       DtGdbNode::DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN,
00608       DtVectorNetworkRecord *vectorDatarecord = 0, 
00609       DtList *vectorListList = 0) const;
00610 
00611 
00613    // Vector Network Intersection Functions
00615    // 
00616    // The following functions all intersect a chord, location,
00617    // or list thereof with the vector network.  
00618    // The functions all:
00619    // Return true if intersection(s) occurred.  
00620    // Return false otherwise, including when no vector data exists
00621    // or if input parameters are 0
00622    // 
00623    // 
00624    // Common parameters:
00625    // irtFlag - All of these functions specify a flag that determines what 
00626    //           data is requested by the intersection call.  This flag specifies
00627    //           the type and amount of data returned.
00628    // vectorRecord - the vectorRecord specifies such things as the metric(s) 
00629    //                to use and the interest range in searching the vector data.
00630    // vectorIntersectionRecord - either a single record or list of records, 
00631    //                            these hold the returned vector intersection records.
00632    //                            When more than one is returned, they are sorted in
00633    //                            relevance/closeness order.  
00634    // For example:  a bridge is more relevant than a river under it.
00635    // 
00636    // \note  The user is responsible for allocating and deallocating the 
00637    // vectorNetworkRecord and vector intersection records.
00638    // \note  The vectorIntersectionRecords (or lists thereof) must be 
00639    //          initialized properly if they are going to be reused.
00640    virtual bool intersectVectorNetwork(
00641       const DtChord& chord,
00642       DtGdbNode::DtIntersectRecordType irtFlag,
00643       DtVectorNetworkRecord* vectorRecord, 
00644       DtVectorNetworkIntersectionRecord* vectorIntersectionRecord) const;
00645 
00646    // Parameters:
00647    // vectorList - DtList of the DtVectorNetworkIntersectionRecords
00648    //              for the chord.
00649    // \note  The user is responsible for deleting the DtList and
00650    // all associated items.
00651    virtual bool intersectVectorNetwork(
00652       const DtChord& chord,
00653       DtGdbNode::DtIntersectRecordType irtFlag,
00654       DtVectorNetworkRecord* vectorRecord, 
00655       DtList* vectorList) const;
00656 
00657    // 
00658    // \param vectorList DtList of the best (as defined above) 
00659    //                   DtVectorNetworkIntersectionRecord
00660    //                   for each chord in the list.
00661    // \note  The user is responsible for deleting the DtList and
00662    // all associated items.
00663    virtual bool intersectChordsWithVectorNetwork(
00664       const DtList& chordList,
00665       DtGdbNode::DtIntersectRecordType irtFlag,
00666       DtVectorNetworkRecord* vectorRecord, 
00667       DtList* vectorList) const;
00668 
00669    // Intersections a list of local (DB) locations with the vector network.
00670    // The single best intersections, not a list, per location are put in the
00671    // list of vector network intersection records.  
00672    //
00673    // \note  The user is responsible for deleting the list of 
00674    // DtVectorNetworkIntersectionRecords (and the records too).
00675    virtual bool intersectLocationsOnVectorNetwork(
00676       const DtList& localLocationList,
00677       DtGdbNode::DtIntersectRecordType irtFlag,
00678       DtVectorNetworkRecord* vectorRecord, 
00679       DtList* vectorList) const;
00680 
00681    // Intersects a list of chords with the vector network.
00682    // Parameters:  
00683    // vectorListList - list of DtVectorNetworkIntersectionRecordLists which
00684    //                  will contain all the DtVectorNetworkIntersectionRecordLists
00685    //                  associated with each chord.  If the actual recordList is
00686    //                  empty, then that chord intersected nothing.
00687    // \note  The user is responsible for allocating and deallocating the list of
00688    //        DtVectorNetworkIntersectionRecordsLists.
00689    virtual bool allIntersectionsWithVectorNetworkAlongChordList(
00690       const DtList& chordList,
00691       DtGdbNode::DtIntersectRecordType irtFlag,
00692       DtVectorNetworkRecord* record, 
00693       DtList* vectorListList) const;
00694 
00695 
00696    //-------------------------------------------------------
00697    // Post-processing
00698    //-------------------------------------------------------
00699    virtual void reduce();
00700 
00701    // Eliminates duplicate vertices in all polygons and triangles in the 
00702    // terrain database.
00703    // This should save memory if many vertices are shared among polygons
00704    // and/or triangles, but may take a while to process.
00705    virtual void eliminateDuplicateVertices(const double tol);
00706 
00707    // Eliminates duplicate surfaces in the terrain database.
00708    virtual void eliminateDuplicateSurfaces(void);
00709 
00710    // Converts all three-sided polygons nodes to triangle nodes
00711    // 
00712    // \note  Does NOT triangulate polygons with more than 3 sides.
00713    virtual void polygonNodesToTriangleNodes();
00714 
00715    // Attempts to balance the terrain node (tree structure of DtGdbNodes)
00716    // according to the branching and leafing parameters specified.
00717    // 
00718    // \note  Balancing the tree is an extremely computationally expensive
00719    // operation for all but the simplest terrains.  Use with caution.
00720    //  
00721    // KNOWN ISSUE:  balancing the terrain *will* reorder the nodes in the 
00722    // tree, thus potentially causing drawing issues.  
00723    virtual void balanceTerrain(unsigned int branching,
00724                                unsigned int bushiness);
00725   
00726    // Returns the type of intersection model being used.  Calls down to intersection model pointer
00727    // to return type
00728    virtual int terrainIntersectorType() const;
00729 
00730    //-------------------------------------------------------
00731    // Miscellaneous
00732    //-------------------------------------------------------
00733 
00734    // Try to figure out what most common terrain skin poly color is so we
00735    // can clear to it.
00736    virtual DtColor mostCommonTerrainSkinColorWithin(const DtExtent& e) const;
00737 
00738 
00739    // Creates two terrain triangles formed from the specified extent.  The 
00740    // altitude of the vertices is determined by the altitude of the left, back, 
00741    // bottom vertex and the right, front, upper vertex.  These are used as the 
00742    // SW and NE vertices respectively.  The altitude of the SE vertex matches 
00743    // the altitude of the SW vertex and the altitude of the NW vertex equals the
00744    // altitude of the NE vertex.
00745    // 
00746    // (NW) *----------* (NE)
00747    //      |\         |
00748    //      | \        |
00749    //      |  \       |
00750    //      |   \      |
00751    //      |    \     |
00752    //      |     \    |
00753    //      |      \   |
00754    //      |       \  |
00755    //      |        \ |
00756    //      |         \|
00757    // (SW) *----------* (SE)
00758    //
00759    virtual bool setFromExtent(const DtExtent& e);
00760 
00762    virtual bool groundClamp(DtPoint& databaseCoord, float const offset = 0) const;
00763 
00764    // Terrain Modified callback registration.
00765    virtual void addTerrainModifiedCallback(
00766       DtTerrainModifiedCallbackFunction cb, void* userData);
00767 
00768    // Terrain Modified callback cancellation.
00769    virtual void removeTerrainModifiedCallback(
00770       DtTerrainModifiedCallbackFunction cb, void* userData);
00771 
00772    // Notify the terrain object (and any registered callbacks) that the
00773    // terrain database has just changed somewhere.
00774    virtual void terrainWasModified(const DtExtent& changedVolume);
00775 
00776    // \return a pointer to a memory manager class that handles
00777    // allocations of a group of objects (polygons, groups, grids, 
00778    // features, etc.)
00779    virtual DtMemoryManager* memoryMgr() const;
00780 
00782    // transforms to all nodes under them.
00783    virtual bool collapseNodeTree();
00784 
00785    // Prints in the output console/log file (as verbose) the amount
00786    // of memory being used by this object
00787    virtual void printMemoryUsage(DtMemoryUsageDetails details=ShowDetails) const;
00788 
00789    virtual int sizeInBytes() const;
00790 
00792    virtual DtVertex highestPoint();
00793 
00795    virtual DtVertex lowestPoint();
00796 
00798    virtual int totalOfPolygons() const;
00799 
00804    virtual int loadExternalReferences(int level=1);
00805 
00807    DtTerrainIntersector* terrainIntersector() const;
00808 
00810    DtTerrainIntersector* terrainIntersector();
00811 
00812    void setOptionalDataFlag(DtTerrainFileOptionalData, bool onOff);
00813    int optionalDataFlags() const;
00814 
00815    // While reading a GDB file, reports whether this database will contain
00816    // optional data
00817    bool fileHasOptionalData(DtTerrainFileOptionalData optData) const;
00818 
00819 public:
00820 
00821    // \return a newly created instance of a DtTerrainDatabase.
00822    static DtTerrainDatabase* create();
00823 
00824 protected:
00825 
00826    bool calculateExtremePoints();  
00827 
00828    bool testInvariant() const;
00829 
00830    // Process the modified callbacks
00831    virtual void processTerrainModifiedCallbacks(const DtExtent& changedVolume); 
00832 
00833    // Remaps the vertex and surface IDs for all nodes below the current node.
00834    // Assumes that both parameters are non-null and valid.
00835    virtual bool remapVertexIDs(DtGdbNode* currentNode, DtVertexID* oldIDToNewIDMap);
00836    virtual bool remapSurfaceIDs(DtGdbNode* currentNode, DtSurfaceID* oldIDToNewIDMap);
00837 
00838    // Transform all appropriate parts of the terrain database from/to the
00839    // specified coordinate system.  
00840    // Requires that the coordinate system be set as specified
00841    // in the function title.
00842    virtual bool xformCoordinateSystemTo(Coordinate_System* coordSys, DtVectorNetworkTransformFlag transformVectorNetwork);
00843 
00844    // Should only be used when re-projecting withing the same database to a different zone
00845    virtual bool xformUTMtoUTM(Coordinate_System* coordSys, DtVectorNetworkTransformFlag transformVectorNetwork);
00846    
00847    virtual void xformVectorNetwork(Coordinate_System* newCoordSys, locationConversionFunction conversionFcn, const DtVector* offset=0);
00848    virtual void xformVertexManager(Coordinate_System* newCoordSys, locationConversionFunction conversionFcn, const DtVector* offset=0);
00849    virtual void xformTreeNodes(Coordinate_System* newCoordSys, locationConversionFunction conversionFcn, const DtVector* offset=0);
00850 
00851 protected:
00852    DtFilename              myFileName;
00853 
00854    // a group node encompassing all of the nodes that
00855    // constitute the terrain skin.
00856    DtGroup*                myTerrain;
00857    DtTerrainIntersector*   myTerrainIntersector;
00858 
00859    DtVertexManager*        myVertexManager;
00860    DtSurfaceManager*       mySurfaceManager;
00861 
00862    // holds number of features in terrain database.
00863    int                     myFeatureCount;
00864    DtGroup*                myFeatures;
00865    DtVectorNetwork*        myVectorNetwork;
00866    DtVectorNetworkTool*    myVectorNetworkTool;
00867 
00868    DtString                myDataType;
00869    unsigned int            myVersionNumberFromFile;
00870    unsigned int            myOptionalDataFlagFromFile;
00871 
00872    mutable DtMemoryManager* myMemoryMgr;
00873 
00874    Coordinate_System*      myCoordinateSystem;
00875 
00876    progressCallbackIncrementalProgressFunction* myProgSetValueFcnp;
00877    DtIntrusiveList myTerrainModifiedCallbacks;
00878 
00879    // Lowest and highest points in the terrain
00880    DtVertex                myLowestPoint;
00881    DtVertex                myHighestPoint;
00882    bool                    myExtremePointsCalculated;
00883 
00884    // Total of polygons in the terrain
00885    int                     myTotalOfTriangles;
00886 };
00887 
00888 inline int DtTerrainDatabase::totalOfPolygons() const
00889 {
00890    return myTotalOfTriangles;
00891 }
00892 
00893 inline DtVertex DtTerrainDatabase::highestPoint() 
00894 {
00895    if (!myExtremePointsCalculated)
00896    {
00897       calculateExtremePoints();
00898    }
00899    return myHighestPoint;
00900 }
00901 
00902 inline DtVertex DtTerrainDatabase::lowestPoint() 
00903 {
00904    if (!myExtremePointsCalculated)
00905    {
00906       calculateExtremePoints();
00907    }
00908    return myLowestPoint;
00909 }
00910 
00911 inline DtMemoryManager* DtTerrainDatabase::memoryMgr() const
00912 {
00913    return myMemoryMgr;
00914 }
00915 
00916 inline DtGroup* DtTerrainDatabase::terrain()
00917 {
00918    return myTerrain; 
00919 }
00920 
00921 inline const DtGroup* DtTerrainDatabase::terrain() const
00922 {
00923    return myTerrain; 
00924 }
00925 
00926 
00927 inline DtGroup* DtTerrainDatabase::features()
00928 {
00929    return myFeatures;
00930 }
00931 
00932 inline const DtGroup* DtTerrainDatabase::features() const
00933 {
00934    return myFeatures;
00935 }
00936 
00937 inline DtVectorNetwork* DtTerrainDatabase::vectorNetwork()
00938 {
00939    return myVectorNetwork;
00940 }
00941 inline const DtVectorNetwork* DtTerrainDatabase::vectorNetwork() const
00942 {
00943    return myVectorNetwork;
00944 }
00945 
00946 inline CS_Type DtTerrainDatabase::coordinateSystemType() const
00947 {
00948    if (myCoordinateSystem)
00949    {
00950       return myCoordinateSystem->getCS_Type();
00951    }
00952    else
00953    {
00954       return CS_NONE;
00955    }
00956 }
00957 
00958 inline Coordinate_System* DtTerrainDatabase::coordinateSystem() 
00959 {
00960    return myCoordinateSystem;
00961 }
00962 inline const Coordinate_System* DtTerrainDatabase::coordinateSystem() const
00963 {
00964    return myCoordinateSystem;
00965 }
00966 
00967 inline void DtTerrainDatabase::setCoordinateSystem(Coordinate_System* coordSys)
00968 {
00969    myCoordinateSystem = coordSys;
00970 }
00971 
00972 inline int DtTerrainDatabase::featureCount() const
00973 {
00974    return myFeatureCount;
00975 }
00976 
00977 inline void DtTerrainDatabase::setOptionalDataFlag(DtTerrainFileOptionalData flag, bool onOff)
00978 {
00979    if (onOff)
00980    {
00981       myOptionalDataFlagFromFile |= flag;
00982    }
00983    else
00984    {
00985       myOptionalDataFlagFromFile &= ~flag;
00986    }
00987 }
00988 
00989 // While reading a GDB file, reports whether this database will contain
00990 // optional data
00991 inline bool DtTerrainDatabase::fileHasOptionalData(DtTerrainFileOptionalData optData) const
00992 {
00993    bool retVal = false;
00994 
00995    if (myOptionalDataFlagFromFile & optData)
00996    {
00997       return true;
00998    }
00999 
01000    return retVal;
01001 }
01002 
01003 inline int DtTerrainDatabase::optionalDataFlags() const
01004 {
01005    return myOptionalDataFlagFromFile;
01006 }
01007 
01008 inline DtTerrainIntersector* DtTerrainDatabase::terrainIntersector()
01009 {
01010    return myTerrainIntersector;
01011 }
01012 
01013 inline DtTerrainIntersector* DtTerrainDatabase::terrainIntersector() const
01014 {
01015    return myTerrainIntersector;
01016 }
01017 
01018 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)