From 7f8260b0a4d954c94bdd1e5777f1f39e6f12301d Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Tue, 23 Mar 2021 16:20:31 +0100 Subject: [PATCH] ConstPerEdgeAttributeHandle --- vcg/complex/allocate.h | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index b1bed546..f185d83f 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -1628,6 +1628,15 @@ public: return false; } + template + static + bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerEdgeAttributeHandle & a){ + if(a._handle == nullptr) return false; + for(AttrIterator i = m.edge_attr.begin(); i!=m.edge_attr.end();++i) + if ( (*i).n_attr == a.n_attr ) return true; + return false; + } + template static typename MeshType::template PerEdgeAttributeHandle @@ -1674,6 +1683,12 @@ public: return AddPerEdgeAttribute(m,name); } + template + static + typename MeshType::template ConstPerEdgeAttributeHandle + GetPerEdgeAttribute( const MeshType & m, std::string name = std::string("")){ + return FindPerEdgeAttribute(m,name); + } template static @@ -1700,6 +1715,24 @@ public: return typename MeshType:: template PerEdgeAttributeHandle(nullptr,0); } + template + static + typename MeshType::template ConstPerEdgeAttributeHandle + FindPerEdgeAttribute( const MeshType & m, const std::string & name){ + if(!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set ::const_iterator i; + + i =m.edge_attr.find(h1); + if(i!=m.edge_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerEdgeAttributeHandle((*i)._handle,(*i).n_attr); + } + } + } + return typename MeshType:: template ConstPerEdgeAttributeHandle(nullptr,0); + } + template static void GetAllPerEdgeAttribute(const MeshType & m, std::vector &all){ all.clear(); @@ -1707,7 +1740,7 @@ public: for(i = m.edge_attr.begin(); i != m.edge_attr.end(); ++i ) if(!(*i)._name.empty()) { - typename MeshType:: template PerEdgeAttributeHandle hh; + typename MeshType:: template ConstPerEdgeAttributeHandle hh; hh = Allocator:: template FindPerEdgeAttribute (m,(*i)._name); if(IsValidHandle(m,hh)) all.push_back((*i)._name);