Blender  V2.93
bvh_build.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 __BVH_BUILD_H__
19 #define __BVH_BUILD_H__
20 
21 #include <float.h>
22 
23 #include "bvh/bvh_params.h"
24 #include "bvh/bvh_unaligned.h"
25 
26 #include "util/util_array.h"
27 #include "util/util_task.h"
28 #include "util/util_vector.h"
29 
31 
32 class Boundbox;
33 class BVHBuildTask;
34 class BVHNode;
35 class BVHSpatialSplitBuildTask;
36 class BVHParams;
37 class InnerNode;
38 class Geometry;
39 class Hair;
40 class Mesh;
41 class Object;
42 class Progress;
43 
44 /* BVH Builder */
45 
46 class BVHBuild {
47  public:
48  /* Constructor/Destructor */
54  const BVHParams &params,
56  ~BVHBuild();
57 
58  BVHNode *run();
59 
60  protected:
61  friend class BVHMixedSplit;
62  friend class BVHObjectSplit;
63  friend class BVHSpatialSplit;
64  friend class BVHBuildTask;
66  friend class BVHObjectBinning;
67 
68  /* Adding references. */
70  void add_reference_curves(BoundBox &root, BoundBox &center, Hair *hair, int i);
71  void add_reference_geometry(BoundBox &root, BoundBox &center, Geometry *geom, int i);
72  void add_reference_object(BoundBox &root, BoundBox &center, Object *ob, int i);
73  void add_references(BVHRange &root);
74 
75  /* Building. */
76  BVHNode *build_node(const BVHRange &range,
78  int level,
79  BVHSpatialStorage *storage);
80  BVHNode *build_node(const BVHObjectBinning &range, int level);
82  BVHNode *create_object_leaf_nodes(const BVHReference *ref, int start, int num);
83 
84  bool range_within_max_leaf_size(const BVHRange &range,
85  const vector<BVHReference> &references) const;
86 
87  /* Threads. */
88  enum { THREAD_TASK_SIZE = 4096 };
89  void thread_build_node(InnerNode *node, int child, const BVHObjectBinning &range, int level);
91  int child,
92  const BVHRange &range,
94  int level);
96 
97  /* Progress. */
98  void progress_update();
99 
100  /* Tree rotations. */
101  void rotate(BVHNode *node, int max_depth);
102  void rotate(BVHNode *node, int max_depth, int iterations);
103 
104  /* Objects and primitive references. */
108 
109  /* Output primitive indexes and objects. */
114 
116 
117  /* Build parameters. */
119 
120  /* Progress reporting. */
126 
127  /* Spatial splitting. */
129  enumerable_thread_specific<BVHSpatialStorage> spatial_storage;
132 
133  /* Threads. */
135 
136  /* Unaligned building. */
138 };
139 
141 
142 #endif /* __BVH_BUILD_H__ */
NSNotificationCenter * center
BVHNode * create_object_leaf_nodes(const BVHReference *ref, int start, int num)
Definition: bvh_build.cpp:777
BVHNode * create_leaf_node(const BVHRange &range, const vector< BVHReference > &references)
Definition: bvh_build.cpp:814
void thread_build_spatial_split_node(InnerNode *node, int child, const BVHRange &range, vector< BVHReference > &references, int level)
Definition: bvh_build.cpp:510
size_t progress_count
Definition: bvh_build.h:123
BVHBuild(const vector< Object * > &objects, array< int > &prim_type, array< int > &prim_index, array< int > &prim_object, array< float2 > &prim_time, const BVHParams &params, Progress &progress)
Definition: bvh_build.cpp:44
bool range_within_max_leaf_size(const BVHRange &range, const vector< BVHReference > &references) const
Definition: bvh_build.cpp:530
thread_spin_lock spatial_spin_lock
Definition: bvh_build.h:131
thread_mutex build_mutex
Definition: bvh_build.h:95
void add_references(BVHRange &root)
Definition: bvh_build.cpp:314
void add_reference_object(BoundBox &root, BoundBox &center, Object *ob, int i)
Definition: bvh_build.cpp:283
BVHNode * build_node(const BVHRange &range, vector< BVHReference > &references, int level, BVHSpatialStorage *storage)
Definition: bvh_build.cpp:656
void add_reference_curves(BoundBox &root, BoundBox &center, Hair *hair, int i)
Definition: bvh_build.cpp:156
friend class BVHBuildTask
Definition: bvh_build.h:64
bool need_prim_time
Definition: bvh_build.h:115
size_t spatial_free_index
Definition: bvh_build.h:130
BVHUnaligned unaligned_heuristic
Definition: bvh_build.h:137
BVHNode * run()
Definition: bvh_build.cpp:370
TaskPool task_pool
Definition: bvh_build.h:134
void add_reference_geometry(BoundBox &root, BoundBox &center, Geometry *geom, int i)
Definition: bvh_build.cpp:271
Progress & progress
Definition: bvh_build.h:121
array< float2 > & prim_time
Definition: bvh_build.h:113
vector< Object * > objects
Definition: bvh_build.h:105
array< int > & prim_index
Definition: bvh_build.h:111
void rotate(BVHNode *node, int max_depth)
Definition: bvh_build.cpp:1070
enumerable_thread_specific< BVHSpatialStorage > spatial_storage
Definition: bvh_build.h:129
size_t progress_total
Definition: bvh_build.h:124
friend class BVHSpatialSplitBuildTask
Definition: bvh_build.h:65
size_t progress_original_total
Definition: bvh_build.h:125
BVHParams params
Definition: bvh_build.h:118
void thread_build_node(InnerNode *node, int child, const BVHObjectBinning &range, int level)
Definition: bvh_build.cpp:485
float spatial_min_overlap
Definition: bvh_build.h:128
int num_original_references
Definition: bvh_build.h:107
@ THREAD_TASK_SIZE
Definition: bvh_build.h:88
array< int > & prim_type
Definition: bvh_build.h:110
double progress_start_time
Definition: bvh_build.h:122
array< int > & prim_object
Definition: bvh_build.h:112
void progress_update()
Definition: bvh_build.cpp:470
vector< BVHReference > references
Definition: bvh_build.h:106
void add_reference_triangles(BoundBox &root, BoundBox &center, Mesh *mesh, int i)
Definition: bvh_build.cpp:70
__forceinline int start() const
Definition: bvh_params.h:262
OperationNode * node
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition: util_thread.h:40
tbb::spin_mutex thread_spin_lock
Definition: util_thread.h:68