3#include "AttributeRegistry.hpp"
4#include "AttributeTypes.hpp"
5#include "../utils/Contract.hpp"
10#include <unordered_map>
22inline const std::unordered_map<AttributeGroup, std::vector<Attribute>>& ATTRIBUTE_GROUPS = attributes::registry::attributeGroups();
35 std::unordered_map<NodeAttributeSampleKey, int>
indexMap;
59 std::unordered_map<NodeAttributeSampleKey, int>
map;
62 for (std::size_t
i = 0;
i < attributes.size(); ++
i) {
66 inserted,
throw std::invalid_argument(
"NodeAttributeSampleLayout::create received duplicate attribute " +
toString(
key)));
133 std::string name(attributes::registry::name(attribute));
135 if (sampleOffset < 0) {
136 name +=
"_ANCESTOR_" + std::to_string(-sampleOffset);
137 }
else if (sampleOffset > 0) {
138 name +=
"_DESCENDANT_" + std::to_string(sampleOffset);
190 std::unordered_map<Attribute, int>
map;
192 for (
auto attr : attributes) {
195 throw std::invalid_argument(
"AttributeNames::fromList received duplicate attribute " +
toString(
attr)));
207 auto it = ATTRIBUTE_GROUPS.find(
group);
263 static std::string
describe(Attribute
attr) {
return std::string(attributes::registry::description(
attr)); }
273 [[
nodiscard]]
static std::optional<Attribute>
parse(
const std::string&
str) {
return attributes::registry::parse(
str); }
#define MMCFILTERS_CONTRACT_REQUIRE(condition,...)
Evaluates a caller precondition and its failure action only in checked builds.
Layout object that maps scalar attributes to flat-buffer offsets.
static std::string describe(Attribute attr)
Returns a user-facing description of an attribute.
static std::string toString(Attribute attr)
Returns the stable symbolic name associated with attr.
static AttributeNames fromList(const std::vector< Attribute > &attributes)
Builds a dense layout from an explicit attribute list.
static AttributeNames fromGroup(AttributeGroup group)
Builds a layout from a public attribute group.
int getIndex(Attribute attr) const
Returns the per-node offset associated with attr.
static std::optional< Attribute > parse(const std::string &str)
Parses a stable symbolic attribute name.
int linearIndex(int nodeIndex, Attribute attr) const
Returns the linear index in the flat buffer for (node, attr).
const int NUM_ATTRIBUTES
Number of scalar attributes stored for each node.
int offset(Attribute attr) const
Returns the per-node offset associated with attr.
AttributeNames(std::unordered_map< Attribute, int > &&map)
Constructs a layout from an already validated offset map.
std::unordered_map< Attribute, int > indexMap
Maps each requested attribute to its per-node offset.
bool contains(Attribute attr) const noexcept
Returns whether this layout contains attr.
Layout for node attributes sampled at signed ancestor/current/descendant offsets.
const int NUM_ATTRIBUTES
Number of sampled entries stored for each node.
static NodeAttributeSampleLayout create(int samplingRadius, const std::vector< Attribute > &attributes)
Builds the canonical dense layout for offsets in [-samplingRadius, samplingRadius].
int getIndex(NodeAttributeSampleKey sampleKey) const
Returns the per-node offset associated with a composite sample key.
std::unordered_map< NodeAttributeSampleKey, int > indexMap
Maps each (attribute, sampleOffset) key to its per-node offset.
int getIndex(Attribute attribute, int sampleOffset) const
Returns the per-node offset associated with (attribute, sampleOffset).
NodeAttributeSampleLayout(std::unordered_map< NodeAttributeSampleKey, int > &&map)
Constructs a layout from an already validated offset map.
static std::string toString(Attribute attribute, int sampleOffset)
Returns a serialized label for an attribute at a sample offset.
static std::string toString(NodeAttributeSampleKey sampleKey)
Returns a human-readable label for a composite key.
int linearIndex(int nodeIndex, NodeAttributeSampleKey sampleKey) const
Convenience overload taking a NodeAttributeSampleKey.
int linearIndex(int nodeIndex, Attribute attribute, int sampleOffset) const
Returns the linear index in the flat buffer for a given node and sampled attribute.
Owning result for one computed scalar attribute layout and buffer.
std::vector< Real > second
Flat per-node attribute buffer indexed through first.
Composite key used to index sampled node-attribute layouts.