Added zero initialization to quality component. (and corrected a small bug in the ocf quality component)

This commit is contained in:
Paolo Cignoni 2013-09-24 13:55:23 +00:00
parent eeccd23f71
commit df97ef0c36
4 changed files with 106 additions and 100 deletions

View File

@ -400,6 +400,7 @@ public: static void Name(std::vector<std::string> & name){name.push_back(std::st
template <class A, class T> class Quality: public T { template <class A, class T> class Quality: public T {
public: public:
typedef A QualityType; typedef A QualityType;
Quality():_quality(0) {}
QualityType &Q() { return _quality; } QualityType &Q() { return _quality; }
QualityType cQ() const { return _quality; } QualityType cQ() const { return _quality; }
template <class RightValueType> template <class RightValueType>

View File

@ -36,7 +36,7 @@ All the Components that can be added to a faceex should be defined in the namesp
template <class VALUE_TYPE> template <class VALUE_TYPE>
class vector_ocf: public std::vector<VALUE_TYPE> { class vector_ocf: public std::vector<VALUE_TYPE> {
typedef std::vector<VALUE_TYPE> BaseType; typedef std::vector<VALUE_TYPE> BaseType;
typedef typename vector_ocf<VALUE_TYPE>::iterator ThisTypeIterator; typedef typename vector_ocf<VALUE_TYPE>::iterator ThisTypeIterator;
public: public:
vector_ocf():std::vector<VALUE_TYPE>() vector_ocf():std::vector<VALUE_TYPE>()
@ -62,9 +62,9 @@ struct AdjTypePack {
// Needed because we need to know if adjacency is initialized or not // Needed because we need to know if adjacency is initialized or not
// when resizing vectors and during an allocate face. // when resizing vectors and during an allocate face.
AdjTypePack() { AdjTypePack() {
_fp[0]=0; _fp[0]=0;
_fp[1]=0; _fp[1]=0;
_fp[2]=0; _fp[2]=0;
} }
}; };
@ -87,13 +87,13 @@ class WedgeColorTypePack {
public: public:
WedgeColorTypePack() { WedgeColorTypePack() {
typedef typename VALUE_TYPE::ColorType::ScalarType WedgeColorScalarType; typedef typename VALUE_TYPE::ColorType::ScalarType WedgeColorScalarType;
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
{ {
wc[i][0] = WedgeColorScalarType(255); wc[i][0] = WedgeColorScalarType(255);
wc[i][1] = WedgeColorScalarType(255); wc[i][1] = WedgeColorScalarType(255);
wc[i][2] = WedgeColorScalarType(255); wc[i][2] = WedgeColorScalarType(255);
wc[i][3] = WedgeColorScalarType(255); wc[i][3] = WedgeColorScalarType(255);
} }
} }
typename VALUE_TYPE::ColorType wc[3]; typename VALUE_TYPE::ColorType wc[3];
@ -103,12 +103,12 @@ class WedgeNormalTypePack {
public: public:
WedgeNormalTypePack() { WedgeNormalTypePack() {
typedef typename VALUE_TYPE::NormalType::ScalarType WedgeNormalScalarType; typedef typename VALUE_TYPE::NormalType::ScalarType WedgeNormalScalarType;
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
{ {
wn[i][0] = WedgeNormalScalarType(0); wn[i][0] = WedgeNormalScalarType(0);
wn[i][1] = WedgeNormalScalarType(0); wn[i][1] = WedgeNormalScalarType(0);
wn[i][2] = WedgeNormalScalarType(1); wn[i][2] = WedgeNormalScalarType(1);
} }
} }
typename VALUE_TYPE::NormalType wn[3]; typename VALUE_TYPE::NormalType wn[3];
@ -121,55 +121,55 @@ public:
void push_back(const VALUE_TYPE & v) void push_back(const VALUE_TYPE & v)
{ {
BaseType::push_back(v); BaseType::push_back(v);
BaseType::back()._ovp = this; BaseType::back()._ovp = this;
if (QualityEnabled) QV.push_back(0); if (QualityEnabled) QV.push_back(0);
if (_ColorEnabled) CV.push_back(vcg::Color4b(vcg::Color4b::White)); if (_ColorEnabled) CV.push_back(vcg::Color4b(vcg::Color4b::White));
if (MarkEnabled) MV.push_back(0); if (MarkEnabled) MV.push_back(0);
if (NormalEnabled) NV.push_back(typename VALUE_TYPE::NormalType()); if (NormalEnabled) NV.push_back(typename VALUE_TYPE::NormalType());
if (CurvatureDirEnabled) CDV.push_back(typename VALUE_TYPE::CurvatureDirType()); if (CurvatureDirEnabled) CDV.push_back(typename VALUE_TYPE::CurvatureDirType());
if (VFAdjacencyEnabled) AV.push_back(AdjTypePack()); if (VFAdjacencyEnabled) AV.push_back(AdjTypePack());
if (FFAdjacencyEnabled) AF.push_back(AdjTypePack()); if (FFAdjacencyEnabled) AF.push_back(AdjTypePack());
if (WedgeTexEnabled) WTV.push_back(WedgeTexTypePack()); if (WedgeTexEnabled) WTV.push_back(WedgeTexTypePack());
if (WedgeColorEnabled) WCV.push_back(WedgeColorTypePack()); if (WedgeColorEnabled) WCV.push_back(WedgeColorTypePack());
if (WedgeNormalEnabled) WNV.push_back(WedgeNormalTypePack()); if (WedgeNormalEnabled) WNV.push_back(WedgeNormalTypePack());
} }
void pop_back(); void pop_back();
void resize(const unsigned int & _size) void resize(const unsigned int & _size)
{ {
unsigned int oldsize = BaseType::size(); unsigned int oldsize = BaseType::size();
BaseType::resize(_size); BaseType::resize(_size);
if(oldsize<_size){ if(oldsize<_size){
ThisTypeIterator firstnew = BaseType::begin(); ThisTypeIterator firstnew = BaseType::begin();
advance(firstnew,oldsize); advance(firstnew,oldsize);
_updateOVP(firstnew,(*this).end()); _updateOVP(firstnew,(*this).end());
} }
if (QualityEnabled) QV.resize(_size); if (QualityEnabled) QV.resize(_size,0);
if (_ColorEnabled) CV.resize(_size); if (_ColorEnabled) CV.resize(_size);
if (MarkEnabled) MV.resize(_size); if (MarkEnabled) MV.resize(_size);
if (NormalEnabled) NV.resize(_size); if (NormalEnabled) NV.resize(_size);
if (CurvatureDirEnabled)CDV.resize(_size); if (CurvatureDirEnabled)CDV.resize(_size);
if (VFAdjacencyEnabled) AV.resize(_size); if (VFAdjacencyEnabled) AV.resize(_size);
if (FFAdjacencyEnabled) AF.resize(_size); if (FFAdjacencyEnabled) AF.resize(_size);
if (WedgeTexEnabled) WTV.resize(_size,WedgeTexTypePack()); if (WedgeTexEnabled) WTV.resize(_size,WedgeTexTypePack());
if (WedgeColorEnabled) WCV.resize(_size); if (WedgeColorEnabled) WCV.resize(_size);
if (WedgeNormalEnabled) WNV.resize(_size); if (WedgeNormalEnabled) WNV.resize(_size);
} }
void reserve(const unsigned int & _size) void reserve(const unsigned int & _size)
{ {
BaseType::reserve(_size); BaseType::reserve(_size);
if (QualityEnabled) QV.reserve(_size); if (QualityEnabled) QV.reserve(_size);
if (_ColorEnabled) CV.reserve(_size); if (_ColorEnabled) CV.reserve(_size);
if (MarkEnabled) MV.reserve(_size); if (MarkEnabled) MV.reserve(_size);
if (NormalEnabled) NV.reserve(_size); if (NormalEnabled) NV.reserve(_size);
if (CurvatureDirEnabled)CDV.reserve(_size); if (CurvatureDirEnabled)CDV.reserve(_size);
if (VFAdjacencyEnabled) AV.reserve(_size); if (VFAdjacencyEnabled) AV.reserve(_size);
if (FFAdjacencyEnabled) AF.reserve(_size); if (FFAdjacencyEnabled) AF.reserve(_size);
if (WedgeTexEnabled) WTV.reserve(_size); if (WedgeTexEnabled) WTV.reserve(_size);
if (WedgeColorEnabled) WCV.reserve(_size); if (WedgeColorEnabled) WCV.reserve(_size);
if (WedgeNormalEnabled) WNV.reserve(_size); if (WedgeNormalEnabled) WNV.reserve(_size);
if( BaseType::empty()) return ; if( BaseType::empty()) return ;
ThisTypeIterator oldbegin=(*this).begin(); ThisTypeIterator oldbegin=(*this).begin();
if(oldbegin!=(*this).begin()) _updateOVP((*this).begin(),(*this).end()); if(oldbegin!=(*this).begin()) _updateOVP((*this).begin(),(*this).end());
@ -218,8 +218,8 @@ void ReorderFace(std::vector<size_t> &newFaceIndex )
} }
} }
if (QualityEnabled) QV.resize(BaseType::size()); if (QualityEnabled) QV.resize(BaseType::size(),0);
if (_ColorEnabled) CV.resize(BaseType::size()); if (_ColorEnabled) CV.resize(BaseType::size());
if (MarkEnabled) MV.resize(BaseType::size()); if (MarkEnabled) MV.resize(BaseType::size());
if (NormalEnabled) NV.resize(BaseType::size()); if (NormalEnabled) NV.resize(BaseType::size());
if (CurvatureDirEnabled) CDV.resize(BaseType::size()); if (CurvatureDirEnabled) CDV.resize(BaseType::size());
@ -237,7 +237,7 @@ bool IsQualityEnabled() const {return QualityEnabled;}
void EnableQuality() { void EnableQuality() {
assert(VALUE_TYPE::HasQualityOcf()); assert(VALUE_TYPE::HasQualityOcf());
QualityEnabled=true; QualityEnabled=true;
QV.resize((*this).size()); QV.resize((*this).size(),0);
} }
void DisableQuality() { void DisableQuality() {

View File

@ -332,6 +332,8 @@ The Quality Component is a generic place for storing a float. The term 'quality'
template <class A, class TT> class Quality: public TT { template <class A, class TT> class Quality: public TT {
public: public:
typedef A QualityType; typedef A QualityType;
Quality():_quality(0) {}
inline const QualityType &Q() const { return _quality; } inline const QualityType &Q() const { return _quality; }
inline QualityType &Q() { return _quality; } inline QualityType &Q() { return _quality; }
inline QualityType cQ() const {return _quality; } inline QualityType cQ() const {return _quality; }

View File

@ -63,20 +63,21 @@ public:
// All the standard methods of std::vector that can change the reallocation are // All the standard methods of std::vector that can change the reallocation are
// redefined in order to manage the additional data. // redefined in order to manage the additional data.
void push_back(const VALUE_TYPE & v) void push_back(const VALUE_TYPE & v)
{ {
BaseType::push_back(v); BaseType::push_back(v);
BaseType::back()._ovp = this; BaseType::back()._ovp = this;
if (ColorEnabled) CV.push_back(vcg::Color4b(vcg::Color4b::White)); if (ColorEnabled) CV.push_back(vcg::Color4b(vcg::Color4b::White));
if (MarkEnabled) MV.push_back(0); if (QualityEnabled) QV.push_back(0);
if (NormalEnabled) NV.push_back(typename VALUE_TYPE::NormalType()); if (MarkEnabled) MV.push_back(0);
if (TexCoordEnabled) TV.push_back(typename VALUE_TYPE::TexCoordType()); if (NormalEnabled) NV.push_back(typename VALUE_TYPE::NormalType());
if (VFAdjacencyEnabled) AV.push_back(VFAdjType()); if (TexCoordEnabled) TV.push_back(typename VALUE_TYPE::TexCoordType());
if (CurvatureEnabled) CuV.push_back(typename VALUE_TYPE::CurvatureType()); if (VFAdjacencyEnabled) AV.push_back(VFAdjType());
if (CurvatureDirEnabled) CuDV.push_back(typename VALUE_TYPE::CurvatureDirType()); if (CurvatureEnabled) CuV.push_back(typename VALUE_TYPE::CurvatureType());
if (RadiusEnabled) RadiusV.push_back(typename VALUE_TYPE::RadiusType()); if (CurvatureDirEnabled) CuDV.push_back(typename VALUE_TYPE::CurvatureDirType());
} if (RadiusEnabled) RadiusV.push_back(typename VALUE_TYPE::RadiusType());
}
void pop_back(); void pop_back();
void resize(const unsigned int & _size) void resize(const unsigned int & _size)
{ {
@ -88,6 +89,7 @@ public:
_updateOVP(firstnew,(*this).end()); _updateOVP(firstnew,(*this).end());
} }
if (ColorEnabled) CV.resize(_size); if (ColorEnabled) CV.resize(_size);
if (QualityEnabled) QV.resize(_size,0);
if (MarkEnabled) MV.resize(_size); if (MarkEnabled) MV.resize(_size);
if (NormalEnabled) NV.resize(_size); if (NormalEnabled) NV.resize(_size);
if (TexCoordEnabled) TV.resize(_size); if (TexCoordEnabled) TV.resize(_size);
@ -101,6 +103,7 @@ public:
{ {
BaseType::reserve(_size); BaseType::reserve(_size);
if (ColorEnabled) CV.reserve(_size); if (ColorEnabled) CV.reserve(_size);
if (QualityEnabled) QV.reserve(_size);
if (MarkEnabled) MV.reserve(_size); if (MarkEnabled) MV.reserve(_size);
if (NormalEnabled) NV.reserve(_size); if (NormalEnabled) NV.reserve(_size);
if (TexCoordEnabled) TV.reserve(_size); if (TexCoordEnabled) TV.reserve(_size);
@ -124,7 +127,7 @@ bool IsQualityEnabled() const {return QualityEnabled;}
void EnableQuality() { void EnableQuality() {
assert(VALUE_TYPE::HasQualityOcf()); assert(VALUE_TYPE::HasQualityOcf());
QualityEnabled=true; QualityEnabled=true;
QV.resize((*this).size()); QV.resize((*this).size(),0);
} }
void DisableQuality() { void DisableQuality() {
assert(VALUE_TYPE::HasQualityOcf()); assert(VALUE_TYPE::HasQualityOcf());
@ -285,9 +288,9 @@ public:
} }
template <class RightVertexType> template <class RightVertexType>
void ImportData(const RightVertexType & rightV) void ImportData(const RightVertexType & rightV)
{ {
T::ImportData(rightV); T::ImportData(rightV);
} }
static bool HasVFAdjacency() { return true; } static bool HasVFAdjacency() { return true; }
static bool HasVFAdjacencyOcf() { return true; } static bool HasVFAdjacencyOcf() { return true; }
@ -538,11 +541,11 @@ template <class T> class RadiusdOcf: public RadiusOcf<double, T> {};
template < class T> class InfoOcf: public T { template < class T> class InfoOcf: public T {
public: public:
// You should never ever try to copy a vertex that has OCF stuff. // You should never ever try to copy a vertex that has OCF stuff.
// use ImportData function. // use ImportData function.
inline InfoOcf &operator=(const InfoOcf & /*other*/) { inline InfoOcf &operator=(const InfoOcf & /*other*/) {
assert(0); return *this; assert(0); return *this;
} }
vector_ocf<typename T::VertexType> &Base() const { return *_ovp;} vector_ocf<typename T::VertexType> &Base() const { return *_ovp;}