// KdTreeAccel Method Definitions KdTreeAccel:: KdTreeAccel(const vector<Reference<Primitive> > &p, int icost, int tcost, float ebonus, int maxp, int maxDepth) : isectCost(icost), traversalCost(tcost), maxPrims(maxp), emptyBonus(ebonus) { vector<Reference<Primitive > > prims; for (u_int i = 0; i < p.size(); ++i) p[i]->FullyRefine(prims); // Initialize mailboxes for _KdTreeAccel_ curMailboxId = 0; nMailboxes = prims.size(); mailboxPrims = (MailboxPrim *)AllocAligned(nMailboxes * sizeof(MailboxPrim)); for (u_int i = 0; i < nMailboxes; ++i) new (&mailboxPrims[i]) MailboxPrim(prims[i]); // Build kd-tree for accelerator nextFreeNode = nAllocedNodes = 0; if (maxDepth <= 0) maxDepth = Round2Int(8 + 1.3f * Log2Int(float(prims.size()))); // Compute bounds for kd-tree construction vector<BBox> primBounds; primBounds.reserve(prims.size()); for (u_int i = 0; i < prims.size(); ++i) { BBox b = prims[i]->WorldBound(); bounds = Union(bounds, b); primBounds.push_back(b); } // Allocate working memory for kd-tree construction BoundEdge *edges[3]; for (int i = 0; i < 3; ++i) edges[i] = new BoundEdge[2*prims.size()]; int *prims0 = new int[prims.size()]; int *prims1 = new int[(maxDepth+1) * prims.size()]; // Initialize _primNums_ for kd-tree construction int *primNums = new int[prims.size()]; for (u_int i = 0; i < prims.size(); ++i) primNums[i] = i; // Start recursive construction of kd-tree buildTree(0, bounds, primBounds, primNums, prims.size(), maxDepth, edges, prims0, prims1); // Free working memory for kd-tree construction delete[] primNums; for (int i = 0; i < 3; ++i) delete[] edges[i]; delete[] prims0; delete[] prims1; }
// KDTree Method Definitions KDTree::KDTree(Primitive** a_Primitives, unsigned int a_NumPrimitives, int icost, int tcost, float ebonus, int maxp, int md) : isectCost(icost), traversalCost(tcost), maxPrims(maxp), maxDepth(md), emptyBonus(ebonus) { g_candidates = 0; m_sName = "KDTree"; m_pPrimitives = a_Primitives; m_uiNumPrimitives = a_NumPrimitives; // Build kd-tree nextFreeNode = nAllocedNodes = 0; if (maxDepth <= 0) maxDepth = Round2Int(8 + 1.3f * Log2Int(float(m_uiNumPrimitives))); totalNodes = 0; }
int RankManager::getMeasueIndex(){ // 매수 인덱스 설정하고 구매 첫날인지 측정 int index = -1; // 보유기간 isFirstDay = false; remainDay = getRemainDay(); cout << "잔존일수 : " << remainDay << endl; if (remainDay < 0){ cout << "교체기간이 아닙니다." << endl; } else if (remainDay > ExSection - (baseInterval / 2)){ // 앞부분 index = 0; } else if (remainDay > 0){ // 잔존일 수 3일까지는 index = Round2Int((ExSection - remainDay) / (float)baseInterval); if ((remainDay + (baseInterval / 2)) % baseInterval == 0){ // 58, 54, 2.. 또는 29,27,.. 1) isFirstDay = true; } } else{ // == 0 index = 20; isFirstDay = true; } return index; }
// GridAccel Method Definitions GridAccel::GridAccel(const vector<Reference<Primitive> > &p, bool forRefined, bool refineImmediately) : gridForRefined(forRefined) { // Initialize _prims_ with primitives for grid vector<Reference<Primitive> > prims; if (refineImmediately) for (u_int i = 0; i < p.size(); ++i) p[i]->FullyRefine(prims); else prims = p; // Initialize mailboxes for grid nMailboxes = prims.size(); mailboxes = (MailboxPrim *)AllocAligned(nMailboxes * sizeof(MailboxPrim)); for (u_int i = 0; i < nMailboxes; ++i) new (&mailboxes[i]) MailboxPrim(prims[i]); // Compute bounds and choose grid resolution for (u_int i = 0; i < prims.size(); ++i) bounds = Union(bounds, prims[i]->WorldBound()); Vector delta = bounds.pMax - bounds.pMin; // Find _voxelsPerUnitDist_ for grid int maxAxis = bounds.MaximumExtent(); float invMaxWidth = 1.f / delta[maxAxis]; Assert(invMaxWidth > 0.f); // NOBOOK float cubeRoot = 3.f * powf(float(prims.size()), 1.f/3.f); float voxelsPerUnitDist = cubeRoot * invMaxWidth; for (int axis = 0; axis < 3; ++axis) { NVoxels[axis] = Round2Int(delta[axis] * voxelsPerUnitDist); NVoxels[axis] = Clamp(NVoxels[axis], 1, 64); } // Compute voxel widths and allocate voxels for (int axis = 0; axis < 3; ++axis) { Width[axis] = delta[axis] / NVoxels[axis]; InvWidth[axis] = (Width[axis] == 0.f) ? 0.f : 1.f / Width[axis]; } int nVoxels = NVoxels[0] * NVoxels[1] * NVoxels[2]; voxels = (Voxel **)AllocAligned(nVoxels * sizeof(Voxel *)); memset(voxels, 0, nVoxels * sizeof(Voxel *)); // Add primitives to grid voxels for (u_int i = 0; i < prims.size(); ++i) { // Find voxel extent of primitive BBox pb = prims[i]->WorldBound(); int vmin[3], vmax[3]; for (int axis = 0; axis < 3; ++axis) { vmin[axis] = PosToVoxel(pb.pMin, axis); vmax[axis] = PosToVoxel(pb.pMax, axis); } // Add primitive to overlapping voxels for (int z = vmin[2]; z <= vmax[2]; ++z) for (int y = vmin[1]; y <= vmax[1]; ++y) for (int x = vmin[0]; x <= vmax[0]; ++x) { int offset = Offset(x, y, z); if (!voxels[offset]) { // Allocate new voxel and store primitive in it voxels[offset] = new (voxelArena) Voxel(&mailboxes[i]); } else { // Add primitive to already-allocated voxel voxels[offset]->AddPrimitive(&mailboxes[i]); } } static StatsRatio nPrimitiveVoxels("Grid Accelerator", // NOBOOK "Voxels covered vs # / primitives"); // NOBOOK nPrimitiveVoxels.Add((1 + vmax[0]-vmin[0]) * (1 + vmax[1]-vmin[1]) * // NOBOOK (1 + vmax[2]-vmin[2]), 1); // NOBOOK } // Update grid statistics static StatsPercentage nEmptyVoxels("Grid Accelerator", "Empty voxels"); static StatsRatio avgPrimsInVoxel("Grid Accelerator", "Average # of primitives in voxel"); static StatsCounter maxPrimsInVoxel("Grid Accelerator", "Max # of primitives in a grid voxel"); nEmptyVoxels.Add(0, NVoxels[0] * NVoxels[1] * NVoxels[2]); avgPrimsInVoxel.Add(0,NVoxels[0] * NVoxels[1] * NVoxels[2]); for (int z = 0; z < NVoxels[2]; ++z) for (int y = 0; y < NVoxels[1]; ++y) for (int x = 0; x < NVoxels[0]; ++x) { int offset = Offset(x, y, z); if (!voxels[offset]) nEmptyVoxels.Add(1, 0); else { int nPrims = voxels[offset]->nPrimitives; maxPrimsInVoxel.Max(nPrims); avgPrimsInVoxel.Add(nPrims, 0); } } }
// GridAccel Method Definitions GridAccel::GridAccel(const vector<Reference<Primitive> > &p, bool forRefined, bool refineImmediately) : gridForRefined(forRefined) { PBRT_GRID_STARTED_CONSTRUCTION(this, p.size()); // Create reader-writeer mutex for grid rwMutex = RWMutex::Create(); // Initialize _primitives_ with primitives for grid if (refineImmediately) for (u_int i = 0; i < p.size(); ++i) p[i]->FullyRefine(primitives); else primitives = p; // Compute bounds and choose grid resolution for (u_int i = 0; i < primitives.size(); ++i) bounds = Union(bounds, primitives[i]->WorldBound()); Vector delta = bounds.pMax - bounds.pMin; // Find _voxelsPerUnitDist_ for grid int maxAxis = bounds.MaximumExtent(); float invMaxWidth = 1.f / delta[maxAxis]; Assert(invMaxWidth > 0.f); float cubeRoot = 3.f * powf(float(primitives.size()), 1.f/3.f); float voxelsPerUnitDist = cubeRoot * invMaxWidth; for (int axis = 0; axis < 3; ++axis) { NVoxels[axis] = Round2Int(delta[axis] * voxelsPerUnitDist); NVoxels[axis] = Clamp(NVoxels[axis], 1, 64); } PBRT_GRID_BOUNDS_AND_RESOLUTION(&bounds, NVoxels); // Compute voxel widths and allocate voxels for (int axis = 0; axis < 3; ++axis) { Width[axis] = delta[axis] / NVoxels[axis]; InvWidth[axis] = (Width[axis] == 0.f) ? 0.f : 1.f / Width[axis]; } int nVoxels = NVoxels[0] * NVoxels[1] * NVoxels[2]; voxels = AllocAligned<Voxel *>(nVoxels); memset(voxels, 0, nVoxels * sizeof(Voxel *)); // Add primitives to grid voxels for (u_int i = 0; i < primitives.size(); ++i) { // Find voxel extent of primitive BBox pb = primitives[i]->WorldBound(); int vmin[3], vmax[3]; for (int axis = 0; axis < 3; ++axis) { vmin[axis] = posToVoxel(pb.pMin, axis); vmax[axis] = posToVoxel(pb.pMax, axis); } // Add primitive to overlapping voxels PBRT_GRID_VOXELIZED_PRIMITIVE(vmin, vmax); for (int z = vmin[2]; z <= vmax[2]; ++z) for (int y = vmin[1]; y <= vmax[1]; ++y) for (int x = vmin[0]; x <= vmax[0]; ++x) { int o = offset(x, y, z); if (!voxels[o]) { // Allocate new voxel and store primitive in it voxels[o] = voxelArena.Alloc<Voxel>(); *voxels[o] = Voxel(primitives[i]); } else { // Add primitive to already-allocated voxel voxels[o]->AddPrimitive(primitives[i]); } } } PBRT_GRID_FINISHED_CONSTRUCTION(this); }