![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsHalfEdgeModel.hpp 00003 00004 A Polygonal Model based on half-edge data structure contains: 00005 HEVertexList<T> *m_listVertex; // HEVertex in a list 00006 HEFaceList<T> *m_listFace; // HEFace in a list 00007 HEFaceList<T> *m_listHoleFace; // Hole HEFace in a list 00008 00009 A hole face represents a hole in the surface. 00010 00011 SUKITTI PUNAK (04/05/2005) 00012 UPDATE (10/03/2010) 00013 ******************************************************************************/ 00014 #ifndef TAPs_HALF_EDGE_MODEL_HPP 00015 #define TAPs_HALF_EDGE_MODEL_HPP 00016 00017 #ifdef TAPs_USE_DATA_POOL 00018 #include "../DataStructure/TAPsD1Array.hpp" 00019 #endif//TAPs_USE_DATA_POOL 00020 00021 #include "TAPsOpenGLMeshModel.hpp" 00022 #include "../GeometricDataStructure/HalfEdge/TAPsHalfEdgeDataStructure.hpp" 00023 #include <list> 00024 00025 /*============================================================================== 00026 Half-Edge Data Structure: 00027 ========================= 00028 HEVertex class is a class for 3D half-edge vertex. 00029 - position 00030 - normal 00031 - incident half-edge 00032 HEFace class is a class for 3D half-edge Face. 00033 - normal 00034 - vertex loop (in CCW order) 00035 - texture coordinates for the vertex loop 00036 - incident half-edge 00037 HEHalfEdge class is a class for 3D half-edge. 00038 - originating vertex 00039 - incident face 00040 - pair of this half-edge 00041 - next half-edge (CCW) 00042 - previous half-edge (CW) 00043 * 00044 * 00045 E2 * 00046 V3 <--------------------- V2 * 00047 \ /\ * 00048 \ / * 00049 E3 \ F0 E1 / * 00050 \ / * 00051 \ / * 00052 _\/ E0 / * 00053 V0 --------> V1 * 00054 * 00055 * 00056 | * 00057 \_ | _/ * 00058 \_ | _/ * 00059 \ | / * 00060 -------- V -------- * 00061 _/ | \_ * 00062 _/ | \_ * 00063 / | \ * 00064 | * 00065 * 00066 * 00067 ==============================================================================*/ 00068 00069 00070 BEGIN_NAMESPACE_TAPs__OpenGL 00071 //============================================================================= 00072 template <typename T> 00073 class HalfEdgeModel : public /*virtual*/ OpenGLMeshModel<T> { 00074 //------------------------------------------------------------------------- 00075 // (Friend Fn) put it through ostream 00076 friend std::ostream & operator<< ( std::ostream &output, HalfEdgeModel<T> const &o ) 00077 { 00078 output << "\n======================\n" 00079 << "TAPs::HalfEdgeModel<" 00080 << typeid(T).name() << "> Class:\n" 00081 << "======================\n"; 00082 //---------------------------------------------------------------- 00083 if ( o.GetName() != NULL ) { 00084 output << "Name: " << o.GetName() << "\n"; 00085 } 00086 //---------------------------------------------------------------- 00087 // Vertex Nodes 00088 output << "Vertices " << o.m_listVertex->Size() << "\n"; 00089 /* 00090 int i; 00091 i = 0; 00092 HEVertex<T> *vertex = o.m_listVertex->Head(); 00093 output << "\n{"; 00094 while ( vertex ) { 00095 output << "\n #" << ++i << "\t" << *vertex; 00096 vertex = vertex->Next(); 00097 } 00098 output << "\n}"; 00099 //*/ 00100 //---------------------------------------------------------------- 00101 // Face Nodes 00102 output << "Faces " << o.m_listFace->Size() << "\n"; 00103 /* 00104 i = 0; 00105 HEFace<T> *face = o.m_listFace->Head(); 00106 output << "\n{"; 00107 while ( face ) { 00108 output << "\n #" << ++i << "\t" << *face; 00109 face = face->Next(); 00110 } 00111 output << "\n}"; 00112 //*/ 00113 //---------------------------------------------------------------- 00114 // Hole Face Nodes 00115 output << "Hole Faces " << o.m_listHoleFace->Size() << "\n"; 00116 /* 00117 i = 0; 00118 face = o.m_listHoleFace->Head(); 00119 output << "\n{"; 00120 while ( face ) { 00121 output << "\n #" << ++i << "\t" << *face; 00122 face = face->Next(); 00123 } 00124 output << "\n}"; 00125 //*/ 00126 //---------------------------------------------------------------- 00127 return output; 00128 } 00129 //----------------------------------------------------------------------------- 00130 // Member Functions ------------------------------------------------------------ 00131 public: 00132 //------------------------------------------------------------------------- 00133 // default constructor 00134 HalfEdgeModel (); 00135 //------------------------------------------------------------------------- 00136 // destructor 00137 virtual ~HalfEdgeModel (); 00138 //------------------------------------------------------------------------- 00139 // Virtual Fns from Model class 00140 virtual void Initialize (); 00141 virtual T GetMaxHalfLength () const; // get half length 00142 00153 virtual void ApplyAndResetTransform (); 00154 00155 //------------------------------------------------------------------------- 00156 // Calculate and set the normals 00157 virtual void CalAndSetNormals(); 00158 protected: 00159 //------------------------------------------------------------------------- 00160 // Helper Fn(s) 00161 virtual inline void CalAndSetFaceNormalsNotNormalized (); 00162 virtual inline void NormalizeFaceNormals (); 00163 //virtual inline void DetermineFaceRings (); 00164 virtual inline void CalAndSetVertexNormals (); 00165 //------------------------------------------------------------------------- 00166 // Virtual Fns from Collision Detection from ColDetSupport class <----- 00167 // OpenGLModel class 00168 virtual void CalBoundingAABB (); // AABB for the whole object 00169 virtual void CalBoundingEllipsoid (); // Ellipsoid for the whole object 00170 virtual void CalBoundingSphere (); // Sphere for the whole object 00171 public: 00172 virtual void BuildBVHTree ( TAPs::Enum::CD treeType ); // Create BVHTree 00173 //------------------------------------------------------------------------- 00174 00175 #ifdef TAPs_USE_DATA_POOL 00176 DS::D1Array<T> & GetArrayOfVertexPositions () { return m_ArrayOfVertexPositions; } 00177 DS::D1Array<T> & GetArrayOfVertexNormals () { return m_ArrayOfVertexNormals; } 00178 DS::D1Array<unsigned int> & GetArrayOfIndexFaces () { return m_ArrayOfIndexFaces; } 00179 void SetTriFace ( unsigned int faceNo, unsigned int v0, unsigned int v1, unsigned int v2 ) 00180 { 00181 unsigned int * pIndex = GetArrayOfIndexFaces().GetAddressOfDataNumber( faceNo ); 00182 pIndex[0] = v0; 00183 pIndex[1] = v1; 00184 pIndex[2] = v2; 00185 } 00186 #endif//TAPs_USE_DATA_POOL 00187 00188 public: 00189 //------------------------------------------------------------------------- 00190 // Get/Set Fn(s) 00191 inline HEVertexList<T> * const GetVertexList() const { return m_listVertex; } 00192 inline HEFaceList<T> * const GetFaceList() const { return m_listFace; } 00193 inline HEFaceList<T> * const GetHoleFaceList() const { return m_listHoleFace; } 00194 // inline void SetVertexList( HEVertexList<T> *p ) { m_listVertex = p; } 00195 // inline void SetFaceList ( HEFaceList<T> *p ) { m_listFace = p; } 00196 // inline void SetHoleFaceList ( HEFaceList<T> *p ) { m_listHoleFace = p; } 00197 00198 #ifdef TAPs_ADD_STORED_POSITION 00199 00200 void StoreCurrentPositionsToStoredPositions (); 00202 void RestorePositionsFromStoredPositions (); 00204 #endif//TAPs_ADD_STORED_POSITION 00205 00206 00207 #if defined(__gl_h_) || defined(__GL_H__) 00208 void DrawPositions () const; 00209 #ifdef TAPs_ADD_STORED_POSITION 00210 void DrawStoredPositions () const; 00211 #endif//TAPs_ADD_STORED_POSITION 00212 #endif 00213 00214 // Inherited from class MeshModel 00215 #ifdef TAPs_USE_DATA_POOL 00216 inline virtual void SetNumVertices( int n ); 00217 inline virtual void SetNumFaces( int n ); 00218 inline virtual void SetNumTexCoords( int n ); 00219 inline virtual void SetNoVertices( int n ) { SetNumVertices( n ); } 00220 inline virtual void SetNoFaces( int n ) { SetNumFaces( n ); } 00221 inline virtual void SetNoTexCoords( int n ) { SetNumTexCoords(n ); } 00222 #endif//TAPs_USE_DATA_POOL 00223 00224 //------------------------------------------------------------------------- 00225 // Get/Set Vertex 00226 //void AddVertex (); 00227 //void DelVertex (); 00228 //------------------------------------------------------------------------- 00229 // Get/Set Face 00230 //void AddFace (); 00231 //void DelFace (); 00232 //------------------------------------------------------------------------- 00233 // Get/Set HalfEdge 00234 //void AddHalfEdge (); 00235 //void DelHalfEdge (); 00236 //------------------------------------------------------------------------- 00237 //========================================================================== 00238 // Euler (and Euler Like) Opertator Fns 00239 //========================================================================== 00240 //------------------------------------------------------------------------- 00241 inline void InsertVertexSplitEdge ( ) {}; 00242 inline void SplitVertexMakeEdge ( ) {}; 00243 inline void JoinVertexKillEdge ( ) {}; 00244 inline void SplitFaceMakeEdge ( ) {}; 00245 inline void JoinFaceKillEdge ( ) {}; 00246 //--------------------------------------------------------------- 00247 void IVSE ( HEHalfEdge<T> * he, Vector3<T> const * const pos = NULL ); 00248 //void IVSF ( HEFace<T> * he, Vector3<T> const * const pos = NULL ); 00249 //void KVJF ( HEFace<T> * he ); 00250 void SVME ( HEHalfEdge<T> * he1, HEHalfEdge<T> * he2, 00251 Vector3<T> const * const pos1 = NULL, 00252 Vector3<T> const * const pos2 = NULL ); 00253 void JVKE ( HEHalfEdge<T> * he, Vector3<T> const * const pos = NULL ); 00254 void SFME ( HEHalfEdge<T> * he1, HEHalfEdge<T> * he2 ); 00255 void JFKE ( HEHalfEdge<T> * he ); 00256 //void Split (); 00257 //void Join (); 00258 //------------------------------------------------------------------------- 00259 //========================================================================== 00260 //----------------------------------------------------------------------------- 00261 // Data Members --------------------------------------------------------------- 00262 protected: 00263 //---------------------------------------------------------------- 00264 // Geometric Surface Data 00265 HEVertexList<T> * m_listVertex; // HEVertex in a list 00266 HEFaceList<T> * m_listFace; // HEFace in a list 00267 HEFaceList<T> * m_listHoleFace; // Hole HEFace in a list 00268 //---------------------------------------------------------------- 00269 00270 #ifdef TAPs_USE_DATA_POOL 00271 DS::D1Array<T> m_ArrayOfVertexPositions; 00272 DS::D1Array<T> m_ArrayOfVertexNormals; 00273 DS::D1Array<unsigned int> m_ArrayOfIndexFaces; 00274 #endif//TAPs_USE_DATA_POOL 00275 00276 // For Fast Access (e.g. for OpenGL Drawing) 00277 // std::vector< Vector3<T> * > m_vListOfVertexPositions; 00278 // std::vector< Vector3<T> * > m_vListOfVertexNormals; 00279 //public: 00280 // std::vector< Vector3<T> * > & GetListOfVertexPositions () 00281 // { return m_vListOfVertexPositions; } 00282 // std::vector< Vector3<T> * > & GetListOfVertexNormals () 00283 // { return m_vListOfVertexNormals; } 00284 // void SetListOfVertexPositionsAndNormals (); 00285 //----------------------------------------------------------------------------- 00286 }; // CLASS END: HalfEdgeModel ************************************************* 00287 //============================================================================= 00288 END_NAMESPACE_TAPs__OpenGL 00289 //----------------------------------------------------------------------------- 00290 // Include definition if TAPs_USE_EXPORT is not defined 00291 //#if !defined( TAPs_USE_EXPORT ) 00292 #include "TAPsHalfEdgeModel.cpp" 00293 //#endif 00294 //----------------------------------------------------------------------------- 00295 #endif 00296 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00297 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8