3#include "AttributeComputerDomain.hpp"
4#include "AttributeComputerFamily.hpp"
5#include "../detail/AttributeKernelSupport.hpp"
6#include "../../trees/detail/TreeTraversalDetail.hpp"
7#include "../../trees/detail/CommittedTreeAccess.hpp"
8#include "../../utils/Contract.hpp"
9#include "../../trees/MorphologicalTree.hpp"
16namespace mmcfilters::attributes::computers {
20template <std::
floating_po
int Real>
inline void validateAreaContext(
const AttributeComputeContext<Real>& context) {
21 requireAttributeBufferShape(context.tree, context.buffer, context.attrNames);
22 if (!context.attrNames.contains(Area)) {
23 throw std::invalid_argument(
"AREA computation requires an AREA column in the output layout.");
30template <std::
floating_po
int Real>
inline void computeArea(
const AttributeComputeContext<Real>& context) {
31 const int stride = context.attrNames.NUM_ATTRIBUTES;
32 const int offset = context.attrNames.indexMap.find(Area)->
second;
33 auto indexOfArea = [&](
NodeId node) {
return static_cast<std::size_t
>(node * stride + offset); };
34 ::mmcfilters::detail::kernel::traversePostOrder(
35 context.tree, context.tree.root(),
37 context.buffer[indexOfArea(node)] = static_cast<Real>(::mmcfilters::detail::CommittedTreeAccess::properPartCardinality(context.tree, node));
39 [&](NodeId parent, NodeId child) { context.buffer[indexOfArea(parent)] += context.buffer[indexOfArea(child)]; }, [](NodeId) {});
70 static constexpr AttributeComputerFamily
family = AttributeComputerFamily::Area;
73 static constexpr AttributeComputerDomain
domain = AttributeComputerDomain::Topology;
93 detail::kernel::computeArea(
context);
int NodeId
Node identifier type used throughout the project.
#define MMCFILTERS_CONTRACT_CHECKED_ONLY(...)
Executes validation statements only when defensive checks are enabled.
Computes the canonical subtree area attribute.
static constexpr std::array< Attribute, 1 > producedAttributes
Canonical list of attributes produced by this computer.
static void computeUnitRows(const UnitAttributeComputeContext< Real > &context)
Materializes AREA for one-pixel unit supports.
static constexpr AttributeComputerDomain domain
Execution domain required by the computer.
static constexpr std::string_view familyName
Family name used in dependency-plan diagnostics.
static constexpr AttributeComputerFamily family
Stable family id used by the scheduler.
static void compute(const AttributeComputeContext< Real > &context)
Computes area by summing direct proper-part counts bottom-up.
Owning result for one computed scalar attribute layout and buffer.
std::vector< Real > second
Flat per-node attribute buffer indexed through first.