31 #include <cugar/radixtree/cuda/radixtree.h> 38 template <
typename integer, u
int32 DIM>
44 static const uint32 value = 32u;
46 CUGAR_HOST_DEVICE
static inline float convert(
float a,
float b,
const uint32 i)
48 const float x = float(i) / float(1u << 16u);
49 return a + (b - a) * x;
56 static const uint32 value = 64u;
58 CUGAR_HOST_DEVICE
static inline float convert(
float a,
float b,
const uint64 i)
60 const float x = float(i) / float(0xFFFFFFFFu);
61 return a + (b - a) * x;
68 static const uint32 value = 30u;
70 CUGAR_HOST_DEVICE
static inline float convert(
float a,
float b,
const uint64 i)
72 const float x = float(i) / float(1u << 10u);
73 return a + (b - a) * x;
80 static const uint32 value = 60u;
82 CUGAR_HOST_DEVICE
static inline float convert(
float a,
float b,
const uint64 i)
84 const float x = float(i) / float(1u << 20u);
85 return a + (b - a) * x;
91 template <u
int32 DIM,
typename BboxType,
typename Integer,
typename OutputTree>
94 typedef typename OutputTree::Context BaseContext;
100 CUGAR_HOST_DEVICE
Context(
const BaseContext context,
const Integer* codes, BboxType bbox) :
101 m_context( context ), m_codes( codes ), m_bbox( bbox ) {}
105 CUGAR_HOST_DEVICE
void write_node(
const uint32 node,
const uint32 parent,
bool p1,
bool p2,
const uint32 offset,
const uint32 skip_node,
const uint32 level,
const uint32
begin,
const uint32 end,
const uint32 split_index)
113 Integer code = m_codes[ split_index ];
114 const uint32 split_dim = level % DIM;
117 Integer split_coord = 0;
125 for (
int i = 0; code; i++)
127 split_coord |= (((code >> split_dim) & 1u) << i);
135 m_context.write_node(
148 m_context.write_node(
158 CUGAR_HOST_DEVICE
void write_leaf(
const uint32 leaf_index,
const uint32 node_index,
const uint32
begin,
const uint32 end)
160 m_context.write_leaf( leaf_index, begin, end );
163 BaseContext m_context;
164 const Integer* m_codes;
171 const Integer* codes,
173 m_context( context ), m_codes( codes ), m_bbox( bbox ) {}
185 m_context.get_context(),
190 OutputTree m_context;
191 const Integer* m_codes;
196 template <
typename Po
intIterator,
typename Integer,
typename MortonFunctor>
198 void morton_kernel(
const uint32 n_points,
const PointIterator points_begin, Integer* out,
const MortonFunctor morton)
200 const uint32 thread_id = threadIdx.x + blockIdx.x * blockDim.x;
202 if (thread_id < n_points)
204 typedef typename std::iterator_traits<PointIterator>::value_type VectorType;
206 const VectorType p = points_begin[thread_id];
207 out[thread_id] = morton(p);
214 template <
typename Integer>
215 template <
typename OutputTree,
typename Iterator,
typename BboxType>
220 const Iterator points_begin,
221 const Iterator points_end,
222 const uint32 max_leaf_size)
224 const uint32 DIM = BboxType::vector_type::DIMENSION;
225 const uint32 n_points = uint32( points_end - points_begin );
227 need_space( m_codes, n_points );
228 need_space( index, n_points );
229 need_space( m_temp_codes, n_points );
230 need_space( m_temp_index, n_points );
243 points_begin + n_points,
250 thrust::counting_iterator<uint32>(0),
251 thrust::counting_iterator<uint32>(0) + n_points,
263 sort_buffers.values[1] =
raw_pointer(m_temp_index);
266 sort_enactor.sort(n_points, sort_buffers);
269 if (sort_buffers.selector)
271 thrust::copy(m_temp_codes.begin(), m_temp_codes.begin() + n_points, m_codes.begin());
272 thrust::copy(m_temp_index.begin(), m_temp_index.begin() + n_points, index.begin());
291 m_leaf_count = m_kd_context.m_leaves;
292 m_node_count = m_kd_context.m_nodes;
void reserve_leaves(const uint32 n)
reserve space for more leaves
Definition: kd_builder_inline.h:179
void transform(const uint32 n, const Iterator in, const Output out, const Functor functor)
Definition: primitives_inl.h:357
Defines some general purpose algorithms.
Definition: kd_builder_inline.h:39
Kd_context(OutputTree context, const Integer *codes, BboxType bbox)
constructor
Definition: kd_builder_inline.h:169
thrust::device_vector< T >::iterator begin(thrust::device_vector< T > &vec)
Definition: thrust_view.h:89
void reserve_nodes(const uint32 n)
reserve space for more nodes
Definition: kd_builder_inline.h:176
T * raw_pointer(thrust::device_vector< T, Alloc > &vec)
Definition: thrust_view.h:69
Definition: kd_builder_inline.h:92
Define CUDA based sort primitives.
CUGAR_HOST_DEVICE L divide_ri(const L x, const R y)
Definition: numbers.h:180
Context get_context()
return a cuda context
Definition: kd_builder_inline.h:182
Cuda accessor struct.
Definition: kd_builder_inline.h:97
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
void build(OutputTree &out_tree, vector< device_tag, uint32 > &out_index, const BboxType bbox, const Iterator points_begin, const Iterator points_end, const uint32 max_leaf_size)
Definition: kd_builder_inline.h:216
void generate_radix_tree(const uint32 n_codes, const Integer *codes, const uint32 bits, const uint32 max_leaf_size, const bool keep_singletons, const bool middle_splits, Tree_writer &tree)
Definition: radixtree_inline.h:381
CUGAR_HOST_DEVICE void write_leaf(const uint32 leaf_index, const uint32 node_index, const uint32 begin, const uint32 end)
Definition: kd_builder_inline.h:158
CUGAR_HOST_DEVICE void write_node(const uint32 node, const uint32 parent, bool p1, bool p2, const uint32 offset, const uint32 skip_node, const uint32 level, const uint32 begin, const uint32 end, const uint32 split_index)
Definition: kd_builder_inline.h:105