mmcfilters
Public API documentation
Loading...
Searching...
No Matches
MorphologicalTreeSemantics.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "../utils/Common.hpp"
9#include "../utils/RegularGridAdjacency2D.hpp"
10
11#include <utility>
12#include <stdexcept>
13#include <variant>
14
15namespace mmcfilters {
16
19 Generic,
20 MaxTree,
21 MinTree,
22 TreeOfShapes,
23 ExtremumResidualTree
24};
25
35
38
43
49
52
54enum class ComplementaryPairing { Min4Max8, Min8Max4 };
55
64 ComplementaryPairing pairing = ComplementaryPairing::Min4Max8;
65};
66
71
73using TreeOfShapesImmersion = std::variant<CanonicalComplementaryGridImmersion, ComplementaryGridImmersion, SelfDualSpanImmersion>;
74
76enum class TopographicDomainExtension { ExteriorRing, None };
77
88enum class TopographicAltitudeEncoding { UInt8, ExactDoubled };
89
97
111inline TopographicConvention selfDualSpanConvention(TopographicDomainExtension domainExtension = TopographicDomainExtension::ExteriorRing,
112 PixelId infinityPixel = 0,
113 TopographicAltitudeEncoding altitudeEncoding = TopographicAltitudeEncoding::ExactDoubled) {
114 return TopographicConvention{SelfDualSpanImmersion{}, domainExtension, infinityPixel, altitudeEncoding};
115}
116
119 std::variant<NoConstructionContext, SharedAdjacencyContext, TopographicConvention>;
120
132
135 switch (kind) {
136 case MorphologicalTreeKind::MaxTree:
137 return NodeAltitudeOrder::Increasing;
138 case MorphologicalTreeKind::MinTree:
139 return NodeAltitudeOrder::Decreasing;
140 case MorphologicalTreeKind::Generic:
141 case MorphologicalTreeKind::TreeOfShapes:
142 case MorphologicalTreeKind::ExtremumResidualTree:
143 return NodeAltitudeOrder::Unconstrained;
144 }
145 return NodeAltitudeOrder::Unconstrained;
146}
147
152 return MorphologicalTreeSemantics{kind, defaultNodeAltitudeOrder(kind), std::move(constructionContext)};
153}
154
164 if (semantics.kind != MorphologicalTreeKind::Generic && semantics.nodeAltitudeOrder != defaultNodeAltitudeOrder(semantics.kind)) {
165 throw std::invalid_argument("Morphological-tree kind and node-altitude order are incompatible.");
166 }
167 if (std::holds_alternative<NoConstructionContext>(semantics.constructionContext)) {
168 return;
169 }
170 if (std::holds_alternative<SharedAdjacencyContext>(semantics.constructionContext)) {
171 if (semantics.kind == MorphologicalTreeKind::Generic || semantics.kind == MorphologicalTreeKind::MaxTree ||
172 semantics.kind == MorphologicalTreeKind::MinTree || semantics.kind == MorphologicalTreeKind::ExtremumResidualTree) {
173 return;
174 }
175 throw std::invalid_argument("SharedAdjacencyContext is incompatible with the declared morphological-tree kind.");
176 }
177 if (std::holds_alternative<TopographicConvention>(semantics.constructionContext)) {
178 if (semantics.kind == MorphologicalTreeKind::TreeOfShapes) {
179 return;
180 }
181 throw std::invalid_argument("TopographicConvention requires TreeOfShapes kind.");
182 }
183 throw std::invalid_argument("Unsupported morphological-tree construction context.");
184}
185
186} // namespace mmcfilters
MorphologicalTreeSemantics makeMorphologicalTreeSemantics(MorphologicalTreeKind kind, MorphologicalTreeConstructionContext constructionContext=NoConstructionContext{})
Constructs semantics using the conventional altitude order of kind.
TopographicConvention selfDualSpanConvention(TopographicDomainExtension domainExtension=TopographicDomainExtension::ExteriorRing, PixelId infinityPixel=0, TopographicAltitudeEncoding altitudeEncoding=TopographicAltitudeEncoding::ExactDoubled)
Builds a self-dual span convention in one call.
std::variant< NoConstructionContext, SharedAdjacencyContext, TopographicConvention > MorphologicalTreeConstructionContext
Tagged construction context retained by morphological-tree semantics.
NodeAltitudeOrder
Global ordering constraint of node altitudes along parent-child arcs.
@ Unconstrained
No global parent-child altitude order is declared.
@ Decreasing
Every alive parent-child arc satisfies nodeAltitude(parent) > nodeAltitude(child).
@ Increasing
Every alive parent-child arc satisfies nodeAltitude(parent) < nodeAltitude(child).
TopographicDomainExtension
Relation between the source pixel domain and active topographic domain.
std::variant< CanonicalComplementaryGridImmersion, ComplementaryGridImmersion, SelfDualSpanImmersion > TreeOfShapesImmersion
Tagged tree-of-shapes immersion family.
TopographicAltitudeEncoding
Scale in which tree-of-shapes node altitudes are published.
MorphologicalTreeKind
Declared construction family of one morphological tree.
NodeAltitudeOrder defaultNodeAltitudeOrder(MorphologicalTreeKind kind) noexcept
Returns the conventional node-altitude order of a declared tree kind.
void validateMorphologicalTreeSemantics(const MorphologicalTreeSemantics &semantics)
Validates the scientific compatibility of a semantics descriptor.
ComplementaryPairing
Canonical ordered pairing of complementary 4- and 8-connectivities.
Immutable regular-grid 2D adjacency with allocation-free traversal.
Selects a canonical complementary-grid immersion without binding a domain.
ComplementaryPairing pairing
Canonical minimum/maximum pairing.
Ordered pair of complementary minimum and maximum adjacencies.
RegularGridAdjacency2D minAdjacency
Adjacency used for minimum-oriented processing.
RegularGridAdjacency2D maxAdjacency
Adjacency used for maximum-oriented processing.
Selects the optimized complementary-grid immersion.
ComplementaryAdjacencies complementaryAdjacencies
Ordered minimum/maximum adjacency pair.
Owning result for one computed scalar attribute layout and buffer.
Immutable scientific interpretation attached to one morphological tree.
NodeAltitudeOrder nodeAltitudeOrder
Global parent-child altitude order.
MorphologicalTreeConstructionContext constructionContext
Typed retained construction context.
MorphologicalTreeKind kind
Declared construction/result kind.
Explicitly records that no construction context is available.
Selects the self-dual span-valued tree-of-shapes immersion.
Records one adjacency shared by both construction polarities.
RegularGridAdjacency2D adjacency
Shared construction adjacency.
Complete discrete convention retained by a tree-of-shapes result.
TreeOfShapesImmersion immersion
Selected topographic immersion.
TopographicAltitudeEncoding altitudeEncoding
Published node-altitude scale.
PixelId infinityPixel
Declared infinity pixel in the active topographic domain.
TopographicDomainExtension domainExtension
Active-domain extension convention.