Blender  V2.93
bvh2.h
Go to the documentation of this file.
1 /*
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011, Blender Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __BVH2_H__
19 #define __BVH2_H__
20 
21 #include "bvh/bvh.h"
22 #include "bvh/bvh_params.h"
23 
24 #include "util/util_types.h"
25 #include "util/util_vector.h"
26 
28 
29 #define BVH_NODE_SIZE 4
30 #define BVH_NODE_LEAF_SIZE 1
31 #define BVH_UNALIGNED_NODE_SIZE 7
32 
33 /* Pack Utility */
34 struct BVHStackEntry {
35  const BVHNode *node;
36  int idx;
37 
38  BVHStackEntry(const BVHNode *n = 0, int i = 0);
39  int encodeIdx() const;
40 };
41 
42 /* BVH2
43  *
44  * Typical BVH with each node having two children.
45  */
46 class BVH2 : public BVH {
47  public:
48  void build(Progress &progress, Stats *stats);
49  void refit(Progress &progress);
50 
52 
53  protected:
54  /* constructor */
55  friend class BVH;
56  BVH2(const BVHParams &params,
58  const vector<Object *> &objects);
59 
60  /* Building process. */
61  virtual BVHNode *widen_children_nodes(const BVHNode *root);
62 
63  /* pack */
64  void pack_nodes(const BVHNode *root);
65 
66  void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf);
67  void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1);
68 
70  const BVHStackEntry &e0,
71  const BVHStackEntry &e1);
72  void pack_aligned_node(int idx,
73  const BoundBox &b0,
74  const BoundBox &b1,
75  int c0,
76  int c1,
77  uint visibility0,
78  uint visibility1);
79 
81  const BVHStackEntry &e0,
82  const BVHStackEntry &e1);
83  void pack_unaligned_node(int idx,
84  const Transform &aligned_space0,
85  const Transform &aligned_space1,
86  const BoundBox &b0,
87  const BoundBox &b1,
88  int c0,
89  int c1,
90  uint visibility0,
91  uint visibility1);
92 
93  /* refit */
94  void refit_nodes();
95  void refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility);
96 
97  /* Refit range of primitives. */
98  void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility);
99 
100  /* triangles and strands */
101  void pack_primitives();
102  void pack_triangle(int idx, float4 storage[3]);
103 
104  /* merge instance BVH's */
105  void pack_instances(size_t nodes_size, size_t leaf_nodes_size);
106 };
107 
109 
110 #endif /* __BVH2_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
Definition: bvh2.h:46
void pack_instances(size_t nodes_size, size_t leaf_nodes_size)
Definition: bvh2.cpp:504
void pack_aligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition: bvh2.cpp:151
void refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility)
Definition: bvh2.cpp:325
void pack_triangle(int idx, float4 storage[3])
Definition: bvh2.cpp:442
void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf)
Definition: bvh2.cpp:118
void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility)
Definition: bvh2.cpp:375
void pack_aligned_node(int idx, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
Definition: bvh2.cpp:164
PackedBVH pack
Definition: bvh2.h:51
void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition: bvh2.cpp:141
virtual BVHNode * widen_children_nodes(const BVHNode *root)
Definition: bvh2.cpp:113
void pack_unaligned_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1)
Definition: bvh2.cpp:196
void pack_primitives()
Definition: bvh2.cpp:460
void pack_nodes(const BVHNode *root)
Definition: bvh2.cpp:243
void refit(Progress &progress)
Definition: bvh2.cpp:101
void pack_unaligned_node(int idx, const Transform &aligned_space0, const Transform &aligned_space1, const BoundBox &b0, const BoundBox &b1, int c0, int c1, uint visibility0, uint visibility1)
Definition: bvh2.cpp:211
BVH2(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition: bvh2.cpp:42
void refit_nodes()
Definition: bvh2.cpp:316
void build(Progress &progress, Stats *stats)
Definition: bvh2.cpp:49
Definition: bvh/bvh.h:80
vector< Geometry * > geometry
Definition: bvh/bvh.h:83
BVHParams params
Definition: bvh/bvh.h:82
vector< Object * > objects
Definition: bvh/bvh.h:84
#define CCL_NAMESPACE_END
const BVHNode * node
Definition: bvh2.h:35
BVHStackEntry(const BVHNode *n=0, int i=0)
Definition: bvh2.cpp:33
int idx
Definition: bvh2.h:36
int encodeIdx() const
Definition: bvh2.cpp:37