本文整理汇总了C++中BoundBox::safe_area方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundBox::safe_area方法的具体用法?C++ BoundBox::safe_area怎么用?C++ BoundBox::safe_area使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundBox
的用法示例。
在下文中一共展示了BoundBox::safe_area方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
void BVHSpatialSplit::split(BVHBuild *builder,
BVHRange& left,
BVHRange& right,
const BVHRange& range)
{
/* Categorize references and compute bounds.
*
* Left-hand side: [left_start, left_end[
* Uncategorized/split: [left_end, right_start[
* Right-hand side: [right_start, refs.size()[ */
vector<BVHReference>& refs = *references_;
int left_start = range.start();
int left_end = left_start;
int right_start = range.end();
int right_end = range.end();
BoundBox left_bounds = BoundBox::empty;
BoundBox right_bounds = BoundBox::empty;
for(int i = left_end; i < right_start; i++) {
if(refs[i].bounds().max[this->dim] <= this->pos) {
/* entirely on the left-hand side */
left_bounds.grow(refs[i].bounds());
swap(refs[i], refs[left_end++]);
}
else if(refs[i].bounds().min[this->dim] >= this->pos) {
/* entirely on the right-hand side */
right_bounds.grow(refs[i].bounds());
swap(refs[i--], refs[--right_start]);
}
}
/* Duplicate or unsplit references intersecting both sides.
*
* Duplication happens into a temporary pre-allocated vector in order to
* reduce number of memmove() calls happening in vector.insert().
*/
vector<BVHReference>& new_refs = storage_->new_references;
new_refs.clear();
new_refs.reserve(right_start - left_end);
while(left_end < right_start) {
/* split reference. */
BVHReference lref, rref;
split_reference(*builder, lref, rref, refs[left_end], this->dim, this->pos);
/* compute SAH for duplicate/unsplit candidates. */
BoundBox lub = left_bounds; // Unsplit to left: new left-hand bounds.
BoundBox rub = right_bounds; // Unsplit to right: new right-hand bounds.
BoundBox ldb = left_bounds; // Duplicate: new left-hand bounds.
BoundBox rdb = right_bounds; // Duplicate: new right-hand bounds.
lub.grow(refs[left_end].bounds());
rub.grow(refs[left_end].bounds());
ldb.grow(lref.bounds());
rdb.grow(rref.bounds());
float lac = builder->params.primitive_cost(left_end - left_start);
float rac = builder->params.primitive_cost(right_end - right_start);
float lbc = builder->params.primitive_cost(left_end - left_start + 1);
float rbc = builder->params.primitive_cost(right_end - right_start + 1);
float unsplitLeftSAH = lub.safe_area() * lbc + right_bounds.safe_area() * rac;
float unsplitRightSAH = left_bounds.safe_area() * lac + rub.safe_area() * rbc;
float duplicateSAH = ldb.safe_area() * lbc + rdb.safe_area() * rbc;
float minSAH = min(min(unsplitLeftSAH, unsplitRightSAH), duplicateSAH);
if(minSAH == unsplitLeftSAH) {
/* unsplit to left */
left_bounds = lub;
left_end++;
}
else if(minSAH == unsplitRightSAH) {
/* unsplit to right */
right_bounds = rub;
swap(refs[left_end], refs[--right_start]);
}
else {
/* duplicate */
left_bounds = ldb;
right_bounds = rdb;
refs[left_end++] = lref;
new_refs.push_back(rref);
right_end++;
}
}
/* Insert duplicated references into actual array in one go. */
if(new_refs.size() != 0) {
refs.insert(refs.begin() + (right_end - new_refs.size()),
new_refs.begin(),
new_refs.end());
}
left = BVHRange(left_bounds, left_start, left_end - left_start);
right = BVHRange(right_bounds, right_start, right_end - right_start);
}