![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsHEVertex.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (04/04/2005) 00009 UPDATE (12/03/2010) 00010 ******************************************************************************/ 00011 #include "TAPsHEVertex.hpp" 00012 // Using Inclusion Model (i.e. definitions are included in declarations) 00013 // (this name.cpp is included in name.hpp) 00014 // Each friend is defined directly inside its declaration. 00015 00016 BEGIN_NAMESPACE_TAPs 00017 //============================================================================= 00018 template <typename T> unsigned int HEVertex<T>::g_Total = 0; 00019 //============================================================================= 00020 // Constructors 00021 //----------------------------------------------------------------------------- 00022 template <typename T> 00023 HEVertex<T>::HEVertex ( T x, T y, T z, T u, T v, T w, 00024 #ifdef TAPs_USE_DATA_POOL 00025 T * pPosition, T * pNormal, 00026 #endif//TAPs_USE_DATA_POOL 00027 HEHalfEdge<T> * const incidentHalfEdge ) 00028 : 00029 #ifdef TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00030 m_id( g_Total++ ), 00031 m_bMarked( false ), 00032 m_pBarycentric( NULL ), 00033 #endif//TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00034 #ifdef TAPs_USE_DATA_POOL 00035 m_paPosition( pPosition ), 00036 m_paNormal( pNormal ), 00037 #else //TAPs_USE_DATA_POOL 00038 m_vPosition( x, y, z ), 00039 m_vNormal( u, v, w ), 00040 #endif//TAPs_USE_DATA_POOL 00041 nIncidentHalfEdge( incidentHalfEdge ), 00042 nPrev( NULL ), 00043 nNext( NULL ) 00044 { 00045 #ifdef TAPs_USE_DATA_POOL 00046 m_paPosition[0] = x; 00047 m_paPosition[1] = y; 00048 m_paPosition[2] = z; 00049 m_paNormal[0] = u; 00050 m_paNormal[1] = v; 00051 m_paNormal[2] = w; 00052 #endif//TAPs_USE_DATA_POOL 00053 } 00054 //----------------------------------------------------------------------------- 00055 template <typename T> 00056 HEVertex<T>::HEVertex ( Vector3<T> position, Vector3<T> normal, 00057 #ifdef TAPs_USE_DATA_POOL 00058 T * pPosition, T * pNormal, 00059 #endif//TAPs_USE_DATA_POOL 00060 HEHalfEdge<T> * const incidentHalfEdge ) 00061 : 00062 #ifdef TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00063 m_id( g_Total++ ), 00064 m_bMarked( false ), 00065 m_pBarycentric( NULL ), 00066 #endif//TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00067 #ifdef TAPs_USE_DATA_POOL 00068 m_paPosition( pPosition ), 00069 m_paNormal( pNormal ), 00070 #else //TAPs_USE_DATA_POOL 00071 m_vPosition( position ), 00072 m_vNormal( normal ), 00073 #endif//TAPs_USE_DATA_POOL 00074 nIncidentHalfEdge( incidentHalfEdge ), 00075 nPrev( NULL ), 00076 nNext( NULL ) 00077 { 00078 #ifdef TAPs_USE_DATA_POOL 00079 m_paPosition[0] = position[0]; 00080 m_paPosition[1] = position[1]; 00081 m_paPosition[2] = position[2]; 00082 m_paNormal[0] = normal[0]; 00083 m_paNormal[1] = normal[1]; 00084 m_paNormal[2] = normal[2]; 00085 #endif//TAPs_USE_DATA_POOL 00086 } 00087 //----------------------------------------------------------------------------- 00088 template <typename T> 00089 HEVertex<T>::HEVertex ( Vector3<T> position, 00090 #ifdef TAPs_USE_DATA_POOL 00091 T * pPosition, T * pNormal, 00092 #endif//TAPs_USE_DATA_POOL 00093 HEHalfEdge<T> * const incidentHalfEdge ) 00094 : 00095 #ifdef TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00096 m_id( g_Total++ ), 00097 m_bMarked( false ), 00098 m_pBarycentric( NULL ), 00099 #endif//TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00100 #ifdef TAPs_USE_DATA_POOL 00101 m_paPosition( v.m_paPosition ), 00102 m_paNormal( v.m_paNormal ), 00103 #else //TAPs_USE_DATA_POOL 00104 m_vPosition( position ), 00105 m_vNormal(), 00106 #endif//TAPs_USE_DATA_POOL 00107 nIncidentHalfEdge( incidentHalfEdge ), 00108 nPrev( NULL ), 00109 nNext( NULL ) 00110 { 00111 #ifdef TAPs_USE_DATA_POOL 00112 m_paPosition[0] = position[0]; 00113 m_paPosition[1] = position[1]; 00114 m_paPosition[2] = position[2]; 00115 m_paNormal[0] = m_paNormal[1] = m_paNormal[2] = T(0); 00116 #endif//TAPs_USE_DATA_POOL 00117 } 00118 //----------------------------------------------------------------------------- 00119 template <typename T> 00120 HEVertex<T>::HEVertex ( T a[3], 00121 #ifdef TAPs_USE_DATA_POOL 00122 T * pPosition, T * pNormal, 00123 #endif//TAPs_USE_DATA_POOL 00124 HEHalfEdge<T> * const incidentHalfEdge ) 00125 : 00126 #ifdef TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00127 m_id( g_Total++ ), 00128 m_bMarked( false ), 00129 m_pBarycentric( NULL ), 00130 #endif//TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00131 #ifdef TAPs_USE_DATA_POOL 00132 m_paPosition( v.m_paPosition ), 00133 m_paNormal( v.m_paNormal ), 00134 #else //TAPs_USE_DATA_POOL 00135 m_vPosition( a[0], a[1], a[2] ), 00136 m_vNormal(), 00137 #endif//TAPs_USE_DATA_POOL 00138 nIncidentHalfEdge( incidentHalfEdge ), 00139 nPrev( NULL ), 00140 nNext( NULL ) 00141 { 00142 #ifdef TAPs_USE_DATA_POOL 00143 m_paPosition[0] = a[0]; 00144 m_paPosition[1] = a[1]; 00145 m_paPosition[2] = a[2]; 00146 m_paNormal[0] = m_paNormal[1] = m_paNormal[2] = T(0); 00147 #endif//TAPs_USE_DATA_POOL 00148 } 00149 //----------------------------------------------------------------------------- 00150 template <typename T> 00151 HEVertex<T>::HEVertex ( T a[3], T b[3], 00152 #ifdef TAPs_USE_DATA_POOL 00153 T * pPosition, T * pNormal, 00154 #endif//TAPs_USE_DATA_POOL 00155 HEHalfEdge<T> * const incidentHalfEdge ) 00156 : 00157 #ifdef TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00158 m_id( g_Total++ ), 00159 m_bMarked( false ), 00160 m_pBarycentric( NULL ), 00161 #endif//TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00162 #ifdef TAPs_USE_DATA_POOL 00163 m_paPosition( v.m_paPosition ), 00164 m_paNormal( v.m_paNormal ), 00165 #else //TAPs_USE_DATA_POOL 00166 m_vPosition( a[0], a[1], a[2] ), 00167 m_vNormal( b[0], b[1], b[2] ), 00168 #endif//TAPs_USE_DATA_POOL 00169 nIncidentHalfEdge( incidentHalfEdge ), 00170 nPrev( NULL ), 00171 nNext( NULL ) 00172 { 00173 #ifdef TAPs_USE_DATA_POOL 00174 m_paPosition[0] = a[0]; 00175 m_paPosition[1] = a[1]; 00176 m_paPosition[2] = a[2]; 00177 m_paNormal[0] = b[0]; 00178 m_paNormal[1] = b[1]; 00179 m_paNormal[2] = b[2]; 00180 #endif//TAPs_USE_DATA_POOL 00181 } 00182 //----------------------------------------------------------------------------- 00183 template <typename T> 00184 HEVertex<T>::HEVertex ( HEVertex<T> const &v ) 00185 : 00186 #ifdef TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00187 m_id( g_Total++ ), 00188 m_bMarked( v.m_bMarked ), 00189 m_pBarycentric( v.m_pBarycentric ), 00190 #endif//TAPs_ADD_DEFORMABLE_MODEL_BASED_ON_FEM 00191 #ifdef TAPs_USE_DATA_POOL 00192 m_paPosition( v.m_paPosition ), 00193 m_paNormal( v.m_paNormal ), 00194 #else //TAPs_USE_DATA_POOL 00195 m_vPosition( v.m_vPosition ), 00196 m_vNormal( v.m_vNormal ), 00197 #endif//TAPs_USE_DATA_POOL 00198 nIncidentHalfEdge( v.nIncidentHalfEdge ), 00199 nPrev( v.nPrev ), 00200 nNext( v.nNext ) 00201 { 00202 ++g_Total; 00203 } 00204 //----------------------------------------------------------------------------- 00205 template <typename T> 00206 HEVertex<T>::~HEVertex () 00207 {} 00208 //----------------------------------------------------------------------------- 00209 //============================================================================= 00210 // Position Member Access i.e. return x, y, or z of this vertex position 00211 //----------------------------------------------------------------------------- 00212 template <typename T> 00213 inline T & HEVertex<T>::operator[] ( int i ) 00214 { 00215 //assert( 0 <= i && i < 3 ); 00216 #ifdef TAPs_USE_DATA_POOL 00217 return m_paPosition[i]; 00218 #else //TAPs_USE_DATA_POOL 00219 return m_vPosition[i]; 00220 #endif//TAPs_USE_DATA_POOL 00221 } 00222 //----------------------------------------------------------------------------- 00223 template <typename T> 00224 inline T const & HEVertex<T>::operator[] ( int i ) const 00225 { 00226 //assert( 0 <= i && i < 3 ); 00227 #ifdef TAPs_USE_DATA_POOL 00228 return m_paPosition[i]; 00229 #else //TAPs_USE_DATA_POOL 00230 return m_vPosition[i]; 00231 #endif//TAPs_USE_DATA_POOL 00232 } 00233 //----------------------------------------------------------------------------- 00234 //============================================================================= 00235 // Operations 00236 //----------------------------------------------------------------------------- 00237 template <typename T> 00238 HEVertex<T> * HEVertex<T>::Insert ( HEVertex<T> * const n ) 00239 { 00240 HEVertex<T> *c = nNext; 00241 n->nNext = c; 00242 n->nPrev = this; 00243 nNext = n; 00244 c->nPrev = n; 00245 return n; 00246 } 00247 //----------------------------------------------------------------------------- 00248 template <typename T> 00249 HEVertex<T> * HEVertex<T>::Remove () 00250 { 00251 if ( nPrev ) { 00252 nPrev->nNext = nNext; 00253 nPrev = NULL; 00254 } 00255 if ( nNext ) { 00256 nNext->nPrev = nPrev; 00257 nNext = NULL; 00258 } 00259 return this; 00260 } 00261 //----------------------------------------------------------------------------- 00262 template <typename T> 00263 void HEVertex<T>::Delete () 00264 { 00265 delete Remove(); 00266 } 00267 //----------------------------------------------------------------------------- 00268 template <typename T> 00269 HEVertex<T> * HEVertex<T>::Splice ( HEVertex<T> * const n ) 00270 { 00271 HEVertex<T> *a = this; 00272 HEVertex<T> *an = a->nNext; 00273 HEVertex<T> *bn = b->nNext; 00274 a->nNext = bn; 00275 b->nNext = an; 00276 an->nPrev = b; 00277 bn->nPrev = a; 00278 } 00279 //----------------------------------------------------------------------------- 00280 template <typename T> 00281 std::vector< HEVertex<T> * > HEVertex<T>::FindTheFirstRingOfVertices () 00282 { 00283 std::vector< HEVertex<T> * > firstRing; 00284 00285 if ( nIncidentHalfEdge == NULL ) return firstRing; 00286 00287 HEHalfEdge<T> * pE = nIncidentHalfEdge->Pair(); 00288 HEVertex<T> * pFirstVertex = pE->Vertex(); 00289 do { 00290 firstRing.push_back( pE->Vertex() ); 00291 pE = pE->Next()->Pair(); 00292 } while ( pE->Vertex() != pFirstVertex ); 00293 00294 return firstRing; 00295 } 00296 00297 00298 00299 00300 //----------------------------------------------------------------------------- 00301 #if defined(__gl_h_) || defined(__GL_H__) 00302 template <typename T> 00303 void HEVertex<T>::Draw () const 00304 { 00305 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00306 glPointSize( 3 ); 00307 glDisable( GL_LIGHTING ); 00308 //glDisable( GL_DEPTH_TEST ); 00309 glColor3f( 0, 1, 1 ); 00310 glBegin( GL_POINTS ); 00311 glVertex3f( static_cast<GLfloat>(m_vPosition[0]), static_cast<GLfloat>(m_vPosition[1]), static_cast<GLfloat>(m_vPosition[2]) ); 00312 glEnd(); 00313 glPopAttrib(); 00314 } 00315 00316 #ifdef TAPs_ADD_STORED_POSITION 00317 template <typename T> 00318 void HEVertex<T>::DrawStoredPosition () const 00319 { 00320 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00321 glPointSize( 3 ); 00322 glDisable( GL_LIGHTING ); 00323 //glDisable( GL_DEPTH_TEST ); 00324 glColor3f( 0, 1, 1 ); 00325 glBegin( GL_POINTS ); 00326 glVertex3f( static_cast<GLfloat>(m_vStoredPosition[0]), static_cast<GLfloat>(m_vStoredPosition[1]), static_cast<GLfloat>(m_vStoredPosition[2]) ); 00327 glEnd(); 00328 glPopAttrib(); 00329 } 00330 #endif//TAPs_ADD_STORED_POSITION 00331 00332 #endif 00333 //----------------------------------------------------------------------------- 00334 //============================================================================= 00335 END_NAMESPACE_TAPs 00336 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00337 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----