OpenVDB: NodeVisitor.h Source File

OpenVDB 8.1.0

NodeVisitor.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
14
15 #ifndef OPENVDB_TOOLS_NODE_VISITOR_HAS_BEEN_INCLUDED
16 #define OPENVDB_TOOLS_NODE_VISITOR_HAS_BEEN_INCLUDED
17
18 #include <openvdb/version.h>
19 #include <openvdb/Types.h>
20
21 namespace openvdb {
22 OPENVDB_USE_VERSION_NAMESPACE
23 namespace OPENVDB_VERSION_NAME {
24 namespace tools {
25
175 template <typename TreeT, typename OpT>
176 size_t visitNodesDepthFirst(TreeT& tree, OpT& op, size_t idx = 0);
177
178
188 template <typename NodeT, Index LEVEL = NodeT::LEVEL>
189 struct DepthFirstNodeVisitor;
190
191
193
194
195 template <typename NodeT, Index LEVEL>
196 struct DepthFirstNodeVisitor
197 {
198 using NonConstChildType = typename NodeT::ChildNodeType;
199 using ChildNodeType = typename CopyConstness<NodeT, NonConstChildType>::Type;
200
201 template <typename OpT>
202 static size_t visit(NodeT& node, OpT& op, size_t idx = 0)
203 {
204 size_t offset = 0;
205 op(node, idx + offset++);
206 for (auto iter = node.beginChildOn(); iter; ++iter) {
207 offset += DepthFirstNodeVisitor<ChildNodeType>::visit(
208 *iter, op, idx + offset);
209 }
210 return offset;
211 }
212 };
213
214
215 // terminate recursion
216 template <typename NodeT>
217 struct DepthFirstNodeVisitor<NodeT, 0>
218 {
219 template <typename OpT>
220 static size_t visit(NodeT& node, OpT& op, size_t idx = 0)
221 {
222 op(node, idx);
223 return size_t(1);
224 }
225 };
226
227
228 template <typename TreeT, typename OpT>
229 size_t visitNodesDepthFirst(TreeT& tree, OpT& op, size_t idx)
230 {
231 using NonConstRootNodeType = typename TreeT::RootNodeType;
232 using RootNodeType = typename CopyConstness<TreeT, NonConstRootNodeType>::Type;
233
234 return DepthFirstNodeVisitor<RootNodeType>::visit(tree.root(), op, idx);
235 }
236
237
238 } // namespace tools
239 } // namespace OPENVDB_VERSION_NAME
240 } // namespace openvdb
241
242 #endif // OPENVDB_TOOLS_NODE_VISITOR_HAS_BEEN_INCLUDED
openvdb::v8_1::tools::visitNodesDepthFirst
size_t visitNodesDepthFirst(TreeT &tree, OpT &op, size_t idx=0)
Visit all nodes in the tree depth-first and apply a user-supplied functor to each node.
Definition: NodeVisitor.h:229
openvdb
Definition: openvdb/Exceptions.h:13
Types.h
openvdb::v8_1::CopyConstness::Type
typename std::remove_const< ToType >::type Type
Definition: openvdb/Types.h:317
openvdb::v8_1::tools::DepthFirstNodeVisitor< NodeT, 0 >::visit
static size_t visit(NodeT &node, OpT &op, size_t idx=0)
Definition: NodeVisitor.h:220
openvdb::v8_1::tools::DepthFirstNodeVisitor
Visit all nodes that are downstream of a specific node in depth-first order and apply a user-supplied...
Definition: NodeVisitor.h:197
openvdb::v8_1::tools::DepthFirstNodeVisitor::ChildNodeType
typename CopyConstness< NodeT, NonConstChildType >::Type ChildNodeType
Definition: NodeVisitor.h:199
openvdb::v8_1::tools::DepthFirstNodeVisitor::visit
static size_t visit(NodeT &node, OpT &op, size_t idx=0)
Definition: NodeVisitor.h:202
openvdb::v8_1::tools::DepthFirstNodeVisitor::NonConstChildType
typename NodeT::ChildNodeType NonConstChildType
Definition: NodeVisitor.h:198
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178