From a88ee5b2443f8d44d1658358567883a5ea815a82 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 23 Jun 2009 20:45:44 +0000 Subject: [PATCH] Added ocf management of per vertex texture coord --- vcg/simplex/vertex/component.h | 1 + vcg/simplex/vertex/component_ocf.h | 55 ++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index 347af04f..02515a02 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -228,6 +228,7 @@ template class EmptyTexCoord: public TT { public: typedef vcg::TexCoord2 TexCoordType; TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } + const TexCoordType &cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } template < class LeftV> void ImportLocal(const LeftV & left ) { TT::ImportLocal( left); } static bool HasTexCoord() { return false; } diff --git a/vcg/simplex/vertex/component_ocf.h b/vcg/simplex/vertex/component_ocf.h index cfcedb68..76b1fe80 100644 --- a/vcg/simplex/vertex/component_ocf.h +++ b/vcg/simplex/vertex/component_ocf.h @@ -176,13 +176,14 @@ public: void ReorderVert(std::vector &newVertIndex ) { size_t i=0; - if (ColorEnabled) assert( CV.size() == newVertIndex.size() ); - if (MarkEnabled) assert( MV.size() == newVertIndex.size() ); - if (NormalEnabled) assert( NV.size() == newVertIndex.size() ); - if (VFAdjacencyEnabled) assert( AV.size() == newVertIndex.size() ); - if (CurvatureEnabled) assert(CuV.size() == newVertIndex.size() ); - if (CurvatureDirEnabled)assert(CuDV.size() == newVertIndex.size() ); - assert( (!RadiusEnabled) || RadiusV.size() == newVertIndex.size() ); + assert( (!ColorEnabled) || ( CV.size() == newVertIndex.size() ) ); + assert( (!MarkEnabled) || ( MV.size() == newVertIndex.size() ) ); + assert( (!NormalEnabled) || ( NV.size() == newVertIndex.size() ) ); + assert( (!VFAdjacencyEnabled) || ( AV.size() == newVertIndex.size() ) ); + assert( (!CurvatureEnabled) || ( CuV.size() == newVertIndex.size() ) ); + assert( (!CurvatureDirEnabled) || ( CuDV.size() == newVertIndex.size() ) ); + assert( (!RadiusEnabled) || ( RadiusV.size() == newVertIndex.size() ) ); + assert( (!TexCoordEnabled) || ( TV.size() == newVertIndex.size() ) ); for(i=0;i &newVertIndex ) if (CurvatureEnabled) CuV[newVertIndex[i]] = CuV[i]; if (CurvatureDirEnabled) CuDV[newVertIndex[i]] =CuDV[i]; if (RadiusEnabled) RadiusV[newVertIndex[i]] = RadiusV[i]; + if (TexCoordEnabled) TV[newVertIndex[i]] = TV[i]; } } @@ -206,6 +208,7 @@ void ReorderVert(std::vector &newVertIndex ) if (CurvatureEnabled) CuV.resize(BaseType::size()); if (CurvatureDirEnabled) CuDV.resize(BaseType::size()); if (RadiusEnabled) RadiusV.resize(BaseType::size()); + if (TexCoordEnabled) TV.resize(BaseType::size()); } @@ -316,6 +319,19 @@ void DisableRadius() { RadiusV.clear(); } + +bool IsTexCoordEnabled() const {return TexCoordEnabled;} +void EnableTexCoord() { + assert(VALUE_TYPE::HasTexCoordOcf()); + TexCoordEnabled=true; + TV.resize((*this).size()); +} + +void DisableTexCoord() { + assert(VALUE_TYPE::HasTexCoordOcf()); + TexCoordEnabled=false; + TV.clear(); +} struct VFAdjType { typename VALUE_TYPE::FacePointer _fp ; int _zp ; @@ -328,12 +344,14 @@ public: std::vector RadiusV; std::vector CV; std::vector NV; + std::vector TV; std::vector AV; std::vector MV; bool QualityEnabled; bool ColorEnabled; bool NormalEnabled; + bool TexCoordEnabled; bool VFAdjacencyEnabled; bool CurvatureEnabled; bool CurvatureDirEnabled; @@ -449,6 +467,28 @@ public: template class QualityfOcf: public QualityOcf {}; + +///*-------------------------- TEXTURE ----------------------------------*/ + +template class TexCoordOcf: public TT { +public: + typedef A TexCoordType; + TexCoordType &T() { assert((*this).Base().TexCoordEnabled); return (*this).Base().TV[(*this).Index()]; } + const TexCoordType &cT() const { assert((*this).Base().TexCoordEnabled); return (*this).Base().TV[(*this).Index()]; } + template < class LeftV> + void ImportLocal(const LeftV & leftV) + { + //if((*this).Base().TexCoordEnabled && leftV.Base().TexCoordEnabled ) // WRONG I do not know anything about leftV! + if((*this).Base().TexCoordEnabled) // copy the data only if they are enabled in both vertices + T() = leftV.cT(); + TT::ImportLocal(leftV); + } + static bool HasTexCoord() { return true; } + static bool HasTexCoordOcf() { assert(!TT::HasTexCoordOcf()); return true; } +}; + +template class TexCoordfOcf: public TexCoordOcf, T> {}; + ///*-------------------------- MARK ----------------------------------*/ template class MarkOcf: public T { @@ -598,6 +638,7 @@ public: vector_ocf *_ovp; static bool HasQualityOcf() { return false; } + static bool HasTexCoordOcf() { return false; } static bool HasVFAdjacencyOcf() { return false; } };