- Most of CUGAR's functions and data structures are C++ templates providing the flexibility and compile-time code generation needed to accomodate the exponential amount of type combinations possible in typical applications.
- Just as an example, consider the following code, building a K-d tree over a set of points:
- The following code snippet shows how to use this builder:
thrust::device_vector<Vector3f> points;
...
thrust::device_vector<Kd_node> kd_nodes;
thrust::device_vector<uint2> kd_leaves;
thrust::device_vector<uint32> kd_index;
builder.build(
kd_tree,
kd_index,
Bbox3f( Vector3f(0.0f), Vector3f(1.0f) ),
points.begin(),
points.end(),
4 );
- In the above code, the builder stores the nodes of the resulting K-d tree into a flat array of Kd_node's. But what if we wanted to store them using a different layout? It turns out the builder itself doesn't know anything about the actual output it produces, but rather, it delegates everything to an OutputTree template class which must possess the following interface:
struct OutputTree
{
void reserve_nodes(const uint32 n);
void reserve_leaves(const uint32 n);
Context get_context();
struct Context
{
void write_node(
const uint32 node,
const uint32 offset,
const uint32 skip_node,
const uint32 end,
const uint32 split_index,
const uint32 split_dim,
const uint32 split_plane);
void write_node(
const uint32 node,
const uint32 offset,
const uint32 skip_node,
const uint32 end);
void write_leaf(
const uint32 index,
const uint32 end);
};
};
- allowing its behaviour to be completely customized. In this case, we just relied on the default implementation provided by cugar::cuda::Kd_context.
Next: Host & Device Top: mainpage