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>
45 extrema(
const IterT& iter,
bool threaded =
true);
53 template<
typename IterT>
55 statistics(
const IterT& iter,
bool threaded =
true);
86 template<
typename IterT,
typename ValueOp>
88 extrema(
const IterT& iter,
const ValueOp& op,
bool threaded);
119 template<
typename IterT,
typename ValueOp>
121 statistics(
const IterT& iter,
const ValueOp& op,
bool threaded);
186 template<
typename OperatorT,
typename IterT>
188 opStatistics(
const IterT& iter,
const OperatorT& op = OperatorT(),
bool threaded =
true);
191 template<
typename OperatorT,
typename IterT>
193 opExtrema(
const IterT& iter,
const OperatorT& op = OperatorT(),
bool threaded =
true);
199 namespace stats_internal {
204 template<
typename IterT,
typename AuxT =
void>
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>
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;
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); }
341 template<
typename IterT>
342 inline math::Histogram
343 histogram(
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);
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>
370 extrema(
const IterT& iter,
const ValueOp& valOp,
bool threaded)
372 stats_internal::StatsOp<IterT, const ValueOp, math::Extrema> op(valOp);
377 template<
typename IterT,
typename ValueOp>
379 statistics(
const IterT& iter,
const ValueOp& valOp,
bool threaded)
381 stats_internal::StatsOp<IterT, const ValueOp, math::Stats> op(valOp);
387 template<
typename OperatorT,
typename IterT>
389 opExtrema(
const IterT& iter,
const OperatorT& op,
bool threaded)
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
GLdouble GLdouble GLdouble z
#define OPENVDB_USE_VERSION_NAMESPACE
__hostdev__ float getValue(uint32_t i) const
Classes to compute statistics and histograms.
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
This class computes statistics (minimum value, maximum value, mean, variance and standard deviation) ...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
#define OPENVDB_THROW(exception, message)
This class computes the minimum and maximum values of a population of floating-point values...