本文整理汇总了C++中Bounds3f::surfaceArea方法的典型用法代码示例。如果您正苦于以下问题:C++ Bounds3f::surfaceArea方法的具体用法?C++ Bounds3f::surfaceArea怎么用?C++ Bounds3f::surfaceArea使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bounds3f
的用法示例。
在下文中一共展示了Bounds3f::surfaceArea方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildTree
void KdTreeAccel::buildTree(KdAccelNode* node, const Bounds3f &bound, vector<int> &prims,
int depth, BoundEdge* edges[3])
{
node->bbox = bound;
int np = prims.size();
//If not enough primitives or reach max depth of a tree
//Create a leaf node
if (np <= maxPrims || depth == 0)
{
node->initLeaf(prims);
return;
}
//Interior node parameters
int bestAxis = -1, bestOffest = -1;//Split axis and split index*2
Float bestCost = INFINITY;
Float oldCost = np;
Float totalSA = bound.surfaceArea();
Float invTotalSA = 1.0 / totalSA;
Vector3f bbDiag = bound.pMax - bound.pMin;
//choose max extension axis of bounding box
int axis = bound.maxExtent();//axis is the longest edge of bounding box
int retries = 0;
RETRY_SPLIT:
//
//Calculate surface cost
for (int i = 0; i < np; ++i)
{
int prmIdx = prims[i];
const Bounds3f tmpBox = primitives[prmIdx]->ObjBound;
edges[axis][i * 2] = BoundEdge(tmpBox.pMin[axis], prmIdx, true);
edges[axis][i * 2 + 1] = BoundEdge(tmpBox.pMax[axis], prmIdx, false);
}
sort(&edges[axis][0], &edges[axis][2 * np]);
int nBelow(0), nAbove(np);
for (int i = 0; i < 2 * np; ++i)
{
if (edges[axis][i].type == BoundEdge::END)
{
--nAbove;
}
Float edget = edges[axis][i].t;
//when t is in between the boundary
if (edget > bound.pMin[axis] && edget < bound.pMax[axis])
{
//Compute cost for split at ith edge
//get other two axes
int axis0 = (axis + 1) % 3, axis1 = (axis + 2) % 3;
Float belowSA = 2 * (bbDiag[axis0] * bbDiag[axis1] +
(edget - bound.pMin[axis]) *
(bbDiag[axis0] + bbDiag[axis1]));
Float aboveSA = 2 * (bbDiag[axis0] * bbDiag[axis1] +
(bound.pMax[axis] - edget) *
(bbDiag[axis0] + bbDiag[axis1]));
Float pBelow = belowSA * invTotalSA;
Float pAbove = aboveSA * invTotalSA;
Float eb = (nAbove == 0 || nBelow == 0) ? emptyBonus : 0;
Float cost = (1.0 - eb) * (pBelow * nBelow + pAbove * nAbove);
//cout << "cost at i:" << i << " is " << cost << endl;
if (cost < bestCost)
{
bestCost = cost;
bestAxis = axis;
bestOffest = i;// edges[axis][i].type ? i + 1 : i;//When end use next node
}
}
if (edges[axis][i].type == BoundEdge::START)
{
++nBelow;
}
}
if (retries < 2)//(bestAxis == -1 && retries < 2)//
{
++retries;
axis = (axis + 1) % 3;
goto RETRY_SPLIT;
}
//if no good split, init as leaf
if (bestAxis == -1)
{
node->initLeaf(prims);
return;
}
//recursively build subtree
vector<int> primsBelow;
vector<int> primsAbove;
//Store indices of below primitives
for (int i = 0; i < bestOffest; ++i)
{
if (edges[bestAxis][i].type == BoundEdge::START)
{
primsBelow.push_back(edges[bestAxis][i].primNum);
}
}
//Store indices of above primitives
//.........这里部分代码省略.........