added typechecking and function to return the list of attributes of a given type

This commit is contained in:
ganovelli 2010-06-16 15:17:42 +00:00
parent 2bbf1c86ef
commit 0a64a31e6e
1 changed files with 94 additions and 45 deletions

View File

@ -41,11 +41,19 @@ namespace vcg {
size_t Index(MeshType &m, typename MeshType::VertexType &v) {return &v-&*m.vert.begin();} size_t Index(MeshType &m, typename MeshType::VertexType &v) {return &v-&*m.vert.begin();}
template<class MeshType> template<class MeshType>
size_t Index(MeshType &m, typename MeshType::FaceType &f) {return &f-&*m.face.begin();} size_t Index(MeshType &m, typename MeshType::FaceType &f) {return &f-&*m.face.begin();}
template<class MeshType>
size_t Index(MeshType &m, typename MeshType::EdgeType &e) {return &e-&*m.edge.begin();}
template<class MeshType>
size_t Index(MeshType &m, typename MeshType::HEdgeType &h) {return &h-&*m.hedge.begin();}
template<class MeshType> template<class MeshType>
size_t Index(MeshType &m, const typename MeshType::VertexType *vp) {return vp-&*m.vert.begin();} size_t Index(MeshType &m, const typename MeshType::VertexType *vp) {return vp-&*m.vert.begin();}
template<class MeshType> template<class MeshType>
size_t Index(MeshType &m, const typename MeshType::FaceType * fp) {return fp-&*m.face.begin();} size_t Index(MeshType &m, const typename MeshType::FaceType * fp) {return fp-&*m.face.begin();}
template<class MeshType>
size_t Index(MeshType &m, typename MeshType::EdgeType* e) {return e-&*m.edge.begin();}
template<class MeshType>
size_t Index(MeshType &m, typename MeshType::HEdgeType* h) {return h-&*m.hedge.begin();}
// Placeholder. // Placeholder.
// this one is called by the Compact and overridden by more specialized functions for OCF classes. // this one is called by the Compact and overridden by more specialized functions for OCF classes.
@ -172,7 +180,7 @@ namespace vcg {
for (ei=m.edge.begin(); ei!=m.edge.end(); ++ei) for (ei=m.edge.begin(); ei!=m.edge.end(); ++ei)
if(!(*ei).IsD()) if(!(*ei).IsD())
{ {
if(HasEVAdjacency (m)) { pu.Update((*ei).V(0));pu.Update((*ei).V(1));} if(HasEVAdjacency (m)) { pu.Update((*ei).EVp(0));pu.Update((*ei).EVp(1));}
// if(HasEVAdjacency(m)) pu.Update((*ei).EVp()); // if(HasEVAdjacency(m)) pu.Update((*ei).EVp());
} }
HEdgeIterator hi; HEdgeIterator hi;
@ -578,7 +586,7 @@ namespace vcg {
if(newVertIndex[i]<size_t(m.vn)) if(newVertIndex[i]<size_t(m.vn))
{ {
assert(!m.vert[i].IsD()); assert(!m.vert[i].IsD());
m.vert[ newVertIndex[i] ].ImportLocal(m.vert[i]); m.vert[ newVertIndex[i] ].ImportData(m.vert[i]);
if(HasVFAdjacency(m)) if(HasVFAdjacency(m))
if (m.vert[i].cVFp()!=0) if (m.vert[i].cVFp()!=0)
{ {
@ -664,7 +672,7 @@ namespace vcg {
{ {
if(pos!=i) if(pos!=i)
{ {
m.face[pos].ImportLocal(m.face[i]); m.face[pos].ImportData(m.face[i]);
m.face[pos].V(0) = m.face[i].V(0); m.face[pos].V(0) = m.face[i].V(0);
m.face[pos].V(1) = m.face[i].V(1); m.face[pos].V(1) = m.face[i].V(1);
m.face[pos].V(2) = m.face[i].V(2); m.face[pos].V(2) = m.face[i].V(2);
@ -760,6 +768,7 @@ public:
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._typename = typeid(ATTR_TYPE).name();
h._sizeof = sizeof(ATTR_TYPE); h._sizeof = sizeof(ATTR_TYPE);
h._padding = 0; h._padding = 0;
h._handle = (void*) new SimpleTempData<VertContainer,ATTR_TYPE>(m.vert); h._handle = (void*) new SimpleTempData<VertContainer,ATTR_TYPE>(m.vert);
@ -785,7 +794,8 @@ public:
typename std::set<PointerToAttribute > :: iterator i; typename std::set<PointerToAttribute > :: 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)._typename == typeid(ATTR_TYPE).name() ){
if( (*i)._padding != 0 ){ if( (*i)._padding != 0 ){
PointerToAttribute attr = (*i); // copy the PointerToAttribute PointerToAttribute attr = (*i); // copy the PointerToAttribute
m.vert_attr.erase(i); // remove it from the set m.vert_attr.erase(i); // remove it from the set
@ -796,13 +806,20 @@ public:
} }
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
return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE>
static void GetAllPerVertexAttribute(const MeshType & m, std::vector<std::string> &all){
typename std::set<PointerToAttribute > :: iterator i;
for(i = m.vert_attr.begin(); i != m.vert_attr.end(); ++i )
if((*i)._typename == typeid(ATTR_TYPE).name())
all.push_back((*i)._name);
}
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
void void
@ -849,6 +866,8 @@ public:
i = m.edge_attr.find(h); i = m.edge_attr.find(h);
assert(i ==m.edge_attr.end() );// an attribute with this name exists assert(i ==m.edge_attr.end() );// an attribute with this name exists
} }
h._sizeof = sizeof(ATTR_TYPE);
h._typename = typeid(ATTR_TYPE).name();
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;
@ -872,12 +891,22 @@ public:
typename std::set<PointerToAttribute > ::const_iterator i; typename std::set<PointerToAttribute > ::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())
return typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr); if((*i)._typename == typeid(ATTR_TYPE).name() )
else return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0);
return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE>
static void GetAllPerEdgeAttribute(const MeshType & m, std::vector<std::string> &all){
typename std::set<PointerToAttribute > :: iterator i;
for(i = m.edge_attr.begin(); i != m.edge_attr.end(); ++i )
if((*i)._typename == typeid(ATTR_TYPE).name())
all.push_back((*i)._name);
}
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
void void
@ -922,6 +951,7 @@ public:
i = m.face_attr.find(h); i = m.face_attr.find(h);
assert(i ==m.face_attr.end() );// an attribute with this name exists assert(i ==m.face_attr.end() );// an attribute with this name exists
} }
h._typename = typeid(ATTR_TYPE).name();
h._sizeof = sizeof(ATTR_TYPE); h._sizeof = sizeof(ATTR_TYPE);
h._handle = (void*) new SimpleTempData<FaceContainer,ATTR_TYPE>(m.face); h._handle = (void*) new SimpleTempData<FaceContainer,ATTR_TYPE>(m.face);
m.attrn++; m.attrn++;
@ -946,7 +976,8 @@ public:
typename std::set<PointerToAttribute > ::iterator i; typename std::set<PointerToAttribute > ::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())
if((*i)._typename == typeid(ATTR_TYPE).name() ){
if( (*i)._padding != 0 ){ if( (*i)._padding != 0 ){
PointerToAttribute attr = (*i); // copy the PointerToAttribute PointerToAttribute attr = (*i); // copy the PointerToAttribute
m.face_attr.erase(i); // remove it from the set m.face_attr.erase(i); // remove it from the set
@ -957,10 +988,17 @@ public:
} }
return typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr); return typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
} }
else
return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE>
static void GetAllPerFaceAttribute(const MeshType & m, std::vector<std::string> &all){
typename std::set<PointerToAttribute > :: iterator i;
for(i = m.face_attr.begin(); i != m.face_attr.end(); ++i )
if((*i)._typename == typeid(ATTR_TYPE).name())
all.push_back((*i)._name);
}
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
void void
@ -1005,6 +1043,7 @@ public:
i = m.mesh_attr.find(h); i = m.mesh_attr.find(h);
assert(i ==m.mesh_attr.end() );// an attribute with this name exists assert(i ==m.mesh_attr.end() );// an attribute with this name exists
} }
h._typename = typeid(ATTR_TYPE).name();
h._sizeof = sizeof(ATTR_TYPE); h._sizeof = sizeof(ATTR_TYPE);
h._handle = (void*) new Attribute<ATTR_TYPE>(); h._handle = (void*) new Attribute<ATTR_TYPE>();
m.attrn++; m.attrn++;
@ -1022,7 +1061,8 @@ public:
typename std::set<PointerToAttribute > ::iterator i; typename std::set<PointerToAttribute > ::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())
if((*i)._typename == typeid(ATTR_TYPE).name() ){
if( (*i)._padding != 0 ){ if( (*i)._padding != 0 ){
PointerToAttribute attr = (*i); // copy the PointerToAttribute PointerToAttribute attr = (*i); // copy the PointerToAttribute
m.mesh_attr.erase(i); // remove it from the set m.mesh_attr.erase(i); // remove it from the set
@ -1034,10 +1074,18 @@ public:
return typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr); return typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
} }
else
return typename MeshType:: template PerMeshAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerMeshAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE>
static void GetAllPerMeshAttribute(const MeshType & m, std::vector<std::string> &all){
typename std::set<PointerToAttribute > :: iterator i;
for(i = m.mesh_attr.begin(); i != m.mesh_attr.end(); ++i )
if((*i)._typename == typeid(ATTR_TYPE).name())
all.push_back((*i)._name);
}
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
void void
@ -1145,7 +1193,8 @@ public:
} }
/* This section enables the calling of all allocating/deallocating functions by attribute name /* This section enables the calling of all allocating/deallocating functions just by attribute name,
without knowing the type
*/ */
// base class of all name type bound // base class of all name type bound