VR-Forces 4.0.4 Class Documentation
include/gdb/grid.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1999 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: grid.h,v $ $Revision: 1.8 $ $State: Exp $
00007 *********************************************************************/
00008 
00009 #ifndef grid_H_
00010 #define grid_H_
00011 
00012 // include files
00013 #include "gdb/gdbDefines.h"
00014 #include "gdb/gdbNode.h"
00015 
00016 #include "geometry/point.h"
00017 #include "geometry/tdbextent.h"
00018 #include "gdb/surfMgr.h"
00019 
00020 // forward declarations
00021 class DtGridPostList;
00022 class DtSurface;
00023 class DtTriangleIndirect;
00024  
00025 
00026 //
00027 //
00028 // class DtGrid:
00029 //
00030 // DtGrid is used to represent a section of the terrain using
00031 // elevations and soiltypes in a grid. This is used to import
00032 // ctdb databases that combine patches that are gridded with
00033 // those that are TINned.
00034 //
00035 //
00036 class DT_DLL_gdb DtGrid : public DtGdbNode
00037 {
00038 public:
00039 
00040    // default constructor
00041    DtGrid();
00042 
00043    // additional constructor
00044    DtGrid(DtGridPostList* gplist,
00045           int nwide, 
00046           int nhigh, 
00047           int startGpIndex,
00048           DtTerrainDatabase* terrainDatabase);
00049 
00050    // destructor
00051    virtual ~DtGrid();
00052 
00053    // initialize object parameters
00054    virtual void init(DtGridPostList* gplist, 
00055                      int nwide, 
00056                      int nhigh, 
00057                      int startGpIndex,
00058                      DtTerrainDatabase* terrainDatabase);
00059 
00060    // returns type of gdb node
00061    virtual DtGdbNode::DtGdbNodeType type() const;
00062 
00063    //returns the width of the grid measured in number of posts.
00064    virtual int width() const;
00065 
00066    //returns the height of the grid measured in number of posts.
00067    virtual int height() const;
00068 
00069    // returns the starting post index of the grid with reference to its
00070    // grid post list.
00071    virtual int startingGridPostIndex() const;
00072 
00073    //returns pointer to gridpost list associated with the grid.
00074    virtual DtGridPostList* gridPostList() const;
00075 
00076    // returns the number of posts on this grid
00077    virtual  int numberOfPosts() const;
00078 
00079    // returns the extent of the grid in 3-dimensions
00080    virtual const DtExtent& extent() const;
00081 
00082    // given the post number on this grid, return the corresponding
00083    // post number in the associated grid post list.
00084    virtual  int gridPostIndex(int postIndex) const;
00085 
00086    // returns the index in the grid post list that corresponds
00087    // to a post col intervals to the East, and row intervals to the
00088    // North from the starting post on this grid.
00089    virtual int gridPostIndex(int col, int row) const;
00090 
00091    // return the bottom left vertex of grid
00092    virtual const DtVertex& bottomLeftVertex() const;
00093 
00094    // return the top right vertex of grid
00095    virtual const DtVertex& topRightVertex() const;
00096 
00097    // process the polygons included in the node that fall within the input
00098    // extent, and update the color count in the colorCountRecord which is
00099    // an in-out parameter.
00100    virtual void countPolyColors(DtColorCountRecord& cr,const DtExtent& e) const;
00101 
00102    // reduce the grid object to two DtTriangleIndirects if the height and surface
00103    // are uniform across the grid.Otherwise, return the grid unaltered.
00104    virtual DtGdbNode* reduce(int& numReductions);
00105 
00106    // expand the input extent to include all of the terrain
00107    // represented by the grid.
00108    virtual  void expandExtent(DtExtent& extent) const;
00109 
00110    // determines the intersection of chord with the terrain
00111    // section represented by the grid.
00112    virtual  bool intersect(const DtChord& chord, 
00113                            DtPoint& intersectionPoint, 
00114                            double& intersectionTime) const;
00115 
00116    // Computes the intersection of the terrain section represented by the grid
00117    // and a chord. In addition to the intersection point and a parametric
00118    // value, optionally computes and returns surface description for the
00119    // intersecting surface, and normal. Identifies the lowest level
00120    // intersecting polygon.  This function will only replace the contents of
00121    // the intersection record if it finds an intersection with a smaller
00122    // intersectionTime value.
00123    virtual  bool intersect(const DtChord& chord, 
00124       DtChordIntersectionRecord& record, DtIntersectRecordType irtFlag) const;
00125 
00126    // Computes the list of all intersections of a chord with terrain section
00127    // represented by the DtGrid. Adds to a list of DtChordIntersectionRecords
00128    // sorted by distance along the chord. Returns false if no intersections
00129    // exist.
00130    virtual bool allIntersectsAlongChord(const DtChord& chord,
00131       DtChordIntersectRecordList& intList,
00132       DtIntersectRecordType irtFlag) const;
00133 
00134    // Computes the intersection of terrain section represented by the terrain
00135    // section represented by the grid and a bundle of chords. The returned
00136    // record list is a a DtList of DtChordIntersectionRecords (one for each
00137    // chord) each of which must be created and deleted by the caller.  The
00138    // irtFlag value specifies which data should be calculated and returned for
00139    // each intersection point.  The return value of this function is the
00140    // number of the chords that had any intersections with the terrain.  This
00141    // function will only replace the contents of the intersection records if
00142    // it finds an intersection with a smaller intersectionTime value.
00143    virtual int intersectBundle(const DtChordBundle& chordBundle,
00144       DtList& recordList, DtIntersectRecordType irtFlag) const;
00145 
00146    // Computes the list of all intersections of each of a bundle of chords
00147    // with the grid.  For each chord in the bundle, adds to a matching
00148    // DtChordIntersectRecordList sorted by distance along the chord.  The
00149    // caller is responsible for creating and deleting the
00150    // DtChordIntersectRecordLists in the intListList DtList.  The return value
00151    // of this function is the number of the chords that had any intersections
00152    // with the terrain.  Note that passing an irtFlag value of IRT_NO_DATA
00153    // will probably never return more than one intersection per chord.
00154    virtual int allIntersectsAlongChordBundle(const DtChordBundle& chordBundle,
00155       DtList& intListList, DtIntersectRecordType irtFlag) const;
00156 
00157    // returns the vertices of a grid triangle in vertices v0, v1,
00158    // and v2, given its enumeration. The vertices are in counter-
00159    // clockwise order.
00160    virtual bool getTriangleVertices(int polyNum, 
00161                                     DtPoint& v0,
00162                                     DtPoint& v1,
00163                                     DtPoint& v2,
00164                                     DtSurface& triSurface) const;
00165 
00166    // returns true if all of the posts have the same elevation
00167    // and soiltype is uniform.The uniform height is returned in h,
00168    // and a poinetr to the uniform surface is returned in s.
00169    virtual bool isUniformHeightAndSurface(DtSurfaceID& surfID, 
00170                                           double& h) const;
00171 
00172    // returns true if all of the posts have the same
00173    // soiltype.  The ID of the uniform surface is returned in surfID.
00174    virtual bool isUniformSurface(DtSurfaceID& surfID) const;
00175 
00176    // given polyNum, construct and return the triangle indexed by
00177    // polynum.
00178 //   virtual  bool reconstructPoly(int polynum, DtPolygonImmediate& poly) const;
00179 
00180    // prints the contents of the object
00181    virtual void dump(int indentLevel) const;
00182 
00183    virtual int sizeInBytes() const;
00184 
00185 protected:
00186 
00187    // copy constructor
00188    DtGrid(const DtGrid& orig);
00189 
00190    // assignment operator
00191    DtGrid& operator=(const DtGrid& orig);
00192 
00193    // initialization
00194    virtual void init();
00195 
00196    // given an extent, compute the smallest subgrid that overlaps
00197    // the extent in x and y dimensions.
00198    virtual void computeOverlappingSubGrid(const DtExtent& chordExtent,
00199                       int&  minPostNum, int& maxPostNum) const;
00200 
00201    // given a chord and a post number, return the segment of the chord 
00202    // that overlaps the post.
00203    virtual void getChordSegment(const DtChord& chord, int postNum, 
00204                    DtChord& chordSegment) const;
00205 
00206    // given a point in 3-space, determine if the point lies
00207    // directly above(below) the square area associated with
00208    // a post.
00209    virtual bool pointProjectsOntoPost(const DtPoint& p,
00210                                       int PostNum) const;
00211 
00212    // determines if chord intersects a grid triangle; returns intersection
00213    // point and parametric value, if intersection exists.
00214    virtual bool intersects(const DtChord& chord, 
00215                            int polyNum,
00216                            DtPoint& intersectionPoint, 
00217                            double& intersectionTime) const;
00218 
00219    // determines if chord intersects a grid triangle; returns intersection
00220    // record, if intersection exists.
00221    virtual bool intersects(const DtChord& chord, 
00222                            int polyNum,
00223                            DtChordIntersectionRecord& record,
00224                            DtIntersectRecordType irtFlag = DtGdbNode::IRT_ALL_DATA_TERRAIN) const;
00225 
00226 
00227 protected:
00228 
00229    // Terrain database which holds pointers to the vertex and surface managers
00230    // as well as the memory manager.
00231    DtTerrainDatabase* myTerrainDb;
00232 
00233    DtGridPostList*   myGridPostList;
00234    int               myNumWide;
00235    int               myNumHigh;
00236    int               myStartingGridpostIndex;
00237 
00238    DtExtent          myExtent;
00239    DtVertex          myBottomLeftVertex;
00240    DtVertex          myTopRightVertex;
00241 };
00242 
00246 
00247 // returns the type of gdb node
00248 inline DtGdbNode::DtGdbNodeType DtGrid::type() const
00249 {
00250    return DtGdbNode::GRID;
00251 }
00252 
00253 // returns the number of posts in the grid
00254 inline int DtGrid::numberOfPosts(void) const
00255 {
00256    return (myNumWide * myNumHigh);
00257 }
00258 
00259 // return the bottom left vertex of grid
00260 inline const DtVertex& DtGrid::bottomLeftVertex() const
00261 {
00262    return myBottomLeftVertex;
00263 }
00264 
00265 // return the top right vertex of grid
00266 inline const DtVertex& DtGrid::topRightVertex() const
00267 {
00268    return(myTopRightVertex);
00269 }
00270 
00271 //returns the width of the grid measured in number of posts.
00272 inline int DtGrid::width() const
00273 {
00274    return myNumWide;
00275 }
00276 
00277 //returns the height of the grid measured in number of posts.
00278 inline int DtGrid::height() const
00279 {
00280    return myNumHigh;
00281 }
00282 
00283 // returns the starting post index of the grid with reference to its
00284 // grid post list.
00285 inline int DtGrid::startingGridPostIndex() const
00286 {
00287    return myStartingGridpostIndex;
00288 }
00289 
00290 //returns pointer to gridpost list associated with the grid.
00291 inline DtGridPostList* DtGrid::gridPostList() const
00292 {
00293    return myGridPostList;
00294 }
00295 
00296 // returns the extent of the grid
00297 inline const DtExtent& DtGrid::extent() const
00298 {  
00299    return myExtent;     
00300 }
00301 
00302 #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)