MorphologicalAttributeFilters
Public API documentation
Loading...
Searching...
No Matches
AreaComputer.hpp
1#pragma once
2
3#include "AttributeComputerDomain.hpp"
4#include "AttributeComputerFamily.hpp"
5#include "../detail/AttributeKernelSupport.hpp"
6#include "../../trees/detail/TreeTraversalDetail.hpp"
7#include "../../trees/MorphologicalTree.hpp"
8
9#include <array>
10#include <concepts>
11#include <string_view>
12
13namespace mmcfilters::attributes::computers {
14
35public:
37 static constexpr std::string_view familyName = "area";
38
40 static constexpr AttributeComputerFamily family = AttributeComputerFamily::Area;
41
43 static constexpr AttributeComputerDomain domain = AttributeComputerDomain::Topology;
44
48 inline static constexpr std::array<Attribute, 1> producedAttributes{AREA};
49
61 template <std::floating_point Real>
63 computeImpl(context.tree, context.buffer, context.attrNames);
64 }
65
66private:
67 template <std::floating_point Real>
68 static void computeImpl(const MorphologicalTree& tree, std::span<Real> buffer, const AttributeNames& attrNames) {
69 auto indexOfArea = [&](NodeId nodeId) { return attrNames.linearIndex(nodeId, AREA); };
70 ::mmcfilters::detail::traversePostOrder(
71 tree,
72 tree.getRoot(),
73 [&](NodeId nodeId) {
74 buffer[indexOfArea(nodeId)] = static_cast<Real>(tree.getNumProperParts(nodeId));
75 },
77 buffer[indexOfArea(parentNodeId)] += buffer[indexOfArea(childNodeId)];
78 },
79 [](NodeId) {});
80 }
81
82public:
88 template <std::floating_point Real>
90 requireUnitAttributeBufferShape(context.tree, context.unitProperParts, context.buffer, context.attrNames);
91 if (!requestsAttribute(context.requestedAttributes, AREA)) {
92 return;
93 }
94 for (NodeId leafIndex = 0; leafIndex < static_cast<NodeId>(context.unitProperParts.size()); ++leafIndex) {
95 context.buffer[context.attrNames.linearIndex(leafIndex, AREA)] = Real{1};
96 }
97 }
98
99};
100
101} // namespace mmcfilters::attributes::computers
Layout object that maps scalar attributes to flat-buffer offsets.
Mutable morphological tree built directly on proper parts and dense node ids.
NodeId getRoot() const
Returns the current hierarchy root.
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.