diff --git a/src/wmtk/attribute/AttributeManager.cpp b/src/wmtk/attribute/AttributeManager.cpp index ba2227fb82..36d2deae57 100644 --- a/src/wmtk/attribute/AttributeManager.cpp +++ b/src/wmtk/attribute/AttributeManager.cpp @@ -280,13 +280,15 @@ std::vector AttributeManager::get_all_attrib const std::vector>& mesh_attributes = get(); for (size_t pt_index = 0; pt_index < mesh_attributes.size(); ++pt_index) { + const PrimitiveType pt = get_primitive_type_from_id(pt_index); + + auto handle_converter = [pt](const AttributeHandle& h) -> TypedAttributeHandle { + return {h, pt}; + return TypedAttributeHandle{h,pt}; + }; size_t count = mesh_attributes[pt_index].attribute_count(); - for (int64_t index = 0; index < count; ++index) { - TypedAttributeHandle t; - t.m_base_handle.index = index; - t.m_primitive_type = get_primitive_type_from_id(pt_index); - handles.emplace_back(t); - } + const auto active_handles = mesh_attributes[pt_index].active_attributes(); + std::transform(active_handles.begin(), active_handles.end(), std::back_inserter(handles), handle_converter); } }; run(double{}); diff --git a/src/wmtk/attribute/MeshAttributes.cpp b/src/wmtk/attribute/MeshAttributes.cpp index 3d0dd62b38..343b664e21 100644 --- a/src/wmtk/attribute/MeshAttributes.cpp +++ b/src/wmtk/attribute/MeshAttributes.cpp @@ -200,7 +200,21 @@ int64_t MeshAttributes::reserved_size() const template size_t MeshAttributes::attribute_count() const { - return m_attributes.size(); + return active_attributes().size(); +} +template +auto MeshAttributes::active_attributes() const -> std::vector +{ + std::vector handles; + handles.reserve(m_attributes.size()); + for(size_t j = 0; j < m_attributes.size(); ++j) { + if(bool(m_attributes[j])) { + handles.emplace_back(j); + } + } + + return handles; + } template diff --git a/src/wmtk/attribute/MeshAttributes.hpp b/src/wmtk/attribute/MeshAttributes.hpp index fe9f13dbaa..0dbebd348a 100644 --- a/src/wmtk/attribute/MeshAttributes.hpp +++ b/src/wmtk/attribute/MeshAttributes.hpp @@ -95,8 +95,13 @@ class MeshAttributes : public wmtk::utils::MerkleTreeInteriorNode bool has_attribute(const std::string& name) const; - // the number of attributes held in this object + // the number of active attributes held in this object + // Note that the set of active attribute indices is not defined by the integers between 0, attribute_count. To get a list of valid handles use active_attributes + // This function is not that fast size_t attribute_count() const; + + // Returns a vector of handles to the set of active attributes + std::vector active_attributes() const; void assert_capacity_valid(int64_t cap) const; protected: