3#include "AttributeComputerDomain.hpp"
4#include "AttributeComputerFamily.hpp"
5#include "../detail/AttributeKernelSupport.hpp"
6#include "../../trees/detail/TreeKernelAccess.hpp"
7#include "../../utils/Contract.hpp"
8#include "../../trees/MorphologicalTree.hpp"
15namespace mmcfilters::attributes::computers {
19template <std::
floating_po
int Real>
inline void validateAreaContext(
const AttributeComputeContext<Real>& context) {
20 requireAttributeBufferShape(context.tree, context.buffer, context.attrNames);
21 if (!context.attrNames.contains(Area)) {
22 throw std::invalid_argument(
"AREA computation requires an AREA column in the output layout.");
29template <std::
floating_po
int Real>
inline void computeArea(
const AttributeComputeContext<Real>& context) {
30 const int stride = context.attrNames.NUM_ATTRIBUTES;
31 const int offset = context.attrNames.indexMap.find(Area)->
second;
32 auto indexOfArea = [&](
NodeId node) {
return static_cast<std::size_t
>(node * stride + offset); };
33 ::mmcfilters::detail::TreeKernelAccess::traversePostOrder(
34 context.tree, context.tree.root(),
36 context.buffer[indexOfArea(node)] = static_cast<Real>(::mmcfilters::detail::TreeKernelAccess::properPartCardinality(context.tree, node));
38 [&](NodeId parent, NodeId child) { context.buffer[indexOfArea(parent)] += context.buffer[indexOfArea(child)]; }, [](NodeId) {});
69 static constexpr AttributeComputerFamily
family = AttributeComputerFamily::Area;
72 static constexpr AttributeComputerDomain
domain = AttributeComputerDomain::Topology;
92 detail::kernel::computeArea(
context);
105 computeUnitRowsEstablished(
context);
115 template <
class Computer,
class Context>
friend void mmcfilters::detail::kernel::computeUnitRows(
const Context&
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.