Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __VCG_TETRA_POS
00031 #define __VCG_TETRA_POS
00032
00033 namespace vcg {
00034 namespace tetra {
00035
00038
00039
00044 template < class MTTYPE>
00045 class VTIterator
00046 {
00047 public:
00049 typedef MTTYPE TetraType;
00050 private:
00052 TetraType *_vt;
00054 int _vi;
00056 public:
00057 VTIterator() : _vt(0), _vi(-1){}
00059 VTIterator(TetraType * const tp, int const zp)
00060 {
00061 _vt=tp;
00062 _vi=zp;
00063 }
00064
00065 ~VTIterator(){};
00066
00068 inline TetraType* & Vt()
00069 {
00070 return _vt;
00071 }
00072
00074 inline int & Vi()
00075 {
00076 return _vi;
00077 }
00078
00080 inline const int & Vi() const
00081 {
00082 return _vi;
00083 }
00084
00085 inline bool End(){return (Vt()==NULL);}
00086
00088 void operator++()
00089 {
00090 int vi=Vi();
00091 TetraType * tw = Vt();
00092 Vt() = tw->TVp(vi);
00093 Vi() = tw->TVi(vi);
00094
00095 assert((Vt()==NULL)||((tw->V(vi))==(Vt()->V(Vi()))));
00096 }
00097
00098 };
00099
00100
00105 template < class MTTYPE>
00106 class Pos
00107 {
00108 public:
00109
00111 typedef MTTYPE TetraType;
00113 typedef typename TetraType::VertexType VertexType;
00115 typedef typename TetraType::VertexType::CoordType CoordType;
00117 typedef Pos<TetraType> BasePosType;
00118
00119 private:
00121 TetraType *_t;
00123 char _f;
00125 char _e;
00127 char _v;
00128
00129 public:
00131 Pos(){SetNull();};
00133 Pos(TetraType * const tp, char const fap,char const ep,
00134 char const vp){_t=tp;_f=fap;_e=ep;_v=vp;}
00135
00136 ~Pos(){};
00137
00139 inline TetraType* & T()
00140 {
00141 return _t;
00142 }
00143
00145 inline TetraType* const & T() const
00146 {
00147 return _t;
00148 }
00149
00151 inline char & F()
00152 {
00153 return _f;
00154 }
00155
00157 inline const char & F() const
00158 {
00159 return _f;
00160 }
00161
00163 inline char & E()
00164 {
00165 return _e;
00166 }
00167
00169 inline const char & E() const
00170 {
00171 return _e;
00172 }
00173
00175 inline char & V()
00176 {
00177 return _v;
00178 }
00179
00181 inline const char & V() const
00182 {
00183 return _v;
00184 }
00185
00187 inline bool operator == ( BasePosType const & p ) const {
00188 return (T()==p.T() && F()==p.F() && E==p.E() && V==p.V());
00189 }
00190
00192 inline bool operator != ( BasePosType const & p ) const {
00193 return (!((*this)==p));
00194 }
00195
00197 void SetNull(){
00198 T()=0;
00199 F()=-1;
00200 E()=-1;
00201 V()=-1;
00202 }
00203
00205 bool IsNull() const {
00206 return ((T()==0) || (F()<0) || (E()<0) || (V()<0));
00207 }
00208
00209
00211 void FlipE()
00212 {
00213
00214
00215 char e0=vcg::Tetra::EofF(_f ,0);
00216 char e1=vcg::Tetra::EofF(_f ,1);
00217 char e2=vcg::Tetra::EofF(_f ,2);
00218
00219 if (e0==E())
00220 {
00221 e0=e1;
00222 e1=e2;
00223 }
00224 else
00225 if (e1==E())
00226 {
00227 e1=e2;
00228 }
00229
00230
00231 if ((vcg::Tetra::VofE(e1,0)==V())||(vcg::Tetra::VofE(e1,1)==V()))
00232 E()=e1;
00233 else
00234 E()=e0;
00235 }
00236
00237
00239 void FlipV()
00240 {
00241
00242 char v0=vcg::Tetra::VofE(E(),0);
00243 char v1=vcg::Tetra::VofE(E(),1);
00244 if (v0!=V())
00245 V()=v0;
00246 else
00247 V()=v1;
00248 }
00249
00251 void FlipF()
00252 {
00253 char f0=vcg::Tetra::FofE(E(),0);
00254 char f1=vcg::Tetra::FofE(E(),1);
00255 if (f0!=F())
00256 F()=f0;
00257 else
00258 F()=f1;
00259 }
00260
00262 void FlipT()
00263 {
00264
00265
00266 VertexType *v0=T()->V(vcg::Tetra::VofE(E(),0));
00267 VertexType *v1=T()->V(vcg::Tetra::VofE(E(),1));
00268
00269
00270 VertexType *vcurr=T()->V(V());
00271
00272
00273 TetraType *nt=T()->TTp(F());
00274 char nfa=T()->TTi(F());
00275 if (nfa!=-1)
00276 {
00277
00278 char ne0=vcg::Tetra::EofF(nfa,0);
00279 char ne1=vcg::Tetra::EofF(nfa,1);
00280 char ne2=vcg::Tetra::EofF(nfa,2);
00281
00282
00283 VertexType *vn0=nt->V(vcg::Tetra::VofE(ne0,0));
00284 VertexType *vn1=nt->V(vcg::Tetra::VofE(ne0,1));
00285
00286 if (((vn0==v0)&&(vn1==v1))||((vn1==v0)&&(vn0==v1)))
00287 E()=ne0;
00288 else
00289 {
00290 vn0=nt->V(vcg::Tetra::VofE(ne1,0));
00291 vn1=nt->V(vcg::Tetra::VofE(ne1,1));
00292 if (((vn0==v0)&&(vn1==v1))||((vn1==v0)&&(vn0==v1)))
00293 E()=ne1;
00294 else
00295 {
00296 #ifdef _DEBUG
00297 vn0=nt->V(vcg::Tetra::VofE(ne2,0));
00298 vn1=nt->V(vcg::Tetra::VofE(ne2,1));
00299 assert(((vn0==v0)&&(vn1==v1))||((vn1==v0)&&(vn0==v1)));
00300 #endif
00301 E()=ne2;
00302 }
00303 }
00304
00305
00306 vn0=nt->V(vcg::Tetra::VofE(E(),0));
00307 #ifdef _DEBUG
00308 vn1=nt->V(vcg::Tetra::VofE(E(),1));
00309 assert((vn0==vcurr)||(vn1==vcurr));
00310 #endif
00311 if (vn0==vcurr)
00312 V()=vcg::Tetra::VofE(E(),0);
00313 else
00314 V()=vcg::Tetra::VofE(E(),1);
00315
00316 T()=nt;
00317 assert(T()->V(V())==vcurr);
00318 F()=nfa;
00319 }
00320 }
00321
00323 void NextT( )
00324 {
00325 #ifdef _DEBUG
00326 VertexType *vold=T()->V(V());
00327 #endif
00328 FlipT();
00329 FlipF();
00330 #ifdef _DEBUG
00331 VertexType *vnew=T()->V(V());
00332 assert(vold==vnew);
00333 #endif
00334 }
00335
00336 void Assert()
00337 #ifdef _DEBUG
00338 {
00339 HETYPE ht=*this;
00340 ht.FlipT();
00341 ht.FlipT();
00342 assert(ht==*this);
00343
00344 ht=*this;
00345 ht.FlipF();
00346 ht.FlipF();
00347 assert(ht==*this);
00348
00349 ht=*this;
00350 ht.FlipE();
00351 ht.FlipE();
00352 assert(ht==*this);
00353
00354 ht=*this;
00355 ht.FlipV();
00356 ht.FlipV();
00357 assert(ht==*this);
00358 }
00359 #else
00360 {}
00361 #endif
00362 };
00363
00365 template < class MTTYPE>
00366 class PosJump:public Pos<MTTYPE>
00367 {
00368 private:
00369 MTTYPE *_t_initial;
00370 short int _back;
00371 public :
00372 typedef MTTYPE TetraType;
00373 PosJump(const TetraType* tp,const int fap,const int ep,
00374 int vp){this->T()=tp;this->F()=fap;this->E()=ep;this->V()=vp;_t_initial=tp;_back=0;}
00375
00376 void NextT()
00377 {
00378 #ifdef _DEBUG
00379 int cont=0;
00380 #endif
00381 MTTYPE *tpred=this->T();
00382 Pos<MTTYPE>::NextT();
00383
00384 if (tpred==this->T())
00385 {
00386 while (this->T()!=_t_initial)
00387 {
00388 Pos<MTTYPE>::NextT();
00389 #ifdef _DEBUG
00390 cont++;
00391 assert (cont<500);
00392 #endif
00393 }
00394 _back++;
00395 if (_back==1)
00396 {
00397 Pos<MTTYPE>::NextT();
00398 }
00399 }
00400 }
00401 };
00402
00404 template < class MTTYPE>
00405 class PosLoop:public Pos<MTTYPE>
00406 {
00407 private:
00408 MTTYPE *_t_initial;
00409 bool _jump;
00410 bool _loop;
00411 public :
00412 typedef MTTYPE TetraType;
00413 PosLoop(TetraType* tp,const int fap,const int ep,
00414 int vp){this->T()=tp;this->F()=fap;this->E()=ep;this->V()=vp;_t_initial=tp;_jump=false;_loop=false;}
00415
00416 bool LoopEnd()
00417 {
00418 return (_loop);
00419 }
00420
00421 bool Jump()
00422 {
00423 return(_jump);
00424 }
00425
00426 void Reset()
00427 {
00428 _loop=false;
00429 _jump=false;
00430 }
00431
00432 void NextT()
00433 {
00434 #ifdef _DEBUG
00435 TetraType *t_old=this->T();
00436 #endif
00437 TetraType *tpred=this->T();
00438 Pos<TetraType>::NextT();
00439 _loop=false;
00440 _jump=false;
00441
00442
00443 if (tpred==this->T())
00444 {
00445 tpred=this->T();
00446
00447 Pos<TetraType>::NextT();
00448
00449 while (tpred!=this->T())
00450 {
00451 tpred=this->T();
00452 Pos<TetraType>::NextT();
00453 }
00455
00456 _jump=true;
00457 }
00458 if (this->T()==_t_initial)
00459 _loop=true;
00460 #ifdef _DEBUG
00461 if (_loop==false)
00462 assert(t_old!=this->T());
00463 #endif
00464 }
00465
00466 };
00468 }
00469 }
00470
00471 #endif