3#include "MorphologicalTree.hpp"
4#include "TreeAltitudeAlgorithms.hpp"
30template <AltitudeValue T>
class ValuedMorphologicalTreeView {
39 std::size_t topologyMutationVersion_ = 0;
44 void validateNodeAltitudeBufferShape()
const {
46 throw std::runtime_error(
"ValuedMorphologicalTreeView altitude size must match the dense internal-node domain."));
71 : topology_(&
topology), nodeAltitudes_(altitude), topologyMutationVersion_(
topology.getMutationVersion()) {
72 validateNodeAltitudeBufferShape();
87 : ValuedMorphologicalTreeView(
topology, std::span<const T>(altitude)) {}
123 throw std::invalid_argument(
"ValuedMorphologicalTreeView::nodeAltitude requires a valid internal NodeId."));
124 return nodeAltitudes_[
static_cast<std::size_t
>(nodeId)];
141 if (parentNodeId ==
InvalidNode || parentNodeId == nodeId) {
Shared altitude type contracts and buffer aliases.
std::span< const T > NodeAltitudeSpan
Read-only contiguous view over node altitudes.
std::vector< T > NodeAltitudeBuffer
Owning dense altitude buffer indexed by internal node id.
typename detail::AltitudeDifferenceSelector< T >::type AltitudeDifference
Arithmetic result type for altitude differences.
int NodeId
Node identifier type used throughout the project.
constexpr NodeId InvalidNode
Sentinel value used to denote an invalid node identifier.
Compile-time policy for defensive checks at untrusted API boundaries.
#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.
void requireMutationVersion(std::size_t expectedVersion, const char *context) const
Rejects stale read-only views that captured an older mutation version.
bool isAlive(NodeId nodeId) const
Tests whether a node slot currently represents a live node.
std::size_t getMutationVersion() const noexcept
Returns the monotonic mutation counter used by read-only views.
NodeId parent(NodeId nodeId) const
Returns the direct parent of nodeId.
static void validateMonotoneNodeAltitudes(const MorphologicalTree &tree, std::span< const T > altitude)
Validates the hierarchy's declared global altitude order.
static void validateFiniteAltitudeValues(std::span< const T > altitude, const char *context)
Rejects non-finite floating-point altitudes in a contiguous input range.
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.
Wrapper pairing MorphologicalTree topology with an external altitude buffer.
NodeAltitudeSpan< T > nodeAltitudeSpan() const noexcept
Returns a read-only span over the dense altitude buffer.
const MorphologicalTree & topology() const noexcept
Returns read-only access to the owned topology.