From ca26ad417ee0425d1e3749f27640415f788b5bc8 Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 14 Oct 2005 15:07:59 +0000 Subject: [PATCH] First Really Working version --- vcg/simplex/faceplus/component.h | 315 +++++++++++++++++++++++++ vcg/simplex/faceplus/component_ocf.h | 279 ++++++++++++++++++++++ vcg/simplex/vertexplus/component_ocf.h | 235 ++++++++++++++++++ 3 files changed, 829 insertions(+) create mode 100644 vcg/simplex/faceplus/component.h create mode 100644 vcg/simplex/faceplus/component_ocf.h create mode 100644 vcg/simplex/vertexplus/component_ocf.h diff --git a/vcg/simplex/faceplus/component.h b/vcg/simplex/faceplus/component.h new file mode 100644 index 00000000..e95bab7a --- /dev/null +++ b/vcg/simplex/faceplus/component.h @@ -0,0 +1,315 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* 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. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ +#ifndef __VCG_FACE_PLUS_COMPONENT +#define __VCG_FACE_PLUS_COMPONENT + +#include + +namespace vcg { + namespace face { +/* +Some naming Rules +All the Components that can be added to a vertex should be defined in the namespace vert: + +*/ + +/*-------------------------- VERTEX ----------------------------------------*/ +template class EmptyVertexRef: public T { +public: + // typedef typename T::VertexType VertexType; + // typedef typename T::CoordType CoordType; + 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; } + +}; +template class VertexRef: public T { +public: + // typedef typename T::VertexType VertexType; + // typedef typename T::VertexType::CoordType CoordType; + + inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<3); return v[j]; } + inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<3); return v[j]; } + inline typename T::VertexType * const cV( const int j ) const { assert(j>=0 && j<3); return v[j]; } + + // Shortcut per accedere ai punti delle facce + inline typename T::CoordType & P( const int j ) { assert(j>=0 && j<3); return v[j]->P(); } + inline const typename T::CoordType & P( const int j ) const { assert(j>=0 && j<3); return v[j]->cP(); } + inline const typename T::CoordType &cP( const int j ) const { assert(j>=0 && j<3); return v[j]->cP(); } + + /** Return the pointer to the ((j+1)%3)-th vertex of the face. + @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)%3);} + inline typename T::VertexType * & V2( const int j ) { return V((j+2)%3);} + 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)%3);} + inline const typename T::VertexType * const & V2( const int j ) const { return V((j+2)%3);} + 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)%3);} + inline const typename T::VertexType * const & cV2( const int j ) const { return cV((j+2)%3);} + + /// Shortcut per accedere ai punti delle facce + inline typename T::CoordType & P0( const int j ) { return V(j)->P();} + inline typename T::CoordType & P1( const int j ) { return V((j+1)%3)->P();} + inline typename T::CoordType & P2( const int j ) { return V((j+2)%3)->P();} + inline const typename T::CoordType & P0( const int j ) const { return V(j)->P();} + inline const typename T::CoordType & P1( const int j ) const { return V((j+1)%3)->P();} + inline const typename T::CoordType & P2( const int j ) const { return V((j+2)%3)->P();} + inline const typename T::CoordType & cP0( const int j ) const { return cV(j)->P();} + inline const typename T::CoordType & cP1( const int j ) const { return cV((j+1)%3)->P();} + inline const typename T::CoordType & cP2( const int j ) const { return cV((j+2)%3)->P();} + + inline typename T::VertexType * & UberV( const int j ) { assert(j>=0 && j<3); return v[j]; } + inline const typename T::VertexType * const & UberV( const int j ) const { assert(j>=0 && j<3); return v[j]; } + static bool HasVertexRef() { return true; } + + private: + typename T::VertexType *v[3]; +}; + + + +/*-------------------------- NORMAL ----------------------------------------*/ + +template class EmptyNormal: public T { +public: + //typedef vcg::Point3s NormalType; + typedef typename T::VertexType::NormalType NormalType; + NormalType &N() { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + const NormalType cN() const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + NormalType &WN(int) { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + const NormalType cWN(int) const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + + static bool HasWedgeNormal() { return false; } + static bool HasFaceNormal() { return false; } + static bool HasWedgeNormalOpt() { return false; } + static bool HasFaceNormalOpt() { return false; } + void ComputeNormal() {assert(0);} + void ComputeNormalizedNormal() {assert(0);} + +}; +template class NormalFromVert: public T { +public: + typedef typename T::VertexType::NormalType NormalType; + NormalType &N() { return _norm; } + NormalType cN() const { return _norm; } + static bool HasFaceNormal() { return true; } + void ComputeNormal() { _norm = vcg::Normal(*(static_cast(this))); } + void ComputeNormalizedNormal() { _norm = vcg::NormalizedNormal(*this);} + +private: + NormalType _norm; +}; + + +template class NormalAbs: public T { +public: + typedef A NormalType; + NormalType &N() { return _norm; } + NormalType cN() const { return _norm; } + static bool HasFaceNormal() { return true; } + + void ComputeNormal() { _norm = vcg::Normal(*(static_cast(this))); } + void ComputeNormalizedNormal() { _norm = vcg::NormalizedNormal(*this);} + +private: + NormalType _norm; +}; + +template class WedgeNormal: public T { +public: + typedef typename T::VertexType::NormalType NormalType; + NormalType &WN(const int j) { return _wnorm[j]; } + const NormalType cWN(const int j) const { return _wnorm[j]; } + static bool HasWedgeNormal() { return true; } + +private: + NormalType _wnorm[3]; +}; + + +template class Normal3s: public NormalAbs {}; +template class Normal3f: public NormalAbs {}; +template class Normal3d: public NormalAbs {}; + + +/*-------------------------- Texture ----------------------------------------*/ + +template class EmptyWedgeTexture: public TT { +public: + typedef vcg::TCoord2 TexCoordType; + TexCoordType &WT(const int) { static TexCoordType dummy_texture; return dummy_texture;} + TexCoordType const &cWT(const int) const { static TexCoordType dummy_texture; return dummy_texture;} + static bool HasWedgeTexture() { return false; } + +}; +template class WedgeTexture: public TT { +public: + typedef A TexCoordType; + TexCoordType &WT(const int i) { return _t[i]; } + TexCoordType const &cWT(const int i) const { return _t[i]; } + static bool HasWedgeTexture() { return true; } + +private: + TexCoordType _t; +}; + +template class WedgeTexture2s: public WedgeTexture, TT> {}; +template class WedgeTexture2f: public WedgeTexture, TT> {}; +template class WedgeTexture2d: public WedgeTexture, TT> {}; + +/*------------------------- FLAGS -----------------------------------------*/ +template class EmptyFlag: public T { +public: + /// Return the vector of Flags(), senza effettuare controlli sui bit + int &Flags() { static int dummyflags(0); return dummyflags; } + const int Flags() const { return 0; } + static bool HasFlag() { return false; } + +}; + +template class Flag: public T { +public: + Flag(){_flags=0;} + int &Flags() {return _flags; } + const int Flags() const {return _flags; } + static bool HasFlag() { return true; } + + +private: + int _flags; +}; + +/*-------------------------- COLOR ----------------------------------*/ + +template class EmptyColorQuality: public T { +public: + typedef float QualityType; + typedef vcg::Color4b ColorType; + ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); return dumcolor; } + ColorType &WC(const int) { static ColorType dumcolor(vcg::Color4b::White); return dumcolor; } + QualityType &Q() { static QualityType dummyQuality(0); return dummyQuality; } + static bool HasFaceColor() { return false; } + static bool HasWedgeColor() { return false; } + static bool HasFaceQuality() { return false; } +}; +template class Color: public T { +public: + typedef A ColorType; + ColorType &C() { return _color; } + static bool HasFaceColor() { return true; } +private: + ColorType _color; +}; + +template class WedgeColor: public T { +public: + typedef A ColorType; + ColorType &WC(const int i) { return _color[i]; } + static bool HasFaceColor() { return true; } +private: + ColorType _color[3]; +}; + +template class Color4b: public Color {}; + +/*-------------------------- Quality ----------------------------------*/ + +template class EmptyQuality: public T { +public: +}; +template class Quality: public T { +public: + typedef A QualityType; + QualityType &Q() { return _quality; } + static bool HasFaceQuality() { return true; } + +private: + QualityType _quality; +}; + +template class Qualitys: public Quality {}; +template class Qualityf: public Quality {}; +template class Qualityd: public Quality {}; + +/*----------------------------- VFADJ ------------------------------*/ + + +template class EmptyAdj: public T { +public: + typename T::FacePointer &VFp(const int) { static typename T::FacePointer fp=0; return fp; } + typename T::FacePointer const cVFp(const int) { static typename T::FacePointer fp=0; return fp; } + typename T::FacePointer &FFp(const int) { static typename T::FacePointer fp=0; return fp; } + typename T::FacePointer const cFFp(const int) { static typename T::FacePointer fp=0; return fp; } + char &VFi(const int j){static char z=0; return z;}; + char &FFi(const int j){static char z=0; return z;}; + static bool HasVFAdjacency() { return false; } + static bool HasFFAdjacency() { return false; } + static bool HasFFAdjacencyOpt() { return false; } + static bool HasVFAdjacencyOpt() { return false; } +}; + +template class VFAdj: public T { +public: + typename T::FacePointer &VFp(const int j) { assert(j>=0 && j<3); return _vfp[j]; } + typename T::FacePointer const VFp(const int j) const { assert(j>=0 && j<3); return _vfp[j]; } + typename T::FacePointer const cVFp(const int j) const { assert(j>=0 && j<3); return _vfp[j]; } + char &VFi(const int j) {return _vfi[j]; } + static bool HasVFAdjacency() { return true; } + static bool HasVFAdjacencyOpt() { return false; } +private: + typename T::FacePointer _vfp[3] ; + char _vfi[3] ; +}; +/*----------------------------- FFADJ ------------------------------*/ + + +template class FFAdj: public T { +public: + typename T::FacePointer &FFp(const int j) { assert(j>=0 && j<3); return _ffp[j]; } + typename T::FacePointer const FFp(const int j) const { assert(j>=0 && j<3); return _ffp[j]; } + typename T::FacePointer const cFFp(const int j) const { assert(j>=0 && j<3); return _ffp[j]; } + char &FFi(const int j) {return _ffi[j]; } + static bool HasFFAdjacency() { return true; } + static bool HasFFAdjacencyOpt() { return false; } + +private: + typename T::FacePointer _ffp[3] ; + char _ffi[3] ; +}; + + } // end namespace vert +}// end namespace vcg +#endif diff --git a/vcg/simplex/faceplus/component_ocf.h b/vcg/simplex/faceplus/component_ocf.h new file mode 100644 index 00000000..11f9773d --- /dev/null +++ b/vcg/simplex/faceplus/component_ocf.h @@ -0,0 +1,279 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* 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. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + +/* +Note +OCF = Optional Component Fast (hopefully) +compare with OCC(Optional Component Compact) + +Mainly the trick here is to store a base pointer in each simplex... + +****************************************************************************/ +#ifndef __VCG_FACE_PLUS_COMPONENT_OCF +#define __VCG_FACE_PLUS_COMPONENT_OCF + +#include +#include + + +namespace vcg { + namespace face { +/* +All the Components that can be added to a faceex should be defined in the namespace face: + +*/ +template +class vector_ocf: public std::vector { + typedef std::vector BaseType; + typedef typename vector_ocf::iterator ThisTypeIterator; + +public: + vector_ocf():std::vector(){ + ColorEnabled=false; + NormalEnabled=false; + VFAdjacencyEnabled=false; + FFAdjacencyEnabled=false; + } + + // override di tutte le funzioni che possono spostare + // l'allocazione in memoria del container + void push_back(const VALUE_TYPE & v) + { + ThisTypeIterator oldbegin=begin(); + ThisTypeIterator oldend=end(); + BaseType::push_back(v); + if(oldbegin!=begin()) _update(begin(),end()); + else _update(oldend,end()); + } + void pop_back(); + void resize(const unsigned int & _size) + { + ThisTypeIterator oldbegin=begin(); + ThisTypeIterator oldend=end(); + BaseType::resize(_size); + if(oldbegin!=begin()) _update(begin(),end()); + else _update(oldend,end()); + if(ColorEnabled) CV.resize(_size); + if(NormalEnabled) NV.resize(_size); + if(VFAdjacencyEnabled) AV.resize(_size); + if(FFAdjacencyEnabled) AF.resize(_size); + + } + void reserve(const unsigned int & _size) + { + ThisTypeIterator oldbegin=begin(); + BaseType::reserve(_size); + if (ColorEnabled) CV.reserve(_size); + if (NormalEnabled) NV.reserve(_size); + if (VFAdjacencyEnabled) AV.reserve(_size); + if (FFAdjacencyEnabled) AF.reserve(_size); + if(oldbegin!=begin()) _update(begin(),end()); + } + + void _update(ThisTypeIterator lbegin, ThisTypeIterator lend) +{ + ThisTypeIterator vi; + //for(vi=lbegin;vi!=lend;++vi) + for(vi=begin();vi!=end();++vi) + (*vi).EV=this; + } +//////////////////////////////////////// +// Enabling Eunctions + +void EnableColor() { + assert(VALUE_TYPE::HasColorOcf()); + ColorEnabled=true; + CV.resize(size()); +} + +void DisableColor() { + assert(VALUE_TYPE::HasColorOcf()); + ColorEnabled=false; + CV.clear(); +} + +void EnableNormal() { + assert(VALUE_TYPE::HasNormalOcf()); + NormalEnabled=true; + NV.resize(size()); +} + +void DisableNormal() { + assert(VALUE_TYPE::HasNormalOcf()); + NormalEnabled=false; + NV.clear(); +} + +void EnableVFAdjacency() { + assert(VALUE_TYPE::HasVFAdjacencyOcf()); + VFAdjacencyEnabled=true; + AV.resize(size()); +} + +void DisableVFAdjacency() { + assert(VALUE_TYPE::HasVFAdjacencyOcf()); + VFAdjacencyEnabled=false; + AV.clear(); +} + + +void EnableFFAdjacency() { + assert(VALUE_TYPE::HasFFAdjacencyOcf()); + FFAdjacencyEnabled=true; + AF.resize(size()); +} + +void DisableFFAdjacency() { + assert(VALUE_TYPE::HasFFAdjacencyOcf()); + FFAdjacencyEnabled=false; + AF.clear(); +} + + + +struct AdjType { + typename VALUE_TYPE::FacePointer _fp[3] ; + char _zp[3] ; + }; + +public: + std::vector CV; + std::vector NV; + std::vector AV; + std::vector AF; + + bool ColorEnabled; + bool NormalEnabled; + bool VFAdjacencyEnabled; + bool FFAdjacencyEnabled; +}; + + +//template<> void EnableAttribute(){ NormalEnabled=true;} + +/*------------------------- COORD -----------------------------------------*/ +/*----------------------------- VFADJ ------------------------------*/ + + +template class VFAdjOcf: public T { +public: + typename T::FacePointer &VFp(const int j) { + assert(Base().VFAdjacencyEnabled); + return Base().AV[Index()]._fp[j]; + } + + typename T::FacePointer cVFp(const int j) const { + if(! Base().VFAdjacencyEnabled ) return 0; + else return Base().AV[Index()]._fp[j]; + } + + char &VFi(const int j) { + assert(Base().VFAdjacencyEnabled); + return Base().AV[Index()]._zp[j]; + } + static bool HasVFAdjacency() { return true; } + static bool HasVFAdjacencyOcf() { return true; } + +private: +}; +/*----------------------------- FFADJ ------------------------------*/ + + +template class FFAdjOcf: public T { +public: + typename T::FacePointer &FFp(const int j) { + assert(Base().FFAdjacencyEnabled); + return Base().AF[Index()]._fp[j]; + } + + typename T::FacePointer const FFp(const int j) const { return cFFp(j)} + typename T::FacePointer const cFFp(const int j) const { + if(! Base().FFAdjacencyEnabled ) return 0; + else return Base().AF[Index()]._fp[j]; + } + + char &FFi(const int j) { + assert(Base().FFAdjacencyEnabled); + return Base().AF[Index()]._zp[j]; + } + static bool HasFFAdjacency() { return true; } + static bool HasFFAdjacencyOcf() { return true; } + +private: +}; + +/*------------------------- Normal -----------------------------------------*/ + +template class NormalOcf: public T { +public: + typedef A NormalType; + static bool HasNormal() { return true; } + static bool HasNormalOcf() { return true; } + + NormalType &N() { + // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() + assert(Base().NormalEnabled); + return Base().NV[Index()]; } +}; + +template class Normal3sOcf: public NormalOcf {}; +template class Normal3fOcf: public NormalOcf {}; +template class Normal3dOcf: public NormalOcf {}; + +///*-------------------------- COLOR ----------------------------------*/ + +template class ColorOcf: public T { +public: + typedef A ColorType; + ColorType &C() { assert(Base().NormalEnabled); return Base().CV[Index()]; } + static bool HasColor() { return true; } + static bool HasColorOcf() { return true; } +}; + +template class Color4bOcf: public ColorOcf {}; + +///*-------------------------- InfoOpt ----------------------------------*/ + +template < class T> class InfoOcf: public T { +public: + vector_ocf &Base() const { return *EV;} + + inline int Index() const { + typename T::FaceType const *tp=static_cast(this); + int tt2=tp- &*(EV->begin()); + return tt2; + } +public: + vector_ocf *EV; +}; + + + } // end namespace face +}// end namespace vcg +#endif diff --git a/vcg/simplex/vertexplus/component_ocf.h b/vcg/simplex/vertexplus/component_ocf.h new file mode 100644 index 00000000..5b9a260b --- /dev/null +++ b/vcg/simplex/vertexplus/component_ocf.h @@ -0,0 +1,235 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* 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. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + +/* +Note +OCF = Optional Component Fast (hopefully) +compare with OCC(Optional Component Compact) + +Mainly the trick here is to store a base pointer in each simplex... + +****************************************************************************/ +#ifndef __VCG_VERTEX_PLUS_COMPONENT_OCF +#define __VCG_VERTEX_PLUS_COMPONENT_OCF + +#include +#include + + +namespace vcg { + namespace vert { +/* +All the Components that can be added to a vertex should be defined in the namespace vert: + +*/ +template +class vector_ocf: public std::vector { + typedef std::vector BaseType; + typedef typename vector_ocf::iterator ThisTypeIterator; + +public: + vector_ocf():std::vector(){ + ColorEnabled=false; + NormalEnabled=false; + VFAdjacencyEnabled=false; + } + + // override di tutte le funzioni che possono spostare + // l'allocazione in memoria del container + void push_back(const VALUE_TYPE & v) + { + ThisTypeIterator oldbegin=begin(); + ThisTypeIterator oldend=end(); + BaseType::push_back(v); + if(oldbegin!=begin()) _update(begin(),end()); + else _update(oldend,end()); + } + void pop_back(); + void resize(const unsigned int & _size) + { + ThisTypeIterator oldbegin=begin(); + ThisTypeIterator oldend=end(); + BaseType::resize(_size); + if(oldbegin!=begin()) _update(begin(),end()); + else _update(oldend,end()); + if(ColorEnabled) CV.resize(_size); + if(NormalEnabled) NV.resize(_size); + + } + void reserve(const unsigned int & _size) + { + ThisTypeIterator oldbegin=begin(); + BaseType::reserve(_size); + if (ColorEnabled) CV.reserve(_size); + if (NormalEnabled) NV.reserve(_size); + if(oldbegin!=begin()) _update(begin(),end()); + } + + void _update(ThisTypeIterator lbegin, ThisTypeIterator lend) +{ + ThisTypeIterator vi; + //for(vi=lbegin;vi!=lend;++vi) + for(vi=begin();vi!=end();++vi) + (*vi).EV=this; + } +//////////////////////////////////////// +// Enabling Eunctions + +void EnableColor() { + assert(VALUE_TYPE::HasColorOcf()); + ColorEnabled=true; + CV.resize(size()); +} + +void DisableColor() { + assert(VALUE_TYPE::HasColorOcf()); + ColorEnabled=false; + CV.clear(); +} + +void EnableNormal() { + assert(VALUE_TYPE::HasNormalOcf()); + NormalEnabled=true; + NV.resize(size()); +} + +void DisableNormal() { + assert(VALUE_TYPE::HasNormalOcf()); + NormalEnabled=false; + NV.clear(); +} + +void EnableVFAdjacency() { + assert(VALUE_TYPE::HasVFAdjacencyOcf()); + VFAdjacencyEnabled=true; + AV.resize(size()); +} + +void DisableVFAdjacency() { + assert(VALUE_TYPE::HasVFAdjacencyOcf()); + VFAdjacencyEnabled=false; + AV.clear(); +} + + + + +struct VFAdjType { + typename VALUE_TYPE::FacePointer _fp ; + int _zp ; + }; + +public: + std::vector CV; + std::vector NV; + std::vector AV; + + bool ColorEnabled; + bool NormalEnabled; + bool VFAdjacencyEnabled; +}; + + +//template<> void EnableAttribute(){ NormalEnabled=true;} + +/*------------------------- COORD -----------------------------------------*/ +/*----------------------------- VFADJ ------------------------------*/ + + +template class VFAdjOcf: public T { +public: + typename T::FacePointer &VFp() { + assert(Base().VFAdjacencyEnabled); + return Base().AV[Index()]._fp; + } + + typename T::FacePointer cVFp() const { + if(! Base().VFAdjacencyEnabled ) return 0; + else return Base().AV[Index()]._fp; + } + + int &VFi() { + assert(Base().VFAdjacencyEnabled); + return Base().AV[Index()]._zp; + } + static bool HasVFAdjacency() { return true; } + static bool HasVFAdjacencyOcf() { return true; } + +private: +}; + +/*------------------------- Normal -----------------------------------------*/ + +template class NormalOcf: public T { +public: + typedef A NormalType; + static bool HasNormal() { return true; } + static bool HasNormalOcf() { return true; } + + NormalType &N() { + // you cannot use Normals before enabling them with: yourmesh.vert.EnableNormal() + assert(Base().NormalEnabled); + return Base().NV[Index()]; } +}; + +template class Normal3sOcf: public NormalOcf {}; +template class Normal3fOcf: public NormalOcf {}; +template class Normal3dOcf: public NormalOcf {}; + +///*-------------------------- COLOR ----------------------------------*/ + +template class ColorOcf: public T { +public: + typedef A ColorType; + ColorType &C() { assert(Base().NormalEnabled); return Base().CV[Index()]; } + static bool HasColor() { return true; } + static bool HasColorOcf() { return true; } +}; + +template class Color4bOcf: public ColorOcf {}; + +///*-------------------------- InfoOpt ----------------------------------*/ + +template < class T> class InfoOcf: public T { +public: + vector_ocf &Base() const { return *EV;} + + inline int Index() const { + typename T::VertType const *tp=static_cast(this); + int tt2=tp- &*(EV->begin()); + return tt2; + } +public: + vector_ocf *EV; +}; + + + } // end namespace vert +}// end namespace vcg +#endif