3#include "DistanceTransformTypes.hpp"
34 std::vector<std::uint8_t> alive)
35 : accuracy_(
accuracy), bins_(std::move(bins)), spans_(std::move(spans)), alive_(std::move(alive)) {
36 if ((accuracy_ != DistanceTransformAccuracy::Exact && accuracy_ != DistanceTransformAccuracy::Approximate) || spans_.size() != alive_.size()) {
37 throw std::invalid_argument(
"DistanceTransformProfiles requires aligned node spans and liveness flags.");
39 for (std::size_t node = 0; node < spans_.size(); ++node) {
40 const Span span = spans_[node];
41 if (span.
offset > bins_.size() || span.
size > bins_.size() - span.
offset || (alive_[node] != 0 && span.
size == 0) ||
42 (alive_[node] == 0 && span.
size != 0)) {
43 throw std::invalid_argument(
"DistanceTransformProfiles received an invalid node histogram span.");
45 std::int64_t previousDistance = -1;
46 for (std::size_t binIndex = span.
offset; binIndex < span.
offset + span.
size; ++binIndex) {
49 throw std::invalid_argument(
"DistanceTransformProfiles requires positive counts at strictly increasing non-negative levels.");
57 [[nodiscard]] DistanceTransformAccuracy
accuracy() const noexcept {
return accuracy_; }
59 [[nodiscard]] std::size_t
numNodeSlots() const noexcept {
return spans_.size(); }
61 [[nodiscard]] std::size_t
numBins() const noexcept {
return bins_.size(); }
68 [[nodiscard]] std::span<const DistanceTransformHistogramBin>
histogram(
NodeId node)
const {
69 const Span span = checkedSpan(node);
70 return std::span<const DistanceTransformHistogramBin>(bins_.data() + span.
offset, span.
size);
79 const std::span<const DistanceTransformHistogramBin> nodeHistogram =
histogram(node);
80 std::uint64_t total = 0;
82 if (bin.count > std::numeric_limits<std::uint64_t>::max() - total) {
83 throw std::overflow_error(
"Distance-transform survival profile exceeds the 64-bit count domain.");
87 std::vector<DistanceTransformSurvivalBin> result;
88 result.reserve(nodeHistogram.size());
89 std::uint64_t below = 0;
91 result.push_back({bin.squaredDistance, total - below});
99 [[nodiscard]] Span checkedSpan(
NodeId node)
const {
100 if (node < 0 ||
static_cast<std::size_t
>(node) >= spans_.size() || alive_[
static_cast<std::size_t
>(node)] == 0) {
101 throw std::out_of_range(
"Distance-transform profile access requires a live internal node id.");
103 return spans_[
static_cast<std::size_t
>(node)];
106 DistanceTransformAccuracy accuracy_ = DistanceTransformAccuracy::Exact;
107 std::vector<DistanceTransformHistogramBin> bins_;
108 std::vector<Span> spans_;
109 std::vector<std::uint8_t> alive_;
int NodeId
Node identifier type used throughout the project.