3#include "../attributes/AttributeComputation.hpp"
4#include "../trees/detail/TreeStabilityNeighborhood.hpp"
5#include "../trees/MorphologicalTree.hpp"
6#include "../utils/Common.hpp"
7#include "detail/VariationMeasure.hpp"
39template<std::
floating_po
int Real =
float>
47 const Real* attrView_ =
nullptr;
48 std::vector<Real> ownedAttr_;
53 std::vector<Real> variation;
54 std::vector<NodeId> ascendants;
55 std::vector<NodeId> descendants;
57 static void validateOwnedAttributeSize(
const MorphologicalTree& tree,
const std::vector<Real>& attr) {
58 if (attr.size() !=
static_cast<std::size_t
>(tree.getNumInternalNodeSlots())) {
59 throw std::invalid_argument(
"DepthStableRegionComputer attribute size must match the internal node slot count.");
63 DepthStableRegionComputer(
const MorphologicalTree& tree,
const Real* attr, std::vector<Real> ownedAttr)
66 ownedAttr_(std::move(ownedAttr)),
67 maxAttr(static_cast<Real>(tree.getNumColsOfImage() * tree.getNumRowsOfImage())) {
68 this->attrView_ = this->ownedAttr_.empty() ? attr : this->ownedAttr_.data();
77 validateOwnedAttributeSize(tree, attr);
78 return std::move(attr);
86 if (attr ==
nullptr) {
87 throw std::invalid_argument(
"DepthStableRegionComputer requires a non-null attribute buffer for the raw-pointer constructor.");
102 detail::computeDepthStabilityNeighborhood(this->tree,
depthDelta);
104 this->descendants = std::move(
neighborhood.descendants);
110 detail::computeVariationsFromNeighborhood<Real>(
115 return detail::selectStrictVariationMinima<Real>(
131 detail::validateStabilityNeighborhoodShape(
135 "DepthStableRegionComputer::getVariation");
136 if (this->variation.size() !=
static_cast<std::size_t
>(
this->tree.getNumInternalNodeSlots())) {
137 throw std::logic_error(
"DepthStableRegionComputer::getVariation requires computeByDepth to run first.");
142 return detail::computeVariationValue<Real>(
153 if (this->attrView_ ==
nullptr) {
154 auto area = AttributeComputation::computeSingleTopologyAttribute<Real>(this->tree, AREA);
156 this->attrView_ = this->ownedAttr_.data();
158 return this->attrView_[
static_cast<std::size_t
>(node)];
165 detail::validateStabilityNeighborhoodShape(
169 "DepthStableRegionComputer::nodeWithMinimumVariationInWindow");
170 if (this->variation.size() !=
static_cast<std::size_t
>(
this->tree.getNumInternalNodeSlots())) {
171 throw std::logic_error(
"DepthStableRegionComputer::nodeWithMinimumVariationInWindow requires computeByDepth to run first.");
173 return detail::nodeWithMinimumVariationInWindow<Real>(
int NodeId
Node identifier type used throughout the project.
Detects stable regions from a topological depth window.
void setMinAttribute(Real value)
Sets the lower bound of the accepted attribute interval.
NodeId nodeWithMinimumVariationInWindow(NodeId node) const
Returns the node with minimum variation in the depth window.
DepthStableRegionComputer(const MorphologicalTree &tree, const Real *attr)
Creates a detector backed by a non-owning attribute buffer.
int getNumNodes() const
Returns the number of nodes selected in the last run.
NodeId ascendantInStabilityWindow(NodeId node) const
Returns the ascendant used in the current depth window.
Real getVariation(NodeId node)
Returns the variation score currently associated with a node.
void setMaxAttribute(Real value)
Sets the upper bound of the accepted attribute interval.
NodeId descendantInStabilityWindow(NodeId node) const
Returns the descendant used in the current depth window.
void setMaxVariation(Real value)
Sets the maximum accepted variation value.
std::vector< uint8_t > computeByDepth(int depthDelta)
Computes the stable-region indicator vector for a positive depth delta.
DepthStableRegionComputer(const MorphologicalTree &tree, std::vector< Real > attr)
Creates a detector backed by an owned increasing-attribute buffer.
DepthStableRegionComputer(const MorphologicalTree &tree)
Creates a detector that lazily computes topology-only AREA.
Real getAttribute(NodeId node)
Returns the increasing attribute used by the criterion.
std::vector< Real > & getVariations()
Returns the current variation array, indexed by node slot.
Mutable morphological tree built directly on proper parts and dense node ids.
Owning result for one computed scalar attribute layout and buffer.
std::vector< Real > second
Flat per-node attribute buffer indexed through first.