Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/render/intern/raytrace/rayobject_rtbuild.cpp')
-rw-r--r--source/blender/render/intern/raytrace/rayobject_rtbuild.cpp116
1 files changed, 58 insertions, 58 deletions
diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
index 6988e3fcc38..54901db8bdd 100644
--- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
+++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
@@ -54,10 +54,10 @@ static void rtbuild_init(RTBuilder *b)
b->primitives.end = 0;
b->primitives.maxsize = 0;
- for(int i=0; i<RTBUILD_MAX_CHILDS; i++)
+ for (int i=0; i<RTBUILD_MAX_CHILDS; i++)
b->child_offset[i] = 0;
- for(int i=0; i<3; i++)
+ for (int i=0; i<3; i++)
b->sorted_begin[i] = b->sorted_end[i] = 0;
INIT_MINMAX(b->bb, b->bb+3);
@@ -74,7 +74,7 @@ RTBuilder* rtbuild_create(int size)
builder->primitives.begin = builder->primitives.end = memblock;
builder->primitives.maxsize = size;
- for(int i=0; i<3; i++)
+ for (int i=0; i<3; i++)
{
builder->sorted_begin[i] = (RTBuilder::Object**)MEM_mallocN( sizeof(RTBuilder::Object*)*size,"RTBuilder.sorted_objects");
builder->sorted_end[i] = builder->sorted_begin[i];
@@ -86,10 +86,10 @@ RTBuilder* rtbuild_create(int size)
void rtbuild_free(RTBuilder *b)
{
- if(b->primitives.begin) MEM_freeN(b->primitives.begin);
+ if (b->primitives.begin) MEM_freeN(b->primitives.begin);
- for(int i=0; i<3; i++)
- if(b->sorted_begin[i])
+ for (int i=0; i<3; i++)
+ if (b->sorted_begin[i])
MEM_freeN(b->sorted_begin[i]);
MEM_freeN(b);
@@ -107,16 +107,16 @@ void rtbuild_add(RTBuilder *b, RayObject *o)
/* skip objects with invalid bounding boxes, nan causes DO_MINMAX
* to do nothing, so we get these invalid values. this shouldn't
* happen usually, but bugs earlier in the pipeline can cause it. */
- if(bb[0] > bb[3] || bb[1] > bb[4] || bb[2] > bb[5])
+ if (bb[0] > bb[3] || bb[1] > bb[4] || bb[2] > bb[5])
return;
/* skip objects with inf bounding boxes */
- if(!finite(bb[0]) || !finite(bb[1]) || !finite(bb[2]))
+ if (!finite(bb[0]) || !finite(bb[1]) || !finite(bb[2]))
return;
- if(!finite(bb[3]) || !finite(bb[4]) || !finite(bb[5]))
+ if (!finite(bb[3]) || !finite(bb[4]) || !finite(bb[5]))
return;
/* skip objects with zero bounding box, they are of no use, and
* will give problems in rtbuild_heuristic_object_split later */
- if(bb[0] == bb[3] && bb[1] == bb[4] && bb[2] == bb[5])
+ if (bb[0] == bb[3] && bb[1] == bb[4] && bb[2] == bb[5])
return;
copy_v3_v3(b->primitives.end->bb, bb);
@@ -124,7 +124,7 @@ void rtbuild_add(RTBuilder *b, RayObject *o)
b->primitives.end->obj = o;
b->primitives.end->cost = RE_rayobject_cost(o);
- for(int i=0; i<3; i++)
+ for (int i=0; i<3; i++)
{
*(b->sorted_end[i]) = b->primitives.end;
b->sorted_end[i]++;
@@ -141,7 +141,7 @@ int rtbuild_size(RTBuilder *b)
template<class Obj,int Axis>
static bool obj_bb_compare(const Obj &a, const Obj &b)
{
- if(a->bb[Axis] != b->bb[Axis])
+ if (a->bb[Axis] != b->bb[Axis])
return a->bb[Axis] < b->bb[Axis];
return a->obj < b->obj;
}
@@ -149,18 +149,18 @@ static bool obj_bb_compare(const Obj &a, const Obj &b)
template<class Item>
static void object_sort(Item *begin, Item *end, int axis)
{
- if(axis == 0) return std::sort(begin, end, obj_bb_compare<Item,0> );
- if(axis == 1) return std::sort(begin, end, obj_bb_compare<Item,1> );
- if(axis == 2) return std::sort(begin, end, obj_bb_compare<Item,2> );
+ if (axis == 0) return std::sort(begin, end, obj_bb_compare<Item,0> );
+ if (axis == 1) return std::sort(begin, end, obj_bb_compare<Item,1> );
+ if (axis == 2) return std::sort(begin, end, obj_bb_compare<Item,2> );
assert(false);
}
void rtbuild_done(RTBuilder *b, RayObjectControl* ctrl)
{
- for(int i=0; i<3; i++)
- if(b->sorted_begin[i])
+ for (int i=0; i<3; i++)
+ if (b->sorted_begin[i])
{
- if(RE_rayobjectcontrol_test_break(ctrl)) break;
+ if (RE_rayobjectcontrol_test_break(ctrl)) break;
object_sort( b->sorted_begin[i], b->sorted_end[i], i );
}
}
@@ -174,8 +174,8 @@ RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp)
{
rtbuild_init( tmp );
- for(int i=0; i<3; i++)
- if(b->sorted_begin[i])
+ for (int i=0; i<3; i++)
+ if (b->sorted_begin[i])
{
tmp->sorted_begin[i] = b->sorted_begin[i] + b->child_offset[child ];
tmp->sorted_end [i] = b->sorted_begin[i] + b->child_offset[child+1];
@@ -191,9 +191,9 @@ RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp)
void rtbuild_calc_bb(RTBuilder *b)
{
- if(b->bb[0] == 1.0e30f)
+ if (b->bb[0] == 1.0e30f)
{
- for(RTBuilder::Object **index = b->sorted_begin[0]; index != b->sorted_end[0]; index++)
+ for (RTBuilder::Object **index = b->sorted_begin[0]; index != b->sorted_end[0]; index++)
RE_rayobject_merge_bb( (*index)->obj , b->bb, b->bb+3);
}
}
@@ -225,20 +225,20 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis)
assert(nchilds <= RTBUILD_MAX_CHILDS);
//TODO optimize calc of leafs_per_child
- for(s=nchilds; s<tot_leafs; s*=nchilds);
+ for (s=nchilds; s<tot_leafs; s*=nchilds);
Mleafs_per_child = s/nchilds;
mleafs_per_child = Mleafs_per_child/nchilds;
//split min leafs per child
b->child_offset[0] = 0;
- for(i=1; i<=nchilds; i++)
+ for (i=1; i<=nchilds; i++)
b->child_offset[i] = mleafs_per_child;
//split remaining leafs
missing_leafs = tot_leafs - mleafs_per_child*nchilds;
- for(i=1; i<=nchilds; i++)
+ for (i=1; i<=nchilds; i++)
{
- if(missing_leafs > Mleafs_per_child - mleafs_per_child)
+ if (missing_leafs > Mleafs_per_child - mleafs_per_child)
{
b->child_offset[i] += Mleafs_per_child - mleafs_per_child;
missing_leafs -= Mleafs_per_child - mleafs_per_child;
@@ -252,11 +252,11 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis)
}
//adjust for accumulative offsets
- for(i=1; i<=nchilds; i++)
+ for (i=1; i<=nchilds; i++)
b->child_offset[i] += b->child_offset[i-1];
//Count created childs
- for(i=nchilds; b->child_offset[i] == b->child_offset[i-1]; i--);
+ for (i=nchilds; b->child_offset[i] == b->child_offset[i-1]; i--);
split_leafs(b, b->child_offset, i, axis);
assert( b->child_offset[0] == 0 && b->child_offset[i] == tot_leafs );
@@ -281,7 +281,7 @@ int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis)
int size = rtbuild_size(b);
assert(nchilds <= RTBUILD_MAX_CHILDS);
- if(size <= nchilds)
+ if (size <= nchilds)
{
return rtbuild_mean_split(b, nchilds, axis);
}
@@ -293,12 +293,12 @@ int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis)
//Calculate child offsets
b->child_offset[0] = 0;
- for(i=0; i<nchilds-1; i++)
+ for (i=0; i<nchilds-1; i++)
b->child_offset[i+1] = split_leafs_by_plane(b, b->child_offset[i], size, separators[i]);
b->child_offset[nchilds] = size;
- for(i=0; i<nchilds; i++)
- if(b->child_offset[i+1] - b->child_offset[i] == size)
+ for (i=0; i<nchilds; i++)
+ if (b->child_offset[i+1] - b->child_offset[i] == size)
return rtbuild_mean_split(b, nchilds, axis);
return nchilds;
@@ -313,7 +313,7 @@ int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds)
rtbuild_calc_bb(b);
la = bb_largest_axis(b->bb,b->bb+3);
- for(i=1; i<nchilds; i++)
+ for (i=1; i<nchilds; i++)
separators[i-1] = (b->bb[la+3]-b->bb[la])*i / nchilds;
return rtbuild_median_split(b, separators, nchilds, la);
@@ -337,23 +337,23 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
assert(size > 1);
int baxis = -1, boffset = 0;
- if(size > nchilds)
+ if (size > nchilds)
{
float bcost = FLT_MAX;
baxis = -1, boffset = size/2;
SweepCost *sweep = (SweepCost*)MEM_mallocN( sizeof(SweepCost)*size, "RTBuilder.HeuristicSweep" );
- for(int axis=0; axis<3; axis++)
+ for (int axis=0; axis<3; axis++)
{
SweepCost sweep_left;
RTBuilder::Object **obj = b->sorted_begin[axis];
// float right_cost = 0;
- for(int i=size-1; i>=0; i--)
+ for (int i=size-1; i>=0; i--)
{
- if(i == size-1)
+ if (i == size-1)
{
copy_v3_v3(sweep[i].bb, obj[i]->bb);
copy_v3_v3(sweep[i].bb+3, obj[i]->bb+3);
@@ -380,9 +380,9 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
sweep_left.bb[5] = obj[0]->bb[5];
sweep_left.cost = obj[0]->cost;
-// right_cost -= obj[0]->cost; if(right_cost < 0) right_cost = 0;
+// right_cost -= obj[0]->cost; if (right_cost < 0) right_cost = 0;
- for(int i=1; i<size; i++)
+ for (int i=1; i<size; i++)
{
//Worst case heuristic (cost of each child is linear)
float hcost, left_side, right_side;
@@ -398,10 +398,10 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
assert(left_side >= 0);
assert(right_side >= 0);
- if(left_side > bcost) break; //No way we can find a better heuristic in this axis
+ if (left_side > bcost) break; //No way we can find a better heuristic in this axis
assert(hcost >= 0);
- if( hcost < bcost
+ if ( hcost < bcost
|| (hcost == bcost && axis < baxis)) //this makes sure the tree built is the same whatever is the order of the sorting axis
{
bcost = hcost;
@@ -412,7 +412,7 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
DO_MAX( obj[i]->bb+3, sweep_left.bb+3 );
sweep_left.cost += obj[i]->cost;
-// right_cost -= obj[i]->cost; if(right_cost < 0) right_cost = 0;
+// right_cost -= obj[i]->cost; if (right_cost < 0) right_cost = 0;
}
//assert(baxis >= 0 && baxis < 3);
@@ -423,12 +423,12 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
MEM_freeN(sweep);
}
- else if(size == 2)
+ else if (size == 2)
{
baxis = 0;
boffset = 1;
}
- else if(size == 1)
+ else if (size == 1)
{
b->child_offset[0] = 0;
b->child_offset[1] = 1;
@@ -441,9 +441,9 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
/* Adjust sorted arrays for childs */
- for(int i=0; i<boffset; i++) b->sorted_begin[baxis][i]->selected = true;
- for(int i=boffset; i<size; i++) b->sorted_begin[baxis][i]->selected = false;
- for(int i=0; i<3; i++)
+ for (int i=0; i<boffset; i++) b->sorted_begin[baxis][i]->selected = true;
+ for (int i=boffset; i<size; i++) b->sorted_begin[baxis][i]->selected = false;
+ for (int i=0; i<3; i++)
std::stable_partition( b->sorted_begin[i], b->sorted_end[i], selected_node );
return nchilds;
@@ -460,13 +460,13 @@ static void split_leafs(RTBuilder *b, int *nth, int partitions, int split_axis)
int i;
b->split_axis = split_axis;
- for(i=0; i < partitions-1; i++)
+ for (i=0; i < partitions-1; i++)
{
assert(nth[i] < nth[i+1] && nth[i+1] < nth[partitions]);
- if(split_axis == 0) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare<RTBuilder::Object,0>);
- if(split_axis == 1) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare<RTBuilder::Object,1>);
- if(split_axis == 2) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare<RTBuilder::Object,2>);
+ if (split_axis == 0) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare<RTBuilder::Object,0>);
+ if (split_axis == 1) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare<RTBuilder::Object,1>);
+ if (split_axis == 2) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare<RTBuilder::Object,2>);
}
}
#endif
@@ -500,16 +500,16 @@ int bb_largest_axis(float *min, float *max)
sub[0] = max[0]-min[0];
sub[1] = max[1]-min[1];
sub[2] = max[2]-min[2];
- if(sub[0] > sub[1])
+ if (sub[0] > sub[1])
{
- if(sub[0] > sub[2])
+ if (sub[0] > sub[2])
return 0;
else
return 2;
}
else
{
- if(sub[1] > sub[2])
+ if (sub[1] > sub[2])
return 1;
else
return 2;
@@ -519,11 +519,11 @@ int bb_largest_axis(float *min, float *max)
int bb_fits_inside(float *outer_min, float *outer_max, float *inner_min, float *inner_max)
{
int i;
- for(i=0; i<3; i++)
- if(outer_min[i] > inner_min[i]) return 0;
+ for (i=0; i<3; i++)
+ if (outer_min[i] > inner_min[i]) return 0;
- for(i=0; i<3; i++)
- if(outer_max[i] < inner_max[i]) return 0;
+ for (i=0; i<3; i++)
+ if (outer_max[i] < inner_max[i]) return 0;
return 1;
}