VR-Forces 4.0.4 Class Documentation
include/gdb/polyInd.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1999 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: polyInd.h,v $ $Revision: 1.19 $ $State: Exp $
00007 *********************************************************************/
00008 
00009 #ifndef polyInd_H_
00010 #define polyInd_H_
00011 
00012 #include "gdb/gdbDefines.h"
00013 #include "gdb/basePoly.h"
00014 #include "gdb/surfMgr.h"
00015 #include "gdb/vtxMgr.h"
00016 #include <assert.h>
00017 #include "geometry/matrix4x4.h"
00018 
00019 // forward declarations
00020 class DtVertexManager;
00021 class DtSurfaceManager;
00022 class DtMemoryManager;
00023 
00024 // class DtPolygonIndirect:
00025 //
00026 // DtPolygonIndirect allows for the specification of the
00027 // vertices of a polygon as indices into a vertex manager.
00028 
00029 class DT_DLL_gdb DtPolygonIndirect : public DtBasePolygon
00030 {
00031 public:
00032 
00033    // constructor with number of vertices, array of ints (vertex IDs)
00034    // a vertex manager, a surface manager and a surface ID;
00035    // uses DtMemoryManager to allocate vertex index array.
00036    // NOTE:  Does not take ownership of the array of vertex indices
00037    // specified - copies them into its own memory managed list.
00038    DtPolygonIndirect(unsigned int numVertices, 
00039                      DtVertexManager* vertMgr, 
00040                      DtVertexID* vertexIDs,
00041                      DtSurfaceManager* surfMgr, 
00042                      DtSurfaceID surfID, 
00043                      DtMemoryManager* memMgr);
00044 
00045    // destructor
00046    virtual ~DtPolygonIndirect();
00047 
00048    // copy constructor
00049    DtPolygonIndirect(const DtPolygonIndirect& orig);
00050 
00051    // assignment operator
00052    DtPolygonIndirect& operator=(const DtPolygonIndirect& orig);
00053 
00054    // returns type of gdb node
00055    virtual DtGdbNode::DtGdbNodeType type() const;
00056 
00057    // get the i-th vertex of the polygon
00058    virtual bool getVertex(DtPoint& retVal, unsigned int i) const;
00059    const DtPoint& getVertex(unsigned int i) const;
00060 
00061    // set the i-th vertex of the polygon
00062    virtual bool setVertex(unsigned int localIndex, DtVertexID vertexID);
00063 
00064    // get the surface associated with the polygon
00065    virtual bool getSurface(DtSurface& s) const;
00066    const DtSurface& getSurface() const;
00067 
00068    // set the surface associated with the polygon
00069    // If the ID is a valid surface ID, then it sets the 
00070    // surface and returns true.  If the ID is invalid,
00071    // the it returns false and does NOT set the surface.
00072    virtual bool setSurface(DtSurfaceID surfaceID);
00073 
00074    // Set the surface of the polygon with the specified surface.
00075    // \note Checks to see if the same surface has already been added, so there
00076    // is no need to eliminate duplicate surfaces after calling this function.
00077    virtual bool setSurface(const DtSurface& newSurface);
00078 
00079    // get the vertex/surface/memory manager associated with the polygon
00080    virtual const DtVertexManager* vertexManager() const;
00081    virtual const DtSurfaceManager* surfaceManager() const;
00082    virtual const DtMemoryManager* memoryManager() const;
00083 
00084    // debugging aid function
00085    virtual void dump(int indentLevel) const;
00086 
00087    // Applies the specified transform to its vertices.  If the flag 
00088    // is true, will create new vertices instead of modifying existing 
00089    // ones.  Returns false if the transformation fails for any reason.
00090    virtual bool applyTransform(const DtHomogeneousTransfMatrix& matrix,
00091                                bool createNewVertices);
00092 
00093    // UNSAFE PUBLIC FUNCTIONS
00094    // These functions either modify internal state, create 
00095    // instances of the class that are not fully formed, or
00096    // expose implementation details of the class that may change 
00097    // in future releases.
00098    // They do NOT enforce the invariants of the class.
00099 
00100    // default constructor
00101    DtPolygonIndirect();
00102 
00103    // constructor with number of vertices
00104    DtPolygonIndirect(unsigned int numVertices, DtMemoryManager* memMgr);
00105 
00106    // constructor with number of vertices, vertex manager and
00107    // surface manager to index into; uses DtMemoryManager to allocate 
00108    // index array.
00109    DtPolygonIndirect(unsigned int numVertices, 
00110                      DtVertexManager* vertMgr, 
00111                      DtSurfaceManager* surfMgr, 
00112                      DtMemoryManager* memMgr);
00113 
00114    // set the vertex manager, surface manager, memory manager
00115    // and vertex ID list associated with the polygon
00116    virtual  void setVertexManager(DtVertexManager* vertMgr);
00117    virtual  void setSurfaceManager(DtSurfaceManager* surfMgr);
00118 
00119    // Sets the memory manager.  The polygon does *not* take ownership of the 
00120    // memory manager - it just references it.  
00121    // @note The memMgr parameter should not be a 0 pointer.  The invariant
00122    // specifies that the memory manager always be valid, and if it is not, the
00123    // behavior is @b undefined.
00124    virtual  void setMemoryManager(DtMemoryManager* memMgr);
00125 
00126    // get i-th vertex ID of the polygon
00127    // returns false if localIndex is not a valid index into the
00128    // list of vertex IDs
00129    virtual bool getVertexID(DtVertexID& id, unsigned int localIndex) const;
00130    // get the i-th vertex ID of the polygon.
00131    // Requires that i be a valid vertex index.
00132    virtual int getVertexID(unsigned int localIndex) const;
00133 
00134    // get the surface ID associated with the polygon
00135    virtual DtSurfaceID getSurfaceID() const;
00136 
00137    // get the index list associated with the polygon
00138    virtual const DtVertexID* indexList() const;
00139 
00140    // determine if all the vertices have been specified
00141    virtual bool isFull() const; 
00142 
00143    // add a vertex to the polygon.  Returns the index into the polygon's
00144    // local list of vertexIDs associated with the newly added vertex ID.
00145    virtual int addVertex(DtVertexID vertexID);
00146 
00147    // specify the maximum size of the polygon; initializes the index
00148    // array to the specified size; 
00149    virtual void setNumberOfVertices(unsigned int n);
00150 
00151    virtual int sizeInBytes() const;
00152 
00153 protected:
00154    bool testInvariant() const;
00155 
00156    virtual void init();
00157 
00158 protected:
00159    DtMemoryManager*     myMemoryManager;  
00160    DtVertexManager*     myVertexManager;
00161    DtVertexID*          myIndexList;   // an array of size mySize to hold the indices.
00162    unsigned int         myVertexCount; //number of vertices specified thus far.
00163    DtSurfaceManager*    mySurfaceManager;
00164    DtSurfaceID          mySurfaceID;
00165 };
00166 
00167 //returns the type of gdb node
00168 inline DtGdbNode::DtGdbNodeType DtPolygonIndirect::type() const
00169 {
00170    return DtGdbNode::POLYGON_INDIRECT;
00171 }
00172 
00173 // get the vertex manager associated with the polygon
00174 inline const DtVertexManager* DtPolygonIndirect::vertexManager() const
00175 {
00176    assert(testInvariant());
00177    return myVertexManager;
00178 }
00179 
00180 // set the vertex manager associated with the polygon
00181 inline void DtPolygonIndirect::setVertexManager(DtVertexManager* vertMgr)
00182 {
00183    assert(vertMgr);
00184    myVertexManager = vertMgr;
00185 }
00186 
00187 // get the surface manager associated with the polygon
00188 inline const DtSurfaceManager* DtPolygonIndirect::surfaceManager() const
00189 {
00190    assert(testInvariant());
00191    return mySurfaceManager;
00192 }
00193 
00194 // set the surface manager associated with the polygon
00195 inline void DtPolygonIndirect::setSurfaceManager(DtSurfaceManager* surfMgr)
00196 {
00197    assert(surfMgr);
00198    mySurfaceManager = surfMgr;
00199    // every polygon is created with a surface type of 0
00200    // as soon as there is a surface manager, add 1 to the polygon count of this
00201    // surface
00202    mySurfaceManager->updateSurfaceTerrainElementMap(mySurfaceID, 1);
00203 }
00204 
00205 // get the memory manager associated with the polygon
00206 inline const DtMemoryManager* DtPolygonIndirect::memoryManager() const
00207 {
00208    assert(testInvariant());
00209    return myMemoryManager;
00210 }
00211 
00212 inline void DtPolygonIndirect::setMemoryManager(DtMemoryManager* memMgr)
00213 {
00214    assert(memMgr);
00215    myMemoryManager = memMgr;
00216 }
00217 
00218 inline const DtSurface& DtPolygonIndirect::getSurface() const
00219 {
00220    return mySurfaceManager->surface(mySurfaceID);
00221 }
00222 
00223 inline const DtPoint& DtPolygonIndirect::getVertex(unsigned int localIndex) const
00224 {
00225    DtVertexID vertexID = myIndexList[localIndex];
00226    return myVertexManager->vertex(vertexID);
00227 }
00228 
00229 #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)