Fermat
packing.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 
33 #pragma once
34 
35 #include <cugar/bvh/bvh.h>
36 #include <thrust/transform.h>
37 #include <thrust/tuple.h>
38 
39 namespace cugar {
40 namespace cuda {
41 
46 struct bvh_packing_functor
49 {
50  typedef Bbox4f result_type;
51  typedef thrust::tuple<Bbox4f,Bvh_node> argument_type;
52 
53  CUGAR_HOST_DEVICE Bbox4f operator() (const argument_type arg) const
54  {
55  Bbox4f bbox = thrust::get<0>(arg);
56  bbox[0][3] = binary_cast<float>( thrust::get<1>(arg).m_packed_data );
57  bbox[1][3] = binary_cast<float>( thrust::get<1>(arg).m_skip_node );
58  return bbox;
59  }
60 };
61 
91 template <typename Node_iterator, typename Bbox_iterator, typename Output_iterator>
92 void pack(
93  const uint32 n_nodes,
94  Node_iterator nodes,
95  Bbox_iterator bboxes,
96  Output_iterator packed_nodes)
97 {
99  thrust::make_zip_iterator(thrust::make_tuple(bboxes,nodes)),
100  thrust::make_zip_iterator(thrust::make_tuple(bboxes,nodes)) + n_nodes,
101  packed_nodes,
103 }
104 
108 } // namespace cuda
109 } // namespace cugar
Entry point to the generic Bounding Volume Hierarchy library.
void transform(const uint32 n, const Iterator in, const Output out, const Functor functor)
Definition: primitives_inl.h:357
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Out binary_cast(const In in)
Definition: types.h:288
Definition: packing.h:48
void pack(const uint32 n_nodes, Node_iterator nodes, Bbox_iterator bboxes, Output_iterator packed_nodes)
Definition: packing.h:92