mirror of https://github.com/wpkong/Octree.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.3 KiB
61 lines
2.3 KiB
3 years ago
|
/**
|
||
|
* ------------------------------------
|
||
|
* @author: Weipeng Kong
|
||
|
* @date: 2022/2/23
|
||
|
* @email: yjxkwp\@foxmail.com
|
||
|
* @description:
|
||
|
* ------------------------------------
|
||
|
**/
|
||
|
|
||
|
#include "Octree/voxel/SurfaceVoxelBuilder.h"
|
||
|
#include "Octree/voxel/Voxel.h"
|
||
|
#include <queue>
|
||
|
|
||
|
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._x = _x;
|
||
|
voxel._y = _y;
|
||
|
voxel._z = _z;
|
||
|
voxel.aabb = aabb;
|
||
|
voxel.voxels.clear();
|
||
|
voxel.voxels = std::vector<bool>(_x * _y * _z, false);
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|