From bd36c639238d07c13333e0e980874128c08c5b1b Mon Sep 17 00:00:00 2001 From: ganovelli Date: Mon, 17 Mar 2008 11:39:15 +0000 Subject: [PATCH] added curvature and curvatruredir (compiled .net 2005 and gcc) --- vcg/simplex/vertexplus/base.h | 45 ++++++++-- vcg/simplex/vertexplus/component.h | 107 ++++++++++++++++++++++- vcg/simplex/vertexplus/component_occ.h | 106 +++++++++++++++++++++-- vcg/simplex/vertexplus/component_ocf.h | 115 +++++++++++++++++++++++-- 4 files changed, 350 insertions(+), 23 deletions(-) diff --git a/vcg/simplex/vertexplus/base.h b/vcg/simplex/vertexplus/base.h index a07e6132..ba26f46f 100644 --- a/vcg/simplex/vertexplus/base.h +++ b/vcg/simplex/vertexplus/base.h @@ -24,6 +24,12 @@ History $Log: not supported by cvs2svn $ +Revision 1.11 2008/02/04 21:26:49 ganovelli +added ImportLocal which imports all local attributes into vertexplus and faceplus. +A local attribute is everything (N(), C(), Q()....) except pointers to other simplices +(i.e. FFAdj, VFAdj, VertexRef) which are set to NULL. +Added some function for const attributes + Revision 1.10 2007/03/12 15:37:21 tarini Texture coord name change! "TCoord" and "Texture" are BAD. "TexCoord" is GOOD. @@ -113,7 +119,9 @@ class VertexBase: public vert::EmptyTexCoord< vert::EmptyNormal< vert::EmptyBitFlags< vert::EmptyCoord< - VertexTypeHolder > > > > > > >{ + vert::EmptyCurvature< + vert::EmptyCurvatureDir< + VertexTypeHolder > > > > > > > > >{ }; // Metaprogramming Core @@ -142,12 +150,27 @@ template class C, template class D, template class E > class VertexArity5: public E > {}; + template class A, template class B, template class C, template class D, template class E, template class F > class VertexArity6: public F > {}; +template class A, template class B, + template class C, template class D, + template class E, template class F, + template class G> + class VertexArity7: 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 VertexArity8: public H > {}; + /* The Real Big Vertex class; The class __VertexArityMax__ is the one that is the Last to be derived, @@ -164,8 +187,9 @@ template class A, template class B, template class C, template class D, template class E, template class F, - template class G> -class VertexArityMax: public G > { + template class G, template class H, + template class I> +class VertexArityMax: public I > { // ----- Flags stuff ----- public: @@ -290,22 +314,25 @@ 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 > - class VertexSimp3: public VertexArityMax {}; + template class G = DefaultDeriver, template class H = DefaultDeriver, + template class I = DefaultDeriver> + class VertexSimp3: public VertexArityMax {}; 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 > - class VertexSimp2: public VertexArityMax {}; + template class G = DefaultDeriver, template class H = DefaultDeriver, + template class I = DefaultDeriver> + class VertexSimp2: public VertexArityMax {}; 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 > - class VertexSimp1: public VertexArityMax {}; + template class G = DefaultDeriver, template class H = DefaultDeriver, + template class I = DefaultDeriver> + class VertexSimp1: public VertexArityMax {}; }// end namespace #endif diff --git a/vcg/simplex/vertexplus/component.h b/vcg/simplex/vertexplus/component.h index 06787fbc..3eb659ef 100644 --- a/vcg/simplex/vertexplus/component.h +++ b/vcg/simplex/vertexplus/component.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.25 2008/02/05 10:11:34 cignoni +A small typo (a T:: instead of TT::) + Revision 1.24 2008/02/04 21:26:49 ganovelli added ImportLocal which imports all local attributes into vertexplus and faceplus. A local attribute is everything (N(), C(), Q()....) except pointers to other simplices @@ -72,7 +75,7 @@ Revision 1.11 2005/11/01 18:17:52 cignoni Added an assert(0) in all the accesses to empty components Revision 1.10 2005/10/15 16:24:10 ganovelli -Working release (compilata solo su MSVC), component_occ è migrato da component_opt +Working release (compilata solo su MSVC), component_occ � migrato da component_opt Revision 1.9 2005/10/14 13:30:07 cignoni Added constant access functions and reflective functions (HasSomething stuff) @@ -362,6 +365,108 @@ template class Qualityd: public Quality { static void Name(std::vector & name){name.push_back(std::string("Qualityd"));TT::Name(name);} }; +/*-------------------------- Curvature ----------------------------------*/ + +template class EmptyCurvature: public TT { +public: + typedef vcg::Point2 CurvatureType; + + float &H() {static float dummy = 0.f; return dummy;;} + float &K() { static float dummy = 0.f; return dummy;} + const float &cH() const {static float dummy = 0.f; return dummy;;} + const float &cK()const { static float dummy = 0.f; return dummy;} + void SetHK(const float & h,const float & k) { } + + static bool HasCurvatureOcc() { return false; } + static bool HasCurvatureOcf() { return false; } + static bool HasCurvature() { return false; } + static void Name(std::vector & name){TT::Name(name);} +}; + +template class Curvature: public TT { +public: + typedef Point2 CurvatureType; + typedef typename CurvatureType::ScalarType ScalarType; + ScalarType &H(){ return _hk[0];} + ScalarType &K(){ return _hk[1];} + const ScalarType &cH() const { return _hk[0];} + const ScalarType &cK() const { return _hk[1];} + + static bool HasCurvature() { return true; } + static void Name(std::vector & name){name.push_back(std::string("Curvature"));TT::Name(name);} + +private: + Point2 _hk; +}; + + +template class Curvaturef: public Curvature< float, T> { +public: static void Name(std::vector & name){name.push_back(std::string("Curvaturef"));T::Name(name);} +}; +template class Curvatured: public Curvature { +public: static void Name(std::vector & name){name.push_back(std::string("Curvatured"));T::Name(name);} +}; + +/*-------------------------- Curvature Direction ----------------------------------*/ + +template +struct CurvatureDirType{ + typedef Point3 VecType; + typedef S ScalarType; + CurvatureDirType () {} + Point3max_dir,min_dir; // max and min curvature direction + S k1,k2;// max and min curvature values +}; + +template class EmptyCurvatureDir: public TT { +public: + typedef CurvatureDirType CurvatureDirType; + + Point3f &PD1(){static Point3f dummy(0,0,0); return dummy;} + Point3f &PD2(){static Point3f dummy(0,0,0); return dummy;} + const Point3f &cPD1() const {static Point3f dummy(0,0,0); return dummy;} + const Point3f &cPD2()const {static Point3f dummy(0,0,0); return dummy;} + + float &K1(){ static float dummy(0);assert(0);return dummy;} + float &K2(){ static float dummy(0);assert(0);return dummy;} + const float &cK1()const { static float dummy(0);assert(0);return dummy;} + const float &cK2()const { static float dummy(0);assert(0);return dummy;} + + static bool HasCurvatureDir() { return false; } + static void Name(std::vector & name){TT::Name(name);} +}; + +template class CurvatureDir: public TT { +public: + typedef A CurvatureDirType; + typedef typename CurvatureDirType::VecType VecType; + typedef typename CurvatureDirType::ScalarType ScalarType; + + VecType &PD1(){ return _curv.max_dir;} + VecType &PD2(){ return _curv.min_dir;} + const VecType &cPD1() const {return _curv.max_dir;} + const VecType &cPD2() const {return _curv.min_dir;} + + ScalarType &K1(){ return _curv.k1;} + ScalarType &K2(){ return _curv.k2;} + const ScalarType &cK1() const {return _curv.k1;} + const ScalarType &cK2()const {return _curv.k2;} + + static bool HasCurvatureDir() { return true; } + static void Name(std::vector & name){name.push_back(std::string("CurvatureDir"));TT::Name(name);} + +private: + CurvatureDirType _curv; +}; + + +template class CurvatureDirf: public CurvatureDir, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirf"));T::Name(name);} +}; +template class CurvatureDird: public CurvatureDir, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDird"));T::Name(name);} +}; + /*----------------------------- VFADJ ------------------------------*/ diff --git a/vcg/simplex/vertexplus/component_occ.h b/vcg/simplex/vertexplus/component_occ.h index 1e2066b3..d1be3cf8 100644 --- a/vcg/simplex/vertexplus/component_occ.h +++ b/vcg/simplex/vertexplus/component_occ.h @@ -24,8 +24,11 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2007/03/12 15:37:21 tarini +Texture coord name change! "TCoord" and "Texture" are BAD. "TexCoord" is GOOD. + Revision 1.1 2005/10/15 16:24:10 ganovelli -Working release (compilata solo su MSVC), component_occ è migrato da component_opt +Working release (compilata solo su MSVC), component_occ � migrato da component_opt @@ -51,6 +54,7 @@ template class CoordOcc: public T { public: typedef A CoordType; typedef typename CoordType::ScalarType ScalarType; + typedef typename T::VertType VertType; CoordType &P() { return CAT< vector_occ,CoordType>::Instance()->Get((VertType*)this); } CoordType &UberP() { return CAT< vector_occ,CoordType>::Instance()->Get((VertType*)this); } }; @@ -63,6 +67,7 @@ template class Coord3dOcc: public CoordOcc {}; template class NormalOcc: public T { public: typedef A NormalType; + typedef typename T::VertType VertType; NormalType &N() {return CAT< vector_occ,NormalType>::Instance()->Get((VertType*)this); } /*private: NormalType _norm; */ @@ -74,11 +79,13 @@ template class Normal3dOcc: public NormalOcc {}; /*-------------------------- TEXCOORD ----------------------------------------*/ -template class TexCoordOcc: public T { +template class TexCoordOcc: public TT { public: typedef A TexCoordType; + typedef typename TT::VertType VertType; TexCoordType &T() {return CAT< vector_occ,TexCoordType>::Instance()->Get((VertType*)this); } static bool HasTexCoord() { return true; } + static bool HasTexCoordOcc() { return true; } /* private: TexCoordType _t; */ @@ -92,11 +99,13 @@ template class TexCoord2dOcc: public TexCoordOcc, template class FlagOcc: public T { public: + typedef typename T::VertType VertType; int &Flags() {return CAT< vector_occ,int>::Instance()->Get((VertType*)this); } - const int Flags() const {return _flags; } -/* -private: - int _flags; */ + const int Flags() const {return CAT< vector_occ,int>::Instance()->Get((VertType*)this); } + static bool HasFlags() {return true;} + static bool HasFlagsOcc() {return true;} + + }; ///*-------------------------- COLOR ----------------------------------*/ @@ -104,6 +113,7 @@ private: template class ColorOcc: public T { public: typedef A ColorType; + typedef typename T::VertType VertType; ColorType &C() { return CAT< vector_occ,ColorType>::Instance()->Get((VertType*)this); } static bool HasColor() { return true; } /*private: @@ -117,6 +127,7 @@ template class Color4bOcc: public ColorOcc {}; template class QualityOcc: public T { public: typedef A QualityType; + typedef typename T::VertType VertType; QualityType &Q() { return CAT< vector_occ,QualityType>::Instance()->Get((VertType*)this);} static bool HasQuality() { return true; } @@ -128,11 +139,92 @@ template class QualitysOcc: public QualityOcc {}; template class QualityfOcc: public QualityOcc {}; template class QualitydOcc: public QualityOcc {}; // + +///*-------------------------- Curvature ----------------------------------*/ + +template class CurvatureOcc: public TT { +public: + typedef Point2 CurvatureTypeOcc; + typedef typename TT::VertType VertType; + typedef typename CurvatureTypeOcc::ScalarType ScalarType; + + ScalarType &H(){ return CAT< vector_occ,CurvatureTypeOcc>::Instance()->Get((VertType*)this)[0];} + ScalarType &K(){ return CAT< vector_occ,CurvatureTypeOcc>::Instance()->Get((VertType*)this)[1];} + const ScalarType &cH() const { return CAT< vector_occ,CurvatureTypeOcc>::Instance()->Get((VertType*)this)[0];} + const ScalarType &cK() const { return CAT< vector_occ,CurvatureTypeOcc>::Instance()->Get((VertType*)this)[1];} + + template + void ImportLocal(const LeftV & leftV){ + CAT< vector_occ,CurvatureTypeOcc>::Instance()->Get((VertType*)this)[0] = leftV.cH(); + CAT< vector_occ,CurvatureTypeOcc>::Instance()->Get((VertType*)this)[1] = leftV.cK(); + TT::ImporLocal(leftV); + } + + static bool HasCurvature() { return true; } + static bool HasCurvatureOcc() { return true; } + static void Name(std::vector & name){name.push_back(std::string("CurvatureOcc"));TT::Name(name);} + +private: +}; + +template class CurvaturefOcc: public CurvatureOcc { + static void Name(std::vector & name){name.push_back(std::string("CurvaturefOcc"));T::Name(name);} +}; +template class CurvaturedOcc: public CurvatureOcc { + static void Name(std::vector & name){name.push_back(std::string("CurvaturedOcc"));T::Name(name);} +}; + + +/*-------------------------- Curvature Direction ----------------------------------*/ + +template +struct CurvatureDirTypeOcc{ + typedef Point3 VecType; + typedef S ScalarType; + CurvatureDirTypeOcc () {} + Point3max_dir,min_dir; // max and min curvature direction + S k1,k2;// max and min curvature values +}; + + +template class CurvatureDirOcc: public TT { +public: + typedef A CurvatureDirTypeOcc; + typedef typename CurvatureDirTypeOcc::VecType VecType; + typedef typename CurvatureDirTypeOcc::ScalarType ScalarType; + typedef typename TT::VertType VertType; + + VecType &PD1(){ return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).max_dir;} + VecType &PD2(){ return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).min_dir;} + const VecType &cPD1() const {return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).max_dir;} + const VecType &cPD2() const {return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).min_dir;} + + ScalarType &K1(){ return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).k1;} + ScalarType &K2(){ return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).k2;} + const ScalarType &cK1() const {return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).k1;} + const ScalarType &cK2()const {return CAT< vector_occ,CurvatureDirTypeOcc>::Instance()->Get((VertType*)this).k2;} + + static bool HasCurvatureDir() { return true; } + static bool HasCurvatureDirOcc() { return true; } + static void Name(std::vector & name){name.push_back(std::string("CurvatureDir"));TT::Name(name);} + +}; + + +template class CurvatureDirfOcc: public CurvatureDirOcc, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirf"));T::Name(name);} +}; +template class CurvatureDirdOcc: public CurvatureDirOcc, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDird"));T::Name(name);} +}; + ///*----------------------------- VFADJ ------------------------------*/ template class VFAdjOcc: public T { public: - typename T::FacePointer &Fp() {return CAT< vector_occ,T::FacePointer>::Instance()->Get((VertType*)this); } + typedef typename T::VertType VertType; + typedef typename T::FacePointer FacePointer; + FacePointer &Fp() {return CAT< vector_occ,FacePointer>::Instance()->Get((VertType*)this); } int &Zp() {return _zp; } static bool HasVFAdjacency() { return true; } private: diff --git a/vcg/simplex/vertexplus/component_ocf.h b/vcg/simplex/vertexplus/component_ocf.h index 7e598d90..05b8c960 100644 --- a/vcg/simplex/vertexplus/component_ocf.h +++ b/vcg/simplex/vertexplus/component_ocf.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.14 2008/03/11 09:22:07 cignoni +Completed the garbage collecting functions CompactVertexVector and CompactFaceVector. + Revision 1.13 2008/02/05 20:42:43 cignoni Other small typos @@ -103,6 +106,8 @@ public: ColorEnabled=false; NormalEnabled=false; VFAdjacencyEnabled=false; + CurvatureEnabled = false; + } // override di tutte le funzioni che possono spostare @@ -215,6 +220,30 @@ void DisableVFAdjacency() { AV.clear(); } + +void EnableCurvature() { + assert(VALUE_TYPE::HasCurvatureOcf()); + CurvatureEnabled=true; + CuV.resize((*this).size()); +} + +void DisableCurvature() { + assert(VALUE_TYPE::HasCurvatureOcf()); + CurvatureEnabled=false; + CuV.clear(); +} + +void EnableCurvatureDir() { + assert(VALUE_TYPE::HasCurvatureDirOcf()); + CurvatureDirEnabled=true; + CuDV.resize((*this).size()); +} + +void DisableCurvatureDir() { + assert(VALUE_TYPE::HasCurvatureDirOcf()); + CurvatureDirEnabled=false; + CuDV.clear(); +} @@ -225,6 +254,8 @@ struct VFAdjType { public: std::vector QV; + std::vector CuV; + std::vector CuDV; std::vector CV; std::vector NV; std::vector AV; @@ -233,6 +264,9 @@ public: bool ColorEnabled; bool NormalEnabled; bool VFAdjacencyEnabled; + bool CurvatureEnabled; + bool CurvatureDirEnabled; + }; @@ -246,17 +280,17 @@ template class VFAdjOcf: public T { public: typename T::FacePointer &VFp() { assert((*this).Base().VFAdjacencyEnabled); - return (*this).Base().AV[(*this).Index()()]._fp; + return (*this).Base().AV[(*this).Index()]._fp; } typename T::FacePointer cVFp() const { if(! (*this).Base().VFAdjacencyEnabled ) return 0; - else return (*this).Base().AV[(*this).Index()()]._fp; + else return (*this).Base().AV[(*this).Index()]._fp; } int &VFi() { assert((*this).Base().VFAdjacencyEnabled); - return (*this).Base().AV[(*this).Index()()]._zp; + return (*this).Base().AV[(*this).Index()]._zp; } template void ImportLocal(const LeftV & leftV){VFp() = NULL; VFi() = -1; T::ImporLocal(leftV);} @@ -297,8 +331,8 @@ template class Normal3dOcf: public NormalOcf {}; template class ColorOcf: public T { public: typedef A ColorType; - ColorType &C() { assert((*this).Base().NormalEnabled); return (*this).Base().CV[(*this).Index()()]; } - const ColorType &cC() const { assert((*this).Base().NormalEnabled); return (*this).Base().CV[(*this).Index()()]; } + ColorType &C() { assert((*this).Base().NormalEnabled); return (*this).Base().CV[(*this).Index()]; } + const ColorType &cC() const { assert((*this).Base().NormalEnabled); return (*this).Base().CV[(*this).Index()]; } template void ImportLocal(const LeftV & leftV){ C() = leftV.cC(); T::ImporLocal(leftV);} static bool HasColor() { return true; } @@ -312,7 +346,7 @@ template class Color4bOcf: public ColorOcf {}; template class QualityOcf: public T { public: typedef A QualityType; - QualityType &Q() { assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()()]; } + QualityType &Q() { assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()]; } template void ImportLocal(const LeftV & leftV){ Q() = leftV.cQ(); T::ImporLocal(leftV);} static bool HasQuality() { return true; } @@ -322,6 +356,75 @@ public: template class QualityfOcf: public QualityOcf {}; +///*-------------------------- CURVATURE ----------------------------------*/ + +template class CurvatureOcf: public TT { +public: + typedef Point2 CurvatureType; + typedef typename CurvatureType::ScalarType ScalarType; + + ScalarType &H(){ assert((*this).Base().CurvatureEnabled); return (*this).Base().CuV[(*this).Index()][0];} + ScalarType &K(){ assert((*this).Base().CurvatureEnabled); return (*this).Base().CuV[(*this).Index()][1];} + const ScalarType &cH() const { assert((*this).Base().CurvatureEnabled); return (*this).Base().CuV[(*this).Index()][0];} + const ScalarType &cK() const { assert((*this).Base().CurvatureEnabled); return (*this).Base().CuV[(*this).Index()][1];} + + template + void ImportLocal(const LeftV & leftV){ +(*this).Base().CuV[(*this).Index()][0] = leftV.cH(); +(*this).Base().CuV[(*this).Index()][1] = leftV.cK(); TT::ImporLocal(leftV);} + + static bool HasCurvatureOcf() { return true; } + static void Name(std::vector & name){name.push_back(std::string("CurvatureOcf"));TT::Name(name);} + +private: +}; + +template class CurvaturefOcf: public CurvatureOcf {}; +template class CurvaturedOcf: public CurvatureOcf {}; + + +///*-------------------------- CURVATURE DIR ----------------------------------*/ + +template +struct CurvatureDirTypeOcf{ + typedef Point3 VecType; + typedef S ScalarType; + CurvatureDirTypeOcf () {} + Point3max_dir,min_dir; + S k1,k2; +}; + + +template class CurvatureDirOcf: public TT { +public: + typedef A CurvatureDirType; + typedef typename CurvatureDirType::VecType VecType; + typedef typename CurvatureDirType::ScalarType ScalarType; + + VecType &PD1(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].max_dir;} + VecType &PD2(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].max_dir;} + const VecType &cPD1() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuV[(*this).Index()].max_dir;} + const VecType &cPD2() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuV[(*this).Index()].max_dir;} + + ScalarType &K1(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k1;} + ScalarType &K2(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k2;} + const ScalarType &cK1() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k1;} + const ScalarType &cK2()const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k2;} + + static bool HasCurvatureDirOcf() { return true; } + static void Name(std::vector & name){name.push_back(std::string("CurvatureDirOcf"));TT::Name(name);} + +private: + CurvatureDirType _curv; +}; + + +template class CurvatureDirfOcf: public CurvatureDirOcf, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirfOcf"));T::Name(name);} +}; +template class CurvatureDirdOcf: public CurvatureDirOcf, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirdOcf"));T::Name(name);} +}; ///*-------------------------- InfoOpt ----------------------------------*/ template < class T> class InfoOcf: public T {