9 #ifndef OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED 10 #define OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED 32 template<
typename IterT>
33 inline math::Histogram
34 histogram(
const IterT& iter,
double minVal,
double maxVal,
35 size_t numBins = 10,
bool threaded =
true);
43 template<
typename IterT>
53 template<
typename IterT>
86 template<
typename IterT,
typename ValueOp>
119 template<
typename IterT,
typename ValueOp>
186 template<
typename OperatorT,
typename IterT>
191 template<
typename OperatorT,
typename IterT>
199 namespace stats_internal {
204 template<
typename IterT,
typename AuxT =
void>
206 using ValueType =
typename IterT::ValueType;
209 template<
typename TreeT,
typename ValueIterT>
210 struct IterTraits<tree::TreeValueIteratorBase<TreeT, ValueIterT> > {
211 using ValueType =
typename tree::TreeValueIteratorBase<TreeT, ValueIterT>::ValueT;
217 template<
typename T,
bool IsVector>
struct GetValImpl;
220 struct GetValImpl<T, false> {
221 static inline double get(
const T& val) {
return double(val); }
225 struct GetValImpl<T, true> {
226 static inline double get(
const T& val) {
return val.length(); }
233 template<
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());
247 template<
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); }
265 template<
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;
286 template<
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()));
320 CoordBBox bbox = it.getBoundingBox();
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); }
341 template<
typename IterT>
342 inline math::Histogram
345 using ValueOp = stats_internal::GetVal<IterT, math::Histogram>;
347 stats_internal::HistOp<IterT, ValueOp>
op(valOp, vmin, vmax, numBins);
352 template<
typename IterT>
356 stats_internal::GetVal<IterT, math::Extrema> valOp;
357 return extrema(iter, valOp, threaded);
360 template<
typename IterT>
364 stats_internal::GetVal<IterT, math::Stats> valOp;
368 template<
typename IterT,
typename ValueOp>
372 stats_internal::StatsOp<IterT, const ValueOp, math::Extrema>
op(valOp);
377 template<
typename IterT,
typename ValueOp>
381 stats_internal::StatsOp<IterT, const ValueOp, math::Stats>
op(valOp);
387 template<
typename OperatorT,
typename IterT>
391 stats_internal::MathOp<IterT, OperatorT, math::Extrema> func(iter, op);
396 template<
typename OperatorT,
typename IterT>
400 stats_internal::MathOp<IterT, OperatorT, math::Stats> func(iter, op);
409 #endif // OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED #define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Classes to compute statistics and histograms.
Definition: Exceptions.h:13
This class computes the minimum and maximum values of a population of floating-point values...
Definition: Stats.h:89
This class computes statistics (minimum value, maximum value, mean, variance and standard deviation) ...
Definition: Stats.h:179
PromoteType< ValueT >::Highest accumulate(const PointDataTreeT &points, const std::string &attribute, const FilterT &filter=NullFilter())
Evaluates the total value of a point attribute.
Definition: PointStatisticsImpl.h:530
#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:218