9#ifndef OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED
10#define OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED
32template<
typename IterT>
34histogram(
const IterT& iter,
double minVal,
double maxVal,
35 size_t numBins = 10,
bool threaded =
true);
43template<
typename IterT>
45extrema(
const IterT& iter,
bool threaded =
true);
53template<
typename IterT>
55statistics(
const IterT& iter,
bool threaded =
true);
86template<
typename IterT,
typename ValueOp>
88extrema(
const IterT& iter,
const ValueOp& op,
bool threaded);
119template<
typename IterT,
typename ValueOp>
121statistics(
const IterT& iter,
const ValueOp& op,
bool threaded);
186template<
typename OperatorT,
typename IterT>
188opStatistics(
const IterT& iter,
const OperatorT& op = OperatorT(),
bool threaded =
true);
191template<
typename OperatorT,
typename IterT>
193opExtrema(
const IterT& iter,
const OperatorT& op = OperatorT(),
bool threaded =
true);
199namespace stats_internal {
204template<
typename IterT,
typename AuxT =
void>
206 using ValueType =
typename IterT::ValueType;
209template<
typename TreeT,
typename ValueIterT>
210struct IterTraits<tree::TreeValueIteratorBase<TreeT, ValueIterT> > {
211 using ValueType =
typename tree::TreeValueIteratorBase<TreeT, ValueIterT>::ValueT;
217template<
typename T,
bool IsVector>
struct GetValImpl;
220struct GetValImpl<T, false> {
221 static inline double get(
const T& val) {
return double(val); }
225struct GetValImpl<T, true> {
226 static inline double get(
const T& val) {
return val.length(); }
233template<
typename IterT,
typename StatsT>
236 using ValueT =
typename IterTraits<IterT>::ValueType;
237 using ImplT = GetValImpl<ValueT, VecTraits<ValueT>::IsVec>;
239 inline void operator()(
const IterT& iter, StatsT& stats)
const {
240 if (iter.isVoxelValue()) stats.add(ImplT::get(*iter));
241 else stats.add(ImplT::get(*iter), iter.getVoxelCount());
247template<
typename IterT,
typename ValueOp,
typename StatsT>
250 StatsOp(
const ValueOp& op): getValue(op) {}
253 inline void operator()(
const IterT& iter) { getValue(iter, stats); }
256 inline void join(StatsOp& other) { stats.add(other.stats); }
265template<
typename IterT,
typename ValueOp>
268 HistOp(
const ValueOp& op,
double vmin,
double vmax,
size_t bins):
269 hist(vmin, vmax, bins), getValue(op)
273 inline void operator()(
const IterT& iter) { getValue(iter, hist); }
276 inline void join(HistOp& other) { hist.add(other.hist); }
278 math::Histogram hist;
286template<
typename IterT,
typename OpT,
typename StatsT>
289 using TreeT =
typename IterT::TreeT;
290 using ValueT =
typename TreeT::ValueType;
291 using ConstAccessor =
typename tree::ValueAccessor<const TreeT>;
298 template<
typename TreeT>
299 static inline TreeT* THROW_IF_NULL(TreeT* ptr) {
300 if (ptr ==
nullptr)
OPENVDB_THROW(ValueError,
"iterator references a null tree");
304 MathOp(
const IterT& iter,
const OpT& op):
305 mAcc(*THROW_IF_NULL(iter.getTree())), mOp(op)
309 void operator()(
const IterT& it)
311 if (it.isVoxelValue()) {
313 mStats.add(mOp.result(mAcc, it.getCoord()));
322 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
323 for (x = bbox.min().x(); x <= bbox.max().x(); ++x) {
324 for (y = bbox.min().y(); y <= bbox.max().y(); ++y) {
325 for (z = bbox.min().z(); z <= bbox.max().z(); ++z) {
326 mStats.add(mOp.result(mAcc, it.getCoord()));
334 inline void join(MathOp& other) { mStats.add(other.mStats); }
341template<
typename IterT>
342inline math::Histogram
343histogram(
const IterT& iter,
double vmin,
double vmax,
size_t numBins,
bool threaded)
345 using ValueOp = stats_internal::GetVal<IterT, math::Histogram>;
347 stats_internal::HistOp<IterT, ValueOp> op(valOp, vmin, vmax, numBins);
348 tools::accumulate(iter, op, threaded);
352template<
typename IterT>
356 stats_internal::GetVal<IterT, math::Extrema> valOp;
357 return extrema(iter, valOp, threaded);
360template<
typename IterT>
364 stats_internal::GetVal<IterT, math::Stats> valOp;
368template<
typename IterT,
typename ValueOp>
370extrema(
const IterT& iter,
const ValueOp& valOp,
bool threaded)
372 stats_internal::StatsOp<IterT, const ValueOp, math::Extrema> op(valOp);
373 tools::accumulate(iter, op, threaded);
377template<
typename IterT,
typename ValueOp>
379statistics(
const IterT& iter,
const ValueOp& valOp,
bool threaded)
381 stats_internal::StatsOp<IterT, const ValueOp, math::Stats> op(valOp);
382 tools::accumulate(iter, op, threaded);
387template<
typename OperatorT,
typename IterT>
389opExtrema(
const IterT& iter,
const OperatorT& op,
bool threaded)
391 stats_internal::MathOp<IterT, OperatorT, math::Extrema> func(iter, op);
392 tools::accumulate(iter, func, threaded);
396template<
typename OperatorT,
typename IterT>
400 stats_internal::MathOp<IterT, OperatorT, math::Stats> func(iter, op);
401 tools::accumulate(iter, func, threaded);
Classes to compute statistics and histograms.
This class computes the minimum and maximum values of a population of floating-point values.
Definition: Stats.h:93
This class computes statistics (minimum value, maximum value, mean, variance and standard deviation) ...
Definition: Stats.h:183
BBox< Coord > CoordBBox
Definition: NanoVDB.h:1809
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212