OpenVDB  2.0.0
tree/Util.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 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 //
32 
33 #ifndef OPENVDB_TREE_UTIL_HAS_BEEN_INCLUDED
34 #define OPENVDB_TREE_UTIL_HAS_BEEN_INCLUDED
35 
36 #include <openvdb/math/Math.h> // for isNegative and negative
37 #include <openvdb/Types.h> // for Index typedef
38 
39 namespace openvdb {
41 namespace OPENVDB_VERSION_NAME {
42 namespace tree {
43 
46 template<typename ValueType, Index TerminationLevel = 0>
48 {
49  TolerancePrune(const ValueType& tol): tolerance(tol) {}
50 
51  template<typename ChildType>
52  bool operator()(ChildType& child)
53  {
54  return (ChildType::LEVEL < TerminationLevel) ? false : this->isConstant(child);
55  }
56 
57  template<typename ChildType>
58  bool isConstant(ChildType& child)
59  {
60  child.pruneOp(*this);
61  return child.isConstant(value, state, tolerance);
62  }
63 
64  bool state;
65  ValueType value;
66  const ValueType tolerance;
67 };
68 
69 
73 template<typename ValueType>
75 {
76  InactivePrune(const ValueType& val): value(val) {}
77 
78  template <typename ChildType>
79  bool operator()(ChildType& child) const
80  {
81  child.pruneOp(*this);
82  return child.isInactive();
83  }
84 
85  static const bool state = false;
86  const ValueType value;
87 };
88 
89 
98 template<typename ValueType>
100 {
101  LevelSetPrune(const ValueType& background): outside(background) {}
102 
103  template <typename ChildType>
104  bool operator()(ChildType& child)
105  {
106  child.pruneOp(*this);
107  if (!child.isInactive()) return false;
108  value = math::isNegative(child.getFirstValue()) ? math::negative(outside) : outside;
109  return true;
110  }
111 
112  static const bool state = false;
113  const ValueType outside;
114  ValueType value;
115 };
116 
117 } // namespace tree
118 } // namespace OPENVDB_VERSION_NAME
119 } // namespace openvdb
120 
121 #endif // OPENVDB_TREE_UTIL_HAS_BEEN_INCLUDED
122 
123 // Copyright (c) 2012-2013 DreamWorks Animation LLC
124 // All rights reserved. This software is distributed under the
125 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
const ValueType outside
Definition: tree/Util.h:113
const ValueType value
Definition: tree/Util.h:86
ValueType value
Definition: tree/Util.h:65
bool operator()(ChildType &child)
Definition: tree/Util.h:104
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:107
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:306
TolerancePrune(const ValueType &tol)
Definition: tree/Util.h:49
const ValueType tolerance
Definition: tree/Util.h:66
#define OPENVDB_VERSION_NAME
Definition: version.h:45
bool state
Definition: tree/Util.h:64
LevelSetPrune(const ValueType &background)
Definition: tree/Util.h:101
ValueType value
Definition: tree/Util.h:114
Helper class for use with Tree::pruneOp() to replace inactive branches with more memory-efficient ina...
Definition: tree/Util.h:74
bool operator()(ChildType &child)
Definition: tree/Util.h:52
bool operator()(ChildType &child) const
Definition: tree/Util.h:79
Helper class for use with Tree::pruneOp() to replace constant branches (to within the provided tolera...
Definition: tree/Util.h:47
bool isConstant(ChildType &child)
Definition: tree/Util.h:58
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
Helper class for use with Tree::pruneOp() to prune any branches whose values are all inactive and rep...
Definition: tree/Util.h:99
InactivePrune(const ValueType &val)
Definition: tree/Util.h:76