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 UnrestrictedResidualTree,
24 SaturatedResidualTree
25};
26
36
39
44
50
56
59
61enum class ComplementaryPairing { Min4Max8, Min8Max4 };
62
71 ComplementaryPairing pairing = ComplementaryPairing::Min4Max8;
72};
73
78
80using TreeOfShapesImmersion = std::variant<CanonicalComplementaryGridImmersion, ComplementaryGridImmersion, SelfDualSpanImmersion>;
81
83enum class TopographicDomainExtension { ExteriorRing, None };
84
95enum class TopographicAltitudeEncoding { UInt8, ExactDoubled };
96
104
118inline TopographicConvention selfDualSpanConvention(TopographicDomainExtension domainExtension = TopographicDomainExtension::ExteriorRing,
119 PixelId infinityPixel = 0,
120 TopographicAltitudeEncoding altitudeEncoding = TopographicAltitudeEncoding::ExactDoubled) {
121 return TopographicConvention{SelfDualSpanImmersion{}, domainExtension, infinityPixel, altitudeEncoding};
122}
123
126 std::variant<NoConstructionContext, SharedAdjacencyContext, SaturatedResidualContext, TopographicConvention>;
127
139
142 switch (kind) {
143 case MorphologicalTreeKind::MaxTree:
144 return NodeAltitudeOrder::Increasing;
145 case MorphologicalTreeKind::MinTree:
146 return NodeAltitudeOrder::Decreasing;
147 case MorphologicalTreeKind::Generic:
148 case MorphologicalTreeKind::TreeOfShapes:
149 case MorphologicalTreeKind::UnrestrictedResidualTree:
150 case MorphologicalTreeKind::SaturatedResidualTree:
151 return NodeAltitudeOrder::Unconstrained;
152 }
153 return NodeAltitudeOrder::Unconstrained;
154}
155
160 return MorphologicalTreeSemantics{kind, defaultNodeAltitudeOrder(kind), std::move(constructionContext)};
161}
162
172 if (semantics.kind != MorphologicalTreeKind::Generic && semantics.nodeAltitudeOrder != defaultNodeAltitudeOrder(semantics.kind)) {
173 throw std::invalid_argument("Morphological-tree kind and node-altitude order are incompatible.");
174 }
175 if (std::holds_alternative<NoConstructionContext>(semantics.constructionContext)) {
176 return;
177 }
178 if (std::holds_alternative<SharedAdjacencyContext>(semantics.constructionContext)) {
179 if (semantics.kind == MorphologicalTreeKind::Generic || semantics.kind == MorphologicalTreeKind::MaxTree ||
180 semantics.kind == MorphologicalTreeKind::MinTree || semantics.kind == MorphologicalTreeKind::UnrestrictedResidualTree) {
181 return;
182 }
183 throw std::invalid_argument("SharedAdjacencyContext is incompatible with the declared morphological-tree kind.");
184 }
185 if (std::holds_alternative<SaturatedResidualContext>(semantics.constructionContext)) {
186 if (semantics.kind == MorphologicalTreeKind::SaturatedResidualTree) {
187 return;
188 }
189 throw std::invalid_argument("SaturatedResidualContext requires SaturatedResidualTree kind.");
190 }
191 if (std::holds_alternative<TopographicConvention>(semantics.constructionContext)) {
192 if (semantics.kind == MorphologicalTreeKind::TreeOfShapes) {
193 return;
194 }
195 throw std::invalid_argument("TopographicConvention requires TreeOfShapes kind.");
196 }
197 throw std::invalid_argument("Unsupported morphological-tree construction context.");
198}
199
200} // namespace mmcfilters
std::variant< NoConstructionContext, SharedAdjacencyContext, SaturatedResidualContext, TopographicConvention > MorphologicalTreeConstructionContext
Tagged construction context retained by morphological-tree semantics.
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.
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.
Records the shared adjacency and infinity pixel of a saturated residual construction.
RegularGridAdjacency2D adjacency
Shared construction adjacency.
PixelId infinityPixel
Declared infinity pixel in the active domain.
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.