OpenVDB 7.0.0

Util.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #ifndef OPENVDB_UTIL_UTIL_HAS_BEEN_INCLUDED
5 #define OPENVDB_UTIL_UTIL_HAS_BEEN_INCLUDED
6
7 #include <openvdb/Types.h>
8 #include <openvdb/tree/Tree.h>
9 #include <openvdb/tools/ValueTransformer.h>
10 #include <openvdb/tools/Prune.h>// for tree::pruneInactive
11
12
13 namespace openvdb {
14 OPENVDB_USE_VERSION_NAMESPACE
15 namespace OPENVDB_VERSION_NAME {
16 namespace util {
17
18 OPENVDB_API extern const Index32 INVALID_IDX;
19
21 OPENVDB_API extern const Coord COORD_OFFSETS[26];
22
23
25
26
28 inline Coord
29 nearestCoord(const Vec3d& voxelCoord)
30 {
31 Coord ijk;
32 ijk[0] = int(std::floor(voxelCoord[0]));
33 ijk[1] = int(std::floor(voxelCoord[1]));
34 ijk[2] = int(std::floor(voxelCoord[2]));
35 return ijk;
36 }
37
38
40
41
44 template<class TreeType1, class TreeType2>
45 class LeafTopologyIntOp
46 {
47 public:
48 LeafTopologyIntOp(const TreeType2& tree): mOtherTree(&tree) {}
49
50 inline void operator()(const typename TreeType1::LeafIter& lIter) const
51 {
52 const Coord xyz = lIter->origin();
53 const typename TreeType2::LeafNodeType* leaf = mOtherTree->probeConstLeaf(xyz);
54 if (leaf) {//leaf node
55 lIter->topologyIntersection(*leaf, zeroVal<typename TreeType1::ValueType>());
56 } else if (!mOtherTree->isValueOn(xyz)) {//inactive tile
57 lIter->setValuesOff();
58 }
59 }
60
61 private:
62 const TreeType2* mOtherTree;
63 };
64
65
68 template<class TreeType1, class TreeType2>
69 class LeafTopologyDiffOp
70 {
71 public:
72 LeafTopologyDiffOp(const TreeType2& tree): mOtherTree(&tree) {}
73
74 inline void operator()(const typename TreeType1::LeafIter& lIter) const
75 {
76 const Coord xyz = lIter->origin();
77 const typename TreeType2::LeafNodeType* leaf = mOtherTree->probeConstLeaf(xyz);
78 if (leaf) {//leaf node
79 lIter->topologyDifference(*leaf, zeroVal<typename TreeType1::ValueType>());
80 } else if (mOtherTree->isValueOn(xyz)) {//active tile
81 lIter->setValuesOff();
82 }
83 }
84
85 private:
86 const TreeType2* mOtherTree;
87 };
88
89
91
92
95 template<class TreeType1, class TreeType2>
96 inline typename TreeType1::template ValueConverter<bool>::Type::Ptr
97 leafTopologyIntersection(const TreeType1& lhs, const TreeType2& rhs, bool threaded = true)
98 {
99 typedef typename TreeType1::template ValueConverter<bool>::Type BoolTreeType;
100
101 typename BoolTreeType::Ptr topologyTree(new BoolTreeType(
102 lhs, /*inactiveValue=*/false, /*activeValue=*/true, TopologyCopy()));
103
104 tools::foreach(topologyTree->beginLeaf(),
105 LeafTopologyIntOp<BoolTreeType, TreeType2>(rhs), threaded);
106
107 tools::pruneInactive(*topologyTree, threaded);
108 return topologyTree;
109 }
110
111
115 template<class TreeType1, class TreeType2>
116 inline typename TreeType1::template ValueConverter<bool>::Type::Ptr
117 leafTopologyDifference(const TreeType1& lhs, const TreeType2& rhs, bool threaded = true)
118 {
119 typedef typename TreeType1::template ValueConverter<bool>::Type BoolTreeType;
120
121 typename BoolTreeType::Ptr topologyTree(new BoolTreeType(
122 lhs, /*inactiveValue=*/false, /*activeValue=*/true, TopologyCopy()));
123
124 tools::foreach(topologyTree->beginLeaf(),
125 LeafTopologyDiffOp<BoolTreeType, TreeType2>(rhs), threaded);
126
127 tools::pruneInactive(*topologyTree, threaded);
128 return topologyTree;
129 }
130
131 } // namespace util
132 } // namespace OPENVDB_VERSION_NAME
133 } // namespace openvdb
134
135 #endif // OPENVDB_UTIL_UTIL_HAS_BEEN_INCLUDED
openvdb::v7_0::util::leafTopologyIntersection
TreeType1::template ValueConverter< bool >::Type::Ptr leafTopologyIntersection(const TreeType1 &lhs, const TreeType2 &rhs, bool threaded=true)
Perform a boolean intersection between two leaf nodes' topology masks.
Definition: Util.h:97
openvdb::v7_0::util::LeafTopologyIntOp
Functor for use with tools::foreach() to compute the boolean intersection between the value masks of ...
Definition: Util.h:45
Types.h
openvdb::v7_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:25
openvdb::v7_0::util::nearestCoord
Coord nearestCoord(const Vec3d &voxelCoord)
Return voxelCoord rounded to the closest integer coordinates.
Definition: Util.h:29
openvdb::v7_0::util::leafTopologyDifference
TreeType1::template ValueConverter< bool >::Type::Ptr leafTopologyDifference(const TreeType1 &lhs, const TreeType2 &rhs, bool threaded=true)
Perform a boolean difference between two leaf nodes' topology masks.
Definition: Util.h:117
openvdb::v7_0::math::Vec3d
Vec3< double > Vec3d
Definition: Vec3.h:662
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
openvdb::v7_0::util::COORD_OFFSETS
const OPENVDB_API Coord COORD_OFFSETS[26]
coordinate offset table for neighboring voxels
Prune.h
Defined various multi-threaded utility functions for trees.
openvdb::v7_0::util::LeafTopologyIntOp::operator()
void operator()(const typename TreeType1::LeafIter &lIter) const
Definition: Util.h:50
ValueTransformer.h
openvdb::v7_0::util::LeafTopologyDiffOp::LeafTopologyDiffOp
LeafTopologyDiffOp(const TreeType2 &tree)
Definition: Util.h:72
openvdb::v7_0::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:681
openvdb::v7_0::util::INVALID_IDX
const OPENVDB_API Index32 INVALID_IDX
openvdb::v7_0::util::LeafTopologyDiffOp
Functor for use with tools::foreach() to compute the boolean difference between the value masks of co...
Definition: Util.h:69
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::util::LeafTopologyIntOp::LeafTopologyIntOp
LeafTopologyIntOp(const TreeType2 &tree)
Definition: Util.h:48
Tree.h
openvdb::v7_0::tools::foreach
void foreach(const IterT &iter, XformOp &op, bool threaded=true, bool shareOp=true)
Definition: ValueTransformer.h:374
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::Index32
uint32_t Index32
Definition: Types.h:29
openvdb::v7_0::util::LeafTopologyDiffOp::operator()
void operator()(const typename TreeType1::LeafIter &lIter) const
Definition: Util.h:74
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::tools::pruneInactive
void pruneInactive(TreeT &tree, bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with background tiles any nodes whose values are a...
Definition: Prune.h:354