Fermat
bvh_node.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 
35 #include <cugar/linalg/vector.h>
36 #include <cugar/linalg/bbox.h>
37 
38 namespace cugar {
39 
42 
45 struct Bvh_node : public Bintree_node<leaf_range_tag>
46 {
47  typedef leaf_range_tag node_tag;
48 
49  enum internal_type { kInternal = 0 };
50  enum leaf_type { kLeaf = 1 };
51 
54  CUGAR_HOST_DEVICE
55  Bvh_node() {}
56 
59  CUGAR_HOST_DEVICE
60  Bvh_node(const internal_type type, const uint32 child_index, const uint32 range_size = 0) : Bintree_node<leaf_range_tag>(true, true, child_index, range_size) {}
61 
64  CUGAR_HOST_DEVICE
65  Bvh_node(const leaf_type type, const uint32 leaf_begin, const uint32 leaf_end) : Bintree_node<leaf_range_tag>( leaf_begin, leaf_end ) {}
66 
69  CUGAR_HOST_DEVICE
71  {
73  return *this;
74  }
75 };
76 
80 struct Bvh_node_3d : public Bvh_node
81 {
83  typedef Bvh_node::internal_type internal_type;
84  typedef Bvh_node::leaf_type leaf_type;
85 
88  CUGAR_HOST_DEVICE
90 
93  CUGAR_HOST_DEVICE
94  Bvh_node_3d(const internal_type type, const uint32 child_index, const uint32 range_size = 0) : Bvh_node( type, child_index, range_size ) {}
95 
98  CUGAR_HOST_DEVICE
99  Bvh_node_3d(const leaf_type type, const uint32 leaf_begin, const uint32 leaf_end) : Bvh_node( type, leaf_begin, leaf_end ) {}
100 
103  CUGAR_HOST_DEVICE
104  Bvh_node_3d(const float4 f0, const float4 f1)
105  {
108  bbox[0] = Vector3f(f0.z, f0.w, f1.x);
109  bbox[1] = Vector3f(f1.y, f1.z, f1.w);
110  }
111 
114  CUGAR_HOST_DEVICE
116  {
118  return *this;
119  }
120 
123  CUGAR_HOST_DEVICE
124  static Bvh_node_3d load_ldg(const Bvh_node_3d* node)
125  {
126  #if defined(CUGAR_DEVICE_COMPILATION)
127  const float4 f0 = __ldg(reinterpret_cast<const float4*>(node));
128  const float4 f1 = __ldg(reinterpret_cast<const float4*>(node) + 1);
129  return Bvh_node_3d(f0,f1);
130  #else
131  return *node;
132  #endif
133  }
134 
135  Bbox<Vector3f> bbox;
136 };
137 CUGAR_ALIGN_END(16)
138 
139 
141 } // namespace cugar
CUGAR_HOST_DEVICE Bvh_node()
Definition: bvh_node.h:55
CUGAR_HOST_DEVICE Bvh_node_3d(const internal_type type, const uint32 child_index, const uint32 range_size=0)
Definition: bvh_node.h:94
Definition: bvh_node.h:45
Definition: bvh_node.h:80
CUGAR_HOST_DEVICE Bvh_node(const leaf_type type, const uint32 leaf_begin, const uint32 leaf_end)
Definition: bvh_node.h:65
CUGAR_HOST_DEVICE Bvh_node_3d()
Definition: bvh_node.h:89
Define CUDA based scan primitives.
CUGAR_HOST_DEVICE Bvh_node(const internal_type type, const uint32 child_index, const uint32 range_size=0)
Definition: bvh_node.h:60
CUGAR_HOST_DEVICE Bvh_node & operator=(const Bintree_node< leaf_range_tag > &base)
Definition: bvh_node.h:70
Defines an axis-aligned bounding box class.
static CUGAR_HOST_DEVICE Bvh_node_3d load_ldg(const Bvh_node_3d *node)
Definition: bvh_node.h:124
CUGAR_HOST_DEVICE Bvh_node_3d(const leaf_type type, const uint32 leaf_begin, const uint32 leaf_end)
Definition: bvh_node.h:99
Definition: vector.h:54
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: bintree_node.h:60
struct CUGAR_ALIGN_BEGIN(8) Bintree_node< leaf_range_tag >
Definition: bintree_node.h:155
Definition: bintree_node.h:63
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Out binary_cast(const In in)
Definition: types.h:288
CUGAR_HOST_DEVICE Bvh_node_3d(const float4 f0, const float4 f1)
Definition: bvh_node.h:104