/** * ------------------------------------ * @author: Weipeng Kong * @date: 2022/2/23 * @email: yjxkwp\@foxmail.com * @description: * ------------------------------------ **/ #include "Octree/voxel/SurfaceVoxelBuilder.h" #include "Octree/voxel/Voxel.h" #include Octree::SurfaceVoxelBuilder::SurfaceVoxelBuilder(BaseOctree &octree, const pMesh::Triangle3dMesh<> &mesh, double block_size) : block_size(block_size), octree(octree), mesh(mesh) { aabb = AABB::ToIntegerSizeAABB(octree.aabb(), block_size, _x, _y, _z); } void Octree::SurfaceVoxelBuilder::build(Octree::Voxel &voxel) { voxel.aabb = aabb; voxel.create_voxels(_x, _y, _z, 1); BOOST_LOG_TRIVIAL(debug) << "Voxel size: " << _x << " " << _y << " " << _z; for (int i = 0; i < _x; ++i) { double base_x = this->aabb.min().x() + i * block_size; for (int j = 0; j < _y; ++j) { double base_y = this->aabb.min().y() + j * block_size; for (int k = 0; k < _z; ++k) { double base_z = this->aabb.min().z() + k * block_size; AABB vox({base_x, base_y, base_z}, {base_x + block_size, base_y + block_size, base_z + block_size}); auto candidates_vox = octree.map_voxel(vox); bool exit_flag = false; for (auto candidate : candidates_vox) { for (uint32_t tid : candidate->tri_ids) { const pMesh::Triangle3dMesh<>::Face &face = mesh.faces[tid].attr; if (vox.intersect_triangle(mesh.vertices[face.vertices[0].id()].attr.coordinate, mesh.vertices[face.vertices[1].id()].attr.coordinate, mesh.vertices[face.vertices[2].id()].attr.coordinate)) { voxel.voxels[voxel.id_at(i, j, k)] = true; exit_flag = true; break; } } if(exit_flag) { break; } } } } } }