36 #ifndef OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED
37 #define OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED
39 #include <openvdb/Types.h>
40 #include <openvdb/Exceptions.h>
41 #include <openvdb/math/Stats.h>
59 template<
typename IterT>
60 inline math::Histogram
61 histogram(
const IterT& iter,
double minVal,
double maxVal,
62 size_t numBins = 10,
bool threaded =
true);
71 template<
typename IterT>
73 statistics(
const IterT& iter,
bool threaded =
true);
105 template<
typename IterT,
typename ValueOp>
107 statistics(
const IterT& iter,
const ValueOp& op,
bool threaded);
172 template<
typename OperatorT,
typename IterT>
174 opStatistics(
const IterT& iter,
const OperatorT& op = OperatorT(),
bool threaded =
true);
180 namespace stats_internal {
185 template<
typename IterT,
typename AuxT =
void>
190 template<
typename TreeT,
typename ValueIterT>
191 struct IterTraits<tree::TreeValueIteratorBase<TreeT, ValueIterT> > {
202 static inline double get(
const T& val) {
return double(val); }
207 static inline double get(
const T& val) {
return val.length(); }
214 template<
typename IterT,
typename StatsT>
220 inline void operator()(
const IterT& iter, StatsT& stats)
const {
221 if (iter.isVoxelValue()) stats.add(ImplT::get(*iter));
222 else stats.add(ImplT::get(*iter), iter.getVoxelCount());
229 template<
typename IterT,
typename ValueOp>
235 inline void operator()(
const IterT& iter) { getValue(iter, stats); }
247 template<
typename IterT,
typename ValueOp>
250 HistOp(
const ValueOp& op,
double vmin,
double vmax,
size_t bins):
251 hist(vmin, vmax, bins), getValue(op)
255 inline void operator()(
const IterT& iter) { getValue(iter, hist); }
268 template<
typename IterT,
typename OpT>
271 typedef typename IterT::TreeT
TreeT;
272 typedef typename TreeT::ValueType
ValueT;
280 template<
typename TreeT>
286 MathOp(
const IterT& iter,
const OpT& op):
287 mAcc(*THROW_IF_NULL(iter.getTree())), mOp(op)
293 if (it.isVoxelValue()) {
295 mStats.add(mOp.result(
mAcc, it.getCoord()));
304 int &x = xyz.
x(), &y = xyz.
y(), &z = xyz.
z();
305 for (x = bbox.
min().
x(); x <= bbox.
max().
x(); ++x) {
306 for (y = bbox.
min().
y(); y <= bbox.
max().
y(); ++y) {
307 for (z = bbox.
min().
z(); z <= bbox.
max().
z(); ++z) {
308 mStats.add(mOp.result(
mAcc, it.getCoord()));
322 template<
typename IterT>
324 histogram(
const IterT& iter,
double vmin,
double vmax,
size_t numBins,
bool threaded)
334 template<
typename IterT>
343 template<
typename IterT,
typename ValueOp>
345 statistics(
const IterT& iter,
const ValueOp& valOp,
bool threaded)
353 template<
typename OperatorT,
typename IterT>
366 #endif // OPENVDB_TOOLS_STATISTICS_HAS_BEEN_INCLUDED