OpenVDB: Diagnostics.h Source File

OpenVDB 7.1.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>
19 #include <openvdb/tree/LeafManager.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 {
31 OPENVDB_USE_VERSION_NAMESPACE
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 {
110 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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 {
149 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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>
185 struct CheckFinite
186 {
187 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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
194 CheckFinite() {}
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>
223 struct CheckMagnitude
224 {
225 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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
232 CheckMagnitude(const ElementType& a,
233 const ElementType& t = math::Tolerance<ElementType>::value())
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>
278 struct CheckRange
279 {
280 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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 {
334 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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
368 const ElementType minVal;
369 };// CheckMin
370
372
374 template <typename GridT,
375 typename TreeIterT = typename GridT::ValueOnCIter>
376 struct CheckMax
377 {
378 using ElementType = typename VecTraits<typename GridT::ValueType>::ElementType;
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
412 const ElementType maxVal;
413 };// CheckMax
414
416
422 template<typename GridT,
423 typename TreeIterT = typename GridT::ValueOnCIter,
424 math::BiasedGradientScheme GradScheme = math::FIRST_BIAS>//math::WENO5_BIAS>
425 struct CheckNormGrad
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
451 CheckNormGrad(const CheckNormGrad& other)
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
482 AccT acc;
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>
495 struct CheckEikonal
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
517 CheckEikonal(const CheckEikonal& other)
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>
556 struct CheckDivergence
557 {
558 using ValueType = typename GridT::ValueType;
559 using ElementType = typename VecTraits<ValueType>::ElementType;
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
607 AccT acc;
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>
783 class CheckLevelSet
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 {
870 CheckFinite<GridType,typename GridType::ValueAllCIter> c;
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();
891 CheckMagnitude<GridType, typename GridType::ValueOffCIter> c(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>
959 class CheckFogVolume
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 {
1026 CheckFinite<GridType,typename GridType::ValueAllCIter> c;
1027 return mDiagnose.check(c, updateMask, /*voxel*/true, /*tiles*/true, /*background*/true);
1028 }
1029
1033 std::string checkInactiveValues(bool updateMask = false)
1034 {
1035 CheckMagnitude<GridType, typename GridType::ValueOffCIter> c(0);
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>
1099 class InactiveVoxelValues
1100 {
1101 public:
1102 using LeafArray = tree::LeafManager<TreeType>;
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>
1124 InactiveVoxelValues<TreeType>::InactiveVoxelValues(LeafArray& leafs, size_t numValues)
1125 : mLeafArray(leafs)
1126 , mInactiveValues()
1127 , mNumValues(numValues)
1128 {
1129 }
1130
1131 template <typename TreeType>
1132 inline
1133 InactiveVoxelValues<TreeType>::InactiveVoxelValues(
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
1143 InactiveVoxelValues<TreeType>::runParallel()
1144 {
1145 tbb::parallel_reduce(mLeafArray.getRange(), *this);
1146 }
1147
1148
1149 template<typename TreeType>
1150 void
1151 InactiveVoxelValues<TreeType>::runSerial()
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
1176 InactiveVoxelValues<TreeType>::join(const InactiveVoxelValues<TreeType>& rhs)
1177 {
1178 mInactiveValues.insert(rhs.mInactiveValues.begin(), rhs.mInactiveValues.end());
1179 }
1180
1181 template<typename TreeType>
1182 inline void
1183 InactiveVoxelValues<TreeType>::getInactiveValues(SetType& values) const
1184 {
1185 values.insert(mInactiveValues.begin(), mInactiveValues.end());
1186 }
1187
1188
1190
1191
1192 template<typename TreeType>
1193 class InactiveTileValues
1194 {
1195 public:
1196 using IterRange = tree::IteratorRange<typename TreeType::ValueOffCIter>;
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>
1218 InactiveTileValues<TreeType>::InactiveTileValues(size_t numValues)
1219 : mInactiveValues()
1220 , mNumValues(numValues)
1221 {
1222 }
1223
1224 template <typename TreeType>
1225 inline
1226 InactiveTileValues<TreeType>::InactiveTileValues(
1227 const InactiveTileValues<TreeType>& rhs, tbb::split)
1228 : mInactiveValues()
1229 , mNumValues(rhs.mNumValues)
1230 {
1231 }
1232
1233 template<typename TreeType>
1234 void
1235 InactiveTileValues<TreeType>::runParallel(IterRange& range)
1236 {
1237 tbb::parallel_reduce(range, *this);
1238 }
1239
1240
1241 template<typename TreeType>
1242 void
1243 InactiveTileValues<TreeType>::runSerial(IterRange& range)
1244 {
1245 (*this)(range);
1246 }
1247
1248
1249 template<typename TreeType>
1250 inline void
1251 InactiveTileValues<TreeType>::operator()(IterRange& range)
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
1267 InactiveTileValues<TreeType>::join(const InactiveTileValues<TreeType>& rhs)
1268 {
1269 mInactiveValues.insert(rhs.mInactiveValues.begin(), rhs.mInactiveValues.end());
1270 }
1271
1272 template<typename TreeType>
1273 inline void
1274 InactiveTileValues<TreeType>::getInactiveValues(SetType& values) const
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);
1308 diagnostics_internal::InactiveTileValues<TreeType> tileOp(numValues);
1309
1310 tree::IteratorRange<typename TreeType::ValueOffCIter> range(iter);
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
openvdb::v7_1::tools::CheckFinite::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:188
openvdb::v7_1::tools::CheckRange::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:316
openvdb::v7_1::tools::CheckFinite::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:214
openvdb::v7_1::tools::CheckLevelSet::checkFinite
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
openvdb::v7_1::tools::CheckMax::operator()
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
openvdb::v7_1::tools::CheckDivergence::operator()
bool operator()(const ElementType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:585
openvdb::v7_1::tools::CheckNormGrad::ValueType
typename GridT::ValueType ValueType
Definition: Diagnostics.h:427
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::InactiveVoxelValues
InactiveVoxelValues(LeafArray &, size_t numValues)
Definition: Diagnostics.h:1124
openvdb::v7_1::tools::CheckDivergence::acc
AccT acc
Definition: Diagnostics.h:607
openvdb::v7_1::tools::CheckRange::CheckRange
CheckRange(const ElementType &_min, const ElementType &_max)
Definition: Diagnostics.h:287
openvdb::v7_1::tools::CheckMin::minVal
const ElementType minVal
Definition: Diagnostics.h:368
openvdb::v7_1::tools::CheckDivergence::CheckDivergence
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
openvdb::v7_1::tools::CheckDivergence::operator()
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:589
openvdb::v7_1::tools::CheckNan
Checks NaN values.
Definition: Diagnostics.h:109
openvdb::v7_1::tools::CheckMin::CheckMin
CheckMin(const ElementType &_min)
Definition: Diagnostics.h:341
openvdb::v7_1::tools::CheckDivergence::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:562
openvdb::v7_1::tools::CheckRange::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:284
openvdb::v7_1::math::CD_2ND
@ CD_2ND
Definition: FiniteDifference.h:35
openvdb::v7_1::tools::CheckFogVolume::checkBackground
std::string checkBackground() const
Return a nonempty message if the background value is not zero.
Definition: Diagnostics.h:1011
openvdb::v7_1::tools::CheckNan::operator()
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
openvdb::v7_1::math::FIRST_BIAS
@ FIRST_BIAS
Definition: FiniteDifference.h:167
openvdb::v7_1::math::BiasedGradientScheme
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:165
openvdb::v7_1::tools::CheckLevelSet::checkRange
std::string checkRange(bool updateMask=false)
Return a nonempty message if the active voxel values are out-of-range.
Definition: Diagnostics.h:877
openvdb::v7_1::tools::checkLevelSet
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
openvdb::v7_1::tools::CheckLevelSet::checkClassType
std::string checkClassType() const
Return message if the grid's class is a level set.
Definition: Diagnostics.h:826
openvdb::v7_1::tools::CheckFinite::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:191
openvdb::v7_1::tools::CheckNan::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:114
openvdb::v7_1::tools::CheckLevelSet::MaskType
typename GridType::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:787
openvdb::v7_1::tools::CheckInf::operator()
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:171
openvdb::v7_1::tools::CheckNormGrad::AccT
typename GridT::ConstAccessor AccT
Definition: Diagnostics.h:434
openvdb::v7_1::tools::CheckDivergence::operator()
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
openvdb::v7_1::tools::CheckMin::operator()
bool operator()(const ElementType &v) const
Return true if the value is smaller than min.
Definition: Diagnostics.h:344
openvdb::v7_1::tools::CheckDivergence
Checks the divergence against a range.
Definition: Diagnostics.h:557
openvdb::v7_1::tools::CheckLevelSet::checkInactiveValues
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
openvdb::v7_1::tools::CheckFinite::operator()
bool operator()(const ElementType &v) const
Return true if the value is NOT finite, i.e. it's NaN or infinite.
Definition: Diagnostics.h:197
openvdb::v7_1::math::isApproxZero
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance.
Definition: Math.h:313
openvdb::v7_1::tools::CheckFinite::operator()
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is NaN or infinite.
Definition: Diagnostics.h:208
openvdb::v7_1::tools::CheckLevelSet::CheckLevelSet
CheckLevelSet(const GridType &grid)
Definition: Diagnostics.h:789
openvdb::v7_1::tools::CheckRange::operator()
bool operator()(const TreeIterT &iter) const
Return true if the voxel at the iterator location is out of range.
Definition: Diagnostics.h:310
openvdb::v7_1::tools::Diagnose
Performs multithreaded diagnostics of a grid.
Definition: Diagnostics.h:617
openvdb::v7_1::math::ISDivergence
Divergence operator defined in index space using various first derivative schemes.
Definition: Operators.h:470
openvdb::v7_1::tools::CheckFogVolume
Class that performs various types of checks on fog volumes.
Definition: Diagnostics.h:960
openvdb::v7_1::MERGE_ACTIVE_STATES_AND_NODES
@ MERGE_ACTIVE_STATES_AND_NODES
Definition: Types.h:872
openvdb::v7_1::tools::CheckMax::operator()
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is larger than max.
Definition: Diagnostics.h:399
openvdb::v7_1::tools::CheckRange::operator()
bool operator()(const ElementType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:295
openvdb::v7_1::tools::CheckMin::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is smaller than min.
Definition: Diagnostics.h:358
openvdb::v7_1::tools::CheckInf::operator()
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
openvdb::v7_1::math::Sqrt
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:728
openvdb::v7_1::tools::CheckRange::minVal
const ElementType minVal
Definition: Diagnostics.h:324
openvdb::v7_1::tools::CheckLevelSet
Class that performs various types of checks on narrow-band level sets.
Definition: Diagnostics.h:784
openvdb::v7_1::tools::CheckLevelSet::ValueType
typename GridType::ValueType ValueType
Definition: Diagnostics.h:786
openvdb::v7_1::tools::CheckFogVolume::checkFinite
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
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::operator()
void operator()(IterRange &)
Definition: Diagnostics.h:1251
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::ValueType
typename TreeType::ValueType ValueType
Definition: Diagnostics.h:1197
openvdb::v7_1::VecTraits::ElementType
typename T::ValueType ElementType
Definition: Types.h:185
openvdb::v7_1::tools::CheckDivergence::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT >::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:565
openvdb::v7_1::tools::CheckRange::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is out of range.
Definition: Diagnostics.h:313
openvdb::v7_1::tree::LeafManager
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:83
openvdb::v7_1::math::Abs
Coord Abs(const Coord &xyz)
Definition: Coord.h:515
openvdb::v7_1::math::Tolerance
Tolerance for floating-point comparison.
Definition: Math.h:110
openvdb::v7_1::Index64
uint64_t Index64
Definition: Types.h:30
Grid.h
openvdb::v7_1::tools::CheckFogVolume::valueCount
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
openvdb::v7_1::tools::CheckInf
Checks for infinite values, e.g. 1/0 or -1/0.
Definition: Diagnostics.h:148
openvdb::v7_1::tools::CheckNan::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:110
openvdb::v7_1::tools::CheckNormGrad::acc
AccT acc
Definition: Diagnostics.h:482
openvdb::v7_1::tools::CheckFinite
Checks for both NaN and inf values, i.e. any value that is not finite.
Definition: Diagnostics.h:186
openvdb::v7_1::tools::CheckMax::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the voxel at the iterator location is larger than max.
Definition: Diagnostics.h:402
openvdb::v7_1::tools::CheckNormGrad::CheckNormGrad
CheckNormGrad(const CheckNormGrad &other)
Definition: Diagnostics.h:451
openvdb::v7_1::tools::CheckNan::operator()
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is NaN.
Definition: Diagnostics.h:132
openvdb::v7_1::tools::CheckFogVolume::clear
void clear()
Clear the mask and error counter.
Definition: Diagnostics.h:988
openvdb::v7_1::tools::CheckMagnitude::CheckMagnitude
CheckMagnitude(const ElementType &a, const ElementType &t=math::Tolerance< ElementType >::value())
Default constructor.
Definition: Diagnostics.h:232
openvdb::v7_1::tools::Diagnose::mask
MaskType::Ptr mask()
Definition: Diagnostics.h:648
openvdb::v7_1::tools::CheckEikonal::operator()
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
openvdb::v7_1::tools::Diagnose::failureCount
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:658
openvdb::v7_1::tools::CheckNormGrad::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:430
openvdb::v7_1::tools::CheckFinite::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is NaN or infinite.
Definition: Diagnostics.h:211
openvdb::v7_1::tools::CheckMagnitude::operator()
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
openvdb::v7_1::tools::CheckEikonal::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:539
openvdb::v7_1::tools::CheckEikonal::CheckEikonal
CheckEikonal(const CheckEikonal &other)
Definition: Diagnostics.h:517
openvdb::v7_1::tools::CheckEikonal
Checks the norm of the gradient at zero-crossing voxels against a range.
Definition: Diagnostics.h:496
openvdb::v7_1::tools::CheckInf::CheckInf
CheckInf()
Default constructor.
Definition: Diagnostics.h:156
openvdb::v7_1::tools::CheckFogVolume::ValueType
typename GridType::ValueType ValueType
Definition: Diagnostics.h:962
openvdb::v7_1::tools::CheckEikonal::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:503
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::runParallel
void runParallel(IterRange &)
Definition: Diagnostics.h:1235
openvdb::v7_1::tools::CheckLevelSet::checkValueType
static std::string checkValueType()
Return a nonempty message if the grid's value type is a floating point.
Definition: Diagnostics.h:817
openvdb::v7_1::GRID_LEVEL_SET
@ GRID_LEVEL_SET
Definition: Types.h:818
Vec3.h
openvdb::v7_1::math::Pow2
Type Pow2(Type x)
Return x2.
Definition: Math.h:515
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::runSerial
void runSerial()
Definition: Diagnostics.h:1151
openvdb::v7_1::tools::CheckFogVolume::grid
const GridType & grid() const
Return a const reference to the grid.
Definition: Diagnostics.h:985
openvdb::v7_1::tools::CheckFinite::CheckFinite
CheckFinite()
Default constructor.
Definition: Diagnostics.h:194
openvdb::v7_1::tools::CheckNan::operator()
bool operator()(const ElementType &v) const
Return true if the scalar value is NaN.
Definition: Diagnostics.h:120
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v7_1::tools::CheckFogVolume::checkRange
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
openvdb::v7_1::tools::CheckNan::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:111
openvdb::v7_1::tools::CheckMagnitude::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:261
openvdb::v7_1::tools::CheckNormGrad::operator()
bool operator()(const ValueType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:460
openvdb::v7_1::tools::CheckDivergence::ElementType
typename VecTraits< ValueType >::ElementType ElementType
Definition: Diagnostics.h:559
openvdb::v7_1::tree::IterTraits
Definition: TreeIterator.h:60
openvdb::v7_1::tools::CheckFinite::operator()
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
openvdb::v7_1::tools::CheckLevelSet::valueCount
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
openvdb::v7_1::tools::CheckMagnitude::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:225
openvdb::v7_1::tools::CheckLevelSet::failureCount
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:806
openvdb::v7_1::tools::CheckNan::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:138
openvdb::v7_1::tools::CheckNan::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the voxel at the iterator location is NaN.
Definition: Diagnostics.h:135
openvdb::v7_1::tools::uniqueInactiveValues
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
openvdb::v7_1::tools::CheckLevelSet::checkBackground
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
openvdb::v7_1::tools::CheckEikonal::ValueType
typename GridT::ValueType ValueType
Definition: Diagnostics.h:497
openvdb::v7_1::tools::Diagnose::valueCount
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
openvdb::v7_1::tools::CheckDivergence::ValueType
typename GridT::ValueType ValueType
Definition: Diagnostics.h:558
openvdb::v7_1::tools::CheckMax::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:382
openvdb::v7_1::tools::CheckFogVolume::failureCount
Index64 failureCount() const
Return total number of failed checks.
Definition: Diagnostics.h:982
openvdb::v7_1::tools::CheckFogVolume::mask
MaskType::Ptr mask()
Definition: Diagnostics.h:972
openvdb::v7_1::tools::CheckEikonal::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:500
openvdb::v7_1::tools::CheckMagnitude::operator()
bool operator()(const ElementType &v) const
Definition: Diagnostics.h:240
openvdb::v7_1::tools::CheckNan::CheckNan
CheckNan()
Default constructor.
Definition: Diagnostics.h:117
openvdb::v7_1::tools::CheckEikonal::minVal
const ValueType minVal
Definition: Diagnostics.h:547
openvdb::v7_1::tools::CheckFogVolume::CheckFogVolume
CheckFogVolume(const GridType &grid)
Definition: Diagnostics.h:965
openvdb::v7_1::tools::CheckMax::maxVal
const ElementType maxVal
Definition: Diagnostics.h:412
openvdb::v7_1::tools::CheckFogVolume::checkClassType
std::string checkClassType() const
Return a nonempty message if the grid's class is a level set.
Definition: Diagnostics.h:1002
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::runParallel
void runParallel()
Definition: Diagnostics.h:1143
openvdb::v7_1::math::DScheme
DScheme
Different discrete schemes used in the first derivatives.
Definition: FiniteDifference.h:32
openvdb::v7_1::tools::Diagnose::grid
const GridT & grid() const
Return a const reference to the grid.
Definition: Diagnostics.h:661
openvdb::v7_1::tools::CheckMagnitude
Check that the magnitude of a value, a, is close to a fixed magnitude, b, given a fixed tolerance c....
Definition: Diagnostics.h:224
openvdb::v7_1::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
openvdb::v7_1::tools::CheckMin::operator()
bool operator()(const TreeIterT &iter) const
Return true if the voxel at the iterator location is smaller than min.
Definition: Diagnostics.h:355
openvdb::v7_1::tools::CheckNormGrad::minVal2
const ValueType minVal2
Definition: Diagnostics.h:483
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::join
void join(const InactiveVoxelValues< TreeType > &)
Definition: Diagnostics.h:1176
openvdb::v7_1::tools::CheckEikonal::CheckEikonal
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
openvdb::v7_1::tools::CheckInf::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:149
openvdb::v7_1::tools::CheckDivergence::AccT
typename GridT::ConstAccessor AccT
Definition: Diagnostics.h:566
openvdb::v7_1::tools::CheckFinite::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:187
openvdb::v7_1::tools::CheckRange::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:281
openvdb::v7_1::tools::CheckMin::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:338
openvdb::v7_1::tools::CheckInf::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:174
openvdb::v7_1::math::WenoStencil< GridT >
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues
Definition: Diagnostics.h:1194
openvdb::v7_1::tools::CheckMax::operator()
bool operator()(const ElementType &v) const
Return true if the value is larger than max.
Definition: Diagnostics.h:388
openvdb::v7_1::tools::CheckLevelSet::mask
MaskType::Ptr mask()
Definition: Diagnostics.h:796
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
openvdb::v7_1::tools::CheckInf::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:177
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::SetType
std::set< ValueType > SetType
Definition: Diagnostics.h:1198
openvdb::v7_1::tools::CheckMagnitude::operator()
bool operator()(const VoxelIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:258
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::getInactiveValues
void getInactiveValues(SetType &) const
Definition: Diagnostics.h:1183
openvdb::v7_1::tools::CheckEikonal::operator()
bool operator()(const ValueType &v) const
Return true if the value is smaller than min or larger than max.
Definition: Diagnostics.h:523
openvdb::v7_1::tools::CheckNormGrad::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:475
openvdb::v7_1::tools::CheckMagnitude::tolVal
const ElementType tolVal
Definition: Diagnostics.h:268
openvdb::v7_1::tools::CheckFogVolume::checkValueType
static std::string checkValueType()
Return a nonempty message if the grid's value type is a floating point.
Definition: Diagnostics.h:993
openvdb::v7_1::tools::CheckMin
Checks a value against a minimum.
Definition: Diagnostics.h:333
openvdb::v7_1::tools::CheckEikonal::stencil
StencilT stencil
Definition: Diagnostics.h:546
LeafManager.h
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::join
void join(const InactiveTileValues< TreeType > &)
Definition: Diagnostics.h:1267
openvdb::v7_1::tools::checkFogVolume
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
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::getInactiveValues
void getInactiveValues(SetType &) const
Definition: Diagnostics.h:1274
openvdb::v7_1::tools::CheckNormGrad::CheckNormGrad
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
openvdb::v7_1::tools::CheckDivergence::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:600
openvdb::v7_1::GRID_FOG_VOLUME
@ GRID_FOG_VOLUME
Definition: Types.h:819
openvdb::v7_1::tools::CheckFogVolume::MaskType
typename GridType::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:963
openvdb::v7_1::tools::CheckRange::operator()
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
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::runSerial
void runSerial(IterRange &)
Definition: Diagnostics.h:1243
openvdb::v7_1::tools::CheckMax
Checks a value against a maximum.
Definition: Diagnostics.h:377
openvdb::v7_1::tools::CheckLevelSet::clear
void clear()
Clear the mask and error counter.
Definition: Diagnostics.h:812
openvdb::v7_1::tools::CheckMin::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:361
openvdb::v7_1::tools::CheckMax::CheckMax
CheckMax(const ElementType &_max)
Constructor taking a maximum to be tested against.
Definition: Diagnostics.h:385
openvdb::v7_1::tools::CheckMin::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:335
openvdb::v7_1::tools::CheckMin::operator()
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
Stencils.h
Defines various finite difference stencils by means of the "curiously recurring template pattern" on ...
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
openvdb::v7_1::tools::CheckMin::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:334
openvdb::v7_1::tools::CheckLevelSet::checkEikonal
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
openvdb::v7_1::tools::CheckDivergence::minVal
const ValueType minVal
Definition: Diagnostics.h:608
openvdb::v7_1::tools::CheckMagnitude::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:229
openvdb::v7_1::tools::CheckNormGrad::operator()
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
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues
Definition: Diagnostics.h:1100
openvdb::v7_1::tools::CheckMax::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:379
openvdb::v7_1::tools::Diagnose< GridType >::MaskType
typename GridT::template ValueConverter< bool >::Type MaskType
Definition: Diagnostics.h:619
openvdb::v7_1::tools::CheckLevelSet::grid
const GridType & grid() const
Return a const reference to the grid.
Definition: Diagnostics.h:809
openvdb::v7_1::ValueError
Definition: Exceptions.h:65
openvdb::v7_1::tools::Diagnose::clear
void clear()
Clear the mask and error counter.
Definition: Diagnostics.h:664
openvdb::v7_1::tools::CheckInf::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:150
openvdb::v7_1::tools::CheckNormGrad::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:433
openvdb::v7_1::tools::CheckNormGrad::operator()
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:464
openvdb::v7_1::tools::CheckNormGrad
Checks the norm of the gradient against a range, i.e., |∇Φ| ∈ [min, max].
Definition: Diagnostics.h:426
openvdb::v7_1::tools::CheckRange::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:280
openvdb::v7_1::tools::CheckLevelSet::check
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
openvdb::v7_1::tools::CheckMax::ElementType
typename VecTraits< typename GridT::ValueType >::ElementType ElementType
Definition: Diagnostics.h:378
openvdb
Definition: Exceptions.h:13
openvdb::v7_1::tools::CheckFogVolume::checkInactiveValues
std::string checkInactiveValues(bool updateMask=false)
Return a nonempty message if any of the inactive values are not zero.
Definition: Diagnostics.h:1033
openvdb::v7_1::tree::IteratorRange::iterator
const IterT & iterator() const
Return a reference to this range's iterator.
Definition: TreeIterator.h:1323
openvdb::v7_1::tools::CheckMax::str
std::string str() const
Return a string describing a failed check.
Definition: Diagnostics.h:405
openvdb::v7_1::tools::CheckMagnitude::operator()
bool operator()(const TreeIterT &iter) const
Return true if the tile at the iterator location is infinite.
Definition: Diagnostics.h:255
openvdb::v7_1::LEVEL_SET_HALF_WIDTH
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:824
openvdb::v7_1::tools::CheckMagnitude::TileIterT
TreeIterT TileIterT
Definition: Diagnostics.h:226
openvdb::v7_1::tools::Diagnose::Diagnose
Diagnose(const GridT &grid)
Definition: Diagnostics.h:621
openvdb::v7_1::tools::diagnostics_internal::InactiveTileValues::InactiveTileValues
InactiveTileValues(size_t numValues)
Definition: Diagnostics.h:1218
openvdb::v7_1::math::ISGradientNormSqrd
Definition: Operators.h:228
openvdb::v7_1::Real
double Real
Definition: Types.h:37
openvdb::v7_1::tools::CheckInf::operator()
bool operator()(const ElementType &v) const
Return true if the value is infinite.
Definition: Diagnostics.h:159
openvdb::v7_1::tree::IteratorRange
Definition: TreeIterator.h:1303
openvdb::v7_1::tools::CheckEikonal::operator()
bool operator()(const TreeIterT &) const
Return true if zero is outside the range.
Definition: Diagnostics.h:527
Operators.h
openvdb::v7_1::tools::CheckFogVolume::check
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
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::ValueType
typename TreeType::ValueType ValueType
Definition: Diagnostics.h:1103
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
openvdb::v7_1::tools::CheckRange
Checks a value against a range.
Definition: Diagnostics.h:279
openvdb::v7_1::tools::CheckInf::VoxelIterT
typename tree::IterTraits< typename TreeIterT::NodeT, typename TreeIterT::ValueIterT > ::template NodeConverter< typename GridT::TreeType::LeafNodeType >::Type VoxelIterT
Definition: Diagnostics.h:153
openvdb::v7_1::tools::Diagnose::check
std::string check(const CheckT &check, bool updateMask=false, bool checkVoxels=true, bool checkTiles=true, bool checkBackground=true)
Definition: Diagnostics.h:627
openvdb::v7_1::tools::CheckLevelSet::checkTransform
std::string checkTransform() const
Return a nonempty message if the grid's transform does not have uniform scaling.
Definition: Diagnostics.h:835
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::SetType
std::set< ValueType > SetType
Definition: Diagnostics.h:1104
openvdb::v7_1::tools::CheckLevelSet::checkTiles
std::string checkTiles() const
Return a nonempty message if the grid has no active tile values.
Definition: Diagnostics.h:859
openvdb::v7_1::tools::diagnostics_internal::InactiveVoxelValues::operator()
void operator()(const tbb::blocked_range< size_t > &)
Definition: Diagnostics.h:1159