![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsHEFace.cpp 00003 00004 HE <==> Half-Edge 00005 HEFace class is a class for 3D half-edge Face. 00006 It contains: 00007 - normal 00008 - vertex loop 00009 - texture coordinates for the vertex loop 00010 - incident half-edge 00011 It should contain a set of pointers to its vertices in CCW order. 00012 Example: 00013 2-------1 00014 \ \ 00015 \ \ 00016 \ 0 00017 \ / 00018 \ / 00019 \ / 00020 3 00021 00022 Not supposed to be a parent class. 00023 Support only manifold objects. 00024 00025 SUKITTI PUNAK (04/04/2005) 00026 UPDATE (04/15/2006) 00027 ******************************************************************************/ 00028 #include "TAPsHEFace.hpp" 00029 // Using Inclusion Model (i.e. definitions are included in declarations) 00030 // (this name.cpp is included in name.hpp) 00031 // Each friend is defined directly inside its declaration. 00032 00033 BEGIN_NAMESPACE_TAPs 00034 //============================================================================= 00035 // Constructors 00036 //----------------------------------------------------------------------------- 00037 template <typename T> 00038 HEFace<T>::HEFace ( Vector3<T> normal ) 00039 : m_vNormal( normal ), 00040 nIncidentHalfEdge( NULL ), 00041 nPrev( NULL ), 00042 nNext( NULL ) 00043 {} 00044 //----------------------------------------------------------------------------- 00045 template <typename T> 00046 HEFace<T>::HEFace ( HEHalfEdge<T> * const incidentHalfEdge ) 00047 : m_vNormal(), 00048 nIncidentHalfEdge( incidentHalfEdge ), 00049 nPrev( NULL ), 00050 nNext( NULL ) 00051 {} 00052 //----------------------------------------------------------------------------- 00053 template <typename T> 00054 HEFace<T>::HEFace ( HEFace<T> const &he ) 00055 : m_2DTexCoordsVector( he.m_2DTexCoordsVector ), 00056 m_vNormal( normal ), 00057 nIncidentHalfEdge( he.nIncidentHalfEdge ), 00058 nPrev( he.nPrev ), 00059 nNext( he.nNext ) 00060 {} 00061 //----------------------------------------------------------------------------- 00062 template <typename T> 00063 HEFace<T>::~HEFace () 00064 { 00065 // nIncidentHalfEdge->ClearExceptItself(); 00066 // delete nIncidentHalfEdge; 00067 } 00068 //----------------------------------------------------------------------------- 00069 00070 #ifdef TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00071 00072 #else //TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00073 //============================================================================= 00074 // Member Access for Texture Coordinates 00075 //----------------------------------------------------------------------------- 00076 template <typename T> 00077 inline int HEFace<T>::GetNoTexCoords () const 00078 { return static_cast<int>(m_2DTexCoordsVector.size()) / 2; } 00079 //----------------------------------------------------------------------------- 00080 template <typename T> 00081 inline T HEFace<T>::GetTexCoordNoS ( int i ) const 00082 { 00083 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00084 return m_2DTexCoordsVector[i*2]; 00085 } 00086 //----------------------------------------------------------------------------- 00087 template <typename T> 00088 inline T HEFace<T>::GetTexCoordNoT ( int i ) const 00089 { 00090 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00091 return m_2DTexCoordsVector[i*2 + 1]; 00092 } 00093 //----------------------------------------------------------------------------- 00094 template <typename T> 00095 inline void HEFace<T>::GetTexCoordNoS ( int i, T &s ) const 00096 { 00097 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00098 s = m_2DTexCoordsVector[i*2]; 00099 } 00100 //----------------------------------------------------------------------------- 00101 template <typename T> 00102 inline void HEFace<T>::GetTexCoordNoT ( int i, T &t ) const 00103 { 00104 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00105 t = m_2DTexCoordsVector[i*2 + 1]; 00106 } 00107 //----------------------------------------------------------------------------- 00108 template <typename T> 00109 inline void HEFace<T>::SetTexCoordNoS ( int i, T s ) 00110 { 00111 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00112 m_2DTexCoordsVector[i*2] = s; 00113 } 00114 //----------------------------------------------------------------------------- 00115 template <typename T> 00116 inline void HEFace<T>::SetTexCoordNoT ( int i, T t ) 00117 { 00118 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00119 m_2DTexCoordsVector[i*2 + 1] = t; 00120 } 00121 //----------------------------------------------------------------------------- 00122 template <typename T> 00123 inline void HEFace<T>::GetTexCoordNo ( int i, T &s, T &t ) const 00124 { 00125 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00126 s = m_2DTexCoordsVector[i*2 ]; 00127 t = m_2DTexCoordsVector[i*2 + 1]; 00128 } 00129 //----------------------------------------------------------------------------- 00130 template <typename T> 00131 inline void HEFace<T>::SetTexCoordNo ( int i, T s, T t ) 00132 { 00133 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00134 m_2DTexCoordsVector[i*2 ] = s; 00135 m_2DTexCoordsVector[i*2 + 1] = t; 00136 } 00137 //----------------------------------------------------------------------------- 00138 template <typename T> 00139 inline T HEFace<T>::GetTexCoordHalfNo ( int i ) const 00140 { 00141 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size()) ); 00142 return m_2DTexCoordsVector[i]; 00143 } 00144 //----------------------------------------------------------------------------- 00145 template <typename T> 00146 inline void HEFace<T>::GetTexCoordHalfNo ( int i, T &v ) const 00147 { 00148 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size()) ); 00149 v = m_2DTexCoordsVector[i]; 00150 } 00151 //----------------------------------------------------------------------------- 00152 template <typename T> 00153 inline void HEFace<T>::SetTexCoordHalfNo ( int i, T v ) 00154 { 00155 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size()) ); 00156 m_2DTexCoordsVector[i] = v; 00157 } 00158 //----------------------------------------------------------------------------- 00159 template <typename T> 00160 inline void HEFace<T>::InsertTexCoordNo ( int i, T s, T t ) 00161 { 00162 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00163 m_2DTexCoordsVector.insert( i*2, s ); 00164 m_2DTexCoordsVector.insert( i*2+1, t ); 00165 } 00166 //----------------------------------------------------------------------------- 00167 template <typename T> 00168 inline void HEFace<T>::AppendTexCoord ( T s, T t ) 00169 { 00170 m_2DTexCoordsVector.push_back( s ); 00171 m_2DTexCoordsVector.push_back( t ); 00172 } 00173 //----------------------------------------------------------------------------- 00174 template <typename T> 00175 inline void HEFace<T>::RemoveTexCoordNo ( int i ) 00176 { 00177 assert( 0 <= i && i < static_cast<int>(m_2DTexCoordsVector.size())/2 ); 00178 m_2DTexCoordsVector.erase(i*2, i*2+2); 00179 } 00180 //----------------------------------------------------------------------------- 00181 #endif//TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00182 00183 00184 //============================================================================= 00185 // Operations 00186 //----------------------------------------------------------------------------- 00187 template <typename T> 00188 HEFace<T> * HEFace<T>::Insert ( HEFace<T> * const n ) 00189 { 00190 HEFace<T> *c = nNext; 00191 n->nNext = c; 00192 n->nPrev = this; 00193 nNext = n; 00194 c->nPrev = n; 00195 return n; 00196 } 00197 //----------------------------------------------------------------------------- 00198 template <typename T> 00199 HEFace<T> * HEFace<T>::Remove () 00200 { 00201 if ( nPrev ) { 00202 nPrev->nNext = nNext; 00203 nPrev = NULL; 00204 } 00205 if ( nNext ) { 00206 nNext->nPrev = nPrev; 00207 nNext = NULL; 00208 } 00209 return this; 00210 } 00211 //----------------------------------------------------------------------------- 00212 template <typename T> 00213 void HEFace<T>::Delete () 00214 { 00215 delete Remove(); 00216 } 00217 //----------------------------------------------------------------------------- 00218 template <typename T> 00219 HEFace<T> * HEFace<T>::Splice ( HEFace<T> * const n ) 00220 { 00221 HEFace<T> *a = this; 00222 HEFace<T> *an = a->nNext; 00223 HEFace<T> *bn = b->nNext; 00224 a->nNext = bn; 00225 b->nNext = an; 00226 an->nPrev = b; 00227 bn->nPrev = a; 00228 } 00229 //----------------------------------------------------------------------------- 00230 //============================================================================= 00231 // Data Conversion(s) / Operation(s) 00232 //----------------------------------------------------------------------------- 00233 template <typename T> 00234 int HEFace<T>::CountNumberOfVertices () const 00235 { 00236 int numberOfVertices = 0; 00237 if ( nIncidentHalfEdge == NULL ) return 0; 00238 //-------------------------------------------------------------------- 00239 HEHalfEdge<T> firstHalfEdge = nIncidentHalfEdge; 00240 HEHalfEdge<T> currentHalfEdge = nIncidentHalfEdge; 00241 do { 00242 ++numberOfVertices; 00243 currentHalfEdge = currentHalfEdge->Next(); 00244 } while ( firstHalfEdge != currentHalfEdge ); 00245 //-------------------------------------------------------------------- 00246 return numberOfVertices; 00247 } 00248 //----------------------------------------------------------------------------- 00249 template <typename T> 00250 std::vector< HEVertex<T> * const > HEFace<T>::GetPtrsToVertices () 00251 { 00252 std::vector< HEVertex<T> * const > ptrsToVertices; 00253 if ( nIncidentHalfEdge == NULL ) return ptrsToVertices; 00254 //-------------------------------------------------------------------- 00255 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00256 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00257 do { 00258 ptrsToVertices.push_back( currentHalfEdge->Vertex() ); 00259 currentHalfEdge = currentHalfEdge->Next(); 00260 } while ( firstHalfEdge != currentHalfEdge ); 00261 //-------------------------------------------------------------------- 00262 return ptrsToVertices; 00263 } 00264 //----------------------------------------------------------------------------- 00265 template <typename T> 00266 std::vector< HEVertex<T> const * const > HEFace<T>::GetPtrsToVertices () const 00267 { 00268 std::vector< HEVertex<T> const * const > ptrsToVertices; 00269 if ( nIncidentHalfEdge == NULL ) return ptrsToVertices; 00270 //-------------------------------------------------------------------- 00271 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00272 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00273 do { 00274 ptrsToVertices.push_back( currentHalfEdge->Vertex() ); 00275 currentHalfEdge = currentHalfEdge->Next(); 00276 } while ( firstHalfEdge != currentHalfEdge ); 00277 //-------------------------------------------------------------------- 00278 return ptrsToVertices; 00279 } 00280 //----------------------------------------------------------------------------- 00281 template <typename T> 00282 std::vector< HEVertex<T> * const > 00283 HEFace<T>::GetPtrsToVerticesAndNumberOfVertices ( int & numberOfVertices ) 00284 { 00285 numberOfVertices = 0; 00286 std::vector< HEVertex<T> * const > ptrsToVertices; 00287 if ( nIncidentHalfEdge == NULL ) return ptrsToVertices; 00288 //-------------------------------------------------------------------- 00289 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00290 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00291 do { 00292 ++numberOfVertices; 00293 ptrsToVertices.push_back( currentHalfEdge->Vertex() ); 00294 currentHalfEdge = currentHalfEdge->Next(); 00295 } while ( firstHalfEdge != currentHalfEdge ); 00296 //-------------------------------------------------------------------- 00297 return ptrsToVertices; 00298 } 00299 //----------------------------------------------------------------------------- 00300 template <typename T> 00301 std::vector< HEVertex<T> const * const > 00302 HEFace<T>::GetPtrsToVerticesAndNumberOfVertices ( int & numberOfVertices ) const 00303 { 00304 numberOfVertices = 0; 00305 std::vector< HEVertex<T> const * const > ptrsToVertices; 00306 if ( nIncidentHalfEdge == NULL ) return ptrsToVertices; 00307 //-------------------------------------------------------------------- 00308 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00309 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00310 do { 00311 ++numberOfVertices; 00312 ptrsToVertices.push_back( currentHalfEdge->Vertex() ); 00313 currentHalfEdge = currentHalfEdge->Next(); 00314 } while ( firstHalfEdge != currentHalfEdge ); 00315 //-------------------------------------------------------------------- 00316 return ptrsToVertices; 00317 } 00318 //----------------------------------------------------------------------------- 00319 template <typename T> 00320 std::vector< HEVertex<T> * const > HEFace<T>::GetPtrsToVertices ( int i ) 00321 { 00322 std::vector< HEVertex<T> * const > ptrsToVertices; 00323 if ( nIncidentHalfEdge == NULL ) return ptrsToVertices; 00324 //-------------------------------------------------------------------- 00325 int count = 0; 00326 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00327 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00328 do { 00329 ++count; 00330 ptrsToVertices.push_back( currentHalfEdge->Vertex() ); 00331 currentHalfEdge = currentHalfEdge->Next(); 00332 } while ( firstHalfEdge != currentHalfEdge && count < i ); 00333 //-------------------------------------------------------------------- 00334 return ptrsToVertices; 00335 } 00336 //----------------------------------------------------------------------------- 00337 template <typename T> 00338 std::vector< HEVertex<T> const * const > HEFace<T>::GetPtrsToVertices ( int i ) const 00339 { 00340 std::vector< HEVertex<T> const * const > ptrsToVertices; 00341 if ( nIncidentHalfEdge == NULL ) return ptrsToVertices; 00342 //-------------------------------------------------------------------- 00343 int count = 0; 00344 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00345 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00346 do { 00347 ++count; 00348 ptrsToVertices.push_back( currentHalfEdge->Vertex() ); 00349 currentHalfEdge = currentHalfEdge->Next(); 00350 } while ( firstHalfEdge != currentHalfEdge && count < i ); 00351 //-------------------------------------------------------------------- 00352 return ptrsToVertices; 00353 } 00354 //----------------------------------------------------------------------------- 00355 template <typename T> 00356 std::vector< Vector3<T> > HEFace<T>::GetCopyOfVertexPositions () const 00357 { 00358 std::vector< Vector3<T> > vertexPositions; 00359 if ( nIncidentHalfEdge == NULL ) return vertexPositions; 00360 //-------------------------------------------------------------------- 00361 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00362 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00363 do { 00364 ++count; 00365 vertexPositions.push_back( currentHalfEdge->Vertex()->GetPosition() ); 00366 currentHalfEdge = currentHalfEdge->Next(); 00367 } while ( firstHalfEdge != currentHalfEdge ); 00368 //-------------------------------------------------------------------- 00369 return vertexPositions; 00370 } 00371 //----------------------------------------------------------------------------- 00372 template <typename T> 00373 std::vector< Vector3<T> > HEFace<T>::GetCopyOfVertexPositions ( int i ) const 00374 { 00375 std::vector< Vector3<T> > vertexPositions; 00376 if ( nIncidentHalfEdge == NULL ) return vertexPositions; 00377 //-------------------------------------------------------------------- 00378 int count = 0; 00379 HEHalfEdge<T> * firstHalfEdge = nIncidentHalfEdge; 00380 HEHalfEdge<T> * currentHalfEdge = nIncidentHalfEdge; 00381 do { 00382 ++count; 00383 vertexPositions.push_back( currentHalfEdge->Vertex()->GetPosition() ); 00384 currentHalfEdge = currentHalfEdge->Next(); 00385 } while ( firstHalfEdge != currentHalfEdge && count < i ); 00386 //-------------------------------------------------------------------- 00387 return vertexPositions; 00388 } 00389 //----------------------------------------------------------------------------- 00390 00391 //=================================================================== 00392 #ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00393 //------------------------------------------------------------------- 00394 template <typename T> 00395 void HEFace<T>::InitVertexColorList( int i ) 00396 { 00397 m_sviVertexColorList.resize( i ); 00398 } 00399 00400 template <typename T> 00401 int HEFace<T>::GetVertexColorNo( int i ) const 00402 { 00403 return m_sviVertexColorList.at( i ); 00404 } 00405 00406 template <typename T> 00407 void HEFace<T>::SetVertexColorNo( int i, int vNo ) 00408 { 00409 m_sviVertexColorList.at( i ) = vNo; 00410 } 00411 //------------------------------------------------------------------- 00412 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 00413 //=================================================================== 00414 00415 //=================================================================== 00416 #ifdef TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00417 //------------------------------------------------------------------- 00418 template <typename T> 00419 void HEFace<T>::InitVertexTextureList( int i ) 00420 { 00421 m_sviVertexTextureList.resize( i ); 00422 } 00423 00424 template <typename T> 00425 int HEFace<T>::GetVertexTextureNo( int i ) const 00426 { 00427 return m_sviVertexTextureList.at( i ); 00428 } 00429 00430 template <typename T> 00431 void HEFace<T>::SetVertexTextureNo( int i, int vNo ) 00432 { 00433 m_sviVertexTextureList.at( i ) = vNo; 00434 } 00435 //------------------------------------------------------------------- 00436 #endif//TAPs_ENABLE_FACE_VERTEX_TEXTURE_COORDINATES 00437 //=================================================================== 00438 00439 //----------------------------------------------------------------------------- 00440 //============================================================================= 00441 END_NAMESPACE_TAPs 00442 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00443 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8