Cycles: Remove odd definition from CMake file
[blender.git] / intern / cycles / bvh / bvh_build.h
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.h"
24 #include "bvh_binning.h"
25 #include "bvh_unaligned.h"
26
27 #include "util_boundbox.h"
28 #include "util_task.h"
29 #include "util_vector.h"
30
31 CCL_NAMESPACE_BEGIN
32
33 class BVHBuildTask;
34 class BVHSpatialSplitBuildTask;
35 class BVHParams;
36 class InnerNode;
37 class Mesh;
38 class Object;
39 class Progress;
40
41 /* BVH Builder */
42
43 class BVHBuild
44 {
45 public:
46         /* Constructor/Destructor */
47         BVHBuild(const vector<Object*>& objects,
48                  array<int>& prim_type,
49                  array<int>& prim_index,
50                  array<int>& prim_object,
51                  const BVHParams& params,
52                  Progress& progress);
53         ~BVHBuild();
54
55         BVHNode *run();
56
57 protected:
58         friend class BVHMixedSplit;
59         friend class BVHObjectSplit;
60         friend class BVHSpatialSplit;
61         friend class BVHBuildTask;
62         friend class BVHSpatialSplitBuildTask;
63         friend class BVHObjectBinning;
64
65         /* Adding references. */
66         void add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, int i);
67         void add_reference_object(BoundBox& root, BoundBox& center, Object *ob, int i);
68         void add_references(BVHRange& root);
69
70         /* Building. */
71         BVHNode *build_node(const BVHRange& range,
72                             vector<BVHReference> *references,
73                             int level,
74                             int thread_id);
75         BVHNode *build_node(const BVHObjectBinning& range, int level);
76         BVHNode *create_leaf_node(const BVHRange& range,
77                                   const vector<BVHReference>& references);
78         BVHNode *create_object_leaf_nodes(const BVHReference *ref, int start, int num);
79
80         bool range_within_max_leaf_size(const BVHRange& range,
81                                         const vector<BVHReference>& references) const;
82
83         /* Threads. */
84         enum { THREAD_TASK_SIZE = 4096 };
85         void thread_build_node(InnerNode *node,
86                                int child,
87                                BVHObjectBinning *range,
88                                int level);
89         void thread_build_spatial_split_node(InnerNode *node,
90                                              int child,
91                                              BVHRange *range,
92                                              vector<BVHReference> *references,
93                                              int level,
94                                              int thread_id);
95         thread_mutex build_mutex;
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. */
105         vector<Object*> objects;
106         vector<BVHReference> references;
107         int num_original_references;
108
109         /* Output primitive indexes and objects. */
110         array<int>& prim_type;
111         array<int>& prim_index;
112         array<int>& prim_object;
113
114         /* Build parameters. */
115         BVHParams params;
116
117         /* Progress reporting. */
118         Progress& progress;
119         double progress_start_time;
120         size_t progress_count;
121         size_t progress_total;
122         size_t progress_original_total;
123
124         /* Spatial splitting. */
125         float spatial_min_overlap;
126         vector<BVHSpatialStorage> spatial_storage;
127         size_t spatial_free_index;
128         thread_spin_lock spatial_spin_lock;
129
130         /* Threads. */
131         TaskPool task_pool;
132
133         /* Unaligned building. */
134         BVHUnaligned unaligned_heuristic;
135 };
136
137 CCL_NAMESPACE_END
138
139 #endif /* __BVH_BUILD_H__ */