34 #include <cugar/basic/types.h> 44 template <
typename node_type,
typename leaf_type =
typename node_type::node_tag>
50 template <
typename Node_type>
53 typedef Node_type node_type;
58 m_num_nodes(0), m_num_leaves(0), m_nodes(NULL), m_node_sizes(NULL), m_leaf_pointers(NULL), m_leaf_ranges(NULL), m_parents(NULL), m_skip_nodes(NULL) {}
60 void set_node_count(
const uint32 num_nodes) { m_num_nodes = num_nodes; }
61 void set_leaf_count(
const uint32 num_leaves) { m_num_leaves = num_leaves; }
63 void set_nodes(
const node_type* nodes) { m_nodes = nodes; }
64 void set_parents(
const uint32* parents) { m_parents = parents; }
65 void set_skip_nodes(
const uint32* skip_nodes) { m_skip_nodes = skip_nodes; }
66 void set_leaf_pointers(
const uint32* leaf_pointers) { m_leaf_pointers = leaf_pointers; }
67 void set_leaf_ranges(
const uint2* leaf_ranges) { m_leaf_ranges = leaf_ranges; }
82 return m_nodes[node].get_child_count();
88 CUGAR_HOST_DEVICE
bool is_leaf(
const uint32 node)
const 90 return m_nodes[node].is_leaf();
97 CUGAR_HOST_DEVICE uint32
get_child(
const uint32 node,
const uint32 i)
const 99 return m_nodes[node].get_child(i);
107 return m_parents[node];
115 return m_skip_nodes[node];
123 const uint32 leaf_index = m_nodes[node].get_leaf_index();
124 return m_leaf_ranges ?
125 m_leaf_ranges[leaf_index] :
126 make_uint2(leaf_index,leaf_index+1);
134 return m_node_sizes[node];
145 return m_leaf_pointers[i];
150 const node_type* m_nodes;
151 const uint32* m_node_sizes;
152 const uint32* m_leaf_pointers;
153 const uint2* m_leaf_ranges;
154 const uint32* m_parents;
155 const uint32* m_skip_nodes;
161 template <
typename Node_type>
164 typedef Node_type node_type;
169 m_num_nodes(0), m_num_leaves(0), m_nodes(NULL), m_leaf_pointers(NULL), m_parents(NULL), m_skip_nodes(NULL) {}
171 void set_node_count(
const uint32 num_nodes) { m_num_nodes = num_nodes; }
172 void set_leaf_count(
const uint32 num_leaves) { m_num_leaves = num_leaves; }
174 void set_nodes(
const node_type* nodes) { m_nodes = nodes; }
175 void set_parents(
const uint32* parents) { m_parents = parents; }
176 void set_skip_nodes(
const uint32* skip_nodes) { m_skip_nodes = skip_nodes; }
177 void set_leaf_pointers(
const uint32* leaf_pointers) { m_leaf_pointers = leaf_pointers; }
190 CUGAR_HOST_DEVICE
bool is_leaf(
const uint32 node)
const 192 return m_nodes[node].is_leaf() ? true :
false;
200 return m_nodes[node].get_child_count();
207 CUGAR_HOST_DEVICE uint32
get_child(
const uint32 node,
const uint32 i)
const 209 return m_nodes[node].get_child(i);
217 return m_parents[node];
225 return m_skip_nodes[node];
233 return m_nodes[node].get_leaf_range();
241 return m_nodes[node].get_range_size();
252 return m_leaf_pointers[i];
257 const node_type* m_nodes;
258 const uint32* m_leaf_pointers;
259 const uint32* m_parents;
260 const uint32* m_skip_nodes;
263 template <
typename bvh_visitor_type>
264 void check_tree_rec(
const uint32 node_id,
const uint32 parent_id,
const bvh_visitor_type& visitor,
const uint32 n_prims,
const uint32 max_leaf_size)
267 if (parent_id != visitor.get_parent( node_id ))
268 throw cugar::logic_error(
"node[%u] has wrong parent: %u != %u", node_id, parent_id, visitor.get_parent( node_id ));
270 if (visitor.is_leaf( node_id ) ==
false)
273 const uint32 child_count = visitor.get_child_count( node_id );
274 if (child_count == 0 || child_count > 2)
278 for (uint32 i = 0; i < 2; ++i)
280 const uint32 child_id = visitor.get_child( node_id, i );
281 if (child_id >= visitor.get_node_count())
282 throw cugar::logic_error(
"node[%u].child(%u) out of bounds : %u / %u", node_id, i, child_id, visitor.get_node_count());
284 check_tree_rec( child_id, node_id, visitor, n_prims, max_leaf_size );
290 const uint2 leaf_range = visitor.get_leaf_range( node_id );
293 if (leaf_range.x > leaf_range.y)
294 throw cugar::logic_error(
"leaf[%u] : malformed range (%u, %u)", node_id, leaf_range.x, leaf_range.y);
297 if (leaf_range.y > n_prims)
298 throw cugar::logic_error(
"leaf[%u] : range out of bounds (%u, %u) / %u", node_id, leaf_range.x, leaf_range.y, n_prims);
301 if (leaf_range.y - leaf_range.x > max_leaf_size)
302 throw cugar::logic_error(
"leaf[%u] : maximum size overflow (%u, %u) / %u", node_id, leaf_range.x, leaf_range.y, max_leaf_size);
308 template <
typename node_type,
typename leaf_type>
311 check_tree_rec( 0u, uint32(-1), visitor, n_prims, max_leaf_size );
CUGAR_HOST_DEVICE uint32 get_leaf_node(const uint32 i) const
Definition: bintree_visitor.h:250
Bintree_visitor()
Definition: bintree_visitor.h:168
Definition: exceptions.h:72
CUGAR_HOST_DEVICE uint32 get_leaf_count() const
Definition: bintree_visitor.h:185
CUGAR_HOST_DEVICE uint32 get_range_size(const uint32 node) const
Definition: bintree_visitor.h:132
Definition: bintree_node.h:56
CUGAR_HOST_DEVICE uint32 get_skip_node(const uint32 node) const
Definition: bintree_visitor.h:113
CUGAR_HOST_DEVICE bool is_leaf(const uint32 node) const
Definition: bintree_visitor.h:88
CUGAR_HOST_DEVICE uint32 get_child(const uint32 node, const uint32 i) const
Definition: bintree_visitor.h:97
CUGAR_HOST_DEVICE uint2 get_leaf_range(const uint32 node) const
Definition: bintree_visitor.h:231
CUGAR_HOST_DEVICE uint32 get_parent(const uint32 node) const
Definition: bintree_visitor.h:215
CUGAR_HOST_DEVICE bool has_leaf_pointers() const
Definition: bintree_visitor.h:139
CUGAR_HOST_DEVICE uint32 get_range_size(const uint32 node) const
Definition: bintree_visitor.h:239
Bintree_visitor()
Definition: bintree_visitor.h:57
void check_tree(const Bintree_visitor< node_type, leaf_type > &visitor, const uint32 n_prims, const uint32 max_leaf_size=uint32(-1))
Definition: bintree_visitor.h:309
CUGAR_HOST_DEVICE uint32 get_skip_node(const uint32 node) const
Definition: bintree_visitor.h:223
CUGAR_HOST_DEVICE uint32 get_parent(const uint32 node) const
Definition: bintree_visitor.h:105
CUGAR_HOST_DEVICE uint32 get_node_count() const
Definition: bintree_visitor.h:71
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: bintree_visitor.h:45
Definition: bintree_node.h:60
CUGAR_HOST_DEVICE uint32 get_child_count(const uint32 node) const
Definition: bintree_visitor.h:80
CUGAR_HOST_DEVICE uint32 get_leaf_node(const uint32 i) const
Definition: bintree_visitor.h:143
CUGAR_HOST_DEVICE bool has_leaf_pointers() const
Definition: bintree_visitor.h:246
CUGAR_HOST_DEVICE uint32 get_node_count() const
Definition: bintree_visitor.h:181
CUGAR_HOST_DEVICE uint32 get_leaf_count() const
Definition: bintree_visitor.h:75
CUGAR_HOST_DEVICE uint32 get_child_count(const uint32 node) const
Definition: bintree_visitor.h:198
CUGAR_HOST_DEVICE uint2 get_leaf_range(const uint32 node) const
Definition: bintree_visitor.h:121
CUGAR_HOST_DEVICE bool is_leaf(const uint32 node) const
Definition: bintree_visitor.h:190
CUGAR_HOST_DEVICE uint32 get_child(const uint32 node, const uint32 i) const
Definition: bintree_visitor.h:207