From 94dc161edb8471026ac11f156db566501cc0ad8f Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Tue, 23 Mar 2021 16:30:36 +0100 Subject: [PATCH] ConstPerTetraAttributeHandle --- vcg/complex/allocate.h | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index f185d83f..170ac390 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -1957,6 +1957,17 @@ public: return false; } + template + static bool IsValidHandle(const MeshType & m, const typename MeshType::template ConstPerTetraAttributeHandle & a) + { + if (a._handle == nullptr) + return false; + for (AttrIterator i = m.tetra_attr.begin(); i != m.tetra_attr.end(); ++i) + if ((*i).n_attr == a.n_attr) + return true; + return false; + } + template static typename MeshType::template PerTetraAttributeHandle AddPerTetraAttribute(MeshType & m, std::string name) { @@ -2002,6 +2013,12 @@ public: return AddPerTetraAttribute(m, name); } + template + static typename MeshType::template ConstPerTetraAttributeHandle GetPerTetraAttribute(const MeshType &m, std::string name = std::string("")) + { + return FindPerTetraAttribute(m, name); + } + template static typename MeshType::template PerTetraAttributeHandle FindPerTetraAttribute(MeshType &m, const std::string &name) { @@ -2029,14 +2046,33 @@ public: } template - static void GetAllPerTetraAttribute(MeshType &m, std::vector &all) + static typename MeshType::template ConstPerTetraAttributeHandle FindPerTetraAttribute(MeshType &m, const std::string &name) + { + if(!name.empty()){ + PointerToAttribute h1; + h1._name = name; + typename std::set::iterator i; + + i = m.tetra_attr.find(h1); + if (i != m.tetra_attr.end()){ + if ((*i)._sizeof == sizeof(ATTR_TYPE)) + { + return typename MeshType::template ConstPerTetraAttributeHandle((*i)._handle, (*i).n_attr); + } + } + } + return typename MeshType::template ConstPerTetraAttributeHandle(nullptr, 0); + } + + template + static void GetAllPerTetraAttribute(const MeshType &m, std::vector &all) { all.clear(); typename std::set::const_iterator i; for (i = m.tetra_attr.begin(); i != m.tetra_attr.end(); ++i) if (!(*i)._name.empty()) { - typename MeshType::template PerTetraAttributeHandle hh; + typename MeshType::template ConstPerTetraAttributeHandle hh; hh = Allocator::template FindPerTetraAttribute(m, (*i)._name); if (IsValidHandle(m, hh)) all.push_back((*i)._name);