OpenVDB  7.0.0
Diagnostics.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
11 #ifndef OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
12 #define OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
13 
14 #include <openvdb/Grid.h>
15 #include <openvdb/math/Math.h>
16 #include <openvdb/math/Vec3.h>
17 #include <openvdb/math/Stencils.h>
18 #include <openvdb/math/Operators.h>
20 #include <tbb/blocked_range.h>
21 #include <tbb/parallel_reduce.h>
22 #include <cmath> // for std::isnan(), std::isfinite()
23 #include <set>
24 #include <sstream>
25 #include <string>
26 #include <type_traits>
27 #include <vector>
28 
29 
30 namespace openvdb {
32 namespace OPENVDB_VERSION_NAME {
33 namespace tools {
34 
36 
62 template<class GridType>
63 std::string
64 checkLevelSet(const GridType& grid, size_t number=9);
65 
67 
86 template<class GridType>
87 std::string
88 checkFogVolume(const GridType& grid, size_t number=6);
89 
91 
98 template<class GridType>
99 bool
100 uniqueInactiveValues(const GridType& grid,
101  std::vector<typename GridType::ValueType>& values, size_t numValues);
102 
103 
105 
107 template<typename GridT, typename TreeIterT = typename GridT::ValueOnCIter>
108 struct CheckNan
109 {
111  using TileIterT = TreeIterT;
112  using VoxelIterT = typename tree::IterTraits<
113  typename TreeIterT::NodeT, typename TreeIterT::ValueIterT>::template
114  NodeConverter<typename GridT::TreeType::LeafNodeType>::Type;
115 
117  CheckNan() {}
118 
120  inline bool operator()(const ElementType& v) const { return std::isnan(v); }
121 
123  template<typename T>
124  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
125  operator()(const T& v) const
126  {
127  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;//should unroll
128  return false;
129  }
130 
132  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
133 
135  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
136 
138  std::string str() const { return "NaN"; }
139 
140 };// CheckNan
141 
143 
145 template <typename GridT,
146  typename TreeIterT = typename GridT::ValueOnCIter>
147 struct CheckInf
148 {
150  using TileIterT = TreeIterT;
151  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
152  typename TreeIterT::ValueIterT> ::template NodeConverter<
153  typename GridT::TreeType::LeafNodeType>::Type;
154 
156  CheckInf() {}
157 
159  inline bool operator()(const ElementType& v) const { return std::isinf(v); }
160 
162  template<typename T>
163  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
164  operator()(const T& v) const
165  {
166  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
167  return false;
168  }
169 
171  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
172 
174  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
175 
177  std::string str() const { return "infinite"; }
178 };// CheckInf
179 
181 
183 template <typename GridT,
184  typename TreeIterT = typename GridT::ValueOnCIter>
186 {
188  using TileIterT = TreeIterT;
189  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
190  typename TreeIterT::ValueIterT> ::template NodeConverter<
191  typename GridT::TreeType::LeafNodeType>::Type;
192 
195 
197  inline bool operator()(const ElementType& v) const { return !std::isfinite(v); }
198 
200  template<typename T>
201  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
202  operator()(const T& v) const {
203  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
204  return false;
205  }
206 
208  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
209 
211  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
212 
214  std::string str() const { return "not finite"; }
215 };// CheckFinite
216 
218 
221 template <typename GridT,
222  typename TreeIterT = typename GridT::ValueOffCIter>
224 {
226  using TileIterT = TreeIterT;
227  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
228  typename TreeIterT::ValueIterT> ::template NodeConverter<
229  typename GridT::TreeType::LeafNodeType>::Type;
230 
234  : absVal(math::Abs(a)), tolVal(math::Abs(t))
235  {
236  }
237 
240  inline bool operator()(const ElementType& v) const
241  {
242  return math::Abs(math::Abs(v) - absVal) > tolVal;
243  }
244 
246  template<typename T>
247  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
248  operator()(const T& v) const
249  {
250  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
251  return false;
252  }
253 
255  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
256 
258  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
259 
261  std::string str() const
262  {
263  std::ostringstream ss;
264  ss << "not equal to +/-"<<absVal<<" with a tolerance of "<<tolVal;
265  return ss.str();
266  }
267 
268  const ElementType absVal, tolVal;
269 };// CheckMagnitude
270 
272 
274 template <typename GridT,
275  bool MinInclusive = true,//is min part of the range?
276  bool MaxInclusive = true,//is max part of the range?
277  typename TreeIterT = typename GridT::ValueOnCIter>
279 {
281  using TileIterT = TreeIterT;
282  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
283  typename TreeIterT::ValueIterT> ::template NodeConverter<
284  typename GridT::TreeType::LeafNodeType>::Type;
285 
286  // @brief Constructor taking a range to be tested against.
287  CheckRange(const ElementType& _min, const ElementType& _max) : minVal(_min), maxVal(_max)
288  {
289  if (minVal > maxVal) {
290  OPENVDB_THROW(ValueError, "CheckRange: Invalid range (min > max)");
291  }
292  }
293 
295  inline bool operator()(const ElementType& v) const
296  {
297  return (MinInclusive ? v<minVal : v<=minVal) ||
298  (MaxInclusive ? v>maxVal : v>=maxVal);
299  }
300 
302  template<typename T>
303  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
304  operator()(const T& v) const {
305  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
306  return false;
307  }
308 
310  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
311 
313  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
314 
316  std::string str() const
317  {
318  std::ostringstream ss;
319  ss << "outside the value range " << (MinInclusive ? "[" : "]")
320  << minVal << "," << maxVal << (MaxInclusive ? "]" : "[");
321  return ss.str();
322  }
323 
324  const ElementType minVal, maxVal;
325 };// CheckRange
326 
328 
330 template <typename GridT,
331  typename TreeIterT = typename GridT::ValueOnCIter>
332 struct CheckMin
333 {
335  using TileIterT = TreeIterT;
336  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
337  typename TreeIterT::ValueIterT> ::template NodeConverter<
338  typename GridT::TreeType::LeafNodeType>::Type;
339 
340  // @brief Constructor taking a minimum to be tested against.
341  CheckMin(const ElementType& _min) : minVal(_min) {}
342 
344  inline bool operator()(const ElementType& v) const { return v<minVal; }
345 
347  template<typename T>
348  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
349  operator()(const T& v) const {
350  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
351  return false;
352  }
353 
355  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
356 
358  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
359 
361  std::string str() const
362  {
363  std::ostringstream ss;
364  ss << "smaller than "<<minVal;
365  return ss.str();
366  }
367 
369 };// CheckMin
370 
372 
374 template <typename GridT,
375  typename TreeIterT = typename GridT::ValueOnCIter>
376 struct CheckMax
377 {
379  using TileIterT = TreeIterT;
380  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
381  typename TreeIterT::ValueIterT> ::template NodeConverter<
382  typename GridT::TreeType::LeafNodeType>::Type;
383 
385  CheckMax(const ElementType& _max) : maxVal(_max) {}
386 
388  inline bool operator()(const ElementType& v) const { return v>maxVal; }
389 
391  template<typename T>
392  inline typename std::enable_if<VecTraits<T>::IsVec, bool>::type
393  operator()(const T& v) const {
394  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
395  return false;
396  }
397 
399  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
400 
402  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
403 
405  std::string str() const
406  {
407  std::ostringstream ss;
408  ss << "larger than "<<maxVal;
409  return ss.str();
410  }
411 
413 };// CheckMax
414 
416 
422 template<typename GridT,
423  typename TreeIterT = typename GridT::ValueOnCIter,
424  math::BiasedGradientScheme GradScheme = math::FIRST_BIAS>//math::WENO5_BIAS>
426 {
427  using ValueType = typename GridT::ValueType;
428  static_assert(std::is_floating_point<ValueType>::value,
429  "openvdb::tools::CheckNormGrad requires a scalar, floating-point grid");
430  using TileIterT = TreeIterT;
431  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
432  typename TreeIterT::ValueIterT> ::template NodeConverter<
433  typename GridT::TreeType::LeafNodeType>::Type;
434  using AccT = typename GridT::ConstAccessor;
435 
437  CheckNormGrad(const GridT& grid, const ValueType& _min, const ValueType& _max)
438  : acc(grid.getConstAccessor())
439  , invdx2(ValueType(1.0/math::Pow2(grid.voxelSize()[0])))
440  , minVal2(_min*_min)
441  , maxVal2(_max*_max)
442  {
443  if ( !grid.hasUniformVoxels() ) {
444  OPENVDB_THROW(ValueError, "CheckNormGrad: The transform must have uniform scale");
445  }
446  if (_min > _max) {
447  OPENVDB_THROW(ValueError, "CheckNormGrad: Invalid range (min > max)");
448  }
449  }
450 
452  : acc(other.acc.tree())
453  , invdx2(other.invdx2)
454  , minVal2(other.minVal2)
455  , maxVal2(other.maxVal2)
456  {
457  }
458 
460  inline bool operator()(const ValueType& v) const { return v<minVal2 || v>maxVal2; }
461 
464  inline bool operator()(const TreeIterT&) const { return (*this)(ValueType(0)); }
465 
468  inline bool operator()(const VoxelIterT &iter) const
469  {
470  const Coord ijk = iter.getCoord();
471  return (*this)(invdx2 * math::ISGradientNormSqrd<GradScheme>::result(acc, ijk));
472  }
473 
475  std::string str() const
476  {
477  std::ostringstream ss;
478  ss << "outside the range of NormGrad ["<<math::Sqrt(minVal2)<<","<<math::Sqrt(maxVal2)<<"]";
479  return ss.str();
480  }
481 
483  const ValueType invdx2, minVal2, maxVal2;
484 };// CheckNormGrad
485 
487 
492 template<typename GridT,
493  typename TreeIterT = typename GridT::ValueOnCIter,
494  typename StencilT = math::WenoStencil<GridT> >//math::GradStencil<GridT>
496 {
497  using ValueType = typename GridT::ValueType;
498  static_assert(std::is_floating_point<ValueType>::value,
499  "openvdb::tools::CheckEikonal requires a scalar, floating-point grid");
500  using TileIterT = TreeIterT;
501  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
502  typename TreeIterT::ValueIterT> ::template NodeConverter<
503  typename GridT::TreeType::LeafNodeType>::Type;
504 
506  CheckEikonal(const GridT& grid, const ValueType& _min, const ValueType& _max)
507  : stencil(grid), minVal(_min), maxVal(_max)
508  {
509  if ( !grid.hasUniformVoxels() ) {
510  OPENVDB_THROW(ValueError, "CheckEikonal: The transform must have uniform scale");
511  }
512  if (minVal > maxVal) {
513  OPENVDB_THROW(ValueError, "CheckEikonal: Invalid range (min > max)");
514  }
515  }
516 
518  : stencil(other.stencil.grid()), minVal(other.minVal), maxVal(other.maxVal)
519  {
520  }
521 
523  inline bool operator()(const ValueType& v) const { return v<minVal || v>maxVal; }
524 
527  inline bool operator()(const TreeIterT&) const { return (*this)(ValueType(0)); }
528 
531  inline bool operator()(const VoxelIterT &iter) const
532  {
533  stencil.moveTo(iter);
534  if (!stencil.zeroCrossing()) return false;
535  return (*this)(stencil.normSqGrad());
536  }
537 
539  std::string str() const
540  {
541  std::ostringstream ss;
542  ss << "outside the range of NormGrad ["<<minVal<<","<<maxVal<<"]";
543  return ss.str();
544  }
545 
546  mutable StencilT stencil;
547  const ValueType minVal, maxVal;
548 };// CheckEikonal
549 
551 
553 template<typename GridT,
554  typename TreeIterT = typename GridT::ValueOnCIter,
555  math::DScheme DiffScheme = math::CD_2ND>
557 {
558  using ValueType = typename GridT::ValueType;
560  static_assert(std::is_floating_point<ElementType>::value,
561  "openvdb::tools::CheckDivergence requires a floating-point vector grid");
562  using TileIterT = TreeIterT;
563  using VoxelIterT = typename tree::IterTraits<typename TreeIterT::NodeT,
564  typename TreeIterT::ValueIterT>::template NodeConverter<
565  typename GridT::TreeType::LeafNodeType>::Type;
566  using AccT = typename GridT::ConstAccessor;
567 
569  CheckDivergence(const GridT& grid,
570  const ValueType& _min,
571  const ValueType& _max)
572  : acc(grid.getConstAccessor())
573  , invdx(ValueType(1.0/grid.voxelSize()[0]))
574  , minVal(_min)
575  , maxVal(_max)
576  {
577  if ( !grid.hasUniformVoxels() ) {
578  OPENVDB_THROW(ValueError, "CheckDivergence: The transform must have uniform scale");
579  }
580  if (minVal > maxVal) {
581  OPENVDB_THROW(ValueError, "CheckDivergence: Invalid range (min > max)");
582  }
583  }
585  inline bool operator()(const ElementType& v) const { return v<minVal || v>maxVal; }
586 
589  inline bool operator()(const TreeIterT&) const { return (*this)(ElementType(0)); }
590 
593  inline bool operator()(const VoxelIterT &iter) const
594  {
595  const Coord ijk = iter.getCoord();
596  return (*this)(invdx * math::ISDivergence<DiffScheme>::result(acc, ijk));
597  }
598 
600  std::string str() const
601  {
602  std::ostringstream ss;
603  ss << "outside the range of divergence ["<<minVal<<","<<maxVal<<"]";
604  return ss.str();
605  }
606 
608  const ValueType invdx, minVal, maxVal;
609 };// CheckDivergence
610 
612 
615 template <typename GridT>
616 class Diagnose
617 {
618 public:
619  using MaskType = typename GridT::template ValueConverter<bool>::Type;
620 
621  Diagnose(const GridT& grid) : mGrid(&grid), mMask(new MaskType()), mCount(0)
622  {
623  mMask->setTransform(grid.transformPtr()->copy());
624  }
625 
626  template <typename CheckT>
627  std::string check(const CheckT& check,
628  bool updateMask = false,
629  bool checkVoxels = true,
630  bool checkTiles = true,
631  bool checkBackground = true)
632  {
633  typename MaskType::TreeType* mask = updateMask ? &(mMask->tree()) : nullptr;
634  CheckValues<CheckT> cc(mask, mGrid, check);
635  std::ostringstream ss;
636  if (checkBackground) ss << cc.checkBackground();
637  if (checkTiles) ss << cc.checkTiles();
638  if (checkVoxels) ss << cc.checkVoxels();
639  mCount += cc.mCount;
640  return ss.str();
641  }
642 
644  typename MaskType::ConstPtr mask() const { return mMask; }
648  typename MaskType::Ptr mask() { return mMask; }
650 
653  Index64 valueCount() const { return mMask->activeVoxelCount(); }
654 
658  Index64 failureCount() const { return mCount; }
659 
661  const GridT& grid() const { return *mGrid; }
662 
664  void clear() { mMask = new MaskType(); mCount = 0; }
665 
666 private:
667  // disallow copy construction and copy by assignment!
668  Diagnose(const Diagnose&);// not implemented
669  Diagnose& operator=(const Diagnose&);// not implemented
670 
671  const GridT* mGrid;
672  typename MaskType::Ptr mMask;
673  Index64 mCount;
674 
676  template <typename CheckT>
677  struct CheckValues
678  {
679  using MaskT = typename MaskType::TreeType;
680  using LeafT = typename GridT::TreeType::LeafNodeType;
681  using LeafManagerT = typename tree::LeafManager<const typename GridT::TreeType>;
682  const bool mOwnsMask;
683  MaskT* mMask;
684  const GridT* mGrid;
685  const CheckT mCheck;
686  Index64 mCount;
687 
688  CheckValues(MaskT* mask, const GridT* grid, const CheckT& check)
689  : mOwnsMask(false)
690  , mMask(mask)
691  , mGrid(grid)
692  , mCheck(check)
693  , mCount(0)
694  {
695  }
696  CheckValues(CheckValues& other, tbb::split)
697  : mOwnsMask(true)
698  , mMask(other.mMask ? new MaskT() : nullptr)
699  , mGrid(other.mGrid)
700  , mCheck(other.mCheck)
701  , mCount(0)
702  {
703  }
704  ~CheckValues() { if (mOwnsMask) delete mMask; }
705 
706  std::string checkBackground()
707  {
708  std::ostringstream ss;
709  if (mCheck(mGrid->background())) {
710  ++mCount;
711  ss << "Background is " + mCheck.str() << std::endl;
712  }
713  return ss.str();
714  }
715 
716  std::string checkTiles()
717  {
718  std::ostringstream ss;
719  const Index64 n = mCount;
720  typename CheckT::TileIterT i(mGrid->tree());
721  for (i.setMaxDepth(GridT::TreeType::RootNodeType::LEVEL - 1); i; ++i) {
722  if (mCheck(i)) {
723  ++mCount;
724  if (mMask) mMask->fill(i.getBoundingBox(), true, true);
725  }
726  }
727  if (const Index64 m = mCount - n) {
728  ss << m << " tile" << (m==1 ? " is " : "s are ") + mCheck.str() << std::endl;
729  }
730  return ss.str();
731  }
732 
733  std::string checkVoxels()
734  {
735  std::ostringstream ss;
736  LeafManagerT leafs(mGrid->tree());
737  const Index64 n = mCount;
738  tbb::parallel_reduce(leafs.leafRange(), *this);
739  if (const Index64 m = mCount - n) {
740  ss << m << " voxel" << (m==1 ? " is " : "s are ") + mCheck.str() << std::endl;
741  }
742  return ss.str();
743  }
744 
745  void operator()(const typename LeafManagerT::LeafRange& r)
746  {
747  using VoxelIterT = typename CheckT::VoxelIterT;
748  if (mMask) {
749  for (typename LeafManagerT::LeafRange::Iterator i=r.begin(); i; ++i) {
750  typename MaskT::LeafNodeType* maskLeaf = nullptr;
751  for (VoxelIterT j = tree::IterTraits<LeafT, VoxelIterT>::begin(*i); j; ++j) {
752  if (mCheck(j)) {
753  ++mCount;
754  if (maskLeaf == nullptr) maskLeaf = mMask->touchLeaf(j.getCoord());
755  maskLeaf->setValueOn(j.pos(), true);
756  }
757  }
758  }
759  } else {
760  for (typename LeafManagerT::LeafRange::Iterator i=r.begin(); i; ++i) {
761  for (VoxelIterT j = tree::IterTraits<LeafT, VoxelIterT>::begin(*i); j; ++j) {
762  if (mCheck(j)) ++mCount;
763  }
764  }
765  }
766  }
767  void join(const CheckValues& other)
768  {
769  if (mMask) mMask->merge(*(other.mMask), openvdb::MERGE_ACTIVE_STATES_AND_NODES);
770  mCount += other.mCount;
771  }
772  };//End of private class CheckValues
773 
774 };// End of public class Diagnose
775 
776 
778 
782 template<class GridType>
784 {
785 public:
786  using ValueType = typename GridType::ValueType;
787  using MaskType = typename GridType::template ValueConverter<bool>::Type;
788 
789  CheckLevelSet(const GridType& grid) : mDiagnose(grid) {}
790 
792  typename MaskType::ConstPtr mask() const { return mDiagnose.mask(); }
796  typename MaskType::Ptr mask() { return mDiagnose.mask(); }
798 
801  Index64 valueCount() const { return mDiagnose.valueCount(); }
802 
806  Index64 failureCount() const { return mDiagnose.failureCount(); }
807 
809  const GridType& grid() const { return mDiagnose.grid(); }
810 
812  void clear() { mDiagnose.clear(); }
813 
817  static std::string checkValueType()
818  {
819  static const bool test = std::is_floating_point<ValueType>::value;
820  return test ? "" : "Value type is not floating point\n";
821  }
822 
826  std::string checkClassType() const
827  {
828  const bool test = mDiagnose.grid().getGridClass() == GRID_LEVEL_SET;
829  return test ? "" : "Class type is not \"GRID_LEVEL_SET\"\n";
830  }
831 
835  std::string checkTransform() const
836  {
837  return mDiagnose.grid().hasUniformVoxels() ? "" : "Does not have uniform voxels\n";
838  }
839 
844  std::string checkBackground(Real halfWidth = LEVEL_SET_HALF_WIDTH) const
845  {
846  const Real w = mDiagnose.grid().background() / mDiagnose.grid().voxelSize()[0];
847  if (w < halfWidth) {
848  std::ostringstream ss;
849  ss << "The background value ("<< mDiagnose.grid().background()<<") is less than "
850  << halfWidth << " voxel units\n";
851  return ss.str();
852  }
853  return "";
854  }
855 
859  std::string checkTiles() const
860  {
861  const bool test = mDiagnose.grid().tree().hasActiveTiles();
862  return test ? "Has active tile values\n" : "";
863  }
864 
868  std::string checkFinite(bool updateMask = false)
869  {
871  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/true, /*background*/true);
872  }
873 
877  std::string checkRange(bool updateMask = false)
878  {
879  const ValueType& background = mDiagnose.grid().background();
880  CheckRange<GridType> c(-background, background);
881  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/false, /*background*/false);
882  }
883 
888  std::string checkInactiveValues(bool updateMask = false)
889  {
890  const ValueType& background = mDiagnose.grid().background();
892  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/true, /*background*/false);
893  }
894 
899  std::string checkEikonal(bool updateMask = false, ValueType minV = 0.5, ValueType maxV = 1.5)
900  {
901  CheckEikonal<GridType> c(mDiagnose.grid(), minV, maxV);
902  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/false, /*background*/false);
903  }
904 
922  std::string check(size_t n=9, bool updateMask = false)
923  {
924  std::string str = this->checkValueType();
925  if (str.empty() && n>1) str = this->checkClassType();
926  if (str.empty() && n>2) str = this->checkTransform();
927  if (str.empty() && n>3) str = this->checkBackground();
928  if (str.empty() && n>4) str = this->checkTiles();
929  if (str.empty() && n>5) str = this->checkFinite(updateMask);
930  if (str.empty() && n>6) str = this->checkRange(updateMask);
931  if (str.empty() && n>7) str = this->checkInactiveValues(updateMask);
932  if (str.empty() && n>8) str = this->checkEikonal(updateMask);
933  return str;
934  }
935 
936 private:
937  // disallow copy construction and copy by assignment!
938  CheckLevelSet(const CheckLevelSet&);// not implemented
939  CheckLevelSet& operator=(const CheckLevelSet&);// not implemented
940 
941  // Member data
942  Diagnose<GridType> mDiagnose;
943 };// CheckLevelSet
944 
945 template<class GridType>
946 std::string
947 checkLevelSet(const GridType& grid, size_t n)
948 {
949  CheckLevelSet<GridType> c(grid);
950  return c.check(n, false);
951 }
952 
954 
958 template<class GridType>
960 {
961 public:
962  using ValueType = typename GridType::ValueType;
963  using MaskType = typename GridType::template ValueConverter<bool>::Type;
964 
965  CheckFogVolume(const GridType& grid) : mDiagnose(grid) {}
966 
968  typename MaskType::ConstPtr mask() const { return mDiagnose.mask(); }
972  typename MaskType::Ptr mask() { return mDiagnose.mask(); }
974 
977  Index64 valueCount() const { return mDiagnose.valueCount(); }
978 
982  Index64 failureCount() const { return mDiagnose.failureCount(); }
983 
985  const GridType& grid() const { return mDiagnose.grid(); }
986 
988  void clear() { mDiagnose.clear(); }
989 
993  static std::string checkValueType()
994  {
995  static const bool test = std::is_floating_point<ValueType>::value;
996  return test ? "" : "Value type is not floating point";
997  }
998 
1002  std::string checkClassType() const
1003  {
1004  const bool test = mDiagnose.grid().getGridClass() == GRID_FOG_VOLUME;
1005  return test ? "" : "Class type is not \"GRID_LEVEL_SET\"";
1006  }
1007 
1011  std::string checkBackground() const
1012  {
1013  if (!math::isApproxZero(mDiagnose.grid().background())) {
1014  std::ostringstream ss;
1015  ss << "The background value ("<< mDiagnose.grid().background()<<") is not zero";
1016  return ss.str();
1017  }
1018  return "";
1019  }
1020 
1024  std::string checkFinite(bool updateMask = false)
1025  {
1027  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/true, /*background*/true);
1028  }
1029 
1033  std::string checkInactiveValues(bool updateMask = false)
1034  {
1036  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/true, /*background*/true);
1037  }
1038 
1043  std::string checkRange(bool updateMask = false)
1044  {
1045  CheckRange<GridType> c(0, 1);
1046  return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/true, /*background*/false);
1047  }
1048 
1061  std::string check(size_t n=6, bool updateMask = false)
1062  {
1063  std::string str = this->checkValueType();
1064  if (str.empty() && n>1) str = this->checkClassType();
1065  if (str.empty() && n>2) str = this->checkBackground();
1066  if (str.empty() && n>3) str = this->checkFinite(updateMask);
1067  if (str.empty() && n>4) str = this->checkInactiveValues(updateMask);
1068  if (str.empty() && n>5) str = this->checkRange(updateMask);
1069  return str;
1070  }
1071 
1072 private:
1073  // disallow copy construction and copy by assignment!
1074  CheckFogVolume(const CheckFogVolume&);// not implemented
1075  CheckFogVolume& operator=(const CheckFogVolume&);// not implemented
1076 
1077  // Member data
1078  Diagnose<GridType> mDiagnose;
1079 };// CheckFogVolume
1080 
1081 template<class GridType>
1082 std::string
1083 checkFogVolume(const GridType& grid, size_t n)
1084 {
1085  CheckFogVolume<GridType> c(grid);
1086  return c.check(n, false);
1087 }
1088 
1089 
1091 
1092 // Internal utility objects and implementation details
1093 
1094 
1095 namespace diagnostics_internal {
1096 
1097 
1098 template<typename TreeType>
1100 {
1101 public:
1103  using ValueType = typename TreeType::ValueType;
1104  using SetType = std::set<ValueType>;
1105 
1106  InactiveVoxelValues(LeafArray&, size_t numValues);
1107 
1108  void runParallel();
1109  void runSerial();
1110 
1111  void getInactiveValues(SetType&) const;
1112 
1113  inline InactiveVoxelValues(const InactiveVoxelValues<TreeType>&, tbb::split);
1114  inline void operator()(const tbb::blocked_range<size_t>&);
1115  inline void join(const InactiveVoxelValues<TreeType>&);
1116 
1117 private:
1118  LeafArray& mLeafArray;
1119  SetType mInactiveValues;
1120  size_t mNumValues;
1121 };// InactiveVoxelValues
1122 
1123 template<typename TreeType>
1125  : mLeafArray(leafs)
1126  , mInactiveValues()
1127  , mNumValues(numValues)
1128 {
1129 }
1130 
1131 template <typename TreeType>
1132 inline
1134  const InactiveVoxelValues<TreeType>& rhs, tbb::split)
1135  : mLeafArray(rhs.mLeafArray)
1136  , mInactiveValues()
1137  , mNumValues(rhs.mNumValues)
1138 {
1139 }
1140 
1141 template<typename TreeType>
1142 void
1144 {
1145  tbb::parallel_reduce(mLeafArray.getRange(), *this);
1146 }
1147 
1148 
1149 template<typename TreeType>
1150 void
1152 {
1153  (*this)(mLeafArray.getRange());
1154 }
1155 
1156 
1157 template<typename TreeType>
1158 inline void
1159 InactiveVoxelValues<TreeType>::operator()(const tbb::blocked_range<size_t>& range)
1160 {
1161  typename TreeType::LeafNodeType::ValueOffCIter iter;
1162 
1163  for (size_t n = range.begin(); n < range.end() && !tbb::task::self().is_cancelled(); ++n) {
1164  for (iter = mLeafArray.leaf(n).cbeginValueOff(); iter; ++iter) {
1165  mInactiveValues.insert(iter.getValue());
1166  }
1167 
1168  if (mInactiveValues.size() > mNumValues) {
1169  tbb::task::self().cancel_group_execution();
1170  }
1171  }
1172 }
1173 
1174 template<typename TreeType>
1175 inline void
1177 {
1178  mInactiveValues.insert(rhs.mInactiveValues.begin(), rhs.mInactiveValues.end());
1179 }
1180 
1181 template<typename TreeType>
1182 inline void
1184 {
1185  values.insert(mInactiveValues.begin(), mInactiveValues.end());
1186 }
1187 
1188 
1190 
1191 
1192 template<typename TreeType>
1194 {
1195 public:
1197  using ValueType = typename TreeType::ValueType;
1198  using SetType = std::set<ValueType>;
1199 
1200  InactiveTileValues(size_t numValues);
1201 
1202  void runParallel(IterRange&);
1203  void runSerial(IterRange&);
1204 
1205  void getInactiveValues(SetType&) const;
1206 
1207  inline InactiveTileValues(const InactiveTileValues<TreeType>&, tbb::split);
1208  inline void operator()(IterRange&);
1209  inline void join(const InactiveTileValues<TreeType>&);
1210 
1211 private:
1212  SetType mInactiveValues;
1213  size_t mNumValues;
1214 };
1215 
1216 
1217 template<typename TreeType>
1219  : mInactiveValues()
1220  , mNumValues(numValues)
1221 {
1222 }
1223 
1224 template <typename TreeType>
1225 inline
1227  const InactiveTileValues<TreeType>& rhs, tbb::split)
1228  : mInactiveValues()
1229  , mNumValues(rhs.mNumValues)
1230 {
1231 }
1232 
1233 template<typename TreeType>
1234 void
1236 {
1237  tbb::parallel_reduce(range, *this);
1238 }
1239 
1240 
1241 template<typename TreeType>
1242 void
1244 {
1245  (*this)(range);
1246 }
1247 
1248 
1249 template<typename TreeType>
1250 inline void
1252 {
1253  for (; range && !tbb::task::self().is_cancelled(); ++range) {
1254  typename TreeType::ValueOffCIter iter = range.iterator();
1255  for (; iter; ++iter) {
1256  mInactiveValues.insert(iter.getValue());
1257  }
1258 
1259  if (mInactiveValues.size() > mNumValues) {
1260  tbb::task::self().cancel_group_execution();
1261  }
1262  }
1263 }
1264 
1265 template<typename TreeType>
1266 inline void
1268 {
1269  mInactiveValues.insert(rhs.mInactiveValues.begin(), rhs.mInactiveValues.end());
1270 }
1271 
1272 template<typename TreeType>
1273 inline void
1275 {
1276  values.insert(mInactiveValues.begin(), mInactiveValues.end());
1277 }
1278 
1279 } // namespace diagnostics_internal
1280 
1281 
1283 
1284 
1285 template<class GridType>
1286 bool
1287 uniqueInactiveValues(const GridType& grid,
1288  std::vector<typename GridType::ValueType>& values, size_t numValues)
1289 {
1290  using TreeType = typename GridType::TreeType;
1291  using ValueType = typename GridType::ValueType;
1292  using SetType = std::set<ValueType>;
1293 
1294  SetType uniqueValues;
1295 
1296  { // Check inactive voxels
1297  TreeType& tree = const_cast<TreeType&>(grid.tree());
1298  tree::LeafManager<TreeType> leafs(tree);
1299  diagnostics_internal::InactiveVoxelValues<TreeType> voxelOp(leafs, numValues);
1300  voxelOp.runParallel();
1301  voxelOp.getInactiveValues(uniqueValues);
1302  }
1303 
1304  // Check inactive tiles
1305  if (uniqueValues.size() <= numValues) {
1306  typename TreeType::ValueOffCIter iter(grid.tree());
1307  iter.setMaxDepth(TreeType::ValueAllIter::LEAF_DEPTH - 1);
1309 
1311  tileOp.runParallel(range);
1312 
1313  tileOp.getInactiveValues(uniqueValues);
1314  }
1315 
1316  values.clear();
1317  values.reserve(uniqueValues.size());
1318 
1319  typename SetType::iterator it = uniqueValues.begin();
1320  for ( ; it != uniqueValues.end(); ++it) {
1321  values.push_back(*it);
1322  }
1323 
1324  return values.size() <= numValues;
1325 }
1326 
1327 } // namespace tools
1328 } // namespace OPENVDB_VERSION_NAME
1329 } // namespace openvdb
1330 
1331 #endif // OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:153
CheckMin(const ElementType &_min)
Definition: Diagnostics.h:341
bool operator()(const VoxelIterT &iter) const
Return true if the norm of the gradient at a zero-crossing voxel location of the iterator is out of r...
Definition: Diagnostics.h:531
typename GridT::ConstAccessor AccT
Definition: Diagnostics.h:566
typename GridT::ValueType ValueType
Definition: Diagnostics.h:427
void clear()
Clear the mask and error counter.
Definition: Diagnostics.h:812
TreeIterT TileIterT
Definition: Diagnostics.h:562
Performs multithreaded diagnostics of a grid.
Definition: Diagnostics.h:616
bool operator()(const VoxelIterT &iter) const
Return true if the voxel at the iterator location is NaN.
Definition: Diagnostics.h:135
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:460
typename GridType::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:963
static std::string checkValueType()
Return a nonempty message if the grid&#39;s value type is a floating point.
Definition: Diagnostics.h:817
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:229
std::string checkFogVolume(const GridType &grid, size_t number=6)
Perform checks on a grid to see if it is a valid fog volume.
Definition: Diagnostics.h:1083
void clear()
Clear the mask and error counter.
Definition: Diagnostics.h:664
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:334
TreeIterT TileIterT
Definition: Diagnostics.h:379
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const ElementType minVal
Definition: Diagnostics.h:324
typename GridType::ValueType ValueType
Definition: Diagnostics.h:962
Index64 valueCount() const
Return the number of values (i.e. background, tiles or voxels) that have failed one or more checks...
Definition: Diagnostics.h:977
bool operator()(const ElementType &v) const
Definition: Diagnostics.h:240
This is a special 19-point stencil that supports optimal fifth-order WENO upwinding, second-order central differencing, Laplacian, and zero-crossing test.
Definition: Stencils.h:1359
Definition: FiniteDifference.h:35
Checks NaN values.
Definition: Diagnostics.h:108
CheckNan()
Default constructor.
Definition: Diagnostics.h:117
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:806
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are smaller than min.
Definition: Diagnostics.h:349
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is NaN or infinite.
Definition: Diagnostics.h:208
MaskType::Ptr mask()
Return a boolean mask of all the values (i.e. tiles and/or voxels) that have failed one or more check...
Definition: Diagnostics.h:972
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:503
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
bool operator()(const TreeIterT &iter) const
Return true if the voxel at the iterator location is out of range.
Definition: Diagnostics.h:310
void getInactiveValues(SetType &) const
Definition: Diagnostics.h:1183
Checks for both NaN and inf values, i.e. any value that is not finite.
Definition: Diagnostics.h:185
Coord Abs(const Coord &xyz)
Definition: Coord.h:515
Index64 valueCount() const
Return the number of values (i.e. background, tiles or voxels) that have failed one or more checks...
Definition: Diagnostics.h:653
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:600
bool operator()(const VoxelIterT &iter) const
Return true if the divergence at a voxel location of the iterator is out of range.
Definition: Diagnostics.h:593
std::string checkBackground() const
Return a nonempty message if the background value is not zero.
Definition: Diagnostics.h:1011
const IterT & iterator() const
Return a reference to this range&#39;s iterator.
Definition: TreeIterator.h:1328
bool operator()(const ElementType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:295
const ValueType minVal2
Definition: Diagnostics.h:483
RangeType getRange(size_t grainsize=1) const
Return a tbb::blocked_range of leaf array indices.
Definition: LeafManager.h:355
std::string checkEikonal(bool updateMask=false, ValueType minV=0.5, ValueType maxV=1.5)
Return a nonempty message if the norm of the gradient of the active voxels is out of the range minV t...
Definition: Diagnostics.h:899
typename GridT::ValueType ValueType
Definition: Diagnostics.h:497
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
This allows for vector values to be checked component-wise.
Definition: Diagnostics.h:125
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:378
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:258
TreeIterT TileIterT
Definition: Diagnostics.h:500
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are infinite.
Definition: Diagnostics.h:248
Type Pow2(Type x)
Return x2.
Definition: Math.h:495
Divergence operator defined in index space using various first derivative schemes.
Definition: Operators.h:469
const GridType & grid() const
Return a const reference to the grid.
Definition: Diagnostics.h:985
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:982
bool operator()(const ValueType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:460
Index64 valueCount() const
Return the number of values (i.e. background, tiles or voxels) that have failed one or more checks...
Definition: Diagnostics.h:801
CheckNormGrad(const GridT &grid, const ValueType &_min, const ValueType &_max)
Constructor taking a grid and a range to be tested against.
Definition: Diagnostics.h:437
double Real
Definition: Types.h:37
std::string checkFinite(bool updateMask=false)
Return a nonempty message if any of the values are not finite. i.e. NaN or inf.
Definition: Diagnostics.h:868
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is smaller than min.
Definition: Diagnostics.h:358
AccT acc
Definition: Diagnostics.h:482
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:191
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:539
void operator()(IterRange &)
Definition: Diagnostics.h:1251
CheckMax(const ElementType &_max)
Constructor taking a maximum to be tested against.
Definition: Diagnostics.h:385
typename GridType::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:619
TreeIterT TileIterT
Definition: Diagnostics.h:150
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are larger than max.
Definition: Diagnostics.h:393
CheckRange(const ElementType &_min, const ElementType &_max)
Definition: Diagnostics.h:287
std::string check(size_t n=6, bool updateMask=false)
Return a nonempty message if an error or issue is detected. Only runs tests with a number lower than ...
Definition: Diagnostics.h:1061
bool operator()(const ElementType &v) const
Return true if the value is infinite.
Definition: Diagnostics.h:159
DScheme
Different discrete schemes used in the first derivatives.
Definition: FiniteDifference.h:32
TreeIterT TileIterT
Definition: Diagnostics.h:281
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:589
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:475
bool uniqueInactiveValues(const GridType &grid, std::vector< typename GridType::ValueType > &values, size_t numValues)
Threaded method to find unique inactive values.
Definition: Diagnostics.h:1287
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:464
MaskType::Ptr mask()
Return a boolean mask of all the values (i.e. tiles and/or voxels) that have failed one or more check...
Definition: Diagnostics.h:648
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:284
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:527
Checks the divergence against a range.
Definition: Diagnostics.h:556
Definition: Exceptions.h:65
typename T::ValueType ElementType
Definition: Types.h:185
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:114
CheckEikonal(const GridT &grid, const ValueType &_min, const ValueType &_max)
Constructor taking a grid and a range to be tested against.
Definition: Diagnostics.h:506
void join(const InactiveVoxelValues< TreeType > &)
Definition: Diagnostics.h:1176
std::string checkClassType() const
Return message if the grid&#39;s class is a level set.
Definition: Diagnostics.h:826
const ValueType minVal
Definition: Diagnostics.h:608
Check that the magnitude of a value, a, is close to a fixed magnitude, b, given a fixed tolerance c...
Definition: Diagnostics.h:223
bool operator()(const ElementType &v) const
Return true if the value is larger than max.
Definition: Diagnostics.h:388
Class that performs various types of checks on narrow-band level sets.
Definition: Diagnostics.h:783
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:433
std::string checkBackground(Real halfWidth=LEVEL_SET_HALF_WIDTH) const
Return a nonempty message if the background value is larger than or equal to the halfWidth*voxelSize...
Definition: Diagnostics.h:844
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:331
Definition: Types.h:455
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is NaN.
Definition: Diagnostics.h:132
std::string checkFinite(bool updateMask=false)
Return a nonempty message if any of the values are not finite. i.e. NaN or inf.
Definition: Diagnostics.h:1024
std::string checkRange(bool updateMask=false)
Return a nonempty message if the active voxel values are out-of-range.
Definition: Diagnostics.h:877
AccT acc
Definition: Diagnostics.h:607
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:214
Checks for infinite values, e.g. 1/0 or -1/0.
Definition: Diagnostics.h:147
std::string checkRange(bool updateMask=false)
Return a nonempty message if the active voxel values are out-of-range, i.e. not in the range [0...
Definition: Diagnostics.h:1043
typename GridType::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:787
Checks the norm of the gradient at zero-crossing voxels against a range.
Definition: Diagnostics.h:495
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:316
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:138
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is larger than max.
Definition: Diagnostics.h:399
std::string checkInactiveValues(bool updateMask=false)
Return a nonempty message if any of the inactive values are not zero.
Definition: Diagnostics.h:1033
bool operator()(const VoxelIterT &iter) const
Return true if the norm of the gradient at a voxel location of the iterator is out of range...
Definition: Diagnostics.h:468
InactiveTileValues(size_t numValues)
Definition: Diagnostics.h:1218
CheckNormGrad(const CheckNormGrad &other)
Definition: Diagnostics.h:451
Checks a value against a minimum.
Definition: Diagnostics.h:332
Definition: Exceptions.h:13
typename TreeType::ValueType ValueType
Definition: Diagnostics.h:1103
typename GridType::ValueType ValueType
Definition: Diagnostics.h:786
void join(const InactiveTileValues< TreeType > &)
Definition: Diagnostics.h:1267
std::string checkClassType() const
Return a nonempty message if the grid&#39;s class is a level set.
Definition: Diagnostics.h:1002
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:658
typename GridT::ValueType ValueType
Definition: Diagnostics.h:558
Definition: TreeIterator.h:64
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:405
void clear()
Clear the mask and error counter.
Definition: Diagnostics.h:988
Checks a value against a range.
Definition: Diagnostics.h:278
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:280
This class manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
TreeIterT TileIterT
Definition: Diagnostics.h:111
std::string checkTransform() const
Return a nonempty message if the grid&#39;s transform does not have uniform scaling.
Definition: Diagnostics.h:835
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:255
const GridType & grid() const
Return a const reference to the grid.
Definition: Diagnostics.h:809
CheckLevelSet(const GridType &grid)
Definition: Diagnostics.h:789
void getInactiveValues(SetType &) const
Definition: Diagnostics.h:1274
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:708
typename VecTraits< ValueType >::ElementType ElementType
Definition: Diagnostics.h:559
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:149
std::string checkTiles() const
Return a nonempty message if the grid has no active tile values.
Definition: Diagnostics.h:859
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are NaN or infinite.
Definition: Diagnostics.h:202
MaskType::Ptr mask()
Return a boolean mask of all the values (i.e. tiles and/or voxels) that have failed one or more check...
Definition: Diagnostics.h:796
Checks the norm of the gradient against a range, i.e., |∇Φ| ∈ [min, max].
Definition: Diagnostics.h:425
static std::string checkValueType()
Return a nonempty message if the grid&#39;s value type is a floating point.
Definition: Diagnostics.h:993
Definition: TreeIterator.h:1307
Tolerance for floating-point comparison.
Definition: Math.h:90
std::string check(const CheckT &check, bool updateMask=false, bool checkVoxels=true, bool checkTiles=true, bool checkBackground=true)
Definition: Diagnostics.h:627
Checks a value against a maximum.
Definition: Diagnostics.h:376
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:565
CheckFinite()
Default constructor.
Definition: Diagnostics.h:194
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is out of range.
Definition: Diagnostics.h:313
const GridT & grid() const
Return a const reference to the grid.
Definition: Diagnostics.h:661
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:261
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:225
bool operator()(const ValueType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:523
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is NaN or infinite.
Definition: Diagnostics.h:211
void runParallel(IterRange &)
Definition: Diagnostics.h:1235
TreeIterT TileIterT
Definition: Diagnostics.h:188
std::string checkInactiveValues(bool updateMask=false)
Return a nonempty message if the the inactive values do not have a magnitude equal to the background ...
Definition: Diagnostics.h:888
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:361
CheckMagnitude(const ElementType &a, const ElementType &t=math::Tolerance< ElementType >::value())
Default constructor.
Definition: Diagnostics.h:232
TreeIterT TileIterT
Definition: Diagnostics.h:430
Definition: Operators.h:227
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:382
CheckEikonal(const CheckEikonal &other)
Definition: Diagnostics.h:517
bool operator()(const ElementType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:585
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:174
std::set< ValueType > SetType
Definition: Diagnostics.h:1104
InactiveVoxelValues(LeafArray &, size_t numValues)
Definition: Diagnostics.h:1124
std::string check(size_t n=9, bool updateMask=false)
Return a nonempty message if an error or issue is detected. Only runs tests with a number lower than ...
Definition: Diagnostics.h:922
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
Definition: Math.h:293
Defines various finite difference stencils by means of the "curiously recurring template pattern" on ...
TreeIterT TileIterT
Definition: Diagnostics.h:226
Definition: FiniteDifference.h:167
uint64_t Index64
Definition: Types.h:30
typename GridT::ConstAccessor AccT
Definition: Diagnostics.h:434
bool operator()(const VoxelIterT &iter) const
Return true if the voxel at the iterator location is larger than max.
Definition: Diagnostics.h:402
std::string checkLevelSet(const GridType &grid, size_t number=9)
Perform checks on a grid to see if it is a valid symmetric, narrow-band level set.
Definition: Diagnostics.h:947
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are infinite.
Definition: Diagnostics.h:164
StencilT stencil
Definition: Diagnostics.h:546
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
A LeafManager manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional au...
std::set< ValueType > SetType
Definition: Diagnostics.h:1198
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:187
bool operator()(const TreeIterT &iter) const
Return true if the voxel at the iterator location is smaller than min.
Definition: Diagnostics.h:355
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:110
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:171
const ElementType maxVal
Definition: Diagnostics.h:412
void operator()(const tbb::blocked_range< size_t > &)
Definition: Diagnostics.h:1159
bool operator()(const ElementType &v) const
Return true if the value is NOT finite, i.e. it&#39;s NaN or infinite.
Definition: Diagnostics.h:197
Class that performs various types of checks on fog volumes.
Definition: Diagnostics.h:959
TreeIterT TileIterT
Definition: Diagnostics.h:335
CheckDivergence(const GridT &grid, const ValueType &_min, const ValueType &_max)
Constructor taking a grid and a range to be tested against.
Definition: Diagnostics.h:569
const ElementType minVal
Definition: Diagnostics.h:368
const ElementType tolVal
Definition: Diagnostics.h:268
std::enable_if< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are out of range.
Definition: Diagnostics.h:304
const ValueType minVal
Definition: Diagnostics.h:547
Definition: Types.h:454
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:177
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:338
CheckFogVolume(const GridType &grid)
Definition: Diagnostics.h:965
bool operator()(const ElementType &v) const
Return true if the value is smaller than min.
Definition: Diagnostics.h:344
bool operator()(const ElementType &v) const
Return true if the scalar value is NaN.
Definition: Diagnostics.h:120
typename TreeType::ValueType ValueType
Definition: Diagnostics.h:1197
CheckInf()
Default constructor.
Definition: Diagnostics.h:156
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:165
void runSerial(IterRange &)
Definition: Diagnostics.h:1243
Diagnose(const GridT &grid)
Definition: Diagnostics.h:621