diff --git a/vcg/simplex/face/base.h b/vcg/simplex/face/base.h index fc1b1729..7d474ce1 100644 --- a/vcg/simplex/face/base.h +++ b/vcg/simplex/face/base.h @@ -71,13 +71,14 @@ we have to build the type a step a time (deriving from a single ancestor at a ti */ template class FaceBase: public face::EmptyPolyInfo< - face::EmptyVertexRef< + face::EmptyVertexRef< face::EmptyAdj< face::EmptyColorMarkQuality< face::EmptyNormal< - face::EmptyBitFlags< + face::EmptyCurvatureDir< + face::EmptyBitFlags< face::EmptyWedgeTexCoord< - FaceTypeHolder > > > > > > > { + FaceTypeHolder > > > > > > > >{ }; diff --git a/vcg/simplex/face/component.h b/vcg/simplex/face/component.h index d7a4ac58..fd7314ca 100644 --- a/vcg/simplex/face/component.h +++ b/vcg/simplex/face/component.h @@ -38,7 +38,7 @@ All the Components that can be added to a vertex should be defined in the namesp */ -/*-------------------------- VERTEX ----------------------------------------*/ +/*-------------------------- VertexRef ----------------------------------------*/ template class EmptyVertexRef: public T { public: // typedef typename T::VertexType VertexType; @@ -130,7 +130,7 @@ public: -/*-------------------------- NORMAL ----------------------------------------*/ +/*-------------------------- Normal ----------------------------------------*/ template class EmptyNormal: public T { public: @@ -297,7 +297,7 @@ template class WedgeTexCoord2d: public WedgeTexCoord & name){name.push_back(std::string("WedgeTexCoord2d"));TT::Name(name);} }; -/*------------------------- FLAGS -----------------------------------------*/ +/*------------------------- BitFlags -----------------------------------------*/ template class EmptyBitFlags: public T { public: /// Return the vector of Flags(), senza effettuare controlli sui bit @@ -331,7 +331,7 @@ private: int _flags; }; -/*-------------------------- COLOR ----------------------------------*/ +/*-------------------------- Color Mark Quality ----------------------------------*/ template class EmptyColorMarkQuality: public T { public: @@ -497,6 +497,76 @@ public: int _imark; }; +/*-------------------------- Curvature Direction ----------------------------------*/ + + template + struct CurvatureDirBaseType{ + typedef Point3 VecType; + typedef S ScalarType; + CurvatureDirBaseType () {} + Point3max_dir,min_dir; // max and min curvature direction + S k1,k2;// max and min curvature values + }; + +template class EmptyCurvatureDir: public TT { +public: + typedef CurvatureDirBaseType 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; } + template < class LeftV> + void ImportData(const LeftV & left ) { TT::ImportData( left); } + 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;} + template < class LeftV> + void ImportData(const LeftV & left ) { + if(LeftV::HasCurvatureDir()) { + PD1() = left.cPD1(); PD2() = left.cPD2(); + K1() = left.cK1(); K2() = left.cK2(); + } + TT::ImportData( left); + } + + 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/face/component_ocf.h b/vcg/simplex/face/component_ocf.h index dc9bfa8b..68e51a14 100644 --- a/vcg/simplex/face/component_ocf.h +++ b/vcg/simplex/face/component_ocf.h @@ -55,6 +55,7 @@ public: QualityEnabled=false; MarkEnabled=false; NormalEnabled=false; + CurvatureDirEnabled = false; WedgeTexEnabled=false; VFAdjacencyEnabled=false; FFAdjacencyEnabled=false; @@ -134,6 +135,7 @@ public: if (ColorEnabled) CV.push_back(vcg::Color4b(vcg::Color4b::White)); if (MarkEnabled) MV.push_back(0); if (NormalEnabled) NV.push_back(typename VALUE_TYPE::NormalType()); + if (CurvatureDirEnabled) CDV.push_back(typename VALUE_TYPE::CurvatureDirType()); if (VFAdjacencyEnabled) AV.push_back(AdjTypePack()); if (FFAdjacencyEnabled) AF.push_back(AdjTypePack()); if (WedgeTexEnabled) WTV.push_back(WedgeTexTypePack()); @@ -154,6 +156,7 @@ public: if (ColorEnabled) CV.resize(_size); if (MarkEnabled) MV.resize(_size); if (NormalEnabled) NV.resize(_size); + if (CurvatureDirEnabled)CDV.resize(_size); if (VFAdjacencyEnabled) AV.resize(_size); if (FFAdjacencyEnabled) AF.resize(_size); if (WedgeTexEnabled) WTV.resize(_size,WedgeTexTypePack()); @@ -168,8 +171,9 @@ public: if (ColorEnabled) CV.reserve(_size); if (MarkEnabled) MV.reserve(_size); if (NormalEnabled) NV.reserve(_size); + if (CurvatureDirEnabled)CDV.reserve(_size); if (VFAdjacencyEnabled) AV.reserve(_size); - if (FFAdjacencyEnabled) AF.reserve(_size); + if (FFAdjacencyEnabled) AF.reserve(_size); if (WedgeTexEnabled) WTV.reserve(_size); if (WedgeColorEnabled) WCV.reserve(_size); if (WedgeNormalEnabled) WNV.reserve(_size); @@ -198,6 +202,7 @@ void ReorderFace(std::vector &newFaceIndex ) if (ColorEnabled) assert( CV.size() == newFaceIndex.size() ); if (MarkEnabled) assert( MV.size() == newFaceIndex.size() ); if (NormalEnabled) assert( NV.size() == newFaceIndex.size() ); + if (CurvatureDirEnabled)assert(CDV.size() == newFaceIndex.size() ); if (VFAdjacencyEnabled) assert( AV.size() == newFaceIndex.size() ); if (FFAdjacencyEnabled) assert( AF.size() == newFaceIndex.size() ); if (WedgeTexEnabled) assert(WTV.size() == newFaceIndex.size() ); @@ -213,6 +218,7 @@ void ReorderFace(std::vector &newFaceIndex ) if (ColorEnabled) CV[newFaceIndex[i]] = CV[i]; if (MarkEnabled) MV[newFaceIndex[i]] = MV[i]; if (NormalEnabled) NV[newFaceIndex[i]] = NV[i]; + if (CurvatureDirEnabled) CDV[newFaceIndex[i]] = CDV[i]; if (VFAdjacencyEnabled) AV[newFaceIndex[i]] = AV[i]; if (FFAdjacencyEnabled) AF[newFaceIndex[i]] = AF[i]; if (WedgeTexEnabled) WTV[newFaceIndex[i]] = WTV[i]; @@ -225,6 +231,7 @@ void ReorderFace(std::vector &newFaceIndex ) if (ColorEnabled) CV.resize(BaseType::size()); if (MarkEnabled) MV.resize(BaseType::size()); if (NormalEnabled) NV.resize(BaseType::size()); + if (CurvatureDirEnabled) CDV.resize(BaseType::size()); if (VFAdjacencyEnabled) AV.resize(BaseType::size()); if (FFAdjacencyEnabled) AF.resize(BaseType::size()); if (WedgeTexEnabled) WTV.resize(BaseType::size()); @@ -286,7 +293,21 @@ void DisableNormal() { NormalEnabled=false; NV.clear(); } - + +bool IsCurvatureDirEnabled() const {return CurvatureDirEnabled;} +void EnableCurvatureDir() { + assert(VALUE_TYPE::HasCurvatureDirOcf()); + CurvatureDirEnabled=true; + CDV.resize((*this).size()); +} + +void DisableCurvatureDir() { + assert(VALUE_TYPE::HasCurvatureDirOcf()); + CurvatureDirEnabled=false; + CDV.clear(); +} + + bool IsVFAdjacencyEnabled() const {return VFAdjacencyEnabled;} void EnableVFAdjacency() { assert(VALUE_TYPE::HasVFAdjacencyOcf()); @@ -358,6 +379,7 @@ public: std::vector CV; std::vector MV; std::vector NV; + std::vector CDV; std::vector AV; std::vector AF; std::vector WTV; @@ -368,6 +390,7 @@ public: bool ColorEnabled; bool MarkEnabled; bool NormalEnabled; + bool CurvatureDirEnabled; bool WedgeTexEnabled; bool VFAdjacencyEnabled; bool FFAdjacencyEnabled; @@ -481,7 +504,89 @@ public: template class Normal3sOcf: public NormalOcf {}; template class Normal3fOcf: public NormalOcf {}; template class Normal3dOcf: public NormalOcf {}; - + + +/*------------------------- CurvatureDir -----------------------------------------*/ + +template +struct CurvatureDirOcfBaseType{ + typedef Point3 VecType; + typedef S ScalarType; + CurvatureDirOcfBaseType () {} + Point3max_dir,min_dir; // max and min curvature direction + S k1,k2;// max and min curvature values +}; + +template class CurvatureDirOcf: public T { +public: + typedef A CurvatureDirType; + typedef typename CurvatureDirType::VecType VecType; + typedef typename CurvatureDirType::ScalarType ScalarType; + + static bool HasCurvatureDir() { return true; } + static bool HaCurvatureDirOcf() { return true; } + + VecType &PD1(){ + assert((*this).Base().CurvatureDirEnabled); + return (*this).Base().CDV[(*this).Index()].max_dir; + } + + VecType &PD2(){ + assert((*this).Base().CurvatureDirEnabled); + return (*this).Base().CDV[(*this).Index()].min_dir; + } + + const VecType &cPD1() const { + assert((*this).Base().CurvatureDirEnabled); + return (*this).Base().CDV[(*this).Index()].max_dir; + } + + const VecType &cPD2() const { + assert((*this).Base().CurvatureDirEnabled); + return (*this).Base().CDV[(*this).Index()].min_dir; + } + + ScalarType &K1(){ + // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() + assert((*this).Base().NormalEnabled); + return (*this).Base().CDV[(*this).Index()].k1; + } + ScalarType &K2(){ + // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() + assert((*this).Base().NormalEnabled); + return (*this).Base().CDV[(*this).Index()].k2; + } + const ScalarType &cK1() const { + // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() + assert((*this).Base().NormalEnabled); + return (*this).Base().CDV[(*this).Index()].k1; + } + const ScalarType &cK2() const { + // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() + assert((*this).Base().NormalEnabled); + return (*this).Base().CDV[(*this).Index()].k2; + } + + + template + void ImportData(const LeftF & leftF){ + if((*this).Base().CurvatureDirEnabled && leftF.Base().CurvatureDirEnabled) + PD1() = leftF.cPD1(); + PD2() = leftF.cPD2(); + K1() = leftF.cK1(); + K2() = leftF.cK2(); + T::ImportData(leftF); + } + +}; + +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);} +}; + ///*-------------------------- QUALITY ----------------------------------*/ template class QualityOcf: public T { @@ -653,6 +758,7 @@ public: static bool HasFaceColorOcf() { return false; } static bool HasFaceNormalOcf() { return false; } + static bool HasFaceCurvatureDirOcf() { return false; } static bool HasFaceMarkOcf() { return false; } static bool HasWedgeTexCoordOcf() { return false; } static bool HasFFAdjacencyOcf() { return false; } @@ -700,13 +806,19 @@ public: else return FaceType::HasWedgeTexCoord(); } - template < class VertContainerType, class FaceType, class Container1, class Container2 > - bool HasPerFaceColor (const TriMesh < VertContainerType , face::vector_ocf< FaceType >, Container1, Container2 > & m) - { - if(FaceType::HasFaceColorOcf()) return m.face.IsColorEnabled(); - else return FaceType::HasFaceColor(); - } - + template < class VertContainerType, class FaceType, class Container1, class Container2 > + bool HasPerFaceColor (const TriMesh < VertContainerType , face::vector_ocf< FaceType >, Container1, Container2 > & m) + { + if(FaceType::HasFaceColorOcf()) return m.face.IsColorEnabled(); + else return FaceType::HasFaceColor(); + } + template < class VertContainerType, class FaceType, class Container1, class Container2 > + bool HasPerFaceCurvatureDir (const TriMesh < VertContainerType , face::vector_ocf< FaceType >, Container1, Container2 > & m) + { + if(FaceType::HasFaceCurvatureDirOcf()) return m.face.IsCurvatureDirEnabled(); + else return FaceType::HasFaceCurvatureDir(); + } + template < class VertContainerType, class FaceType, class Container1, class Container2 > bool HasPerFaceQuality (const TriMesh < VertContainerType , face::vector_ocf< FaceType >, Container1, Container2 > & m) {