From 0a64a31e6e4c21e496d54600cbf1d53f0304a1c1 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Wed, 16 Jun 2010 15:17:42 +0000 Subject: [PATCH] added typechecking and function to return the list of attributes of a given type --- vcg/complex/trimesh/allocate.h | 139 ++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 45 deletions(-) diff --git a/vcg/complex/trimesh/allocate.h b/vcg/complex/trimesh/allocate.h index 0726e2d8..2156d8ef 100644 --- a/vcg/complex/trimesh/allocate.h +++ b/vcg/complex/trimesh/allocate.h @@ -41,11 +41,19 @@ namespace vcg { size_t Index(MeshType &m, typename MeshType::VertexType &v) {return &v-&*m.vert.begin();} template size_t Index(MeshType &m, typename MeshType::FaceType &f) {return &f-&*m.face.begin();} + template + size_t Index(MeshType &m, typename MeshType::EdgeType &e) {return &e-&*m.edge.begin();} + template + size_t Index(MeshType &m, typename MeshType::HEdgeType &h) {return &h-&*m.hedge.begin();} template size_t Index(MeshType &m, const typename MeshType::VertexType *vp) {return vp-&*m.vert.begin();} template size_t Index(MeshType &m, const typename MeshType::FaceType * fp) {return fp-&*m.face.begin();} + template + size_t Index(MeshType &m, typename MeshType::EdgeType* e) {return e-&*m.edge.begin();} + template + size_t Index(MeshType &m, typename MeshType::HEdgeType* h) {return h-&*m.hedge.begin();} // Placeholder. // 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) 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()); } HEdgeIterator hi; @@ -338,7 +346,7 @@ namespace vcg { { if(HasFHAdjacency(m)) if(!(*fi).IsD() && (*fi).FHp()) - pu.Update((*fi).FHp()); + pu.Update((*fi).FHp()); } { @@ -578,7 +586,7 @@ namespace vcg { if(newVertIndex[i](m.vert); @@ -785,24 +794,32 @@ public: typename std::set :: iterator i; i =m.vert_attr.find(h1); - if(i!=m.vert_attr.end()){ - if( (*i)._padding != 0 ){ - PointerToAttribute attr = (*i); // copy the PointerToAttribute - m.vert_attr.erase(i); // remove it from the set - FixPaddedPerVertexAttribute(m,attr); - std::pair new_i = m.vert_attr.insert(attr); // insert the modified PointerToAttribute - assert(new_i.second); - i = new_i.first; - } - - return typename MeshType::template PerVertexAttributeHandle((*i)._handle,(*i).n_attr); + if(i!=m.vert_attr.end()) + if((*i)._typename == typeid(ATTR_TYPE).name() ){ + if( (*i)._padding != 0 ){ + PointerToAttribute attr = (*i); // copy the PointerToAttribute + m.vert_attr.erase(i); // remove it from the set + FixPaddedPerVertexAttribute(m,attr); + std::pair new_i = m.vert_attr.insert(attr); // insert the modified PointerToAttribute + assert(new_i.second); + i = new_i.first; + } + return typename MeshType::template PerVertexAttributeHandle((*i)._handle,(*i).n_attr); } - else - return typename MeshType:: template PerVertexAttributeHandle(NULL,0); + + return typename MeshType:: template PerVertexAttributeHandle(NULL,0); } + template + static void GetAllPerVertexAttribute(const MeshType & m, std::vector &all){ + typename std::set :: 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 static void @@ -849,6 +866,8 @@ public: i = m.edge_attr.find(h); 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(m.edge); m.attrn++; h.n_attr = m.attrn; @@ -872,10 +891,20 @@ public: typename std::set ::const_iterator i; i =m.edge_attr.find(h1); + if(i!=m.edge_attr.end()) - return typename MeshType::template PerFaceAttributeHandle((*i)._handle,(*i).n_attr); - else - return typename MeshType:: template PerFaceAttributeHandle(NULL,0); + if((*i)._typename == typeid(ATTR_TYPE).name() ) + return typename MeshType:: template PerVertexAttributeHandle(NULL,0); + + return typename MeshType:: template PerFaceAttributeHandle(NULL,0); + } + + template + static void GetAllPerEdgeAttribute(const MeshType & m, std::vector &all){ + typename std::set :: 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 @@ -922,6 +951,7 @@ public: i = m.face_attr.find(h); assert(i ==m.face_attr.end() );// an attribute with this name exists } + h._typename = typeid(ATTR_TYPE).name(); h._sizeof = sizeof(ATTR_TYPE); h._handle = (void*) new SimpleTempData(m.face); m.attrn++; @@ -946,19 +976,27 @@ public: typename std::set ::iterator i; i =m.face_attr.find(h1); - if(i!=m.face_attr.end()){ - if( (*i)._padding != 0 ){ - PointerToAttribute attr = (*i); // copy the PointerToAttribute - m.face_attr.erase(i); // remove it from the set - FixPaddedPerFaceAttribute(m,attr); - std::pair new_i = m.face_attr.insert(attr); // insert the modified PointerToAttribute - assert(new_i.second); - i = new_i.first; + if(i!=m.face_attr.end()) + if((*i)._typename == typeid(ATTR_TYPE).name() ){ + if( (*i)._padding != 0 ){ + PointerToAttribute attr = (*i); // copy the PointerToAttribute + m.face_attr.erase(i); // remove it from the set + FixPaddedPerFaceAttribute(m,attr); + std::pair new_i = m.face_attr.insert(attr); // insert the modified PointerToAttribute + assert(new_i.second); + i = new_i.first; + } + return typename MeshType::template PerFaceAttributeHandle((*i)._handle,(*i).n_attr); } - return typename MeshType::template PerFaceAttributeHandle((*i)._handle,(*i).n_attr); - } - else - return typename MeshType:: template PerFaceAttributeHandle(NULL,0); + return typename MeshType:: template PerFaceAttributeHandle(NULL,0); + } + + template + static void GetAllPerFaceAttribute(const MeshType & m, std::vector &all){ + typename std::set :: 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 @@ -1005,6 +1043,7 @@ public: i = m.mesh_attr.find(h); assert(i ==m.mesh_attr.end() );// an attribute with this name exists } + h._typename = typeid(ATTR_TYPE).name(); h._sizeof = sizeof(ATTR_TYPE); h._handle = (void*) new Attribute(); m.attrn++; @@ -1022,20 +1061,29 @@ public: typename std::set ::iterator i; i =m.mesh_attr.find(h1); - if(i!=m.mesh_attr.end()){ - if( (*i)._padding != 0 ){ - PointerToAttribute attr = (*i); // copy the PointerToAttribute - m.mesh_attr.erase(i); // remove it from the set - FixPaddedPerMeshAttribute(m,attr); - std::pair new_i = m.mesh_attr.insert(attr); // insert the modified PointerToAttribute - assert(new_i.second); - i = new_i.first; - } + if(i!=m.mesh_attr.end()) + if((*i)._typename == typeid(ATTR_TYPE).name() ){ + if( (*i)._padding != 0 ){ + PointerToAttribute attr = (*i); // copy the PointerToAttribute + m.mesh_attr.erase(i); // remove it from the set + FixPaddedPerMeshAttribute(m,attr); + std::pair new_i = m.mesh_attr.insert(attr); // insert the modified PointerToAttribute + assert(new_i.second); + i = new_i.first; + } - return typename MeshType::template PerMeshAttributeHandle((*i)._handle,(*i).n_attr); + return typename MeshType::template PerMeshAttributeHandle((*i)._handle,(*i).n_attr); } - else - return typename MeshType:: template PerMeshAttributeHandle(NULL,0); + + return typename MeshType:: template PerMeshAttributeHandle(NULL,0); + } + + template + static void GetAllPerMeshAttribute(const MeshType & m, std::vector &all){ + typename std::set :: 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 @@ -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