GridAccel::~GridAccel() { for (u_int i = 0; i < nMailboxes; ++i) mailboxes[i].~MailboxPrim(); FreeAligned(mailboxes); for (int i = 0; i < NVoxels[0]*NVoxels[1]*NVoxels[2]; ++i) if (voxels[i]) voxels[i]->~Voxel(); FreeAligned(voxels); }
QBVHAccel::~QBVHAccel() { if (initialized) { FreeAligned(prims); FreeAligned(nodes); if (preprocessedMesh) { preprocessedMesh->Delete(); delete preprocessedMesh; } delete[] meshIDs; delete[] meshTriangleIDs; } }
//.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- Dta1xxNwStopWorkerThreads -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- // Int Dta1xxNwStopWorkerThreads(Dta1xxNw_Private* lp) { // Stop Rx thread if (lp->m_pRxThread != NULL) Dta1xxKThreadStop(lp->m_pRxThread); // Stop Tx thread if (lp->m_pTxThread != NULL) Dta1xxKThreadStop(lp->m_pTxThread); // Release buffers if (lp->m_NwTxBuf.m_pBuffer) FreeAligned(lp->m_NwTxBuf.m_pBuffer); lp->m_NwTxBuf.m_pBuffer = NULL; if (lp->m_NwRxBuf.m_pBuffer) FreeAligned(lp->m_NwRxBuf.m_pBuffer); lp->m_NwRxBuf.m_pBuffer = NULL; return STATUS_SUCCESS; }
BVHAccel::~BVHAccel() { FreeAligned(nodes); }
void Mutex::Destroy(Mutex *m) { m->~Mutex(); FreeAligned(m); }
void RWMutex::Destroy(RWMutex *m) { m->~RWMutex(); FreeAligned(m); }
ContributionBuffer::Buffer::~Buffer() { FreeAligned(contribs); }
void SPD::FreeSamples() { // Free Allocate memory for samples if (samples) FreeAligned(samples); }
QBVHAccel::~QBVHAccel() { if (initialized) { FreeAligned(prims); FreeAligned(nodes); } }
void KdTreeAccel::buildTree(int nodeNum, const BBox &nodeBounds, const vector<BBox> &allPrimBounds, int *primNums, int nPrims, int depth, BoundEdge *edges[3], int *prims0, int *prims1, int badRefines) { Assert(nodeNum == nextFreeNode); // NOBOOK // Get next free node from _nodes_ array if (nextFreeNode == nAllocedNodes) { int nAlloc = max(2 * nAllocedNodes, 512); KdAccelNode *n = (KdAccelNode *)AllocAligned(nAlloc * sizeof(KdAccelNode)); if (nAllocedNodes > 0) { memcpy(n, nodes, nAllocedNodes * sizeof(KdAccelNode)); FreeAligned(nodes); } nodes = n; nAllocedNodes = nAlloc; } ++nextFreeNode; // Initialize leaf node if termination criteria met if (nPrims <= maxPrims || depth == 0) { nodes[nodeNum].initLeaf(primNums, nPrims, mailboxPrims, arena); return; } // Initialize interior node and continue recursion // Choose split axis position for interior node int bestAxis = -1, bestOffset = -1; float bestCost = INFINITY; float oldCost = isectCost * float(nPrims); Vector d = nodeBounds.pMax - nodeBounds.pMin; float totalSA = (2.f * (d.x*d.y + d.x*d.z + d.y*d.z)); float invTotalSA = 1.f / totalSA; // Choose which axis to split along int axis; if (d.x > d.y && d.x > d.z) axis = 0; else axis = (d.y > d.z) ? 1 : 2; int retries = 0; retrySplit: // Initialize edges for _axis_ for (int i = 0; i < nPrims; ++i) { int pn = primNums[i]; const BBox &bbox = allPrimBounds[pn]; edges[axis][2*i] = BoundEdge(bbox.pMin[axis], pn, true); edges[axis][2*i+1] = BoundEdge(bbox.pMax[axis], pn, false); } sort(&edges[axis][0], &edges[axis][2*nPrims]); // Compute cost of all splits for _axis_ to find best int nBelow = 0, nAbove = nPrims; for (int i = 0; i < 2*nPrims; ++i) { if (edges[axis][i].type == BoundEdge::END) --nAbove; float edget = edges[axis][i].t; if (edget > nodeBounds.pMin[axis] && edget < nodeBounds.pMax[axis]) { // Compute cost for split at _i_th edge int otherAxis[3][2] = { {1,2}, {0,2}, {0,1} }; int otherAxis0 = otherAxis[axis][0]; int otherAxis1 = otherAxis[axis][1]; float belowSA = 2 * (d[otherAxis0] * d[otherAxis1] + (edget - nodeBounds.pMin[axis]) * (d[otherAxis0] + d[otherAxis1])); float aboveSA = 2 * (d[otherAxis0] * d[otherAxis1] + (nodeBounds.pMax[axis] - edget) * (d[otherAxis0] + d[otherAxis1])); float pBelow = belowSA * invTotalSA; float pAbove = aboveSA * invTotalSA; float eb = (nAbove == 0 || nBelow == 0) ? emptyBonus : 0.f; float cost = traversalCost + isectCost * (1.f - eb) * (pBelow * nBelow + pAbove * nAbove); // Update best split if this is lowest cost so far if (cost < bestCost) { bestCost = cost; bestAxis = axis; bestOffset = i; } } if (edges[axis][i].type == BoundEdge::START) ++nBelow; } Assert(nBelow == nPrims && nAbove == 0); // NOBOOK // Create leaf if no good splits were found if (bestAxis == -1 && retries < 2) { ++retries; axis = (axis+1) % 3; goto retrySplit; } if (bestCost > oldCost) ++badRefines; if ((bestCost > 4.f * oldCost && nPrims < 16) || bestAxis == -1 || badRefines == 3) { nodes[nodeNum].initLeaf(primNums, nPrims, mailboxPrims, arena); return; } // Classify primitives with respect to split int n0 = 0, n1 = 0; for (int i = 0; i < bestOffset; ++i) if (edges[bestAxis][i].type == BoundEdge::START) prims0[n0++] = edges[bestAxis][i].primNum; for (int i = bestOffset+1; i < 2*nPrims; ++i) if (edges[bestAxis][i].type == BoundEdge::END) prims1[n1++] = edges[bestAxis][i].primNum; // Recursively initialize children nodes float tsplit = edges[bestAxis][bestOffset].t; nodes[nodeNum].initInterior(bestAxis, tsplit); BBox bounds0 = nodeBounds, bounds1 = nodeBounds; bounds0.pMax[bestAxis] = bounds1.pMin[bestAxis] = tsplit; buildTree(nodeNum+1, bounds0, allPrimBounds, prims0, n0, depth-1, edges, prims0, prims1 + nPrims, badRefines); nodes[nodeNum].aboveChild = nextFreeNode; buildTree(nodes[nodeNum].aboveChild, bounds1, allPrimBounds, prims1, n1, depth-1, edges, prims0, prims1 + nPrims, badRefines); }
KdTreeAccel::~KdTreeAccel() { for (u_int i = 0; i < nMailboxes; ++i) mailboxPrims[i].~MailboxPrim(); FreeAligned(mailboxPrims); FreeAligned(nodes); }
GridAccel::~GridAccel() { for (int i = 0; i < NVoxels[0]*NVoxels[1]*NVoxels[2]; ++i) if (voxels[i]) voxels[i]->~Voxel(); FreeAligned(voxels); RWMutex::Destroy(rwMutex); }
~RandomSampler() { FreeAligned(imageSamples); }
KDTree::~KDTree() { FreeAligned(nodes); }