diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index 3a6a6b85..b1bed546 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -1423,8 +1423,9 @@ public: public: - /*! \brief Check if an handle to a Per-Vertex Attribute is valid - */ + /** + * @brief Checks if a handle to a Per-Vertex Attribute is valid + */ template static bool IsValidHandle( const MeshType & m, const typename MeshType::template PerVertexAttributeHandle & a){ @@ -1434,8 +1435,9 @@ public: return false; } - /*! \brief Check if a const handle to a Per-Vertex Attribute is valid - */ + /** + * @brief Checks if a const handle to a Per-Vertex Attribute is valid + */ template static bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerVertexAttributeHandle & a){ @@ -1501,12 +1503,8 @@ public: template static typename MeshType::template ConstPerVertexAttributeHandle - GetConstPerVertexAttribute( const MeshType & m, std::string name = std::string("")){ - typename MeshType::template ConstPerVertexAttributeHandle h; - if(!name.empty()){ - return FindConstPerVertexAttribute(m,name); - } - return typename MeshType:: template ConstPerVertexAttributeHandle(nullptr,0); + GetPerVertexAttribute( const MeshType & m, std::string name = std::string("")){ + return FindPerVertexAttribute(m,name); } /*! \brief Try to retrieve an handle to an attribute with a given name and ATTR_TYPE @@ -1537,23 +1535,26 @@ public: } /** - * Same as the one above, but without modifying the attribute if it is found. - * (A "find" function should never modify the container in which is looking for..) - * Input mesh is const. + * @brief Try to retrieve a const handle to an attribute with a given name + * and ATTR_TYPE, from the given const mesh. + * If not found, an invalid handle will be returned. + * Check it with the function IsValidHandle */ template static typename MeshType::template ConstPerVertexAttributeHandle - FindConstPerVertexAttribute( const MeshType & m, const std::string & name) + FindPerVertexAttribute( const MeshType & m, const std::string & name) { - assert(!name.empty()); - PointerToAttribute h1; h1._name = name; - typename std::set :: iterator i; + if(!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set :: iterator i; - i =m.vert_attr.find(h1); - if(i!=m.vert_attr.end()) - if((*i)._sizeof == sizeof(ATTR_TYPE) ){ - return typename MeshType::template ConstPerVertexAttributeHandle((*i)._handle,(*i).n_attr); + i =m.vert_attr.find(h1); + if(i!=m.vert_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerVertexAttributeHandle((*i)._handle,(*i).n_attr); + } } + } return typename MeshType:: template ConstPerVertexAttributeHandle(nullptr,0); } @@ -1568,7 +1569,7 @@ public: if(!(*i)._name.empty()) { typename MeshType:: template ConstPerVertexAttributeHandle hh; - hh = Allocator:: template FindConstPerVertexAttribute (m,(*i)._name); + hh = Allocator:: template FindPerVertexAttribute (m,(*i)._name); if(IsValidHandle(m,hh)) all.push_back((*i)._name); } @@ -1742,6 +1743,9 @@ public: } /// Per Face Attributes + /** + * @brief Checks if a handle to a Per-Face attribute is valid + */ template static bool IsValidHandle( const MeshType & m, const typename MeshType::template PerFaceAttributeHandle & a){ @@ -1751,6 +1755,18 @@ public: return false; } + /** + * @brief Checks if a const handle to a Per-Face attribute is valid + */ + template + static + bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerFaceAttributeHandle & a){ + if(a._handle == nullptr) return false; + for(AttrIterator i = m.face_attr.begin(); i!=m.face_attr.end();++i) + if ( (*i).n_attr == a.n_attr ) return true; + return false; + } + template static typename MeshType::template PerFaceAttributeHandle @@ -1803,13 +1819,9 @@ public: */ template static - typename MeshType::template PerFaceAttributeHandle + typename MeshType::template ConstPerFaceAttributeHandle GetPerFaceAttribute( const MeshType & m, std::string name = std::string("")){ - typename MeshType::template PerFaceAttributeHandle h; - if(!name.empty()){ - return FindPerFaceAttribute(m,name); - } - return typename MeshType:: template PerFaceAttributeHandle(nullptr,0); + return FindPerFaceAttribute(m,name); } template @@ -1823,7 +1835,7 @@ public: i =m.face_attr.find(h1); if(i!=m.face_attr.end()) if((*i)._sizeof == sizeof(ATTR_TYPE) ){ - if( (*i)._padding != 0 ){ + if( (*i)._padding != 0 ){ PointerToAttribute attr = (*i); // copy the PointerToAttribute m.face_attr.erase(i); // remove it from the set FixPaddedPerFaceAttribute(m,attr); @@ -1837,24 +1849,27 @@ public: } /** - * Same as the one above, but without modifying the attribute if it is found. - * (A "find" function should never modify the container in which is looking for..) - * Input mesh is const. + * @brief Try to retrieve a const handle to an attribute with a given name + * and ATTR_TYPE, from the given const mesh. + * If not found, an invalid handle will be returned. + * Check it with the function IsValidHandle */ template static - typename MeshType::template PerFaceAttributeHandle + typename MeshType::template ConstPerFaceAttributeHandle FindPerFaceAttribute( const MeshType & m, const std::string & name){ - assert(!name.empty()); - PointerToAttribute h1; h1._name = name; - typename std::set ::iterator i; + if(!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set ::iterator i; - i =m.face_attr.find(h1); - if(i!=m.face_attr.end()) - if((*i)._sizeof == sizeof(ATTR_TYPE) ){ - return typename MeshType::template PerFaceAttributeHandle((*i)._handle,(*i).n_attr); + i =m.face_attr.find(h1); + if(i!=m.face_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerFaceAttributeHandle((*i)._handle,(*i).n_attr); + } } - return typename MeshType:: template PerFaceAttributeHandle(nullptr,0); + } + return typename MeshType:: template ConstPerFaceAttributeHandle(nullptr,0); } template @@ -1864,7 +1879,7 @@ public: for(i = m.face_attr.begin(); i != m.face_attr.end(); ++i ) if(!(*i)._name.empty()) { - typename MeshType:: template PerFaceAttributeHandle hh; + typename MeshType:: template ConstPerFaceAttributeHandle hh; hh = Allocator:: template FindPerFaceAttribute (m,(*i)._name); if(IsValidHandle(m,hh)) all.push_back((*i)._name); diff --git a/vcg/complex/base.h b/vcg/complex/base.h index 678d715e..2afd27a1 100644 --- a/vcg/complex/base.h +++ b/vcg/complex/base.h @@ -330,7 +330,6 @@ public: ConstPerVertexAttributeHandle( const void *ah,const int & n):ConstAttributeHandle(ah,n){} }; - template class PerFaceAttributeHandle: public AttributeHandle{ public: @@ -338,6 +337,13 @@ public: PerFaceAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){} }; + template + class ConstPerFaceAttributeHandle: public ConstAttributeHandle{ + public: + ConstPerFaceAttributeHandle():ConstAttributeHandle(){} + ConstPerFaceAttributeHandle( void *ah,const int & n):ConstAttributeHandle(ah,n){} + }; + template class PerEdgeAttributeHandle: public AttributeHandle{ public: @@ -345,6 +351,13 @@ public: PerEdgeAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){} }; + template + class ConstPerEdgeAttributeHandle: public ConstAttributeHandle{ + public: + ConstPerEdgeAttributeHandle():ConstAttributeHandle(){} + ConstPerEdgeAttributeHandle( void *ah,const int & n):ConstAttributeHandle(ah,n){} + }; + template class PerTetraAttributeHandle : public AttributeHandle { @@ -353,6 +366,14 @@ public: PerTetraAttributeHandle(void *ah, const int &n) : AttributeHandle(ah, n) {} }; + template + class ConstPerTetraAttributeHandle : public ConstAttributeHandle + { + public: + ConstPerTetraAttributeHandle() : ConstAttributeHandle() {} + ConstPerTetraAttributeHandle(void *ah, const int &n) : ConstAttributeHandle(ah, n) {} + }; + template class PerMeshAttributeHandle{ public: diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index c871d8d2..d2c9d3cf 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -374,22 +374,22 @@ namespace vcg { assert(vcg::tri::HasPerVertexAttribute(m,pi.VertAttrNameVec[i])); switch (pi.VertDescriptorVec[i].stotype1) { - case ply::T_FLOAT : thfv[i] = vcg::tri::Allocator::template FindConstPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; - case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator::template FindConstPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; - case ply::T_INT : thiv[i] = vcg::tri::Allocator::template FindConstPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; - case ply::T_SHORT : thsv[i] = vcg::tri::Allocator::template FindConstPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; - case ply::T_CHAR : thcv[i] = vcg::tri::Allocator::template FindConstPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; - case ply::T_UCHAR : thuv[i] = vcg::tri::Allocator::template FindConstPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_FLOAT : thfv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_INT : thiv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_SHORT : thsv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_CHAR : thcv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_UCHAR : thuv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; default : assert(0); } } } - std::vector > thff(pi.FaceDescriptorVec.size()); - std::vector > thdf(pi.FaceDescriptorVec.size()); - std::vector > thif(pi.FaceDescriptorVec.size()); - std::vector > thsf(pi.FaceDescriptorVec.size()); - std::vector > thcf(pi.FaceDescriptorVec.size()); - std::vector > thuf(pi.FaceDescriptorVec.size()); + std::vector > thff(pi.FaceDescriptorVec.size()); + std::vector > thdf(pi.FaceDescriptorVec.size()); + std::vector > thif(pi.FaceDescriptorVec.size()); + std::vector > thsf(pi.FaceDescriptorVec.size()); + std::vector > thcf(pi.FaceDescriptorVec.size()); + std::vector > thuf(pi.FaceDescriptorVec.size()); for(size_t i=0;i