VR-Forces 4.0.4 Class Documentation
include/gdb/surfMgr.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1999 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: surfMgr.h,v $ $Revision: 1.13 $ $State: Exp $
00007 *********************************************************************/
00008 
00009 // \file surfMgr.h
00010 // \brief Contains the DtSurfaceManager class declaration.
00011 
00012 #ifndef surfMgr_H_
00013 #define surfMgr_H_
00014 
00015 #include "gdb/gdbDefines.h"
00016 #include "geometry/surface.h"
00017 #include <map>
00018 
00019 
00020 #define DEFAULT_SURF_MGR_EXPANSION_AMOUNT 10000
00021 
00022 
00023 // Make an explicit type for the surface IDs so that we can be sure 
00024 // we're working with the appropriate identifiers
00025 typedef unsigned int DtSurfaceID;
00026 
00027 //
00028 // DtSurfaceManager manages the surfaces of the 
00029 // loaded terrain file for the terrain database.
00030 class DT_DLL_gdb DtSurfaceManager
00031 {
00032 public:
00033 
00034    // This map keeps count of how many terrain elements have a certain soil type
00035    typedef unsigned int NumElementsWithSurface;
00036    typedef std::map<DtSurface::DtCharacteristics, NumElementsWithSurface> DtSurfaceToTerrainElementCountMap;
00037 
00038 
00039    // default constructor
00040    DtSurfaceManager();
00041 
00042    // additional constructor with number of 
00043    // surfaces to expect to manage
00044    DtSurfaceManager(unsigned int numSurfaces);
00045 
00046    // destructor
00047    virtual ~DtSurfaceManager();
00048 
00049    // copy constructor
00050    DtSurfaceManager(const DtSurfaceManager& orig);
00051 
00052    // assignment operator
00053    DtSurfaceManager& operator=(const DtSurfaceManager& orig);
00054 
00055    // accessor function
00056    // If the surface manager is managing a surface with the specified ID,
00057    // then this function sets surf to a COPY of the managed surface and returns true. 
00058    // If the given surfaceID is not a surface being managed, then the function
00059    // returns false
00060    virtual bool surface(DtSurfaceID surfID, DtSurface& surf) const;
00061 
00062    // Provided for performance reasons.  
00063    // ASSUMES that the ID provided is valid.
00064    virtual DtSurface& surface(DtSurfaceID surfID) const;
00065 
00066    // Adds a surface to be managed.  
00067    // If allowDuplicates is true, then the surface manager will add the 
00068    // surface even if it be considered a duplicate of an existing 
00069    // managed surface.  surfID will be set to a new associated surface ID.  
00070    // If allowDuplicate is false, surfID will be set to the ID of the first 
00071    // surface it finds that passes the equality criteria.  If it doesn't find
00072    // an equal surface, it adds it as a new surface and sets surfID to the 
00073    // associated ID.
00074    // If for some reason, it cannot add the surface at all, it returns false and
00075    // leaves surfID untouched.
00076    virtual bool addSurface(const DtSurface& surfaceToAdd,
00077                            DtSurfaceID& surfID,
00078                            bool allowDuplicates = false);
00079 
00080    // Analyzes the managed surfaces and removes multiple instances of 
00081    // the same surface where the same is defined by the fitness function.
00082    // All duplicate surfaces will be collapsed and mapped to one surface ID.
00083    // If the manager cannot remove the duplicates for any reason, it returns 
00084    // false.
00085    // Otherwise, it removes the duplicates and sets oldIDToNewIDMapping[OldID]
00086    // to be a the new surface ID that is associated with the original ID's surface.
00087    // This function guarantees that all original IDs will be valid indices into
00088    // the oldIDToNewIDMapping.  The user is responsible for deleting the memory
00089    // allocated by this function for oldIDToNewIDMapping. (use delete[]).
00090    virtual bool removeDuplicates(int& numDuplicates,
00091                                  int& numEntries, 
00092                                  DtSurfaceID*& oldIDToNewIDMapping);
00093 
00094    // Returns the number of surfaces currently managed 
00095    virtual unsigned int numberOfSurfaces() const;
00096 
00097    // Determines if a given surface ID is valid.  Returns true if the
00098    // ID maps to a managed surface and false if it doesn't.
00099    virtual  bool  isValidID(DtSurfaceID surfID) const;
00100 
00101    // debugging aid
00102    // prints out the current state of the Surface Manager
00103    virtual  void dump() const;
00104 
00105    // If numSurfaces is greater than the current number of surfaces managed,
00106    // the the vertex manager increases its storage to be able to handle the
00107    // specified number of surfaces.  This is useful when a large number of 
00108    // surfaces will be given to the manager as it will reduce the number
00109    // of memory operations the manager needs to use to grow to accomodate
00110    // the new surfaces as well as reduces the likelyhood that the system will
00111    // run out of memory.
00112    // Returns true if the operation was a success or if the number specified
00113    // is smaller than the amount already capable of being managed.
00114    // If the manager cannot be expanded due to lack of memory,
00115    // it throws a std::bad_alloc exception.    
00116    // \throws std::bad_alloc
00117    virtual bool expandToManage(unsigned int numSurfaces);
00118 
00119    // updates the surface type given in the key by the amount given in numElements
00120    virtual void updateSurfaceTerrainElementMap(DtSurfaceID key, unsigned int numElements);
00121 
00122    // Gets the number of elements that are referencing the specified surface.
00123    virtual bool numTerrainElements(DtSurfaceID surfID, unsigned int& numTerrainElements);
00124 
00125    virtual DtSurfaceToTerrainElementCountMap& surfaceToTerrainElementCountMap();
00126 
00127    // Returns the size (in bytes) of this object
00128    virtual int sizeInBytes() const;
00129 
00130 protected:
00131    // tests the invariants of the class.  
00132    // Should be called first in every const public member 
00133    // function and both first and last in every other function
00134    bool testInvariant() const;
00135 
00136    // Adds the surface and sets surfID to be the 
00137    // associated surfID.  If it fails to add the surface - most likely
00138    // a memory issue - it returns false.
00139    bool addNewSurface(const DtSurface& surfaceToAdd, DtSurfaceID& surfID);
00140 
00141    // Looks for a duplicate surface of the specified surface 
00142    // in the managed surfaces.  If it finds one, it returns true 
00143    // and sets managedSurfID to the associated surfID.  If not, 
00144    // it returns false and leaves managedSurfID untouched.
00145    // Does NOT sort - performance for large numbers of surfaces may be
00146    // very slow.  (O(n^2))
00147    bool isDuplicate(const DtSurface& surface, DtSurfaceID& managedSurfID) const;
00148    bool isDuplicate(const DtSurfaceID& comparisonSurfID, 
00149                     DtSurfaceID& managedSurfID) const;
00150 
00151    // Expands the surface manager's array of surfaces by the amount 
00152    // specified.  If no amount is specified, then expands by the default 
00153    // amount.  Maintains the order of the surfaces managed.
00154    // \throws std::bad_alloc if there is not enough memory to expand the array
00155    virtual  bool  expandSurfaceArray(unsigned int numToExpandBy = DEFAULT_SURF_MGR_EXPANSION_AMOUNT);
00156 
00157    unsigned int   myNumberOfSurfaces;
00158    unsigned int   myMaxNumberOfSurfaces;
00159 
00160    // Dynamically allocated array of surfaces. 
00161    DtSurface*  mySurfaceArray; 
00162 
00163    // For keeping record of how many things are referencing the surfaces.  
00164    DtSurfaceToTerrainElementCountMap mySurfaceToNumElementsMap;
00165 };
00166 
00167 #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)