diff --git a/vcg/simplex/edge/base.h b/vcg/simplex/edge/base.h index 5435a5e5..102f4e84 100644 --- a/vcg/simplex/edge/base.h +++ b/vcg/simplex/edge/base.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/04/26 19:04:23 ganovelli +created + ****************************************************************************/ #include @@ -38,7 +41,7 @@ namespace vcg { This is the base class for definition of a face of the mesh. @param SVTYPE (Templete Parameter) Specifies the vertex class type. */ -template > class EDGE_TYPE +template > class EDGE_TYPE { public: /// The base type of the segment @@ -347,31 +350,31 @@ const Color4b WC(const int i) const **/ //@{ -#if (defined(__VCGLIB_EDGE_EA) && defined(__VCGLIB_EDGE_EA)) +#if (defined(__VCGLIB_EDGE_EA) && defined(__VCGLIB_EDGE_SA)) #error Error: You cannot specify face-to-face and shared topology together #endif -#if (defined(__VCGLIB_EDGE_VA) && defined(__VCGLIB_EDGE_EA)) +#if (defined(__VCGLIB_EDGE_VA) && defined(__VCGLIB_EDGE_SA)) #error Error: You cannot specify vertex-face and shared topology together #endif protected: #if defined(__VCGLIB_EDGE_EA) /// Vector of face pointer, it's used to indicate the adjacency relations (defines if FACE_A is defined) - EDGE_TYPE *ss[3]; // Facce adiacenti + EDGENAME *ee[3]; // Facce adiacenti /// Index of the face in the arrival face char zs[4]; #endif #ifdef __VCGLIB_EDGE_VA ///Vettore di puntatori a faccia, utilizzato per indicare le adiacenze vertice faccia - EDGE_TYPE *sv[3]; + EDGENAME *ev[3]; char zv[3]; #endif -#ifdef __VCGLIB_EDGE_EA +#ifdef __VCGLIB_EDGE_SA ///Vettore di puntatori a faccia, utilizzato per indicare le adiacenze vertice faccia - EDGE_TYPE *ses[3]; + EDGENAME *es[3]; char zs[3]; #endif public: @@ -382,7 +385,7 @@ public: /** Return the pointer to the j-th adjacent face. @param j Index of the edge. */ - inline EDGE_TYPE * & S( const int j ) + inline EDGENAME * & E( const int j ) { assert( (_flags & DELETED) == 0 ); assert( (_flags & NOTREAD) == 0 ); @@ -390,67 +393,67 @@ public: assert(j>=0); assert(j<2); #if defined(__VCGLIB_EDGE_EA) - return ss[j]; -#elif defined(__VCGLIB_EDGE_EA) - return ses[j]; + return ee[j]; +#elif defined(__VCGLIB_EDGE_SA) + return es[j]; #else assert(0); - static EDGE_TYPE *dum=0; + static EDGENAME *dum=0; return dum; #endif } - inline const EDGE_TYPE * const & S( const int j ) const + inline const EDGENAME * const & E( const int j ) const { assert( (_flags & DELETED) == 0 ); assert( (_flags & NOTREAD) == 0 ); assert(j>=0); assert(j<2); #if defined(__VCGLIB_EDGE_EA) - return ss[j]; -#elif defined(__VCGLIB_EDGE_EA) - return ses[j]; + return ee[j]; +#elif defined(__VCGLIB_EDGE_SA) + return es[j]; #else assert(0); - return (EDGE_TYPE *)this; + return (EDGENAME *)this; #endif } - inline EDGE_TYPE * & S1( const int j ) { return F((j+1)%2);} - inline const EDGE_TYPE * const& S1( const int j ) const { return F((j+1)%2);} + inline EDGENAME * & E1( const int j ) { return F((j+1)%2);} + inline const EDGENAME * const& E1( const int j ) const { return F((j+1)%2);} /** Return the pointer to the j-th adjacent face. @param j Index of the edge. */ - inline EDGE_TYPE * & UberF( const int j ) + inline EDGENAME * & UberE( const int j ) { assert(j>=0); assert(j<2); #if defined(__VCGLIB_EDGE_EA) - return ss[j]; -#elif defined(__VCGLIB_EDGE_EA) - return ses[j]; + return ee[j]; +#elif defined(__VCGLIB_EDGE_SA) + return es[j]; #else assert(0); // if you stop here you are probably trying to use FF topology in a face without it - return *((EDGE_TYPE **)(_flags)); + return *((EDGENAME **)(_flags)); #endif } - inline const EDGE_TYPE * const & UberF( const int j ) const + inline const EDGENAME * const & UberE( const int j ) const { assert(j>=0); assert(j<2); #if defined(__VCGLIB_EDGE_EA) - return ss[j]; -#elif defined(__VCGLIB_EDGE_EA) - return ses[j]; + return ee[j]; +#elif defined(__VCGLIB_EDGE_SA) + return es[j]; #else assert(0); // if you stop here you are probably trying to use FF topology in a face without it - return *((EDGE_TYPE **)(_flags)); + return *((EDGENAME **)(_flags)); #endif } - inline EDGE_TYPE * & Fv( const int j ) + inline EDGENAME * & Ev( const int j ) { assert( (_flags & DELETED) == 0 ); assert( (_flags & NOTREAD) == 0 ); @@ -458,28 +461,28 @@ public: assert(j>=0); assert(j<2); #ifdef __VCGLIB_EDGE_VA - return sv[j]; -#elif defined(__VCGLIB_EDGE_EA) - return ses[j]; + return ev[j]; +#elif defined(__VCGLIB_EDGE_SA) + return es[j]; #else assert(0); // you are probably trying to use VF topology in a vertex without it - return *((EDGE_TYPE **)(_flags)); + return *((EDGENAME **)(_flags)); #endif } - inline const EDGE_TYPE * const & Fv( const int j ) const + inline const EDGENAME * const & Ev( const int j ) const { assert( (_flags & DELETED) == 0 ); assert( (_flags & NOTREAD) == 0 ); assert(j>=0); assert(j<2); #ifdef __VCGLIB_EDGE_VA - return sv[j]; -#elif defined(__VCGLIB_EDGE_EA) - return ses[j]; + return ev[j]; +#elif defined(__VCGLIB_EDGE_SA) + return es[j]; #else assert(0); - return (EDGE_TYPE *)this; + return (EDGENAME *)this; #endif } @@ -496,7 +499,7 @@ public: assert(j<2); #if defined(__VCGLIB_EDGE_EA) return zs[j]; -#elif defined(__VCGLIB_EDGE_EA) +#elif defined(__VCGLIB_EDGE_SA) return zs[j]; #else assert(0); @@ -512,7 +515,7 @@ public: assert(j<2); #if defined(__VCGLIB_EDGE_EA) return zs[j]; -#elif defined(__VCGLIB_EDGE_EA) +#elif defined(__VCGLIB_EDGE_SA) return zs[j]; #else assert(0); @@ -529,7 +532,7 @@ public: assert(j<2); #if defined(__VCGLIB_EDGE_EA) return zs[j]; -#elif defined(__VCGLIB_EDGE_EA) +#elif defined(__VCGLIB_EDGE_SA) return zs[j]; #else assert(0); @@ -543,7 +546,7 @@ public: assert(j<2); #if defined(__VCGLIB_EDGE_EA) return zs[j]; -#elif defined(__VCGLIB_EDGE_EA) +#elif defined(__VCGLIB_EDGE_SA) return zs[j]; #else assert(0); @@ -561,7 +564,7 @@ public: assert(j<2); #ifdef __VCGLIB_EDGE_VA return zv[j]; -#elif defined(__VCGLIB_EDGE_EA) +#elif defined(__VCGLIB_EDGE_SA) return zs[j]; #else assert(0); @@ -577,7 +580,7 @@ public: assert(j<2); #ifdef __VCGLIB_EDGE_VA return zv[j]; -#elif defined(__VCGLIB_EDGE_EA) +#elif defined(__VCGLIB_EDGE_SA) return zs[j]; #else assert(0); @@ -799,7 +802,7 @@ static bool HasEEAdjacency() { return false; #endif } -static bool HasVSAdjacency() { +static bool HasVEAdjacency() { #if (defined(__VCGLIB_EDGE_VA) || defined(__VCGLIB_EDGE_EA)) return true; #else @@ -824,7 +827,7 @@ static bool HasEdgeMark() { //@} /// operator to compare two faces - inline bool operator == ( const EDGE_TYPE & f ) const { + inline bool operator == ( const EDGENAME & f ) const { for(int i=0; i<3; ++i) if( (V(i) != f.V(0)) && (V(i) != f.V(1)) ) return false; diff --git a/vcg/simplex/edge/pos.h b/vcg/simplex/edge/pos.h new file mode 100644 index 00000000..861e3398 --- /dev/null +++ b/vcg/simplex/edge/pos.h @@ -0,0 +1,264 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ +****************************************************************************/ + + +#ifndef __VCG_EDGE_POS +#define __VCG_EDGE_POS + +namespace vcg { +namespace edge { + +/* + Vertex_Edge: run over the fan of a vertex (no order is specified) +*/ +/** Class VertexStar + @param EDGETYPE Specifies the type of the faces + */ +template +class VertexStar +{ +public: + /// Pointer to an edge + EDGETYPE *e; + /// Local index of the vertex + int z; + /// Default Constructor + VertexStar() {} + /// Constructor which associates the EdgePos elementet with a face and its edge + VertexStar(EDGETYPE * const ep, int const zp) + { + e=ep; + z=zp; + } + + /// Function to jump on the next face of the list of vertex z + void NextF() + { + EDGETYPE * t = e; + e = (EDGETYPE *)t->Ev(z); + z = t->Zv(z); + } +}; + + +/* + +*/ +/** Class Pos. + This structure is equivalent to a half-edge. + @param MFTYPE (Template-Parameter) Specifies the type of the edges + */ +template +class Pos +{ +public: + + /// The vertex type + typedef typename EDGETYPE::VertexType VertexType; + /////The HEdgePos type + typedef typename Pos< EDGETYPE> POSTYPE; + ///// The vector type + //typedef typename MVTYPE::coord_type vectorial_type; + ///// The scalar type + //typedef typename MVTYPE::scalar_type scalar_type; + + /// Pointer to the face of the half-edge + typename EDGETYPE *e; + /// Pointer to the vertex + VertexType *v; + + /// Default constructor + Pos(){} + /// Constructor which associates the half-edge elementet with a face, its edge and its vertex + Pos(EDGETYPE * const ep, int const zp, + VertexType * const vp){e=ep;v=vp;} + + /// Operator to compare two half-edge + inline bool operator == ( POSTYPE const & p ) const { + return (e==p.e &&v==p.v); + } + + /// Operator to compare two half-edge + inline bool operator != ( POSTYPE const & p ) const { + return (e!=p.e || v!=p.v); + } + /// Operator to order half-edge; it's compare at the first the face pointers, then the index of the edge and finally the vertex pointers + inline bool operator <= ( POSTYPE const & p) const { + return (e!=p.e)?(eV(0)==v)?e->V(1):e->V(0); + } + void FlipE() + { + assert( (e->V(0)==v) ||(e->V(1)==v)); + e = (e->V(0)==v)?e->E(0):e->E(1); + } + int Z(){ + return (e->V(0)==v)?0:1; + } + // return the vertex that it should have if we make FlipV; + VertexType *VFlip() + { + return (t->V(0)==v)?t->V(1):t->V(0); + } + + // Trova il prossimo half-edge di bordo (nhe) + // tale che + // --nhe.f adiacente per vertice a he.f + // --nhe.v adiacente per edge di bordo a he.v + // l'idea e' che se he e' un half edge di bordo + // si puo scorrere tutto un bordo facendo + // + // hei=he; + // do + // hei.Nextb() + // while(hei!=he); + + /// Finds the next half-edge border + void NextB( ) + { + // assert(f->V((z+2)%3)!=v && (f->V((z+1)%3)==v || f->V((z+0)%3)==v)); + // assert(f->F(z)==f); // f is border along j + //// Si deve cambiare faccia intorno allo stesso vertice v + ////finche' non si trova una faccia di bordo. + // do + // NextE(); + // while(!f->IsBorder(z)); + // + // // L'edge j e' di bordo e deve contenere v + // assert(f->IsBorder(z) &&( f->V(z)==v || f->V((z+1)%3)==v )); + // + // FlipV(); + // assert(f->V((z+2)%3)!=v && (f->V((z+1)%3)==v || f->V((z+0)%3)==v)); + // assert(f->F(z)==f); // f is border along j + } + + /// Checks if the half-edge is of border + bool IsBorder() + { + //return f->IsBorder(z); + } + + /// Return the dimension of the star + int StarSize() + { + //int n=0; + //POSTYPE ht=*this; + //bool bf=false; + //do + //{ + // ++n; + // ht.NextE(); + // if(ht.IsBorder()) bf=true; + //} while(ht!=*this); + + //if(bf) return n/2; + //else return n; + } + + /** Function to inizialize an half-edge. + @param fp Puntatore alla faccia + @param zp Indice dell'edge + @param vp Puntatore al vertice + */ + void Set(EDGETYPE * const ep,VertexType * const vp) + { + e=ep;v=vp; + } + + void Assert() + #ifdef _DEBUG + {/* + POSTYPE ht=*this; + ht.FlipE(); + ht.FlipE(); + assert(ht==*this); + + ht.FlipE(); + ht.FlipE(); + assert(ht==*this); + + ht.FlipV(); + ht.FlipV(); + assert(ht==*this);*/ + } + #else + {} + #endif + + // Controlla la coerenza di orientamento di un hpos con la relativa faccia + /// Checks the orientation coherence of a half-edge with the face + inline bool Coherent() const + { + return v == f->V(z); // e^(ip)+1=0 ovvero E=mc^2 + } + +}; + } // end namespace +} // end namespace +#endif