00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2004 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 /**************************************************************************** 00024 History 00025 00026 $Log: not supported by cvs2svn $ 00027 Revision 1.2 2004/05/10 14:40:47 ganovelli 00028 name of adhacency function updated 00029 00030 Revision 1.1 2004/05/10 14:01:56 ganovelli 00031 created 00032 00033 ****************************************************************************/ 00034 00035 00036 #ifndef __VCG_EDGE_POS 00037 #define __VCG_EDGE_POS 00038 00039 namespace vcg { 00040 namespace edge { 00041 00042 /* 00043 Vertex_Edge: run over the fan of a vertex (no order is specified) 00044 */ 00048 template <class EDGETYPE> 00049 class VertexStar 00050 { 00051 public: 00053 EDGETYPE *e; 00055 int z; 00057 VertexStar() {} 00059 VertexStar(EDGETYPE * const ep, int const zp) 00060 { 00061 e=ep; 00062 z=zp; 00063 } 00064 00066 void NextF() 00067 { 00068 EDGETYPE * t = e; 00069 e = (EDGETYPE *)t->VEp(z); 00070 z = t->VEi(z); 00071 } 00072 }; 00073 00074 00075 /* 00076 00077 */ 00082 template <class EDGETYPE> 00083 class Pos 00084 { 00085 public: 00086 00088 typedef typename EDGETYPE::VertexType VertexType; 00090 typedef Pos< EDGETYPE> POSTYPE; 00092 //typedef typename MVTYPE::coord_type vectorial_type; 00094 //typedef typename MVTYPE::scalar_type scalar_type; 00095 00097 EDGETYPE *e; 00099 VertexType *v; 00100 00102 Pos(){} 00104 Pos(EDGETYPE * const ep, int const zp, 00105 VertexType * const vp){e=ep;v=vp;} 00106 00108 inline bool operator == ( POSTYPE const & p ) const { 00109 return (e==p.e &&v==p.v); 00110 } 00111 00113 inline bool operator != ( POSTYPE const & p ) const { 00114 return (e!=p.e || v!=p.v); 00115 } 00117 inline bool operator <= ( POSTYPE const & p) const { 00118 return (e!=p.e)?(e<e.p): 00119 (v<=p.v); 00120 } 00121 00123 inline POSTYPE & operator = ( const POSTYPE & h ){ 00124 e=h.e; 00125 v=h.v; 00126 return *this; 00127 } 00129 void SetNull(){ 00130 e=0; 00131 v=0; 00132 } 00134 bool IsNull() const { 00135 return e==0 || v==0 ; 00136 } 00137 00138 //Cambia Faccia lungo z 00139 // e' uguale a FlipF solo che funziona anche per non manifold. 00141 void NextE() 00142 { 00143 FlipV(); 00144 FlipE(); 00145 } 00146 00147 // Paolo Cignoni 19/6/99 00148 // Si muove sulla faccia adiacente a f, lungo uno spigolo che 00149 // NON e' j, e che e' adiacente a v 00150 // in questo modo si scandiscono tutte le facce incidenti in un 00151 // vertice f facendo Next() finche' non si ritorna all'inizio 00152 // Nota che sul bordo rimbalza, cioe' se lo spigolo !=j e' di bordo 00153 // restituisce sempre la faccia f ma con nj che e' il nuovo spigolo di bordo 00154 // vecchi parametri: MFTYPE * & f, MVTYPE * v, int & j 00155 00156 // Cambia edge mantenendo la stessa faccia e lo stesso vertice 00158 void FlipV() 00159 { 00160 v = (e->V(0)==v)?e->V(1):e->V(0); 00161 } 00162 void FlipE() 00163 { 00164 assert( (e->V(0)==v) ||(e->V(1)==v)); 00165 e = (e->V(0)==v)?e->EEp(0):e->EEp(1); 00166 } 00167 int Z(){ 00168 return (e->V(0)==v)?0:1; 00169 } 00170 // return the vertex that it should have if we make FlipV; 00171 VertexType *VFlip() 00172 { 00173 return (e->V(0)==v)?e->V(1):e->V(0); 00174 } 00175 00176 // Trova il prossimo half-edge di bordo (nhe) 00177 // tale che 00178 // --nhe.f adiacente per vertice a he.f 00179 // --nhe.v adiacente per edge di bordo a he.v 00180 // l'idea e' che se he e' un half edge di bordo 00181 // si puo scorrere tutto un bordo facendo 00182 // 00183 // hei=he; 00184 // do 00185 // hei.Nextb() 00186 // while(hei!=he); 00187 00189 void NextB( ) 00190 { 00191 // assert(f->V((z+2)%3)!=v && (f->V((z+1)%3)==v || f->V((z+0)%3)==v)); 00192 // assert(f->F(z)==f); // f is border along j 00195 // do 00196 // NextE(); 00197 // while(!f->IsBorder(z)); 00198 // 00199 // // L'edge j e' di bordo e deve contenere v 00200 // assert(f->IsBorder(z) &&( f->V(z)==v || f->V((z+1)%3)==v )); 00201 // 00202 // FlipV(); 00203 // assert(f->V((z+2)%3)!=v && (f->V((z+1)%3)==v || f->V((z+0)%3)==v)); 00204 // assert(f->F(z)==f); // f is border along j 00205 } 00206 00208 //bool IsBorder() 00209 //{ 00210 //return f->IsBorder(z); 00211 //} 00212 00214 //int StarSize() 00215 //{ 00216 //int n=0; 00217 //POSTYPE ht=*this; 00218 //bool bf=false; 00219 //do 00220 //{ 00221 // ++n; 00222 // ht.NextE(); 00223 // if(ht.IsBorder()) bf=true; 00224 //} while(ht!=*this); 00225 00226 //if(bf) return n/2; 00227 //else return n; 00228 //} 00229 00235 void Set(EDGETYPE * const ep,VertexType * const vp) 00236 { 00237 e=ep;v=vp; 00238 } 00239 00240 void Assert() 00241 #ifdef _DEBUG 00242 {/* 00243 POSTYPE ht=*this; 00244 ht.FlipE(); 00245 ht.FlipE(); 00246 assert(ht==*this); 00247 00248 ht.FlipE(); 00249 ht.FlipE(); 00250 assert(ht==*this); 00251 00252 ht.FlipV(); 00253 ht.FlipV(); 00254 assert(ht==*this);*/ 00255 } 00256 #else 00257 {} 00258 #endif 00259 00260 // Controlla la coerenza di orientamento di un hpos con la relativa faccia 00262 //inline bool Coherent() const 00263 //{ 00264 // return v == f->V(z); // e^(ip)+1=0 ovvero E=mc^2 00265 //} 00266 00267 }; 00268 } // end namespace 00269 } // end namespace 00270 #endif