VR-Forces 4.6.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
surfaceManager.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1999 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: surfMgr.h,v $ $Revision: 1.13 $ $State: Exp $
7 *********************************************************************/
8 
9 // \file surfMgr.h
10 // \brief Contains the DtSurfaceManager class declaration.
11 
12 #ifndef surfaceManager_H_
13 #define surfaceManager_H_
14 
15 #include "gdb/gdbDefines.h"
16 #include "geometry/surface.h"
17 #include <map>
18 
19 
20 #define DEFAULT_SURF_MGR_EXPANSION_AMOUNT 10000
21 
22 
23 // Make an explicit type for the surface IDs so that we can be sure
24 // we're working with the appropriate identifiers
25 typedef unsigned int DtSurfaceID;
26 
27 //
28 // DtSurfaceManager manages the surfaces of the
29 // loaded terrain file for the terrain database.
31 {
32 public:
33 
34  // This map keeps count of how many terrain elements have a certain soil type
35  typedef unsigned int NumElementsWithSurface;
36  typedef std::map<DtSurface::DtCharacteristics, NumElementsWithSurface> DtSurfaceToTerrainElementCountMap;
37 
38 
39  // default constructor
41 
42  // additional constructor with number of
43  // surfaces to expect to manage
44  DtSurfaceManager(unsigned int numSurfaces);
45 
46  // destructor
47  virtual ~DtSurfaceManager();
48 
49  // copy constructor
51 
52  // assignment operator
53  DtSurfaceManager& operator=(const DtSurfaceManager& orig);
54 
55  // accessor function
56  // If the surface manager is managing a surface with the specified ID,
57  // then this function sets surf to a COPY of the managed surface and returns true.
58  // If the given surfaceID is not a surface being managed, then the function
59  // returns false
60  virtual bool surface(DtSurfaceID surfID, DtSurface& surf) const;
61 
62  // Provided for performance reasons.
63  // ASSUMES that the ID provided is valid.
64  virtual DtSurface& surface(DtSurfaceID surfID) const;
65 
66  // Adds a surface to be managed.
67  // If allowDuplicates is true, then the surface manager will add the
68  // surface even if it be considered a duplicate of an existing
69  // managed surface. surfID will be set to a new associated surface ID.
70  // If allowDuplicate is false, surfID will be set to the ID of the first
71  // surface it finds that passes the equality criteria. If it doesn't find
72  // an equal surface, it adds it as a new surface and sets surfID to the
73  // associated ID.
74  // If for some reason, it cannot add the surface at all, it returns false and
75  // leaves surfID untouched.
76  virtual bool addSurface(const DtSurface& surfaceToAdd,
77  DtSurfaceID& surfID,
78  bool allowDuplicates = false);
79 
80  // Analyzes the managed surfaces and removes multiple instances of
81  // the same surface where the same is defined by the fitness function.
82  // All duplicate surfaces will be collapsed and mapped to one surface ID.
83  // If the manager cannot remove the duplicates for any reason, it returns
84  // false.
85  // Otherwise, it removes the duplicates and sets oldIDToNewIDMapping[OldID]
86  // to be a the new surface ID that is associated with the original ID's surface.
87  // This function guarantees that all original IDs will be valid indices into
88  // the oldIDToNewIDMapping. The user is responsible for deleting the memory
89  // allocated by this function for oldIDToNewIDMapping. (use delete[]).
90  virtual bool removeDuplicates(int& numDuplicates,
91  int& numEntries,
92  DtSurfaceID*& oldIDToNewIDMapping);
93 
94  // Returns the number of surfaces currently managed
95  virtual unsigned int numberOfSurfaces() const;
96 
97  // Determines if a given surface ID is valid. Returns true if the
98  // ID maps to a managed surface and false if it doesn't.
99  virtual bool isValidID(DtSurfaceID surfID) const;
100 
101  // debugging aid
102  // prints out the current state of the Surface Manager
103  virtual void dump() const;
104 
105  // If numSurfaces is greater than the current number of surfaces managed,
106  // the the vertex manager increases its storage to be able to handle the
107  // specified number of surfaces. This is useful when a large number of
108  // surfaces will be given to the manager as it will reduce the number
109  // of memory operations the manager needs to use to grow to accomodate
110  // the new surfaces as well as reduces the likelyhood that the system will
111  // run out of memory.
112  // Returns true if the operation was a success or if the number specified
113  // is smaller than the amount already capable of being managed.
114  // If the manager cannot be expanded due to lack of memory,
115  // it throws a std::bad_alloc exception.
116  // \throws std::bad_alloc
117  virtual bool expandToManage(unsigned int numSurfaces);
118 
119  // updates the surface type given in the key by the amount given in numElements
120  virtual void updateSurfaceTerrainElementMap(DtSurfaceID key, unsigned int numElements);
121 
122  // Gets the number of elements that are referencing the specified surface.
123  virtual bool numTerrainElements(DtSurfaceID surfID, unsigned int& numTerrainElements);
124 
125  virtual DtSurfaceToTerrainElementCountMap& surfaceToTerrainElementCountMap();
126 
127  // Returns the size (in bytes) of this object
128  virtual int sizeInBytes() const;
129 
130 protected:
131  // tests the invariants of the class.
132  // Should be called first in every const public member
133  // function and both first and last in every other function
134  bool testInvariant() const;
135 
136  // Adds the surface and sets surfID to be the
137  // associated surfID. If it fails to add the surface - most likely
138  // a memory issue - it returns false.
139  bool addNewSurface(const DtSurface& surfaceToAdd, DtSurfaceID& surfID);
140 
141  // Looks for a duplicate surface of the specified surface
142  // in the managed surfaces. If it finds one, it returns true
143  // and sets managedSurfID to the associated surfID. If not,
144  // it returns false and leaves managedSurfID untouched.
145  // Does NOT sort - performance for large numbers of surfaces may be
146  // very slow. (O(n^2))
147  bool isDuplicate(const DtSurface& surface, DtSurfaceID& managedSurfID) const;
148  bool isDuplicate(const DtSurfaceID& comparisonSurfID,
149  DtSurfaceID& managedSurfID) const;
150 
151  // Expands the surface manager's array of surfaces by the amount
152  // specified. If no amount is specified, then expands by the default
153  // amount. Maintains the order of the surfaces managed.
154  // \throws std::bad_alloc if there is not enough memory to expand the array
155  virtual bool expandSurfaceArray(unsigned int numToExpandBy = DEFAULT_SURF_MGR_EXPANSION_AMOUNT);
156 
157  unsigned int myNumberOfSurfaces;
158  unsigned int myMaxNumberOfSurfaces;
159 
160  // Dynamically allocated array of surfaces.
162 
163  // For keeping record of how many things are referencing the surfaces.
165 };
166 
167 #endif

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)