Fermat
kd_context.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2018, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
32 #pragma once
33 
34 #include <cugar/basic/types.h>
35 #include <cugar/basic/vector.h>
36 
37 namespace cugar {
38 namespace cuda {
39 
44 struct Kd_context
48 {
50  struct Context
51  {
52  CUGAR_HOST_DEVICE Context() {}
53  CUGAR_HOST_DEVICE Context(Kd_node* nodes, uint2* leaves, uint2* ranges) :
54  m_nodes(nodes), m_leaves(leaves), m_ranges( ranges ) {}
55 
57  CUGAR_HOST_DEVICE void write_node(const uint32 node, const uint32 offset, const uint32 skip_node, const uint32 begin, const uint32 end, const uint32 split_index, const uint32 split_dim, const float split_plane)
58  {
59  m_nodes[ node ] = Kd_node( split_dim, split_plane, offset );
60 
61  if (m_ranges)
62  m_ranges[ node ] = make_uint2( begin, end );
63  }
65  CUGAR_HOST_DEVICE void write_node(const uint32 node, const uint32 offset, const uint32 skip_node, const uint32 begin, const uint32 end)
66  {
67  m_nodes[ node ] = Kd_node( offset );
68 
69  if (m_ranges)
70  m_ranges[ node ] = make_uint2( begin, end );
71  }
73  CUGAR_HOST_DEVICE void write_leaf(const uint32 index, const uint32 begin, const uint32 end)
74  {
75  m_leaves[ index ] = make_uint2( begin, end );
76  }
77 
79  uint2* m_leaves;
80  uint2* m_ranges;
81  };
82 
91  thrust::device_vector<Kd_node>* nodes,
92  thrust::device_vector<uint2>* leaves,
93  thrust::device_vector<uint2>* ranges) :
94  m_nodes( nodes ), m_leaves( leaves ), m_ranges( ranges ) {}
95 
98  void reserve_nodes(const uint32 n)
99  {
100  if (m_nodes->size() < n) m_nodes->resize(n);
101  if (m_ranges && m_ranges->size() < n) m_ranges->resize(n);
102  }
103 
106  void reserve_leaves(const uint32 n) { if (m_leaves->size() < n) m_leaves->resize(n); }
107 
111  {
112  return Context(
113  thrust::raw_pointer_cast( &m_nodes->front() ),
114  thrust::raw_pointer_cast( &m_leaves->front() ),
115  m_ranges ? thrust::raw_pointer_cast( &m_ranges->front() ) : NULL );
116  }
117 
118  thrust::device_vector<Kd_node>* m_nodes;
119  thrust::device_vector<uint2>* m_leaves;
120  thrust::device_vector<uint2>* m_ranges;
121 };
122 
126 } // namespace cuda
127 } // namespace cugar
CUGAR_HOST_DEVICE void write_leaf(const uint32 index, const uint32 begin, const uint32 end)
write a new leaf
Definition: kd_context.h:73
void reserve_leaves(const uint32 n)
Definition: kd_context.h:106
thrust::device_vector< T >::iterator begin(thrust::device_vector< T > &vec)
Definition: thrust_view.h:89
CUGAR_HOST_DEVICE void write_node(const uint32 node, const uint32 offset, const uint32 skip_node, const uint32 begin, const uint32 end)
write a new node
Definition: kd_context.h:65
void reserve_nodes(const uint32 n)
Definition: kd_context.h:98
Definition: kd_node.h:110
Cuda accessor struct.
Definition: kd_context.h:50
Kd_node * m_nodes
node pointer
Definition: kd_context.h:78
Context get_context()
Definition: kd_context.h:110
Kd_context(thrust::device_vector< Kd_node > *nodes, thrust::device_vector< uint2 > *leaves, thrust::device_vector< uint2 > *ranges)
Definition: kd_context.h:90
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_HOST_DEVICE void write_node(const uint32 node, const uint32 offset, const uint32 skip_node, const uint32 begin, const uint32 end, const uint32 split_index, const uint32 split_dim, const float split_plane)
write a new node
Definition: kd_context.h:57
uint2 * m_ranges
range pointer
Definition: kd_context.h:80
uint2 * m_leaves
leaf pointer
Definition: kd_context.h:79