BBox Triangle::get_bbox() const { // TODO: // Compute the bounding box of the triangle. BBox bb; bb.expand(mesh->positions[v1]); bb.expand(mesh->positions[v2]); bb.expand(mesh->positions[v3]); return bb; }
BVHAccel::BVHAccel(const std::vector<Primitive *> &_primitives, size_t max_leaf_size) { this->primitives = _primitives; // edge case if (primitives.empty()) { return; } // calculate root AABB size BBox bb; for (size_t i = 0; i < primitives.size(); ++i) { bb.expand(primitives[i]->get_bbox()); } root = new BVHNode(bb, 0, primitives.size()); // calculate morton code for each primitives for (size_t i = 0; i < primitives.size(); ++i) { unsigned int morton_code = morton3D(bb.getUnitcubePosOf(primitives[i]->get_bbox().centroid())); primitives[i]->morton_code = morton_code; } // sort primitives using morton code std::sort(primitives.begin(), primitives.end(), mortonCompare); //construct BVH based on the mortan code constructBVH(root); }
void CPUFontBase::bbox(const wchar_t * wstr, BBox & bbox) { if(wstr && (*wstr != wchar_t('\0'))) { #ifndef WIN32 const unsigned wchar_t * wc = (const unsigned wchar_t *)wstr; #else const wchar_t * wc = (const wchar_t *)wstr; #endif float advance = 0.f; if(checkGlyph(*wc)) { bbox = m_glyphList->bbox(*wc); advance = m_glyphList->advance(*wc, *(wc + 1)); } while(*++wc) { if(checkGlyph(*wc)) { BBox tempBBox = m_glyphList->bbox(*wc); tempBBox.move(Nimble::Vector2(advance, 0.0f)); bbox.expand(tempBBox); advance += m_glyphList->advance(*wc, *(wc + 1)); } } } }
BBox Scene::get_bbox() { BBox bbox; for (SceneObject *obj : objects) { bbox.expand(obj->get_bbox()); } return bbox; }
/** * generate bounding box */ BBox BVHAccel::generate_bounding_box(int start, int span) { BBox bb; for (size_t i = start; i < start + span; ++i) { bb.expand(primitives[i]->get_bbox()); } return bb; }
BVHAccel::BVHAccel(const std::vector<Primitive *> &_primitives, size_t max_leaf_size) { this->primitives = _primitives; // edge case if (primitives.empty()) { return; } // calculate root AABB size BBox bb; for (size_t i = 0; i < primitives.size(); ++i) { bb.expand(primitives[i]->get_bbox()); } root = new BVHNode(bb, 0, primitives.size()); // calculate morton code for each primitives for (size_t i = 0; i < primitives.size(); ++i) { unsigned int morton_code = morton3D(bb.getUnitcubePosOf(primitives[i]->get_bbox().centroid())); primitives[i]->morton_code = morton_code; } // sort primitives using morton code std::sort(primitives.begin(), primitives.end(), mortonCompare); // extract bboxes array std::vector<BBox> bboxes(primitives.size()); for(int i=0; i<primitives.size(); i++) bboxes[i] = primitives[i]->get_bbox(); // extract sorted morton code for parallel binary radix tree construction unsigned int sorted_morton_codes[primitives.size()]; for (size_t i = 0; i < primitives.size(); ++i) { sorted_morton_codes[i] = primitives[i]->morton_code; } // delegate the binary radix tree construction process to GPU cout << "start building parallel brtree" << endl; ParallelBRTreeBuilder builder(sorted_morton_codes, &bboxes[0], primitives.size()); builder.build(); cout << "done." << endl; leaf_nodes = builder.get_leaf_nodes(); internal_nodes = builder.get_internal_nodes(); builder.freeDeviceMemory(); // construct BVH based on Binary Radix Tree constructBVHFromBRTree(); // free the host memory because I am a good programmer builder.freeHostMemory(); }
void test_bbox() { dgd_start_scope( geom, "test_bbox()" ); BBox bbox; dgd_echo( dgd_expand(bbox) << std::endl ); bbox.expand( Vector( 1, 1, 1 ) ); dgd_echo( dgd_expand(bbox) << std::endl ); bbox.expand( Vector( 1, -1, 1 ) ); dgd_echo( dgd_expand(bbox) << std::endl ); bbox.expand( Vector( -1, -1, -1 ) ); dgd_echo( dgd_expand(bbox) << std::endl ); dgd_end_scope( geom ); }
void Mesh::setupCells() { double root = 3.0 * pow(faces.size(), 1.0 / 3.0); double voxelsPerUnit = root / bbox.maxExtent(); nx = (int) clamp(round(bbox.wx * voxelsPerUnit), 0, 32) + 1; ny = (int) clamp(round(bbox.wy * voxelsPerUnit), 0, 32) + 1; nz = (int) clamp(round(bbox.wz * voxelsPerUnit), 0, 32) + 1; numCells = nx * ny * nz; voxels = new Voxel*[numCells]; memset(voxels, 0, sizeof(Voxel*) * numCells); for(FaceIter it = faces.begin(), end = faces.end(); it != end; ++it) { BBox fbox; fbox.expand(*points[(*it)->vertIdxs[0]]); fbox.expand(*points[(*it)->vertIdxs[1]]); fbox.expand(*points[(*it)->vertIdxs[2]]); int ixmin = (int) clamp((fbox.x0 - bbox.x0) * nx / bbox.wx, 0, nx - 1); int iymin = (int) clamp((fbox.y0 - bbox.y0) * ny / bbox.wy, 0, ny - 1); int izmin = (int) clamp((fbox.z0 - bbox.z0) * nz / bbox.wz, 0, nz - 1); int ixmax = (int) clamp((fbox.x1 - bbox.x0) * nx / bbox.wx, 0, nx - 1); int iymax = (int) clamp((fbox.y1 - bbox.y0) * ny / bbox.wy, 0, ny - 1); int izmax = (int) clamp((fbox.z1 - bbox.z0) * nz / bbox.wz, 0, nz - 1); // add the object to the cells for(int iz = izmin; iz <= izmax; iz++) { for(int iy = iymin; iy <= iymax; iy++) { for(int ix = ixmin; ix <= ixmax; ix++) { int index = ix + nx * iy + nx * ny * iz; if(voxels[index] == NULL) { voxels[index] = new Voxel(); } voxels[index]->add(*it); } } } } }
/// @todo check the bbox calculations, there seems to be some error here void CPUFontBase::bbox(const char * str, BBox & bbox) { if(str && (*str != '\0')) { const unsigned char * c = (unsigned char *)str; float advance = 0.f; if(checkGlyph(*c)) { bbox = m_glyphList->bbox(*c); advance = m_glyphList->advance(*c, *(c + 1)); } while(*++c) { if(checkGlyph(*c)) { BBox tempBBox = m_glyphList->bbox(*c); tempBBox.move(Nimble::Vector2(advance, 0.f)); bbox.expand(tempBBox); advance += m_glyphList->advance(*c, *(c + 1)); } } } }