OpenVDB  1.1.0
tree/Util.h
Go to the documentation of this file.
1 
2 //
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 zeroVal
37 
38 namespace openvdb {
40 namespace OPENVDB_VERSION_NAME {
41 namespace tree {
42 
46 template<typename ValueType>
48  TolerancePrune(const ValueType &tol) : tolerance(tol) {}
49  template <typename ChildType>
50  bool operator()(ChildType &child) {
51  child.pruneOp(*this);
52  return child.isConstant(value, state, tolerance);
53  }
54  bool state;
55  ValueType value;
56  const ValueType tolerance;
57 };
58 
63 template<typename ValueType>
64 struct InactivePrune {
65  InactivePrune(const ValueType &val) : value(val) {}
66  template <typename ChildType>
67  bool operator()(ChildType &child) const {
68  child.pruneOp(*this);
69  return child.isInactive();
70  }
71  static const bool state = false;
72  const ValueType value;
73 };
74 
83 template<typename ValueType>
84 struct LevelSetPrune {
85  LevelSetPrune(const ValueType &background) : outside(background) {}
86  template <typename ChildType>
87  bool operator()(ChildType &child) {
88  child.pruneOp(*this);
89  if (!child.isInactive()) return false;
90  value = child.getFirstValue() < zeroVal<ValueType>() ? -outside : outside;
91  return true;
92  }
93  static const bool state = false;
94  const ValueType outside;
95  ValueType value;
96 };
97 
98 } // namespace tree
99 } // namespace OPENVDB_VERSION_NAME
100 } // namespace openvdb
101 
102 #endif // OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
103 
104 // Copyright (c) 2012-2013 DreamWorks Animation LLC
105 // All rights reserved. This software is distributed under the
106 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )