diff --git a/vcg/complex/algorithms/update/flag.h b/vcg/complex/algorithms/update/flag.h index 43516012..90c49ac6 100644 --- a/vcg/complex/algorithms/update/flag.h +++ b/vcg/complex/algorithms/update/flag.h @@ -192,7 +192,7 @@ public: if(!(*ti).IsD()) for(int j = 0; j < 4; ++j) { - if (tetrahedron::IsBorder(*fi,j)) (*ti).SetB(j); + if (tetrahedron::IsBorder(*ti,j)) (*ti).SetB(j); else (*ti).ClearB(j); } } diff --git a/vcg/simplex/tetrahedron/base.h b/vcg/simplex/tetrahedron/base.h index 192c1ab3..9fbd015d 100644 --- a/vcg/simplex/tetrahedron/base.h +++ b/vcg/simplex/tetrahedron/base.h @@ -44,30 +44,6 @@ added namespace vcg { /*------------------------------------------------------------------*/ -/* -The base class of all the recusive definition chain. It is just a container of the typenames of the various simplexes. -These typenames must be known form all the derived classes. -*/ - -// template -// class TetraTypeHolder{ -// public: -// typedef BVT VertexType; -// typedef typename VertexType::CoordType CoordType; -// typedef typename VertexType::ScalarType ScalarType; -// typedef BET EdgeType; -// typedef BFT FaceType; -// typedef BTT TetraType; -// typedef BVT *VertPointer; -// typedef BET *EdgePointer; -// typedef BFT *FacePointer; -// typedef BTT *TetraPointer; -// static void Name(std::vector & name){} - - -// // prot - -// }; // /* The base class form which we start to add our components. // it has the empty definition for all the standard members (coords, color flags) @@ -80,87 +56,14 @@ These typenames must be known form all the derived classes. // we have to build the type a step a time (deriving from a single ancestor at a time). -// */ -// template -// class TetraBase: public tetra::EmptyCore< -// TetraTypeHolder > { -// }; - - - -// // Metaprogramming Core - -// template class A> -// class TetraArity1: public A > {}; - -// template class A, template class B> -// class TetraArity2: public B > {}; - -// template class A, template class B, -// template class C > -// class TetraArity3: public C > {}; - -// template class A, template class B, -// template class C, template class D> -// class TetraArity4: public D > {}; - -// template class A, template class B, -// template class C, template class D, -// template class E > -// class TetraArity5: public E > {}; - -// template class A, template class B, -// template class C, template class D, -// template class E, template class F > -// class TetraArity6: public F > {}; - -// template class A, template class B, -// template class C, template class D, -// template class E, template class F, -// template class G > -// class TetraArity7: public G > {}; - -// template class A, template class B, -// template class C, template class D, -// template class E, template class F, -// template class G, template class H > -// class TetraArity8: public H > {}; - -// /* The Real Big Face class; - -// The class __FaceArityMax__ is the one that is the Last to be derived, -// and therefore is the only one to know the real members -// (after the many overrides) so all the functions with common behaviour -// using the members defined in the various Empty/nonEmpty component classes -// MUST be defined here. - -// I.e. IsD() that uses the overridden Flags() member must be defined here. - -// */ - -// template class A, template class B, -// template class C, template class D, -// template class E, template class F, -// template class G, template class H, -// template class I > -// class TetraArityMax: public I > { template class TetraTypeHolder: public UserTypes { public: - template - void ImportData(const LeftT & ){} + template + void ImportData(const RightT & ){} static void Name(std::vector & /* name */){} @@ -209,6 +112,7 @@ public: BORDER1 = 0x00000080, BORDER2 = 0x00000100, BORDER3 = 0x00000200, + BORDER0123 = BORDER0 | BORDER1 | BORDER2 | BORDER3, // Crease _flags, it is assumed that FEATUREi = FEATURE0<Flags() &= ~VISITED;} /// This function checks if the face is selected - bool IsB(int i) const {return (this->Flags() & (BORDER0<cFlags() & (BORDER0<Flags() |=(BORDER0< class A = TetraDefaultDeriver, template class B = TetraDefaultDeriver, -// template class C = TetraDefaultDeriver, template class D = TetraDefaultDeriver, -// template class E = TetraDefaultDeriver, template class F = TetraDefaultDeriver, -// template class G = TetraDefaultDeriver, template class H = TetraDefaultDeriver, -// template class I = TetraDefaultDeriver > -// class TetraSimp3: public TetraArityMax {}; -// class DumTT; -// template class A = TetraDefaultDeriver, template class B = TetraDefaultDeriver, -// template class C = TetraDefaultDeriver, template class D = TetraDefaultDeriver, -// template class E = TetraDefaultDeriver, template class F = TetraDefaultDeriver, -// template class G = TetraDefaultDeriver, template class H = TetraDefaultDeriver, -// template class I = TetraDefaultDeriver > -// class TetraSimp2: public TetraArityMax {}; - template class A = DefaultDeriver, template class B = DefaultDeriver, template class C = DefaultDeriver, template class D = DefaultDeriver, template class E = DefaultDeriver, template class F = DefaultDeriver, template class G = DefaultDeriver, template class H = DefaultDeriver, - template class I = DefaultDeriver, template class J = DefaultDeriver, - template class K = DefaultDeriver, template class L = DefaultDeriver> - class TetraSimp: public TetraArityMax { + template class I = DefaultDeriver, template class J = DefaultDeriver, + template class K = DefaultDeriver, template class L = DefaultDeriver> +class TetraSimp : public TetraArityMax { public: typedef AllTypes::ATetraType IAm; typedef UserTypes TypesPool;}; }// end namespace diff --git a/vcg/simplex/tetrahedron/component.h b/vcg/simplex/tetrahedron/component.h index 801de94e..cf93d437 100644 --- a/vcg/simplex/tetrahedron/component.h +++ b/vcg/simplex/tetrahedron/component.h @@ -8,7 +8,7 @@ * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* 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. * @@ -31,108 +31,108 @@ added ****************************************************************************/ #ifndef __VCG_TETRAHEDRON_PLUS_COMPONENT -#define __VCG_TETRAHEDRON_PLUS_COMPONENT +#define __VCG_TETRAHEDRON_PLUS_COMPONENT #include #include namespace vcg { - namespace tetrahedron { +namespace tetrahedron { /* Some naming Rules All the Components that can be added to a tetra should be defined in the namespace tetra: */ template class EmptyCore : public T { public: - //Empty vertexref - inline typename T::VertexType * & V( const int j ) { assert(0); static typename T::VertexType *vp=0; return vp; } - inline typename T::VertexType * const & V( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } - inline typename T::VertexType * const cV( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } - inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } - inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } - inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } - - static bool HasVertexRef() { return false; } - static bool HasTVAdjacency() { return false; } + //Empty vertexref + inline typename T::VertexType * & V( const int j ) { assert(0); static typename T::VertexType *vp=0; return vp; } + inline typename T::VertexType * const & V( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } + inline typename T::VertexType * const cV( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } + inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } + inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } + inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } - // //Empty normals - // typedef typename T::VertexType::NormalType NormalType; - // NormalType &N(const int & ){ static NormalType dummynormal(0, 0, 0); assert(0); return dummynormal; } - // const NormalType cN(const int & ) const { static NormalType dummynormal(0, 0, 0); assert(0); return dummynormal; } - - // static bool HasFaceNormal() { return false; } - // static bool HasFaceNormalOcc() { return false; } + static bool HasVertexRef() { return false; } + static bool HasTVAdjacency() { return false; } - //Empty color - typedef vcg::Color4b ColorType; - ColorType &C() { static ColorType dummycolor(vcg::Color4b::White); assert(0); return dummycolor; } - ColorType cC() const { static ColorType dummycolor(vcg::Color4b::White); assert(0); return dummycolor; } + // //Empty normals + // typedef typename T::VertexType::NormalType NormalType; + // NormalType &N(const int & ){ static NormalType dummynormal(0, 0, 0); assert(0); return dummynormal; } + // const NormalType cN(const int & ) const { static NormalType dummynormal(0, 0, 0); assert(0); return dummynormal; } - static bool HasColor() { return false; } - static bool IsColorEnabled() { return T::TetraType::HasColor(); } + // static bool HasFaceNormal() { return false; } + // static bool HasFaceNormalOcc() { return false; } - //Empty Quality - typedef float QualityType; - typedef vcg::Point3f Quality3Type; - QualityType &Q() { static QualityType dummyquality(0); assert(0); return dummyquality; } - QualityType cQ() const { static QualityType dummyquality(0); assert(0); return dummyquality; } - Quality3Type &Q3() { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } - Quality3Type cQ3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } + //Empty color + typedef vcg::Color4b ColorType; + ColorType &C() { static ColorType dummycolor(vcg::Color4b::White); assert(0); return dummycolor; } + ColorType cC() const { static ColorType dummycolor(vcg::Color4b::White); assert(0); return dummycolor; } - static bool HasQuality() { return false; } - static bool HasQuality3() { return false; } - inline bool IsQualityEnabled() const { return T::TetraType::HasQuality(); } - inline bool IsQuality3Enabled() const { return T::TetraType::HasQuality3(); } + static bool HasColor() { return false; } + static bool IsColorEnabled() { return T::TetraType::HasColor(); } - //Empty flags - int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } - int cFlags() const { return 0; } + //Empty Quality + typedef float QualityType; + typedef vcg::Point3f Quality3Type; + QualityType &Q() { static QualityType dummyquality(0); assert(0); return dummyquality; } + QualityType cQ() const { static QualityType dummyquality(0); assert(0); return dummyquality; } + Quality3Type &Q3() { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } + Quality3Type cQ3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } - static bool HasFlags() { return false; } - static bool HasFlagsOcc() { return false; } + static bool HasQuality() { return false; } + static bool HasQuality3() { return false; } + inline bool IsQualityEnabled() const { return T::TetraType::HasQuality(); } + inline bool IsQuality3Enabled() const { return T::TetraType::HasQuality3(); } - //Empty IMark - typedef int MarkType; + //Empty flags + int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } + int cFlags() const { return 0; } - inline void InitIMark() { } - inline int & IMark() { assert(0); static int tmp=-1; return tmp;} - inline int cIMark() const {return 0;} - - static bool HasMark() { return false; } - static bool HasMarkOcc() { return false; } - - //Empty Adjacency - typedef int VFAdjType; - typename T::TetraPointer & VTp ( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; } - typename T::TetraPointer const cVTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; } + static bool HasFlags() { return false; } + static bool HasFlagsOcc() { return false; } - typename T::TetraPointer & TTp ( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; } - typename T::TetraPointer const cTTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; } + //Empty IMark + typedef int MarkType; - char & VTi( const int j ) { static char z=0; assert(0); return z; } - char cVTi( const int j ) const { static char z=0; assert(0); return z; } - char & TTi( const int j ) { static char z=0; assert(0); return z; } - char cTTi( const int j ) const { static char z=0; assert(0); return z; } + inline void InitIMark() { } + inline int & IMark() { assert(0); static int tmp=-1; return tmp;} + inline int cIMark() const {return 0;} - bool IsVTInitialized(const int j) const {return static_cast(this)->cVTi(j)!=-1;} - void VTClear(int j) { - if(IsVTInitialized(j)) { - static_cast(this)->VTp(j)=0; - static_cast(this)->VTi(j)=-1; + static bool HasMark() { return false; } + static bool HasMarkOcc() { return false; } + + //Empty Adjacency + typedef int VFAdjType; + typename T::TetraPointer & VTp ( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; } + typename T::TetraPointer const cVTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; } + + typename T::TetraPointer & TTp ( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; } + typename T::TetraPointer const cTTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; } + + char & VTi( const int j ) { static char z=0; assert(0); return z; } + char cVTi( const int j ) const { static char z=0; assert(0); return z; } + char & TTi( const int j ) { static char z=0; assert(0); return z; } + char cTTi( const int j ) const { static char z=0; assert(0); return z; } + + bool IsVTInitialized(const int j) const {return static_cast(this)->cVTi(j)!=-1;} + void VTClear(int j) { + if(IsVTInitialized(j)) { + static_cast(this)->VTp(j)=0; + static_cast(this)->VTi(j)=-1; + } } - } - static bool HasVTAdjacency() { return false; } - static bool HasTTAdjacency() { return false; } - static bool HasTTAdjacencyOcc() { return false; } - static bool HasVTAdjacencyOcc() { return false; } + static bool HasVTAdjacency() { return false; } + static bool HasTTAdjacency() { return false; } + static bool HasTTAdjacencyOcc() { return false; } + static bool HasVTAdjacencyOcc() { return false; } - template - void ImportData(const RightValuteType & ) {} + template + void ImportData(const RightValuteType & ) {} - static void Name(std::vector & name) { T::Name(name); } + static void Name(std::vector & name) { T::Name(name); } }; -/*-------------------------- VERTEX ----------------------------------------*/ +/*-------------------------- VERTEX ----------------------------------------*/ // template class EmptyVertexRef: public T { // public: // // typedef typename T::VertexType VertexType; @@ -143,20 +143,20 @@ public: // inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } // inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } // inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } - + // static bool HasVertexRef() { return false; } // }; template class VertexRef: public T { public: - VertexRef(){ - v[0]=0; - v[1]=0; - v[2]=0; - v[3]=0; + VertexRef(){ + v[0]=0; + v[1]=0; + v[2]=0; + v[3]=0; -/******* vertex and faces indices scheme********* - * + /******* vertex and faces indices scheme********* + * * /2\` * / \ ` * / \ ` @@ -164,69 +164,69 @@ public: * / _ \ ' * / _ \ ' * /0___________1\' - * - */ - findices[0][0] = 0; findices[0][1] = 1; findices[0][2] = 2; - findices[1][0] = 0; findices[1][1] = 3; findices[1][2] = 1; - findices[2][0] = 0; findices[2][1] = 2; findices[2][2] = 3; - findices[3][0] = 1; findices[3][1] = 3; findices[3][2] = 2; - } - - typedef typename T::VertexType::CoordType CoordType; - typedef typename T::VertexType::ScalarType ScalarType; + * + */ + findices[0][0] = 0; findices[0][1] = 1; findices[0][2] = 2; + findices[1][0] = 0; findices[1][1] = 3; findices[1][2] = 1; + findices[2][0] = 0; findices[2][1] = 2; findices[2][2] = 3; + findices[3][0] = 1; findices[3][1] = 3; findices[3][2] = 2; + } - inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<4); return v[j]; } - inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<4); return v[j]; } - inline typename T::VertexType * const cV( const int j ) const { assert(j>=0 && j<4); return v[j]; } + typedef typename T::VertexType::CoordType CoordType; + typedef typename T::VertexType::ScalarType ScalarType; - inline typename size_t const cFtoVi (const int f, const int j) const { assert(f >= 0 && f < 4); assert(j >= 0 && j < 3); return findices[f][j]; } + inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<4); return v[j]; } + inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<4); return v[j]; } + inline typename T::VertexType * const cV( const int j ) const { assert(j>=0 && j<4); return v[j]; } - // Shortcut for tetra points - inline typename CoordType & P( const int j ) { assert(j>=0 && j<4); return v[j]->P(); } - inline const typename CoordType & P( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); } - inline const typename CoordType &cP( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); } + inline typename size_t const cFtoVi (const int f, const int j) const { assert(f >= 0 && f < 4); assert(j >= 0 && j < 3); return findices[f][j]; } - /** Return the pointer to the ((j+1)%4)-th vertex of the tetra. - @param j Index of the face vertex. - */ - inline typename T::VertexType * & V0( const int j ) { return V(j);} - inline typename T::VertexType * & V1( const int j ) { return V((j+1)%4);} - inline typename T::VertexType * & V2( const int j ) { return V((j+2)%4);} - inline typename T::VertexType * & V3( const int j ) { return V((j+3)%4);} - inline const typename T::VertexType * const & V0( const int j ) const { return V(j);} - inline const typename T::VertexType * const & V1( const int j ) const { return V((j+1)%4);} - inline const typename T::VertexType * const & V2( const int j ) const { return V((j+2)%4);} - inline const typename T::VertexType * const & V3( const int j ) const { return V((j+3)%4);} - inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);} - inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%4);} - inline const typename T::VertexType * const & cV2( const int j ) const { return cV((j+2)%4);} - inline const typename T::VertexType * const & cV3( const int j ) const { return cV((j+3)%4);} + // Shortcut for tetra points + inline typename CoordType & P( const int j ) { assert(j>=0 && j<4); return v[j]->P(); } + inline const typename CoordType & P( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); } + inline const typename CoordType &cP( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); } - /// Shortcut to get vertex values - inline typename CoordType &P0 (const int j) { return V(j)->P(); } - inline typename CoordType &P2 (const int j) { return V((j + 2) % 4)->P(); } - inline typename CoordType &P3 (const int j) { return V((j + 3) % 4)->P(); } - inline typename CoordType &P1 (const int j) { return V((j + 1) % 4)->P(); } - inline const typename CoordType &P0 (const int j) const { return V(j)->P(); } - inline const typename CoordType &P1 (const int j) const { return V((j + 1) % 4)->P(); } - inline const typename CoordType &P2 (const int j) const { return V((j + 2) % 4)->P(); } - inline const typename CoordType &P3 (const int j) const { return V((j + 3) % 4)->P(); } - inline const typename CoordType &cP0(const int j) const { return cV(j)->P(); } - inline const typename CoordType &cP1(const int j) const { return cV((j + 1) % 4)->P(); } - inline const typename CoordType &cP2(const int j) const { return cV((j + 2) % 4)->P(); } - inline const typename CoordType &cP3(const int j) const { return cV((j + 3) % 4)->P(); } + /** Return the pointer to the ((j+1)%4)-th vertex of the tetra. + @param j Index of the face vertex. + */ + inline typename T::VertexType * & V0( const int j ) { return V(j);} + inline typename T::VertexType * & V1( const int j ) { return V((j+1)%4);} + inline typename T::VertexType * & V2( const int j ) { return V((j+2)%4);} + inline typename T::VertexType * & V3( const int j ) { return V((j+3)%4);} + inline const typename T::VertexType * const & V0( const int j ) const { return V(j);} + inline const typename T::VertexType * const & V1( const int j ) const { return V((j+1)%4);} + inline const typename T::VertexType * const & V2( const int j ) const { return V((j+2)%4);} + inline const typename T::VertexType * const & V3( const int j ) const { return V((j+3)%4);} + inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);} + inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%4);} + inline const typename T::VertexType * const & cV2( const int j ) const { return cV((j+2)%4);} + inline const typename T::VertexType * const & cV3( const int j ) const { return cV((j+3)%4);} - static bool HasVertexRef() { return true; } - static bool HasTVAdjacency() { return true; } + /// Shortcut to get vertex values + inline typename CoordType &P0 (const int j) { return V(j)->P(); } + inline typename CoordType &P2 (const int j) { return V((j + 2) % 4)->P(); } + inline typename CoordType &P3 (const int j) { return V((j + 3) % 4)->P(); } + inline typename CoordType &P1 (const int j) { return V((j + 1) % 4)->P(); } + inline const typename CoordType &P0 (const int j) const { return V(j)->P(); } + inline const typename CoordType &P1 (const int j) const { return V((j + 1) % 4)->P(); } + inline const typename CoordType &P2 (const int j) const { return V((j + 2) % 4)->P(); } + inline const typename CoordType &P3 (const int j) const { return V((j + 3) % 4)->P(); } + inline const typename CoordType &cP0(const int j) const { return cV(j)->P(); } + inline const typename CoordType &cP1(const int j) const { return cV((j + 1) % 4)->P(); } + inline const typename CoordType &cP2(const int j) const { return cV((j + 2) % 4)->P(); } + inline const typename CoordType &cP3(const int j) const { return cV((j + 3) % 4)->P(); } - static void Name(std::vector & name){name.push_back(std::string("VertexRef"));T::Name(name);} - - template - void ImportData(const RightValueType & rTetra) { T::ImportData(rTetra); } + static bool HasVertexRef() { return true; } + static bool HasTVAdjacency() { return true; } - private: - typename T::VertexType *v[4]; - size_t findices[4][3]; + static void Name(std::vector & name){name.push_back(std::string("VertexRef"));T::Name(name);} + + template + void ImportData(const RightValueType & rTetra) { T::ImportData(rTetra); } + +private: + typename T::VertexType *v[4]; + size_t findices[4][3]; }; @@ -260,9 +260,9 @@ public: // } // static void Name(std::vector & name){name.push_back(std::string("FaceNormal"));T::Name(name);} - + // private: -// NormalType _facenormals[4]; +// NormalType _facenormals[4]; // }; //template class FaceNormal3f: public FaceNormal{ @@ -271,7 +271,7 @@ public: //template class FaceNormal3d: public FaceNormal{ //public:static void Name(std::vector & name){name.push_back(std::string("FaceNormal3d"));T::Name(name);} }; -/*------------------------- FLAGS -----------------------------------------*/ +/*------------------------- FLAGS -----------------------------------------*/ // template class EmptyBitFlags: public T { // public: // /// Return the vector of Flags(), senza effettuare controlli sui bit @@ -285,45 +285,46 @@ public: template class BitFlags: public T { public: - typedef int FlagType; - BitFlags(){_flags=0;} - int &Flags() {return _flags; } - int cFlags() const {return _flags; } - - template - void ImportData(const RightValueType & rightT){ - if(RightValueType::HasFlags()) - Flags() = rightT.cFlags(); - T::ImportData(rightT); - } - - static bool HasFlags() { return true; } - static void Name(std::vector & name){name.push_back(std::string("BitFlags"));T::Name(name);} - - -private: - int _flags; -}; - -/*-------------------------- QUALITY ----------------------------------------*/ -template class Quality: public T { -public: - typedef A QualityType; - Quality():_quality(0) {} - QualityType &Q() { return _quality; } - QualityType cQ() const { return _quality; } + typedef int FlagType; + BitFlags(){_flags=0;} + + inline int &Flags() {return _flags; } + inline int cFlags() const {return _flags; } template void ImportData(const RightValueType & rightT){ - if(rightT.IsQualityEnabled()) - Q() = rightT.cQ(); - T::ImportData(rightT); + if(RightValueType::HasFlags()) + Flags() = rightT.cFlags(); + T::ImportData(rightT); } - static bool HasQuality() { return true; } - static void Name(std::vector & name){name.push_back(std::string("Quality"));T::Name(name);} + static bool HasFlags() { return true; } + static void Name(std::vector & name){name.push_back(std::string("BitFlags"));T::Name(name);} + + private: - QualityType _quality; + int _flags; +}; + +/*-------------------------- QUALITY ----------------------------------------*/ +template class Quality: public T { +public: + typedef A QualityType; + Quality():_quality(0) {} + QualityType &Q() { return _quality; } + QualityType cQ() const { return _quality; } + + template + void ImportData(const RightValueType & rightT){ + if(rightT.IsQualityEnabled()) + Q() = rightT.cQ(); + T::ImportData(rightT); + } + + static bool HasQuality() { return true; } + static void Name(std::vector & name){name.push_back(std::string("Quality"));T::Name(name);} +private: + QualityType _quality; }; template class Qualityf: public Quality { @@ -336,19 +337,19 @@ public: static void Name(std::vector & name){name.push_back(std::s /*-------------------------- Quality3 ----------------------------------*/ template class Quality3: public T { public: - typedef vcg::Point3 Quality3Type; - Quality3Type &Q3() { return _quality; } - Quality3Type cQ3() const { return _quality; } - template - void ImportData(const RightValueType & rightT){ - if(rightT.IsQuality3Enabled()) Q3() = rightT.cQ3(); - T::ImportData(rightT); - } + typedef vcg::Point3 Quality3Type; + Quality3Type &Q3() { return _quality; } + Quality3Type cQ3() const { return _quality; } + template + void ImportData(const RightValueType & rightT){ + if(rightT.IsQuality3Enabled()) Q3() = rightT.cQ3(); + T::ImportData(rightT); + } - static bool HasQuality3() { return true; } - static void Name(std::vector & name){name.push_back(std::string("Quality3"));T::Name(name);} + static bool HasQuality3() { return true; } + static void Name(std::vector & name){name.push_back(std::string("Quality3"));T::Name(name);} private: - Quality3Type _quality; + Quality3Type _quality; }; template class Quality3f: public Quality3 { @@ -358,26 +359,26 @@ template class Quality3d: public Quality3 { public: static void Name(std::vector & name){name.push_back(std::string("Quality3d"));T::Name(name);} }; -/*-------------------------- COLOR ----------------------------------------*/ +/*-------------------------- COLOR ----------------------------------------*/ template class Color: public T { public: - typedef A ColorType; - Color():_color(vcg::Color4b::White) {} - ColorType &C() { return _color; } - ColorType cC() const { return _color; } - template - void ImportData(const RightValueType & rightT){ - if(rightT.IsColorEnabled()) C() = rightT.cC(); - T::ImportData(rightT); - } + typedef A ColorType; + Color():_color(vcg::Color4b::White) {} + ColorType &C() { return _color; } + ColorType cC() const { return _color; } + template + void ImportData(const RightValueType & rightT){ + if(rightT.IsColorEnabled()) C() = rightT.cC(); + T::ImportData(rightT); + } - static bool HasColor() { return true; } - static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} + static bool HasColor() { return true; } + static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} private: - ColorType _color; + ColorType _color; }; -/*-------------------------- INCREMENTAL MARK ----------------------------------------*/ +/*-------------------------- INCREMENTAL MARK ----------------------------------------*/ // template class EmptyMark: public T { // public: @@ -393,26 +394,26 @@ private: template class Mark: public T { public: - static bool HasMark() { return true; } - static bool HasMarkOcc() { return false; } - inline void InitIMark() { _imark = 0; } - inline int & IMark() { return _imark;} - inline int cIMark() const {return _imark;} + static bool HasMark() { return true; } + static bool HasMarkOcc() { return false; } + inline void InitIMark() { _imark = 0; } + inline int & IMark() { return _imark;} + inline int cIMark() const {return _imark;} - template - void ImportData(const RightValueType & rightT){ - if(rightT.IsMarkEnabled()) IMark() = rightT.cIMark(); - T::ImportData(rightT); - } + template + void ImportData(const RightValueType & rightT){ + if(rightT.IsMarkEnabled()) IMark() = rightT.cIMark(); + T::ImportData(rightT); + } - static void Name(std::vector & name){name.push_back(std::string("Mark"));T::Name(name);} - - private: - int _imark; + static void Name(std::vector & name){name.push_back(std::string("Mark"));T::Name(name);} + +private: + int _imark; }; -/*----------------------------- VTADJ ------------------------------*/ +/*----------------------------- VTADJ ------------------------------*/ // template class EmptyAdj: public T { // public: @@ -432,73 +433,73 @@ public: template class VTAdj: public T { public: - VTAdj() { - _vtp[0]=0; - _vtp[1]=0; - _vtp[2]=0; - _vtp[3]=0; - _vti[0]=-1; - _vti[1]=-1; - _vti[2]=-1; - _vti[3]=-1; - } + VTAdj() { + _vtp[0]=0; + _vtp[1]=0; + _vtp[2]=0; + _vtp[3]=0; + _vti[0]=-1; + _vti[1]=-1; + _vti[2]=-1; + _vti[3]=-1; + } - typename T::TetraPointer & VTp( const int j ) { assert( j >= 0 && j < 4 ); return _vtp[j]; } - typename T::TetraPointer const VTp( const int j ) const { assert( j >= 0 && j < 4 ); return _vtp[j]; } - typename T::TetraPointer const cVTp( const int j ) const { assert( j >= 0 && j < 4 ); return _vtp[j]; } - - char & VTi( const int j ) { return _vti[j]; } - const char & cVTi( const int j ) const { return _vti[j]; } - - static bool HasVTAdjacency() { return true; } - static bool HasVTAdjacencyOcc() { return false; } - - static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); } + typename T::TetraPointer & VTp( const int j ) { assert( j >= 0 && j < 4 ); return _vtp[j]; } + typename T::TetraPointer const VTp( const int j ) const { assert( j >= 0 && j < 4 ); return _vtp[j]; } + typename T::TetraPointer const cVTp( const int j ) const { assert( j >= 0 && j < 4 ); return _vtp[j]; } - template - void ImportData(const RightValueType & rightT){T::ImportData(rightT);} + char & VTi( const int j ) { return _vti[j]; } + const char & cVTi( const int j ) const { return _vti[j]; } + + static bool HasVTAdjacency() { return true; } + static bool HasVTAdjacencyOcc() { return false; } + + static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); } + + template + void ImportData(const RightValueType & rightT){T::ImportData(rightT);} private: - typename T::TetraPointer _vtp[4]; - char _vti[4]; + typename T::TetraPointer _vtp[4]; + char _vti[4]; }; -/*----------------------------- TTADJ ------------------------------*/ +/*----------------------------- TTADJ ------------------------------*/ template class TTAdj: public T { public: - TTAdj(){ - _ttp[0]=0; - _ttp[1]=0; - _ttp[2]=0; - _ttp[3]=0; - } - typename T::TetraPointer &TTp(const int j) { assert(j>=0 && j<4); return _ttp[j]; } - typename T::TetraPointer const TTp(const int j) const { assert(j>=0 && j<4); return _ttp[j]; } - typename T::TetraPointer const cTTp(const int j) const { assert(j>=0 && j<4); return _ttp[j]; } - char &TTi(const int j) { return _tti[j]; } - const char &cTTi(const int j) const { return _tti[j]; } + TTAdj(){ + _ttp[0]=0; + _ttp[1]=0; + _ttp[2]=0; + _ttp[3]=0; + } + typename T::TetraPointer &TTp(const int j) { assert(j>=0 && j<4); return _ttp[j]; } + typename T::TetraPointer const TTp(const int j) const { assert(j>=0 && j<4); return _ttp[j]; } + typename T::TetraPointer const cTTp(const int j) const { assert(j>=0 && j<4); return _ttp[j]; } + char &TTi(const int j) { return _tti[j]; } + const char &cTTi(const int j) const { return _tti[j]; } - typename T::TetraPointer &TTp1( const int j ) { return TTp((j+1)%4);} - typename T::TetraPointer &TTp2( const int j ) { return TTp((j+2)%4);} - typename T::TetraPointer &TTp3( const int j ) { return TTp((j+3)%4);} - typename T::TetraPointer const TTp1( const int j ) const { return TTp((j+1)%4);} - typename T::TetraPointer const TTp2( const int j ) const { return TTp((j+2)%4);} - typename T::TetraPointer const TTp3( const int j ) const { return TTp((j+3)%4);} + typename T::TetraPointer &TTp1( const int j ) { return TTp((j+1)%4);} + typename T::TetraPointer &TTp2( const int j ) { return TTp((j+2)%4);} + typename T::TetraPointer &TTp3( const int j ) { return TTp((j+3)%4);} + typename T::TetraPointer const TTp1( const int j ) const { return TTp((j+1)%4);} + typename T::TetraPointer const TTp2( const int j ) const { return TTp((j+2)%4);} + typename T::TetraPointer const TTp3( const int j ) const { return TTp((j+3)%4);} - bool IsBorderF(const int & i) const { assert( (i>=0) && (i < 4)); { return TTp(i) == this;}} + bool IsBorderF(const int & i) const { assert( (i>=0) && (i < 4)); { return TTp(i) == this;}} - static bool HasTTAdjacency() { return true; } - static bool HasTTAdjacencyOcc() { return false; } - static void Name(std::vector & name){name.push_back(std::string("TTAdj"));T::Name(name);} + static bool HasTTAdjacency() { return true; } + static bool HasTTAdjacencyOcc() { return false; } + static void Name(std::vector & name){name.push_back(std::string("TTAdj"));T::Name(name);} - template - void ImportData(const RightValueType & rightT){T::ImportData(rightT);} + template + void ImportData(const RightValueType & rightT){T::ImportData(rightT);} private: - typename T::TetraPointer _ttp[4] ; - char _tti[4] ; + typename T::TetraPointer _ttp[4] ; + char _tti[4] ; }; - } // end namespace vert +} // end namespace vert }// end namespace vcg #endif diff --git a/vcg/simplex/tetrahedron/topology.h b/vcg/simplex/tetrahedron/topology.h index d1c02bcb..ad774eb6 100644 --- a/vcg/simplex/tetrahedron/topology.h +++ b/vcg/simplex/tetrahedron/topology.h @@ -42,7 +42,53 @@ inline bool IsBorder(TetraType const & t, const int j ) return true; } +template +inline void TriMeshFromBorder(TetraMesh & tetramesh, TriMesh & trimesh) +{ + RequireTTAdjacency(tetramesh); + tri::UpdateTopology::TetraTetra(tetramesh); + + trimesh.Clear(); + + std::vector verts; + std::vector faces; + + ForEachTetra(tetramesh, [&] (TetraMesh::TetraType & t) { + for (int i = 0; i < 4; ++i) + if (IsBorder(t, i)) + { + verts.push_back(t.V(Tetra::VofF(i, 0))); + verts.push_back(t.V(Tetra::VofF(i, 1))); + verts.push_back(t.V(Tetra::VofF(i, 2))); + } + }); + + TriMesh::VertexIterator vi = tri::Allocator::AddVertices(trimesh, verts.size()); + TriMesh::FaceIterator fi = tri::Allocator::AddFaces(trimesh, verts.size() / 3); + + for (int i = 0; i < verts.size(); i += 3) + { + fi->Alloc(3); + + vi->P() = verts[i + 0]->P(); + fi->V(0) = &*vi; + ++vi; + + vi->P() = verts[i + 1]->P(); + fi->V(1) = &*vi; + ++vi; + + vi->P() = verts[i + 2]->P(); + fi->V(2) = &*vi; + ++vi; + + ++fi; + } + + tri::Clean::RemoveDuplicateVertex(trimesh); +} + } } -#endif \ No newline at end of file +#endif