MorphologicalAttributeFilters
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
64
66using TreeOfShapesImmersion = std::variant<SelfDualSpanImmersion, ComplementaryGridImmersion>;
67
69enum class TopographicDomainExtension { ExteriorRing, None };
70
77
80 std::variant<NoConstructionContext, SharedAdjacencyContext, SaturatedResidualContext, TopographicConvention>;
81
93
96 switch (kind) {
97 case MorphologicalTreeKind::MaxTree:
98 return NodeAltitudeOrder::Increasing;
99 case MorphologicalTreeKind::MinTree:
100 return NodeAltitudeOrder::Decreasing;
101 case MorphologicalTreeKind::Generic:
102 case MorphologicalTreeKind::TreeOfShapes:
103 case MorphologicalTreeKind::UnrestrictedResidualTree:
104 case MorphologicalTreeKind::SaturatedResidualTree:
105 return NodeAltitudeOrder::Unconstrained;
106 }
107 return NodeAltitudeOrder::Unconstrained;
108}
109
114 return MorphologicalTreeSemantics{kind, defaultNodeAltitudeOrder(kind), std::move(constructionContext)};
115}
116
126 if (semantics.kind != MorphologicalTreeKind::Generic && semantics.nodeAltitudeOrder != defaultNodeAltitudeOrder(semantics.kind)) {
127 throw std::invalid_argument("Morphological-tree kind and node-altitude order are incompatible.");
128 }
129 if (std::holds_alternative<NoConstructionContext>(semantics.constructionContext)) {
130 return;
131 }
132 if (std::holds_alternative<SharedAdjacencyContext>(semantics.constructionContext)) {
133 if (semantics.kind == MorphologicalTreeKind::Generic || semantics.kind == MorphologicalTreeKind::MaxTree ||
134 semantics.kind == MorphologicalTreeKind::MinTree || semantics.kind == MorphologicalTreeKind::UnrestrictedResidualTree) {
135 return;
136 }
137 throw std::invalid_argument("SharedAdjacencyContext is incompatible with the declared morphological-tree kind.");
138 }
139 if (std::holds_alternative<SaturatedResidualContext>(semantics.constructionContext)) {
140 if (semantics.kind == MorphologicalTreeKind::SaturatedResidualTree) {
141 return;
142 }
143 throw std::invalid_argument("SaturatedResidualContext requires SaturatedResidualTree kind.");
144 }
145 if (std::holds_alternative<TopographicConvention>(semantics.constructionContext)) {
146 if (semantics.kind == MorphologicalTreeKind::TreeOfShapes) {
147 return;
148 }
149 throw std::invalid_argument("TopographicConvention requires TreeOfShapes kind.");
150 }
151 throw std::invalid_argument("Unsupported morphological-tree construction context.");
152}
153
154} // 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.
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< SelfDualSpanImmersion, ComplementaryGridImmersion > TreeOfShapesImmersion
Tagged tree-of-shapes immersion family.
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.
Immutable regular-grid 2D adjacency with allocation-free traversal.
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.
PixelId infinityPixel
Declared infinity pixel in the active topographic domain.
TopographicDomainExtension domainExtension
Active-domain extension convention.