OpenVDB  3.0.0
Diagnostics.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
32 #define OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Grid.h>
35 #include <openvdb/math/Math.h>
36 #include <openvdb/math/Vec3.h>
37 #include <openvdb/math/Operators.h>
38 #include <openvdb/tree/LeafManager.h>
39 #include <tbb/blocked_range.h>
40 #include <tbb/parallel_reduce.h>
41 #include <set>
42 #include <boost/math/special_functions/fpclassify.hpp>
43 #include <boost/utility/enable_if.hpp>
44 
45 /* TODO: Ken Museth
46 
47 checkLevelSet
48 1) has level set class type
49 2) value type is floating point
50 3) has uniform scale
51 4) background value is positive and n*dx
52 5) active values in range between +-background
53 6) no active tiles
54 8) abs of inactive values = background
55 9) norm grad is close to one
56 
57 checkDensity volume
58 1) has fog class tag
59 2) value type is a floating point
60 3) background = 0
61 4) all inactive values are zero
62 5) all active values are 0-1
63 
64 */
65 
66 
67 namespace openvdb {
69 namespace OPENVDB_VERSION_NAME {
70 namespace tools {
71 
72 
74 
75 
82 template<class GridType>
83 bool
84 uniqueInactiveValues(const GridType& grid,
85  std::vector<typename GridType::ValueType>& values, size_t numValues);
86 
87 
89 
91 template <typename GridT,
92  typename TreeIterT = typename GridT::ValueOnCIter>
93 struct CheckNan
94 {
96  typedef TreeIterT TileIterT;
98  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
99 
101  CheckNan() {}
102 
104  inline bool operator()(const ElementType& v) const { return boost::math::isnan(v); }
105 
107  template <typename T>
108  inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
109  operator()(const T& v) const
110  {
111  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;//should unroll
112  return false;
113  }
114 
116  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
117 
119  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
120 
122  std::string str() const { return "nan"; }
123 
124 };// CheckNan
125 
127 template <typename GridT,
128  typename TreeIterT = typename GridT::ValueOnCIter>
129 struct CheckInf
130 {
132  typedef TreeIterT TileIterT;
134  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
135 
137  CheckInf() {}
138 
140  inline bool operator()(const ElementType& v) const { return boost::math::isinf(v); }
141 
143  template <typename T> inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
144  operator()(const T& v) const
145  {
146  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
147  return false;
148  }
149 
151  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
152 
154  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
155 
157  std::string str() const { return "infinite"; }
158 };// CheckInf
159 
161 template <typename GridT,
162  typename TreeIterT = typename GridT::ValueOnCIter>
164 {
166  typedef TreeIterT TileIterT;
168  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
169 
172 
174  inline bool operator()(const ElementType& v) const { return !boost::math::isfinite(v); }
175 
177  template <typename T>
178  inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
179  operator()(const T& v) const {
180  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
181  return false;
182  }
183 
185  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
186 
188  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
189 
191  std::string str() const { return "not finite"; }
192 };// CheckFinite
193 
196 template <typename GridT,
197  typename TreeIterT = typename GridT::ValueOffCIter>
199 {
201  typedef TreeIterT TileIterT;
203  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
204 
206  CheckMagnitude(const ElementType& a,
207  const ElementType& t = math::Tolerance<ElementType>::value())
208  : absVal(math::Abs(a)), tolVal(math::Abs(t))
209  {
210  }
211 
214  inline bool operator()(const ElementType& v) const
215  {
216  return math::Abs(math::Abs(v) - absVal) > tolVal;
217  }
218 
220  template <typename T> inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
221  operator()(const T& v) const
222  {
223  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
224  return false;
225  }
226 
228  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
229 
231  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
232 
234  std::string str() const
235  {
236  std::ostringstream ss;
237  ss << "not equal to +/-"<<absVal<<" with a tolerance of "<<tolVal;
238  return ss.str();
239  }
240 
241  const ElementType absVal, tolVal;
242 };// CheckMagnitude
243 
245 template <typename GridT,
246  bool MinInclusive = true,//is min part of the range?
247  bool MaxInclusive = true,//is max part of the range?
248  typename TreeIterT = typename GridT::ValueOnCIter>
250 {
252  typedef TreeIterT TileIterT;
254  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
255 
256  // @brief Constructor taking a range to be tested against.
257  CheckRange(const ElementType& _min, const ElementType& _max) : minVal(_min), maxVal(_max)
258  {
259  }
260 
262  inline bool operator()(const ElementType& v) const
263  {
264  return (MinInclusive ? v<minVal : v<=minVal) ||
265  (MaxInclusive ? v>maxVal : v>=maxVal);
266  }
267 
269  template <typename T>
270  inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
271  operator()(const T& v) const {
272  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
273  return false;
274  }
275 
277  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
278 
280  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
281 
283  std::string str() const
284  {
285  std::ostringstream ss;
286  ss << "outside the range " << (MinInclusive ? "[" : "]")
287  << minVal << "," << maxVal << (MaxInclusive ? "]" : "[");
288  return ss.str();
289  }
290 
291  const ElementType minVal, maxVal;
292 };// CheckRange
293 
295 template <typename GridT,
296  typename TreeIterT = typename GridT::ValueOnCIter>
297 struct CheckMin
298 {
300  typedef TreeIterT TileIterT;
302  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
303 
304  // @brief Constructor taking a minimum to be tested against.
305  CheckMin(const ElementType& _min) : minVal(_min) {}
306 
308  inline bool operator()(const ElementType& v) const { return v<minVal; }
309 
311  template <typename T>
312  inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
313  operator()(const T& v) const {
314  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
315  return false;
316  }
317 
319  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
320 
322  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
323 
325  std::string str() const
326  {
327  std::ostringstream ss;
328  ss << "smaller then "<<minVal;
329  return ss.str();
330  }
331 
332  const ElementType minVal;
333 };// CheckMin
334 
336 template <typename GridT,
337  typename TreeIterT = typename GridT::ValueOnCIter>
338 struct CheckMax
339 {
341  typedef TreeIterT TileIterT;
343  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
344 
346  CheckMax(const ElementType& _max) : maxVal(_max) {}
347 
349  inline bool operator()(const ElementType& v) const { return v>maxVal; }
350 
352  template <typename T>
353  inline typename boost::enable_if_c<VecTraits<T>::IsVec, bool>::type
354  operator()(const T& v) const {
355  for (int i=0; i<VecTraits<T>::Size; ++i) if ((*this)(v[i])) return true;
356  return false;
357  }
358 
360  bool operator()(const TreeIterT &iter) const { return (*this)(*iter); }
361 
363  bool operator()(const VoxelIterT &iter) const { return (*this)(*iter); }
364 
366  std::string str() const
367  {
368  std::ostringstream ss;
369  ss << "larger then "<<maxVal;
370  return ss.str();
371  }
372 
373  const ElementType maxVal;
374 };// CheckMax
375 
377 template<typename GridT,
378  typename TreeIterT = typename GridT::ValueOnCIter,
379  math::BiasedGradientScheme GradScheme = math::FIRST_BIAS>//math::WENO5_BIAS>
381 {
382  typedef typename GridT::ValueType ValueType;
383  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
384  typedef TreeIterT TileIterT;
386  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
387  typedef typename GridT::ConstAccessor AccT;
388 
390  CheckNormGrad(const GridT& grid, const ValueType& _min, const ValueType& _max)
391  : acc(grid.getConstAccessor())
392  , invdx2(ValueType(1.0/math::Pow2(grid.voxelSize()[0])))
393  , minVal(_min)
394  , maxVal(_max)
395  {
396  if ( !grid.hasUniformVoxels() ) {
398  "The transform must have uniform scale for CheckNormGrad to function");
399  }
400  }
401 
403  : acc(other.acc.tree())
404  , invdx2(other.invdx2)
405  , minVal(other.minVal)
406  , maxVal(other.maxVal)
407  {
408  }
409 
411  {
412  if (&other != this) {
413  acc = AccT(other.acc.tree());
414  invdx2 = other.invdx2;
415  minVal = other.minVal;
416  maxVal = other.maxVal;
417  }
418  return *this;
419  }
420 
422  inline bool operator()(const ValueType& v) const { return v<minVal || v>maxVal; }
423 
426  inline bool operator()(const TreeIterT&) const { return (*this)(ValueType(0)); }
427 
430  inline bool operator()(const VoxelIterT &iter) const
431  {
432  const Coord ijk = iter.getCoord();
433  return (*this)(invdx2 * math::ISGradientNormSqrd<GradScheme>::result(acc, ijk));
434  }
435 
437  std::string str() const
438  {
439  std::ostringstream ss;
440  ss << "outside the range ["<<minVal<<","<<maxVal<<"]";
441  return ss.str();
442  }
443 
444  AccT acc;
445  const ValueType invdx2, minVal, maxVal;
446 };// CheckNormGrad
447 
449 template<typename GridT,
450  typename TreeIterT = typename GridT::ValueOnCIter,
451  math::DScheme DiffScheme = math::CD_2ND>
453 {
454  typedef typename GridT::ValueType ValueType;
456  BOOST_STATIC_ASSERT(boost::is_floating_point<ElementType>::value);
457  typedef TreeIterT TileIterT;
459  ::template NodeConverter<typename GridT::TreeType::LeafNodeType>::Type VoxelIterT;
460  typedef typename GridT::ConstAccessor AccT;
461 
463  CheckDivergence(const GridT& grid,
464  const ValueType& _min,
465  const ValueType& _max)
466  : acc(grid.getConstAccessor())
467  , invdx(ValueType(1.0/grid.voxelSize()[0]))
468  , minVal(_min)
469  , maxVal(_max)
470  {
471  if ( !grid.hasUniformVoxels() ) {
473  "The transform must have uniform scale for CheckDivergence to function");
474  }
475  }
477  inline bool operator()(const ElementType& v) const { return v<minVal || v>maxVal; }
478 
481  inline bool operator()(const TreeIterT&) const { return (*this)(ElementType(0)); }
482 
485  inline bool operator()(const VoxelIterT &iter) const
486  {
487  const Coord ijk = iter.getCoord();
488  return (*this)(invdx * math::ISDivergence<DiffScheme>::result(acc, ijk));
489  }
490 
492  std::string str() const
493  {
494  std::ostringstream ss;
495  ss << "outside the range ["<<minVal<<","<<maxVal<<"]";
496  return ss.str();
497  }
498 
499  AccT acc;
500  const ValueType invdx, minVal, maxVal;
501 };// CheckDivergence
502 
505 template <typename GridT>
506 class Diagnose
507 {
508  public:
509  typedef typename GridT::template ValueConverter<bool>::Type MaskType;
510 
511  Diagnose(const GridT& grid) : mGrid(&grid), mMask(new MaskType()), mCount(0)
512  {
513  mMask->setTransform(grid.transformPtr()->copy());
514  }
515 
516  template <typename CheckT>
517  std::string check(const CheckT& check,
518  bool updateMask = false,
519  bool checkVoxels = true,
520  bool checkTiles = true,
521  bool checkBackground = true)
522  {
523  typename MaskType::TreeType* mask = updateMask ? &(mMask->tree()) : NULL;
524  CheckValues<CheckT> cc(mask, mGrid, check);
525  std::ostringstream ss;
526  if (checkBackground) ss << cc.checkBackground();
527  if (checkTiles) ss << cc.checkTiles();
528  if (checkVoxels) ss << cc.checkVoxels();
529  mCount += cc.mCount;
530  return ss.str();
531  }
532 
536  typename MaskType::ConstPtr mask() const { return mMask; }
537 
540  Index64 valueCount() const { return mMask->activeVoxelCount(); }
541 
545  Index64 failureCount() const { return mCount; }
546 
547 private:
548  const GridT* mGrid;
549  typename MaskType::Ptr mMask;
550  Index64 mCount;
551 
553  template <typename CheckT>
554  struct CheckValues
555  {
556  typedef typename MaskType::TreeType MaskT;
557  typedef typename GridT::TreeType::LeafNodeType LeafT;
558  typedef typename tree::LeafManager<const typename GridT::TreeType> LeafManagerT;
559  const bool mOwnsMask;
560  MaskT* mMask;
561  const GridT* mGrid;
562  const CheckT mCheck;
563  Index64 mCount;
564 
565  CheckValues(MaskT* mask, const GridT* grid, const CheckT& check)
566  : mOwnsMask(false)
567  , mMask(mask)
568  , mGrid(grid)
569  , mCheck(check)
570  , mCount(0)
571  {
572  }
573  CheckValues(CheckValues& other, tbb::split)
574  : mOwnsMask(true)
575  , mMask(other.mMask ? new MaskT() : NULL)
576  , mGrid(other.mGrid)
577  , mCheck(other.mCheck)
578  , mCount(0)
579  {
580  }
581  ~CheckValues() { if (mOwnsMask) delete mMask; }
582 
583  std::string checkBackground()
584  {
585  std::ostringstream ss;
586  if (mCheck(mGrid->background())) {
587  ++mCount;
588  ss << "Background is " + mCheck.str() << std::endl;
589  }
590  return ss.str();
591  }
592 
593  std::string checkTiles()
594  {
595  std::ostringstream ss;
596  const Index64 n = mCount;
597  typename CheckT::TileIterT i(mGrid->tree());
598  for (i.setMaxDepth(GridT::TreeType::RootNodeType::LEVEL - 1); i; ++i) {
599  if (mCheck(i)) {
600  ++mCount;
601  if (mMask) mMask->fill(i.getBoundingBox(), true, true);
602  }
603  }
604  if (const Index64 m = mCount - n) {
605  ss << m << (m==1?" tile is ":" tiles are ") + mCheck.str() << std::endl;
606  }
607  return ss.str();
608  }
609 
610  std::string checkVoxels()
611  {
612  std::ostringstream ss;
613  LeafManagerT leafs(mGrid->tree());
614  const Index64 n = mCount;
615  tbb::parallel_reduce(leafs.leafRange(), *this);
616  if (const Index64 m = mCount - n) {
617  ss << m << (m==1?" voxel is ":" voxels are ") + mCheck.str() << std::endl;
618  }
619  return ss.str();
620  }
621 
622  void operator()(const typename LeafManagerT::LeafRange& r)
623  {
624  typedef typename CheckT::VoxelIterT VoxelIterT;
625  if (mMask) {
626  for (typename LeafManagerT::LeafRange::Iterator i=r.begin(); i; ++i) {
627  typename MaskT::LeafNodeType* maskLeaf = NULL;
628  for (VoxelIterT j = tree::IterTraits<LeafT, VoxelIterT>::begin(*i); j; ++j) {
629  if (mCheck(j)) {
630  ++mCount;
631  if (maskLeaf == NULL) maskLeaf = mMask->touchLeaf(j.getCoord());
632  maskLeaf->setValueOn(j.pos(), true);
633  }
634  }
635  }
636  } else {
637  for (typename LeafManagerT::LeafRange::Iterator i=r.begin(); i; ++i) {
638  for (VoxelIterT j = tree::IterTraits<LeafT, VoxelIterT>::begin(*i); j; ++j) {
639  if (mCheck(j)) ++mCount;
640  }
641  }
642  }
643  }
644  void join(const CheckValues& other)
645  {
646  if (mMask) mMask->merge(*(other.mMask), openvdb::MERGE_ACTIVE_STATES_AND_NODES);
647  mCount += other.mCount;
648  }
649  };//End of private class CheckValues
650 
651 };// End of public class Diagnose
652 
653 
655 
656 // Internal utility objects and implementation details
657 
658 
659 namespace diagnostics_internal {
660 
661 
662 template<typename TreeType>
664 {
665 public:
667  typedef typename TreeType::ValueType ValueType;
668  typedef std::set<ValueType> SetType;
669 
670  InactiveVoxelValues(LeafArray&, size_t numValues);
671 
672  void runParallel();
673  void runSerial();
674 
675  void getInactiveValues(SetType&) const;
676 
677  inline InactiveVoxelValues(const InactiveVoxelValues<TreeType>&, tbb::split);
678  inline void operator()(const tbb::blocked_range<size_t>&);
679  inline void join(const InactiveVoxelValues<TreeType>&);
680 
681 private:
682  LeafArray& mLeafArray;
683  SetType mInactiveValues;
684  size_t mNumValues;
685 };
686 
687 template<typename TreeType>
689  : mLeafArray(leafs)
690  , mInactiveValues()
691  , mNumValues(numValues)
692 {
693 }
694 
695 template <typename TreeType>
696 inline
698  const InactiveVoxelValues<TreeType>& rhs, tbb::split)
699  : mLeafArray(rhs.mLeafArray)
700  , mInactiveValues()
701  , mNumValues(rhs.mNumValues)
702 {
703 }
704 
705 template<typename TreeType>
706 void
708 {
709  tbb::parallel_reduce(mLeafArray.getRange(), *this);
710 }
711 
712 
713 template<typename TreeType>
714 void
716 {
717  (*this)(mLeafArray.getRange());
718 }
719 
720 
721 template<typename TreeType>
722 inline void
723 InactiveVoxelValues<TreeType>::operator()(const tbb::blocked_range<size_t>& range)
724 {
725  typename TreeType::LeafNodeType::ValueOffCIter iter;
726 
727  for (size_t n = range.begin(); n < range.end() && !tbb::task::self().is_cancelled(); ++n) {
728  for (iter = mLeafArray.leaf(n).cbeginValueOff(); iter; ++iter) {
729  mInactiveValues.insert(iter.getValue());
730  }
731 
732  if (mInactiveValues.size() > mNumValues) {
733  tbb::task::self().cancel_group_execution();
734  }
735  }
736 }
737 
738 template<typename TreeType>
739 inline void
741 {
742  mInactiveValues.insert(rhs.mInactiveValues.begin(), rhs.mInactiveValues.end());
743 }
744 
745 template<typename TreeType>
746 inline void
748 {
749  values.insert(mInactiveValues.begin(), mInactiveValues.end());
750 }
751 
752 
754 
755 
756 template<typename TreeType>
758 {
759 public:
761  typedef typename TreeType::ValueType ValueType;
762  typedef std::set<ValueType> SetType;
763 
764  InactiveTileValues(size_t numValues);
765 
766  void runParallel(IterRange&);
767  void runSerial(IterRange&);
768 
769  void getInactiveValues(SetType&) const;
770 
771  inline InactiveTileValues(const InactiveTileValues<TreeType>&, tbb::split);
772  inline void operator()(IterRange&);
773  inline void join(const InactiveTileValues<TreeType>&);
774 
775 private:
776  SetType mInactiveValues;
777  size_t mNumValues;
778 };
779 
780 
781 template<typename TreeType>
783  : mInactiveValues()
784  , mNumValues(numValues)
785 {
786 }
787 
788 template <typename TreeType>
789 inline
791  const InactiveTileValues<TreeType>& rhs, tbb::split)
792  : mInactiveValues()
793  , mNumValues(rhs.mNumValues)
794 {
795 }
796 
797 template<typename TreeType>
798 void
800 {
801  tbb::parallel_reduce(range, *this);
802 }
803 
804 
805 template<typename TreeType>
806 void
808 {
809  (*this)(range);
810 }
811 
812 
813 template<typename TreeType>
814 inline void
816 {
817  for (; range && !tbb::task::self().is_cancelled(); ++range) {
818  typename TreeType::ValueOffCIter iter = range.iterator();
819  for (; iter; ++iter) {
820  mInactiveValues.insert(iter.getValue());
821  }
822 
823  if (mInactiveValues.size() > mNumValues) {
824  tbb::task::self().cancel_group_execution();
825  }
826  }
827 }
828 
829 template<typename TreeType>
830 inline void
832 {
833  mInactiveValues.insert(rhs.mInactiveValues.begin(), rhs.mInactiveValues.end());
834 }
835 
836 template<typename TreeType>
837 inline void
839 {
840  values.insert(mInactiveValues.begin(), mInactiveValues.end());
841 }
842 
843 } // namespace diagnostics_internal
844 
845 
847 
848 
849 template<class GridType>
850 bool
851 uniqueInactiveValues(const GridType& grid,
852  std::vector<typename GridType::ValueType>& values, size_t numValues)
853 {
854 
855  typedef typename GridType::TreeType TreeType;
856  typedef typename GridType::ValueType ValueType;
857  typedef std::set<ValueType> SetType;
858 
859  SetType uniqueValues;
860 
861  { // Check inactive voxels
862  TreeType& tree = const_cast<TreeType&>(grid.tree());
863  tree::LeafManager<TreeType> leafs(tree);
864  diagnostics_internal::InactiveVoxelValues<TreeType> voxelOp(leafs, numValues);
865  voxelOp.runParallel();
866  voxelOp.getInactiveValues(uniqueValues);
867  }
868 
869  // Check inactive tiles
870  if (uniqueValues.size() <= numValues) {
871  typename TreeType::ValueOffCIter iter(grid.tree());
872  iter.setMaxDepth(TreeType::ValueAllIter::LEAF_DEPTH - 1);
874 
876  tileOp.runParallel(range);
877 
878  tileOp.getInactiveValues(uniqueValues);
879  }
880 
881  values.clear();
882  values.reserve(uniqueValues.size());
883 
884  typename SetType::iterator it = uniqueValues.begin();
885  for ( ; it != uniqueValues.end(); ++it) {
886  values.push_back(*it);
887  }
888 
889  return values.size() <= numValues;
890 }
891 
892 } // namespace tools
893 } // namespace OPENVDB_VERSION_NAME
894 } // namespace openvdb
895 
896 #endif // OPENVDB_TOOLS_DIAGNOSTICS_HAS_BEEN_INCLUDED
897 
898 // Copyright (c) 2012-2014 DreamWorks Animation LLC
899 // All rights reserved. This software is distributed under the
900 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:251
CheckInf()
Default constructor.
Definition: Diagnostics.h:137
GridT::ConstAccessor AccT
Definition: Diagnostics.h:460
bool operator()(const TreeIterT &iter) const
Return true if the voxel at the iterator location is smaller then min.
Definition: Diagnostics.h:319
const ElementType tolVal
Definition: Diagnostics.h:241
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:284
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is out of range.
Definition: Diagnostics.h:280
void operator()(IterRange &)
Definition: Diagnostics.h:815
bool operator()(const TreeIterT &iter) const
Return true if the voxel at the iterator location is out of range.
Definition: Diagnostics.h:277
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:134
bool operator()(const ElementType &v) const
Definition: Diagnostics.h:214
boost::enable_if_c< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are smaller then min.
Definition: Diagnostics.h:313
boost::enable_if_c< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are larger then max.
Definition: Diagnostics.h:354
Checks a value against a maximum.
Definition: Diagnostics.h:338
CheckFinite()
Default constructor.
Definition: Diagnostics.h:171
uint64_t Index64
Definition: Types.h:58
T ElementType
Definition: Types.h:152
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:426
boost::enable_if_c< 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:179
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:154
bool operator()(const ElementType &v) const
Return true if the scalar value is nan.
Definition: Diagnostics.h:104
Type Pow2(Type x)
Return .
Definition: Math.h:498
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:386
TreeIterT TileIterT
Definition: Diagnostics.h:201
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:231
Checks for infinite values, e.g. 1/0 or -1/0.
Definition: Diagnostics.h:129
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:366
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
bool operator()(const ElementType &v) const
Return true if the value is smaller then min or larger then max.
Definition: Diagnostics.h:262
CheckNormGrad(const CheckNormGrad &other)
Definition: Diagnostics.h:402
Checks a value against a minimum.
Definition: Diagnostics.h:297
Diagnose(const GridT &grid)
Definition: Diagnostics.h:511
bool operator()(const VoxelIterT &iter) const
Return true if the voxel at the iterator location is nan.
Definition: Diagnostics.h:119
Definition: FiniteDifference.h:62
CheckMin(const ElementType &_min)
Definition: Diagnostics.h:305
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:437
TreeType::ValueType ValueType
Definition: Diagnostics.h:761
bool uniqueInactiveValues(const GridType &grid, std::vector< typename GridType::ValueType > &values, size_t numValues)
Threaded method to find unique inactive values.
Definition: Diagnostics.h:851
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:430
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is nan.
Definition: Diagnostics.h:116
const ValueType maxVal
Definition: Diagnostics.h:445
bool operator()(const ElementType &v) const
Return true if the value is infinite.
Definition: Diagnostics.h:140
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:228
void getInactiveValues(SetType &) const
Definition: Diagnostics.h:747
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:122
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:340
void join(const InactiveVoxelValues< TreeType > &)
Definition: Diagnostics.h:740
Index64 valueCount() const
Return the number of values (i.e. background, tiles or voxels) that have failed one or more checks...
Definition: Diagnostics.h:540
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is Nan or infinite.
Definition: Diagnostics.h:188
Checks the divergence against a range.
Definition: Diagnostics.h:452
boost::enable_if_c< 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:271
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:481
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:157
Definition: Exceptions.h:86
void join(const InactiveTileValues< TreeType > &)
Definition: Diagnostics.h:831
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:191
AccT acc
Definition: Diagnostics.h:444
bool operator()(const VoxelIterT &iter) const
Return true if the voxel at the iterator location is larger then max.
Definition: Diagnostics.h:363
DScheme
Different discrete schemes used in the first derivatives.
Definition: FiniteDifference.h:59
std::set< ValueType > SetType
Definition: Diagnostics.h:668
#define OPENVDB_VERSION_NAME
Definition: version.h:43
bool operator()(const ElementType &v) const
Return true if the value is smaller then min.
Definition: Diagnostics.h:308
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:131
CheckDivergence(const GridT &grid, const ValueType &_min, const ValueType &_max)
Constructor taking a grid and a range to be tested against.
Definition: Diagnostics.h:463
const IterT & iterator() const
Return a reference to this range's iterator.
Definition: TreeIterator.h:1360
InactiveVoxelValues(LeafArray &, size_t numValues)
Definition: Diagnostics.h:688
boost::enable_if_c< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are infinite.
Definition: Diagnostics.h:144
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is Nan or infinite.
Definition: Diagnostics.h:185
AccT acc
Definition: Diagnostics.h:499
GridT::ConstAccessor AccT
Definition: Diagnostics.h:387
tree::LeafManager< TreeType > LeafArray
Definition: Diagnostics.h:666
Checks the norm of the gradient against a range.
Definition: Diagnostics.h:380
TreeIterT TileIterT
Definition: Diagnostics.h:457
Definition: Exceptions.h:39
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:165
const ElementType minVal
Definition: Diagnostics.h:291
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:98
tree::IteratorRange< typename TreeType::ValueOffCIter > IterRange
Definition: Diagnostics.h:760
Check that the magnitude of a value, a, is close to a fixed magnitude, b, given a fixed tolerance c...
Definition: Diagnostics.h:198
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:325
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:485
std::set< ValueType > SetType
Definition: Diagnostics.h:762
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:283
const ElementType minVal
Definition: Diagnostics.h:332
TreeIterT TileIterT
Definition: Diagnostics.h:252
Checks nan values.
Definition: Diagnostics.h:93
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:200
Divergence operator defined in index space using various first derivative schemes.
Definition: Operators.h:495
bool operator()(const ElementType &v) const
Return true if the value is NOT finite, i.e. it's Nan or infinite.
Definition: Diagnostics.h:174
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:168
GridT::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:509
const ElementType maxVal
Definition: Diagnostics.h:373
Definition: TreeIterator.h:1339
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:234
TreeIterT TileIterT
Definition: Diagnostics.h:300
TreeIterT TileIterT
Definition: Diagnostics.h:341
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:95
bool operator()(const ElementType &v) const
Return true if the value is larger then max.
Definition: Diagnostics.h:349
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:192
Definition: TreeIterator.h:106
GridT::ValueType ValueType
Definition: Diagnostics.h:382
TreeIterT TileIterT
Definition: Diagnostics.h:96
VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:299
bool operator()(const ElementType &v) const
Return true if the value is smaller then min or larger then max.
Definition: Diagnostics.h:477
CheckNormGrad(const GridT &grid, const ValueType &_min, const ValueType &_max)
Constructor taking a grid and a range to be tested against.
Definition: Diagnostics.h:390
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:492
boost::enable_if_c< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
Return true if any of the vector components are infinite.
Definition: Diagnostics.h:221
TreeIterT TileIterT
Definition: Diagnostics.h:384
void operator()(const tbb::blocked_range< size_t > &)
Definition: Diagnostics.h:723
boost::enable_if_c< VecTraits< T >::IsVec, bool >::type operator()(const T &v) const
This allow for vector values to be checked componentwise.
Definition: Diagnostics.h:109
const ValueType invdx2
Definition: Diagnostics.h:445
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is larger then max.
Definition: Diagnostics.h:360
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is smaller then min.
Definition: Diagnostics.h:322
CheckRange(const ElementType &_min, const ElementType &_max)
Definition: Diagnostics.h:257
void runParallel(IterRange &)
Definition: Diagnostics.h:799
GridT::ValueType ValueType
Definition: Diagnostics.h:454
TreeType::ValueType ValueType
Definition: Diagnostics.h:667
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:343
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:302
bool operator()(const ValueType &v) const
Return true if the value is smaller then min or larger then max.
Definition: Diagnostics.h:422
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:545
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:151
CheckMagnitude(const ElementType &a, const ElementType &t=math::Tolerance< ElementType >::value())
Default constructor.
Definition: Diagnostics.h:206
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:459
CheckNan()
Default constructor.
Definition: Diagnostics.h:101
MaskType::ConstPtr mask() const
Return a boolean mask of all the values (i.e. tiles and/or voxels) that have failed one or more check...
Definition: Diagnostics.h:536
TreeIterT TileIterT
Definition: Diagnostics.h:132
const ValueType minVal
Definition: Diagnostics.h:500
Definition: FiniteDifference.h:194
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:254
CheckNormGrad & operator=(const CheckNormGrad &other)
Definition: Diagnostics.h:410
Checks for both NaN and inf values, i.e. any value that is not finite.
Definition: Diagnostics.h:163
void runSerial(IterRange &)
Definition: Diagnostics.h:807
void getInactiveValues(SetType &) const
Definition: Diagnostics.h:838
Performs multithreaded diagnostics of a grid.
Definition: Diagnostics.h:506
CheckMax(const ElementType &_max)
Constructor taking a maximum to be tested against.
Definition: Diagnostics.h:346
Checks a value against a range.
Definition: Diagnostics.h:249
tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:203
TreeIterT TileIterT
Definition: Diagnostics.h:166
const ValueType minVal
Definition: Diagnostics.h:445
VecTraits< ValueType >::ElementType ElementType
Definition: Diagnostics.h:455
Tolerance for floating-point comparison.
Definition: Math.h:116
InactiveTileValues(size_t numValues)
Definition: Diagnostics.h:782
std::string check(const CheckT &check, bool updateMask=false, bool checkVoxels=true, bool checkTiles=true, bool checkBackground=true)
Definition: Diagnostics.h:517