![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /********************************************************************* 00002 ** Copyright (c) 1998 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 /********************************************************************* 00006 ** $RCSfile: vtxMgr.h,v $ $Revision: 1.11 $ $State: Exp $ 00007 *********************************************************************/ 00008 00009 #ifndef vtxMgr_H_ 00010 #define vtxMgr_H_ 00011 00012 #include "gdb/gdbDefines.h" 00013 #include "geometry/point.h" 00014 #include <vector> 00015 00016 typedef int DtVertexID; 00017 00018 #define DEFAULT_VERT_MGR_EXPANSION_AMOUNT 50000 00019 00020 // 00021 // class DtVertexManager: 00022 // 00023 // DtVertexManager represents a general vertex list. It is used in 00024 // DtPolygonIndirect and in various types of Features. 00025 // 00026 class DT_DLL_gdb DtVertexManager 00027 { 00028 public: 00029 00030 // default constructor 00031 DtVertexManager(); 00032 00033 // additional constructor 00034 DtVertexManager(unsigned int size); 00035 00036 // destructor 00037 virtual ~DtVertexManager(); 00038 00039 // copy constructor 00040 DtVertexManager(const DtVertexManager& orig); 00041 00042 // assignment operator 00043 DtVertexManager& operator=(const DtVertexManager& orig); 00044 00045 // If the vertex associated with the specified vertex ID is managed by 00046 // the vertex manager, returns true and sets retVal to be a reference to 00047 // the associated vertex. Otherwise, returns false. 00048 virtual bool vertex(DtVertexID vertID, DtVertex& vertex) const; 00049 00050 // Provided for performance reasons. 00051 // ASSUMES that the ID provided is valid. 00052 virtual DtVertex& vertex(DtVertexID vertID); 00053 virtual const DtVertex& vertex(DtVertexID vertID) const; 00054 00055 // add vertex v to the DtVertexManager object. 00056 // If allowDuplicate is true, then the vertex manager will add the 00057 // vertex even if it is could be considered a duplicate of an existing 00058 // managed vertex. vertID will be set to a new vertex ID associated with 00059 // the newly added vertex. 00060 // If the manager does not allow duplicates (see allowDuplicates below), 00061 // vertID will be set to the ID of the first vertex it finds that is within 00062 // tolerance of being equal to it. 00063 // If it doesn't find an approximately equal vertex, it adds it as a 00064 // new vertex and sets vertID to the associated ID. 00065 // If it fails to add the vertex due to lack of memory, it throws a 00066 // std::bad_alloc exception. If for some other reason, it cannot add the 00067 // vertex at all, it returns false and leaves vertID untouched. 00068 // \throws std:bad_alloc 00069 virtual bool addVertex(const DtVertex& vertex, 00070 DtVertexID& vertID, 00071 const double tolerance = 0.0000); 00072 00073 // Analyzes the managed vertices and removes multiple instances of 00074 // the same vertex where the same is defined by the fitness function. 00075 // All duplicate vertices will be collapsed and mapped to one vert ID. 00076 // If the manager cannot remove the duplicates for any reason, it returns 00077 // false. 00078 // Otherwise, it removes the duplicates and sets oldIDToNewIDMapping[OldID] 00079 // to be a the new vertex ID that is associated with the original ID's vertex. 00080 // This function guarantees that all original IDs will be valid indices into 00081 // the oldIDToNewIDMapping. The user is responsible for deleting the memory 00082 // allocated by this function for oldIDToNewIDMapping. (use delete[]). 00083 virtual bool removeDuplicates(double tolerance, 00084 int& numDuplicates, 00085 int& numEntries, 00086 DtVertexID*& oldIDToNewIDMapping); 00087 00088 // Returns the number of vertices currently managed by the manager. 00089 virtual unsigned int numberOfVertices() const; 00090 00091 // Determines if a given vertex ID is valid. Returns true if the 00092 // ID maps to a managed vertex and false if it doesn't. 00093 virtual bool isValidID(DtVertexID vertID) const; 00094 00095 virtual bool assignFrom(const DtVertex* vertices, int numVertices); 00096 00097 // debugging aid 00098 virtual void dump(int indexLevel) const; 00099 00100 // If numVertices is greater than the current number of vertices managed, 00101 // the the vertex manager increases its storage to be able to handle the 00102 // specified number of vertices. This is useful when a large number of 00103 // vertices will be given to the manager as it will reduce the number 00104 // of memory operations the manager needs to use to grow to accommodate 00105 // the new vertices as well as reduces the likelihood that the system will 00106 // run out of memory. 00107 // Returns true if the operation was a success or if the number specified 00108 // is smaller than the amount already capable of being managed. Returns false 00109 // otherwise. However, if the manager cannot be expanded due to lack of memory, 00110 // it throws a std::bad_alloc exception. 00111 // \throws std::bad_alloc 00112 virtual bool expandToManage(unsigned int numVertices = DEFAULT_VERT_MGR_EXPANSION_AMOUNT); 00113 00114 // Returns the size (in bytes) of this object 00115 virtual int sizeInBytes(); 00116 00117 // This const accessor allows direct access to the vertex array. In practice, 00118 // only the vertex() accessor should be used to get vertices from the array. 00119 // This access is currently only used by DtOpcodeGdbInterfaceImpl to provide 00120 // the Opcode mesh interface with direct, read access to the array. 00121 virtual const DtVertex* getVertexArray(); 00122 00123 // Returns the lowest and highest points (in the Z coordinate) stored in the manager 00124 virtual bool extremePoints(DtVertex& highest, DtVertex& lowest) const; 00125 00126 // Sets/gets whether the manager should allow duplicate vertices when being 00127 // added. 00128 virtual void setAllowDuplicates(bool flag); 00129 virtual bool allowDuplicates() const; 00130 00131 protected: 00132 // tests the invariants of the class. 00133 // Should be called first in every const public member 00134 // function and both first and last in every other function 00135 virtual bool testInvariant() const; 00136 00137 // Adds the vertex to the vertex manager and sets vertID to be the 00138 // associated vertex ID. If it fails to add the vertex due to lack of memory, 00139 // it throws std::bad_alloc exception. If it fails to add the vertex due to any 00140 // other issue - it returns false. 00141 // \throws std:bad_alloc 00142 bool addNewVertex(const DtVertex& vertexToAdd, DtVertexID& vertID); 00143 00144 // Looks for a duplicate vertex in the group of managed vertices. 00145 // If it finds one, it returns true and sets managedVertID to the 00146 // associated vertex ID. If not, it returns false and leaves managedVertID 00147 // alone. 00148 // Does NOT sort - performance for large numbers of surfaces may be 00149 // very slow. (O(n^2)) 00150 bool isDuplicate(const DtVertex& vertex, 00151 DtVertexID& managedVertID, 00152 const double tol) const; 00153 00154 // Checks to see if the vertex associated with the specified 00155 // ID is a duplicate of a vertex stored BEFORE the specified ID in 00156 // the manager. If one is found, the function returns true and 00157 // sets managedVertID to the associated vertex ID. If the comparisonID 00158 // is not a valid ID, or if no duplicate is found BEFORE the specified ID, 00159 // it returns false and leaves managedVertID alone. 00160 // Does NOT sort - performance for large numbers of surfaces may be 00161 // very slow. (O(n^2)) 00162 bool isDuplicate(const DtVertexID& comparisonVertID, 00163 DtVertexID& managedVertID, 00164 const double tol) const; 00165 00166 // If the vertex manager is not managing any vertices, then 00167 // expand to a default amount. If it is managing vertices, 00168 // then expand by the specified amount. Maintains the order of the 00169 // vertices managed. 00170 // \throws std::bad_alloc if there is not enough memory to expand the array 00171 virtual bool expandVertexArray(unsigned int numToExpandBy); 00172 00173 unsigned int myNumberOfVertices; 00174 unsigned int myMaxNumberOfVertices; 00175 00176 // Vector of vertices. 00177 std::vector<DtVertex> myVertexArray; 00178 00179 // Memory-management flag for vertex array 00180 bool myArrayIsMemoryManaged; 00181 00182 bool myManagerAllowsDuplicates; 00183 }; 00184 00188 inline unsigned int DtVertexManager::numberOfVertices() const 00189 { 00190 return myNumberOfVertices; 00191 } 00192 00193 #endif