3#include "MorphologicalTree.hpp"
4#include "../utils/Altitude.hpp"
5#include "../utils/Contract.hpp"
31 std::size_t topologyMutationVersion_ = 0;
36 void validateNodeAltitudeBufferShape()
const {
38 throw std::runtime_error(
"ValuedMorphologicalTreeView altitude size must match the dense internal-node domain."));
55 : topology_(&
topology), nodeAltitudes_(altitude), topologyMutationVersion_(
topology.getMutationVersion()) {
56 validateNodeAltitudeBufferShape();
69 : topology_(&
topology), nodeAltitudes_(std::
span<
const T>(altitude)), topologyMutationVersion_(
topology.getMutationVersion()) {
70 validateNodeAltitudeBufferShape();
107 throw std::invalid_argument(
"ValuedMorphologicalTreeView::nodeAltitude requires a valid internal NodeId."));
108 return nodeAltitudes_[
static_cast<std::size_t
>(
nodeId)];
constexpr NodeId InvalidNode
Sentinel value used to denote an invalid node identifier.
#define MMCFILTERS_CONTRACT_REQUIRE(condition,...)
Evaluates a caller precondition and its failure action only in checked builds.
Mutable connected-subset tree on a finite pixel domain.
int numInternalNodeSlots() const
Returns the size of the dense internal-node id domain.
bool isAlive(NodeId nodeId) const
Tests whether a node slot currently represents a live node.
NodeId parent(NodeId nodeId) const
Returns the direct parent of nodeId.
Non-owning view pairing a topology with an external altitude span.
AltitudeDifference< T > nodeResidue(NodeId nodeId) const
Returns the altitude difference between a live node and its parent.
const MorphologicalTree & topology() const noexcept
Returns the borrowed tree topology.
T nodeAltitude(NodeId nodeId) const
Returns the altitude associated with an internal node id.
ValuedMorphologicalTreeView(const MorphologicalTree &topology, const NodeAltitudeBuffer< T > &altitude)
Builds a view over a caller-owned altitude buffer.
NodeAltitudeSpan< T > nodeAltitudes() const noexcept
Returns the borrowed altitude span indexed by internal NodeId.
T AltitudeType
Altitude scalar type borrowed by this view.
ValuedMorphologicalTreeView(const MorphologicalTree &, NodeAltitudeBuffer< T > &&)=delete
Rejects temporary altitude buffers that would leave a dangling span.
void requireTopologyUnchanged(const char *context) const
Throws if the borrowed topology changed since view construction.
ValuedMorphologicalTreeView(const MorphologicalTree &topology, NodeAltitudeSpan< T > altitude)
Builds a view over caller-owned topology and altitude storage.
Owning result for one computed scalar attribute layout and buffer.