~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/cycles/bvh/bvh_build.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <float.h>
22
22
 
23
23
#include "bvh.h"
 
24
#include "bvh_binning.h"
24
25
 
25
26
#include "util_boundbox.h"
 
27
#include "util_task.h"
26
28
#include "util_vector.h"
27
29
 
28
30
CCL_NAMESPACE_BEGIN
29
31
 
 
32
class BVHBuildTask;
30
33
class BVHParams;
 
34
class InnerNode;
31
35
class Mesh;
32
36
class Object;
33
37
class Progress;
37
41
class BVHBuild
38
42
{
39
43
public:
40
 
        struct Reference
41
 
        {
42
 
                int prim_index;
43
 
                int prim_object;
44
 
                BoundBox bounds;
45
 
 
46
 
                Reference()
47
 
                {
48
 
                }
49
 
        };
50
 
 
51
 
        struct NodeSpec
52
 
        {
53
 
                int num;
54
 
                BoundBox bounds;
55
 
 
56
 
                NodeSpec()
57
 
                {
58
 
                        num = 0;
59
 
                }
60
 
        };
61
 
 
 
44
        /* Constructor/Destructor */
62
45
        BVHBuild(
63
46
                const vector<Object*>& objects,
 
47
                vector<int>& prim_segment,
64
48
                vector<int>& prim_index,
65
49
                vector<int>& prim_object,
66
50
                const BVHParams& params,
70
54
        BVHNode *run();
71
55
 
72
56
protected:
 
57
        friend class BVHMixedSplit;
 
58
        friend class BVHObjectSplit;
 
59
        friend class BVHSpatialSplit;
 
60
        friend class BVHBuildTask;
 
61
 
73
62
        /* adding references */
74
 
        void add_reference_mesh(NodeSpec& root, Mesh *mesh, int i);
75
 
        void add_reference_object(NodeSpec& root, Object *ob, int i);
76
 
        void add_references(NodeSpec& root);
 
63
        void add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, int i);
 
64
        void add_reference_object(BoundBox& root, BoundBox& center, Object *ob, int i);
 
65
        void add_references(BVHRange& root);
77
66
 
78
67
        /* building */
79
 
        BVHNode *build_node(const NodeSpec& spec, int level, float progress_start, float progress_end);
80
 
        BVHNode *create_leaf_node(const NodeSpec& spec);
81
 
        BVHNode *create_object_leaf_nodes(const Reference *ref, int num);
82
 
 
83
 
        void progress_update(float progress_start, float progress_end);
84
 
 
85
 
        /* object splits */
86
 
        struct ObjectSplit
87
 
        {
88
 
                float sah;
89
 
                int dim;
90
 
                int num_left;
91
 
                BoundBox left_bounds;
92
 
                BoundBox right_bounds;
93
 
 
94
 
                ObjectSplit()
95
 
                : sah(FLT_MAX), dim(0), num_left(0)
96
 
                {
97
 
                }
98
 
        };
99
 
 
100
 
        ObjectSplit find_object_split(const NodeSpec& spec, float nodeSAH);
101
 
        void do_object_split(NodeSpec& left, NodeSpec& right, const NodeSpec& spec, const ObjectSplit& split);
102
 
 
103
 
        /* spatial splits */
104
 
        struct SpatialSplit
105
 
        {
106
 
                float sah;
107
 
                int dim;
108
 
                float pos;
109
 
 
110
 
                SpatialSplit()
111
 
                : sah(FLT_MAX), dim(0), pos(0.0f)
112
 
                {
113
 
                }
114
 
        };
115
 
 
116
 
        struct SpatialBin
117
 
        {
118
 
                BoundBox bounds;
119
 
                int enter;
120
 
                int exit;
121
 
        };
122
 
 
123
 
        SpatialSplit find_spatial_split(const NodeSpec& spec, float nodeSAH);
124
 
        void do_spatial_split(NodeSpec& left, NodeSpec& right, const NodeSpec& spec, const SpatialSplit& split);
125
 
        void split_reference(Reference& left, Reference& right, const Reference& ref, int dim, float pos);
 
68
        BVHNode *build_node(const BVHRange& range, int level);
 
69
        BVHNode *build_node(const BVHObjectBinning& range, int level);
 
70
        BVHNode *create_leaf_node(const BVHRange& range);
 
71
        BVHNode *create_object_leaf_nodes(const BVHReference *ref, int start, int num);
 
72
 
 
73
        /* threads */
 
74
        enum { THREAD_TASK_SIZE = 4096 };
 
75
        void thread_build_node(InnerNode *node, int child, BVHObjectBinning *range, int level);
 
76
        thread_mutex build_mutex;
 
77
 
 
78
        /* progress */
 
79
        void progress_update();
 
80
 
 
81
        /* tree rotations */
 
82
        void rotate(BVHNode *node, int max_depth);
 
83
        void rotate(BVHNode *node, int max_depth, int iterations);
126
84
 
127
85
        /* objects and primitive references */
128
86
        vector<Object*> objects;
129
 
        vector<Reference> references;
 
87
        vector<BVHReference> references;
 
88
        int num_original_references;
130
89
 
131
90
        /* output primitive indexes and objects */
 
91
        vector<int>& prim_segment;
132
92
        vector<int>& prim_index;
133
93
        vector<int>& prim_object;
134
94
 
138
98
        /* progress reporting */
139
99
        Progress& progress;
140
100
        double progress_start_time;
141
 
        int progress_num_duplicates;
 
101
        size_t progress_count;
 
102
        size_t progress_total;
 
103
        size_t progress_original_total;
142
104
 
143
105
        /* spatial splitting */
144
106
        float spatial_min_overlap;
145
107
        vector<BoundBox> spatial_right_bounds;
146
 
        SpatialBin spatial_bins[3][BVHParams::NUM_SPATIAL_BINS];
 
108
        BVHSpatialBin spatial_bins[3][BVHParams::NUM_SPATIAL_BINS];
 
109
 
 
110
        /* threads */
 
111
        TaskPool task_pool;
147
112
};
148
113
 
149
114
CCL_NAMESPACE_END