3#include "../trees/TreeAltitudeAlgorithms.hpp"
4#include "../trees/WeightedMorphologicalTree.hpp"
5#include "../trees/WeightedTreeView.hpp"
6#include "../trees/detail/TreeKindValidation.hpp"
7#include "../utils/Image.hpp"
8#include "../utils/Common.hpp"
9#include "../contours/ContoursComputedIncrementally.hpp"
25template <std::
floating_po
int Real =
float>
74template<AltitudeValue T, std::
floating_po
int Real =
float>
84 std::size_t treeMutationVersion_ = 0;
87 return weighted_ !=
nullptr ? weighted_->asView() :
view_;
90 void requireStableTree(
const char*
context)
const {
95 if (attr ==
nullptr) {
96 throw std::invalid_argument(std::string(
context) +
" requires a non-null attribute buffer.");
102 throw std::invalid_argument(std::string(
context) +
" attribute size must match the internal node slot count.");
116 return std::numeric_limits<Real>::max();
121 throw std::invalid_argument(std::string(
context) +
" requires a non-negative extremaToKeep value.");
160 if (a.extinction != b.extinction) {
161 return a.extinction > b.extinction;
163 if (
a.cutoffNode !=
b.cutoffNode) {
164 return a.cutoffNode < b.cutoffNode;
166 return a.leaf <
b.leaf;
202 tree(
view_.topology()),
203 treeMutationVersion_(tree.getMutationVersion()) {
204 view_.requireTopologyUnchanged(
"ExtinctionValues");
205 detail::validateComponentTreeKind(this->tree,
"ExtinctionValues");
257 requireStableTree(
"ExtinctionValues::saliencyMap");
259 std::vector<uint8_t>
keep(tree.getNumInternalNodeSlots(),
false);
265 if (!
keep[cutoffNode]) {
268 keep[cutoffNode] =
true;
277 for (
int p :
contours.getContour(node)) {
294 requireStableTree(
"ExtinctionValues::filtering");
297 std::vector<uint8_t>
criterion(tree.getNumInternalNodeSlots(),
false);
310 std::stack<NodeId>
stack;
311 stack.push(tree.getRoot());
312 while (!
stack.empty()) {
341 requireStableTree(
"ExtinctionValues::getExtinctionValues");
static IncrementalContours extractCompactContours(const MorphologicalTree &tree)
Runs incremental contour computation and returns compact contours.
Computes and stores extinction values for regional extrema.
ExtinctionValues(const AltitudeView &view, const std::shared_ptr< Real[]> &attr)
Computes extinction values from a weighted view and shared attribute buffer.
ExtinctionValues(const WeightedMorphologicalTree< T > &weighted, const Real *attr)
Computes extinction values from a weighted tree and raw attribute buffer.
ImagePtr< T > filtering(int extremaToKeep)
Reconstructs an image by keeping the strongest extrema.
ExtinctionValues(const AltitudeView &view, const Real *attr)
Computes extinction values from a weighted view and raw attribute buffer.
std::vector< RegionalExtremaNode< Real > > & getExtinctionValues()
Returns the extinction records sorted by decreasing extinction.
ImagePtr< Real > saliencyMap(int extremaToKeep, bool unweighted=true)
Builds a contour saliency image from the strongest extrema.
ExtinctionValues(const WeightedMorphologicalTree< T > &weighted, const std::vector< Real > &attr)
Computes extinction values from a weighted tree and vector attribute buffer.
ExtinctionValues(const WeightedMorphologicalTree< T > &weighted, const std::shared_ptr< Real[]> &attr)
Computes extinction values from a weighted tree and shared attribute buffer.
ExtinctionValues(const AltitudeView &view, const std::vector< Real > &attr)
Computes extinction values from a weighted view and vector attribute buffer.
static Ptr create(int rows, int cols)
Creates an owned image with uninitialised pixel values.
Mutable morphological tree built directly on proper parts and dense node ids.
ChildrenRange getChildren(NodeId nodeId) const
Returns a fail-fast range over the direct children of nodeId.
void requireMutationVersion(std::size_t expectedVersion, const char *context) const
Rejects stale read-only views that captured an older mutation version.
int getNumInternalNodeSlots() const
Returns the size of the dense internal-node id domain.
std::vector< NodeId > getLeaves() const
Returns all live leaf nodes in the current hierarchy.
bool isRoot(NodeId nodeId) const
Tests whether nodeId is the current root.
int getNumChildren(NodeId nodeId) const
Returns the number of direct children of nodeId.
NodeId getNodeParent(NodeId nodeId) const
Returns the direct parent of nodeId.
Owning result for one computed scalar attribute layout and buffer.
Record describing one regional extremum and its extinction value.
RegionalExtremaNode(NodeId leaf, NodeId cutoffNode, Real extinction)
Builds one extinction-value record.
Real extinction
Attribute value at cutoffNode, or numeric_limits<Real>::max() for the dominant extremum that survives...
NodeId cutoffNode
Highest node retained before the extremum merges with a stronger branch.
NodeId leaf
Leaf node that represents the regional extremum in a max-tree/min-tree.