small changes to enable the mesh dumping on VMI file (see wrap/io_trimesh/[import | export]_VMI.h )

and HandlesWrapper renamed to PointerToAttribute
This commit is contained in:
ganovelli 2009-07-29 12:46:46 +00:00
parent 4e1b6897b1
commit f1b1220225
2 changed files with 123 additions and 71 deletions

View File

@ -201,16 +201,16 @@ namespace vcg {
template <class MeshType, class ATTR_CONT> template <class MeshType, class ATTR_CONT>
void ReorderAttribute(ATTR_CONT &c,std::vector<size_t> & newVertIndex, MeshType &m){ void ReorderAttribute(ATTR_CONT &c,std::vector<size_t> & newVertIndex, MeshType &m){
typename std::set<typename MeshType::HandlesWrapper>::iterator ai; typename std::set<typename MeshType::PointerToAttribute>::iterator ai;
for(ai = c.begin(); ai != c.end(); ++ai) for(ai = c.begin(); ai != c.end(); ++ai)
((typename MeshType::HandlesWrapper)(*ai)).Reorder(newVertIndex); ((typename MeshType::PointerToAttribute)(*ai)).Reorder(newVertIndex);
} }
template <class MeshType, class ATTR_CONT> template <class MeshType, class ATTR_CONT>
void ResizeAttribute(ATTR_CONT &c,const int & sz, MeshType &m){ void ResizeAttribute(ATTR_CONT &c,const int & sz, MeshType &m){
typename std::set<typename MeshType::HandlesWrapper>::iterator ai; typename std::set<typename MeshType::PointerToAttribute>::iterator ai;
for(ai =c.begin(); ai != c.end(); ++ai) for(ai =c.begin(); ai != c.end(); ++ai)
((typename MeshType::HandlesWrapper)(*ai)).Resize(m.vn); ((typename MeshType::PointerToAttribute)(*ai)).Resize(m.vn);
} }
/*@{*/ /*@{*/
@ -236,10 +236,10 @@ namespace vcg {
typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator; typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::FaceContainer FaceContainer; typedef typename MeshType::FaceContainer FaceContainer;
typedef typename MeshType::HandlesWrapper HandlesWrapper; typedef typename MeshType::PointerToAttribute PtrToAttr;
typedef typename std::set<HandlesWrapper>::iterator HandlesIterator; typedef typename std::set<PtrToAttr>::iterator AttrIterator;
typedef typename std::set<HandlesWrapper>::const_iterator HandlesConstIterator; typedef typename std::set<PtrToAttr>::const_iterator AttrConstIterator;
typedef typename std::set<HandlesWrapper >::iterator HWIte; typedef typename std::set<PtrToAttr >::iterator PAIte;
/** This class is used when allocating new vertexes and faces to update /** This class is used when allocating new vertexes and faces to update
the pointers that can be changed when resizing the involved vectors of vertex or faces. the pointers that can be changed when resizing the involved vectors of vertex or faces.
@ -290,9 +290,9 @@ namespace vcg {
m.vert.resize(m.vert.size()+n); m.vert.resize(m.vert.size()+n);
m.vn+=n; m.vn+=n;
typename std::set<typename MeshType::HandlesWrapper>::iterator ai; typename std::set<PtrToAttr>::iterator ai;
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai)
((typename MeshType::HandlesWrapper)(*ai)).Resize(m.vert.size()); ((PtrToAttr)(*ai)).Resize(m.vert.size());
pu.newBase = &*m.vert.begin(); pu.newBase = &*m.vert.begin();
pu.newEnd = &m.vert.back()+1; pu.newEnd = &m.vert.back()+1;
@ -365,9 +365,9 @@ namespace vcg {
m.edge.resize(m.edge.size()+n); m.edge.resize(m.edge.size()+n);
m.en+=n; m.en+=n;
//typename std::set<typename MeshType::HandlesWrapper>::iterator ai; typename std::set<typename MeshType::PtrToAttr>::iterator ai;
//for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) for(ai = m.edge_attr.begin(); ai != m.edge_attr.end(); ++ai)
// ((typename MeshType::HandlesWrapper)(*ai)).Resize(m.vert.size()); ((typename MeshType::PtrToAttr)(*ai)).Resize(m.edge.size());
pu.newBase = &*m.edge.begin(); pu.newBase = &*m.edge.begin();
pu.newEnd = &m.edge.back()+1; pu.newEnd = &m.edge.back()+1;
@ -478,9 +478,9 @@ namespace vcg {
m.fn+=n; m.fn+=n;
typename std::set<typename MeshType::HandlesWrapper>::iterator ai; typename std::set<PtrToAttr>::iterator ai;
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai)
((typename MeshType::HandlesWrapper)(*ai)).Resize(m.face.size()); ((PtrToAttr)(*ai)).Resize(m.face.size());
pu.newBase = &*m.face.begin(); pu.newBase = &*m.face.begin();
pu.newEnd = &m.face.back()+1; pu.newEnd = &m.face.back()+1;
@ -708,7 +708,7 @@ public:
static static
bool IsValidHandle( MeshType & m, const typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> & a){ bool IsValidHandle( MeshType & m, const typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> & a){
if(a._handle == NULL) return false; if(a._handle == NULL) return false;
for(HandlesIterator i = m.vert_attr.begin(); i!=m.vert_attr.end();++i) for(AttrIterator i = m.vert_attr.begin(); i!=m.vert_attr.end();++i)
if ( (*i).n_attr == a.n_attr ) return true; if ( (*i).n_attr == a.n_attr ) return true;
return false; return false;
} }
@ -717,17 +717,19 @@ public:
static static
typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>
AddPerVertexAttribute( MeshType & m, std::string name){ AddPerVertexAttribute( MeshType & m, std::string name){
HWIte i; PAIte i;
HandlesWrapper h; PtrToAttr h;
h._name = name; h._name = name;
if(!name.empty()){ if(!name.empty()){
i = m.vert_attr.find(h); i = m.vert_attr.find(h);
assert(i ==m.vert_attr.end() );// an attribute with this name exists assert(i ==m.vert_attr.end() );// an attribute with this name exists
} }
h._sizeof = sizeof(ATTR_TYPE);
h._padding = 0;
h._handle = (void*) new SimpleTempData<VertContainer,ATTR_TYPE>(m.vert); h._handle = (void*) new SimpleTempData<VertContainer,ATTR_TYPE>(m.vert);
m.attrn++; m.attrn++;
h.n_attr = m.attrn; h.n_attr = m.attrn;
std::pair < HandlesIterator , bool> res = m.vert_attr.insert(h); std::pair < AttrIterator , bool> res = m.vert_attr.insert(h);
return typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr ); return typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr );
} }
@ -741,23 +743,35 @@ public:
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>
GetPerVertexAttribute( const MeshType & m, const std::string & name){ GetPerVertexAttribute( MeshType & m, const std::string & name){
assert(!name.empty()); assert(!name.empty());
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
typename std::set<HandlesWrapper > ::const_iterator i; typename std::set<PtrToAttr > :: iterator i;
i =m.vert_attr.find(h1); i =m.vert_attr.find(h1);
if(i!=m.vert_attr.end()) if(i!=m.vert_attr.end()){
if( (*i)._padding != 0 ){
PtrToAttr attr = (*i); // copy the PointerToAttribute
m.vert_attr.erase(i); // remove it from the set
FixPaddedPerVertexAttribute<ATTR_TYPE>(m,attr);
std::pair<AttrIterator,bool> new_i = m.vert_attr.insert(attr); // insert the modified PointerToAttribute
assert(new_i.second);
i = new_i.first;
}
return typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr); return typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
}
else else
return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
void void
DeletePerVertexAttribute( MeshType & m,typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> & h){ DeletePerVertexAttribute( MeshType & m,typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE> & h){
typename std::set<HandlesWrapper > ::iterator i; typename std::set<PtrToAttr > ::iterator i;
for( i = m.vert_attr.begin(); i != m.vert_attr.end(); ++i) for( i = m.vert_attr.begin(); i != m.vert_attr.end(); ++i)
if( (*i)._handle == h._handle ){ if( (*i)._handle == h._handle ){
delete ((SimpleTempData<VertContainer,ATTR_TYPE>*)(*i)._handle); delete ((SimpleTempData<VertContainer,ATTR_TYPE>*)(*i)._handle);
@ -768,20 +782,22 @@ public:
static static
void DeletePerVertexAttribute( MeshType & m, std::string name){ void DeletePerVertexAttribute( MeshType & m, std::string name){
HandlesIterator i; AttrIterator i;
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
i = m.vert_attr.find(h1); i = m.vert_attr.find(h1);
assert(i!=m.vert_attr.end()); assert(i!=m.vert_attr.end());
delete ((SimpleTempDataBase<VertContainer>*)(*i)._handle); delete ((SimpleTempDataBase<VertContainer>*)(*i)._handle);
m.vert_attr.erase(i); m.vert_attr.erase(i);
} }
/// Per Edge Attributes /// Per Edge Attributes
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
bool IsValidHandle( MeshType & m, const typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> & a){ bool IsValidHandle( MeshType & m, const typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> & a){
if(a._handle == NULL) return false; if(a._handle == NULL) return false;
for(HandlesIterator i = m.edge_attr.begin(); i!=m.edge_attr.end();++i) for(AttrIterator i = m.edge_attr.begin(); i!=m.edge_attr.end();++i)
if ( (*i).n_attr == a.n_attr ) return true; if ( (*i).n_attr == a.n_attr ) return true;
return false; return false;
} }
@ -790,8 +806,8 @@ public:
static static
typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE>
AddPerEdgeAttribute( MeshType & m, std::string name){ AddPerEdgeAttribute( MeshType & m, std::string name){
HWIte i; PAIte i;
HandlesWrapper h; PtrToAttr h;
h._name = name; h._name = name;
if(!name.empty()){ if(!name.empty()){
i = m.edge_attr.find(h); i = m.edge_attr.find(h);
@ -800,7 +816,7 @@ public:
h._handle = (void*) new SimpleTempData<EdgeContainer,ATTR_TYPE>(m.edge); h._handle = (void*) new SimpleTempData<EdgeContainer,ATTR_TYPE>(m.edge);
m.attrn++; m.attrn++;
h.n_attr = m.attrn; h.n_attr = m.attrn;
std::pair < HandlesIterator , bool> res = m.edge_attr.insert(h); std::pair < AttrIterator , bool> res = m.edge_attr.insert(h);
return typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr); return typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr);
} }
@ -816,8 +832,8 @@ public:
typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE>
GetPerEdgeAttribute( const MeshType & m, const std::string & name){ GetPerEdgeAttribute( const MeshType & m, const std::string & name){
assert(!name.empty()); assert(!name.empty());
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
typename std::set<HandlesWrapper > ::const_iterator i; typename std::set<PtrToAttr > ::const_iterator i;
i =m.edge_attr.find(h1); i =m.edge_attr.find(h1);
if(i!=m.edge_attr.end()) if(i!=m.edge_attr.end())
@ -830,7 +846,7 @@ public:
static static
void void
DeletePerEdgeAttribute( MeshType & m,typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> & h){ DeletePerEdgeAttribute( MeshType & m,typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> & h){
typename std::set<HandlesWrapper > ::iterator i; typename std::set<PtrToAttr > ::iterator i;
for( i = m.edge_attr.begin(); i != m.edge_attr.end(); ++i) for( i = m.edge_attr.begin(); i != m.edge_attr.end(); ++i)
if( (*i)._handle == h._handle ){ if( (*i)._handle == h._handle ){
delete ((SimpleTempData<FaceContainer,ATTR_TYPE>*)(*i)._handle); delete ((SimpleTempData<FaceContainer,ATTR_TYPE>*)(*i)._handle);
@ -841,8 +857,8 @@ public:
static static
void DeletePerEdgeAttribute( MeshType & m, std::string name){ void DeletePerEdgeAttribute( MeshType & m, std::string name){
HandlesIterator i; AttrIterator i;
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
i = m.edge_attr.find(h1); i = m.edge_attr.find(h1);
assert(i!=m.edge_attr.end()); assert(i!=m.edge_attr.end());
delete ((SimpleTempDataBase<EdgeContainer>*)(*i)._handle); delete ((SimpleTempDataBase<EdgeContainer>*)(*i)._handle);
@ -854,7 +870,7 @@ public:
static static
bool IsValidHandle( MeshType & m, const typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> & a){ bool IsValidHandle( MeshType & m, const typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> & a){
if(a._handle == NULL) return false; if(a._handle == NULL) return false;
for(HandlesIterator i = m.face_attr.begin(); i!=m.face_attr.end();++i) for(AttrIterator i = m.face_attr.begin(); i!=m.face_attr.end();++i)
if ( (*i).n_attr == a.n_attr ) return true; if ( (*i).n_attr == a.n_attr ) return true;
return false; return false;
} }
@ -863,8 +879,8 @@ public:
static static
typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>
AddPerFaceAttribute( MeshType & m, std::string name){ AddPerFaceAttribute( MeshType & m, std::string name){
HWIte i; PAIte i;
HandlesWrapper h; PtrToAttr h;
h._name = name; h._name = name;
if(!name.empty()){ if(!name.empty()){
i = m.face_attr.find(h); i = m.face_attr.find(h);
@ -873,7 +889,7 @@ public:
h._handle = (void*) new SimpleTempData<FaceContainer,ATTR_TYPE>(m.face); h._handle = (void*) new SimpleTempData<FaceContainer,ATTR_TYPE>(m.face);
m.attrn++; m.attrn++;
h.n_attr = m.attrn; h.n_attr = m.attrn;
std::pair < HandlesIterator , bool> res = m.face_attr.insert(h); std::pair < AttrIterator , bool> res = m.face_attr.insert(h);
return typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr); return typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr);
} }
@ -889,8 +905,8 @@ public:
typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>
GetPerFaceAttribute( const MeshType & m, const std::string & name){ GetPerFaceAttribute( const MeshType & m, const std::string & name){
assert(!name.empty()); assert(!name.empty());
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
typename std::set<HandlesWrapper > ::const_iterator i; typename std::set<PtrToAttr > ::const_iterator i;
i =m.face_attr.find(h1); i =m.face_attr.find(h1);
if(i!=m.face_attr.end()) if(i!=m.face_attr.end())
@ -903,7 +919,7 @@ public:
static static
void void
DeletePerFaceAttribute( MeshType & m,typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> & h){ DeletePerFaceAttribute( MeshType & m,typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> & h){
typename std::set<HandlesWrapper > ::iterator i; typename std::set<PtrToAttr > ::iterator i;
for( i = m.face_attr.begin(); i != m.face_attr.end(); ++i) for( i = m.face_attr.begin(); i != m.face_attr.end(); ++i)
if( (*i)._handle == h._handle ){ if( (*i)._handle == h._handle ){
delete ((SimpleTempData<FaceContainer,ATTR_TYPE>*)(*i)._handle); delete ((SimpleTempData<FaceContainer,ATTR_TYPE>*)(*i)._handle);
@ -914,8 +930,8 @@ public:
static static
void DeletePerFaceAttribute( MeshType & m, std::string name){ void DeletePerFaceAttribute( MeshType & m, std::string name){
HandlesIterator i; AttrIterator i;
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
i = m.face_attr.find(h1); i = m.face_attr.find(h1);
assert(i!=m.face_attr.end()); assert(i!=m.face_attr.end());
delete ((SimpleTempDataBase<FaceContainer>*)(*i)._handle); delete ((SimpleTempDataBase<FaceContainer>*)(*i)._handle);
@ -927,7 +943,7 @@ public:
static static
bool IsValidHandle( MeshType & m, const typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> & a){ bool IsValidHandle( MeshType & m, const typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> & a){
if(a._handle == NULL) return false; if(a._handle == NULL) return false;
for(HandlesIterator i = m.mesh_attr.begin(); i!=m.mesh_attr.end();++i) for(AttrIterator i = m.mesh_attr.begin(); i!=m.mesh_attr.end();++i)
if ( (*i).n_attr == a.n_attr ) return true; if ( (*i).n_attr == a.n_attr ) return true;
return false; return false;
} }
@ -936,8 +952,8 @@ public:
static static
typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>
AddPerMeshAttribute( MeshType & m, std::string name){ AddPerMeshAttribute( MeshType & m, std::string name){
HWIte i; PAIte i;
HandlesWrapper h; PtrToAttr h;
h._name = name; h._name = name;
if(!name.empty()){ if(!name.empty()){
i = m.mesh_attr.find(h); i = m.mesh_attr.find(h);
@ -946,7 +962,7 @@ public:
h._handle = (void*) new Attribute<ATTR_TYPE>(); h._handle = (void*) new Attribute<ATTR_TYPE>();
m.attrn++; m.attrn++;
h.n_attr = m.attrn; h.n_attr = m.attrn;
std::pair < HandlesIterator , bool> res = m.mesh_attr.insert(h); std::pair < AttrIterator , bool> res = m.mesh_attr.insert(h);
return typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr); return typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>(res.first->_handle,res.first->n_attr);
} }
@ -955,8 +971,8 @@ public:
typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>
GetPerMeshAttribute( const MeshType & m, const std::string & name){ GetPerMeshAttribute( const MeshType & m, const std::string & name){
assert(!name.empty()); assert(!name.empty());
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
typename std::set<HandlesWrapper > ::const_iterator i; typename std::set<PtrToAttr > ::const_iterator i;
i =m.mesh_attr.find(h1); i =m.mesh_attr.find(h1);
if(i!=m.mesh_attr.end()) if(i!=m.mesh_attr.end())
@ -969,7 +985,7 @@ public:
static static
void void
DeletePerMeshAttribute( MeshType & m,typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> & h){ DeletePerMeshAttribute( MeshType & m,typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> & h){
typename std::set<HandlesWrapper > ::iterator i; typename std::set<PtrToAttr > ::iterator i;
for( i = m.mesh_attr.begin(); i != m.mesh_attr.end(); ++i) for( i = m.mesh_attr.begin(); i != m.mesh_attr.end(); ++i)
if( (*i)._handle == h._handle ){ if( (*i)._handle == h._handle ){
delete (( Attribute<ATTR_TYPE> *)(*i)._handle); delete (( Attribute<ATTR_TYPE> *)(*i)._handle);
@ -980,13 +996,39 @@ public:
static static
void DeletePerMeshAttribute( MeshType & m, std::string name){ void DeletePerMeshAttribute( MeshType & m, std::string name){
HandlesIterator i; AttrIterator i;
HandlesWrapper h1; h1._name = name; PtrToAttr h1; h1._name = name;
i = m.mesh_attr.find(h1); i = m.mesh_attr.find(h1);
assert(i!=m.mesh_attr.end()); assert(i!=m.mesh_attr.end());
delete ((AttributeBase *)(*i)._handle); delete ((AttributeBase *)(*i)._handle);
m.mesh_attr.erase(i); m.mesh_attr.erase(i);
} }
template <class ATTR_TYPE>
static
void FixPaddedPerVertexAttribute ( MeshType & m,PtrToAttr & pa){
// create the container of the right type
SimpleTempData<VertContainer,ATTR_TYPE>* _handle = new SimpleTempData<VertContainer,ATTR_TYPE>(m.vert);
// copy the padded container in the new one
_handle->Resize(m.vert.size());
for(int i = 0; i < m.vert.size(); ++i){
ATTR_TYPE * dest = &(*_handle)[i];
char * ptr = (char*)( ((SimpleTempDataBase<VertContainer> *)pa._handle)->DataBegin());
memcpy((void*)dest ,
(void*) &(ptr[i * pa._sizeof + pa._padding]) ,sizeof(ATTR_TYPE));
}
// remove the padded container
delete ((SimpleTempDataBase<VertContainer>*) pa._handle);
// update the pointer to data
pa._handle = _handle;
// zero the padding
pa._padding = 0;
}
}; // end class }; // end class

View File

@ -238,19 +238,23 @@ class TriMesh: public TriMeshEdgeHolder<VertContainerType,FaceContainerType,Edge
int attrn; // total numer of attribute created int attrn; // total numer of attribute created
class HandlesWrapper{ class PointerToAttribute{
public: public:
void * _handle; std::string _name; void * _handle; // pointer to the SimpleTempData that stores the attribute
int n_attr; std::string _name; // name of the attribute
int _sizeof; // size of the attribute type (used only with VMI loading)
int _padding; // padding (used only with VMI loading)
int n_attr; // unique ID of the attribute
void Resize(const int & sz){((SimpleTempDataBase<VertContainer>*)_handle)->Resize(sz);} void Resize(const int & sz){((SimpleTempDataBase<VertContainer>*)_handle)->Resize(sz);}
void Reorder(std::vector<size_t> & newVertIndex){((SimpleTempDataBase<VertContainer>*)_handle)->Reorder(newVertIndex);} void Reorder(std::vector<size_t> & newVertIndex){((SimpleTempDataBase<VertContainer>*)_handle)->Reorder(newVertIndex);}
bool operator<(const HandlesWrapper b) const { return(_name.empty()&&b._name.empty())?(_handle < b._handle):( _name < b._name);} bool operator<(const PointerToAttribute b) const { return(_name.empty()&&b._name.empty())?(_handle < b._handle):( _name < b._name);}
}; };
std::set< HandlesWrapper > vert_attr; std::set< PointerToAttribute > vert_attr;
std::set< HandlesWrapper > edge_attr; std::set< PointerToAttribute > edge_attr;
std::set< HandlesWrapper > face_attr; std::set< PointerToAttribute > face_attr;
std::set< HandlesWrapper > mesh_attr; std::set< PointerToAttribute > mesh_attr;
template <class ATTR_TYPE, class CONT> template <class ATTR_TYPE, class CONT>
@ -263,8 +267,14 @@ class TriMesh: public TriMeshEdgeHolder<VertContainerType,FaceContainerType,Edge
n_attr = pva.n_attr; n_attr = pva.n_attr;
return (*this); return (*this);
} }
//pointer to the SimpleTempData that stores the attribute
SimpleTempData<CONT,ATTR_TYPE> * _handle; SimpleTempData<CONT,ATTR_TYPE> * _handle;
int n_attr; // its attribute number
// its attribute number
int n_attr;
// access function
template <class RefType> template <class RefType>
ATTR_TYPE & operator [](const RefType & i){return (*_handle)[i];} ATTR_TYPE & operator [](const RefType & i){return (*_handle)[i];}
}; };
@ -337,7 +347,7 @@ public:
/// destructor /// destructor
~TriMesh() ~TriMesh()
{ {
typename std::set< HandlesWrapper>::iterator i; typename std::set< PointerToAttribute>::iterator i;
for( i = vert_attr.begin(); i != vert_attr.end(); ++i) for( i = vert_attr.begin(); i != vert_attr.end(); ++i)
delete ((SimpleTempDataBase<VertContainer>*)(*i)._handle); delete ((SimpleTempDataBase<VertContainer>*)(*i)._handle);
for( i = face_attr.begin(); i != face_attr.end(); ++i) for( i = face_attr.begin(); i != face_attr.end(); ++i)
@ -350,7 +360,7 @@ public:
} }
int Mem(const int & nv, const int & nf) const { int Mem(const int & nv, const int & nf) const {
typename std::set< HandlesWrapper>::const_iterator i; typename std::set< PointerToAttribute>::const_iterator i;
int size = 0; int size = 0;
size += sizeof(TriMesh)+sizeof(VertexType)*nv+sizeof(FaceType)*nf; size += sizeof(TriMesh)+sizeof(VertexType)*nv+sizeof(FaceType)*nf;
@ -583,16 +593,16 @@ bool HasVFAdjacency (const TriMesh < VertContainerType , FaceContainerType, Ed
template <class MESH_TYPE> template <class MESH_TYPE>
bool HasPerVertexAttribute(const MESH_TYPE &m, std::string name){ bool HasPerVertexAttribute(const MESH_TYPE &m, std::string name){
typename std::set< typename MESH_TYPE::HandlesWrapper>::const_iterator ai; typename std::set< typename MESH_TYPE::PointerToAttribute>::const_iterator ai;
typename MESH_TYPE::HandlesWrapper h; typename MESH_TYPE::PointerToAttribute h;
h._name = name; h._name = name;
ai = m.vert_attr.find(h); ai = m.vert_attr.find(h);
return (ai!= m.vert_attr.end() ) ; return (ai!= m.vert_attr.end() ) ;
} }
template <class MESH_TYPE> template <class MESH_TYPE>
bool HasPerFaceAttribute(const MESH_TYPE &m, std::string name){ bool HasPerFaceAttribute(const MESH_TYPE &m, std::string name){
typename std::set< typename MESH_TYPE::HandlesWrapper>::const_iterator ai; typename std::set< typename MESH_TYPE::PointerToAttribute>::const_iterator ai;
typename MESH_TYPE::HandlesWrapper h; typename MESH_TYPE::PointerToAttribute h;
h._name = name; h._name = name;
ai = m.face_attr.find(h); ai = m.face_attr.find(h);
return (ai!= m.face_attr.end() ) ; return (ai!= m.face_attr.end() ) ;
@ -600,8 +610,8 @@ bool HasPerFaceAttribute(const MESH_TYPE &m, std::string name){
template <class MESH_TYPE> template <class MESH_TYPE>
bool HasPerMeshAttribute(const MESH_TYPE &m, std::string name){ bool HasPerMeshAttribute(const MESH_TYPE &m, std::string name){
typename std::set< typename MESH_TYPE::HandlesWrapper>::const_iterator ai; typename std::set< typename MESH_TYPE::PointerToAttribute>::const_iterator ai;
typename MESH_TYPE::HandlesWrapper h; typename MESH_TYPE::PointerToAttribute h;
h._name = name; h._name = name;
ai = m.mesh_attr.find(h); ai = m.mesh_attr.find(h);
return (ai!= m.mesh_attr.end() ) ; return (ai!= m.mesh_attr.end() ) ;