From 68ead4a90f5786c0797868b0163c8a7713432188 Mon Sep 17 00:00:00 2001 From: lab pc Date: Sun, 27 Feb 2022 11:26:39 +0800 Subject: [PATCH] add voxel expand --- include/Octree/voxel/SolidVoxelBuilder.h | 3 +++ include/Octree/voxel/Voxel.h | 8 +++++-- src/voxel/SolidVoxelBuilder.cpp | 7 ++++++ src/voxel/SurfaceVoxelBuilder.cpp | 6 +---- src/voxel/Voxel.cpp | 28 ++++++++++++++++++++---- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/Octree/voxel/SolidVoxelBuilder.h b/include/Octree/voxel/SolidVoxelBuilder.h index a47dda4..def3049 100644 --- a/include/Octree/voxel/SolidVoxelBuilder.h +++ b/include/Octree/voxel/SolidVoxelBuilder.h @@ -14,7 +14,10 @@ namespace Octree { class SolidVoxelBuilder { +public: + explicit SolidVoxelBuilder(const Voxel& surfVoxel); + void build(Voxel& solidVoxel); }; } diff --git a/include/Octree/voxel/Voxel.h b/include/Octree/voxel/Voxel.h index 81fc776..39d17bc 100644 --- a/include/Octree/voxel/Voxel.h +++ b/include/Octree/voxel/Voxel.h @@ -18,12 +18,16 @@ class Voxel { public: AABB aabb; int _x, _y, _z; + int _x_exp, _y_exp, _z_exp; std::vector voxels; + int expand; public: Voxel() = default; - Voxel(int _x, int _y, int _z); - Voxel(const std::vector &value, int _x, int _y, int _z); + Voxel(int _x, int _y, int _z, int expand=0); + Voxel(const std::vector &value, int _x, int _y, int _z, int expand=0); + + void create_voxels(int _x, int _y, int _z, int expand=0); public: /** diff --git a/src/voxel/SolidVoxelBuilder.cpp b/src/voxel/SolidVoxelBuilder.cpp index 98566e9..67d6428 100644 --- a/src/voxel/SolidVoxelBuilder.cpp +++ b/src/voxel/SolidVoxelBuilder.cpp @@ -8,3 +8,10 @@ **/ #include "Octree/voxel/SolidVoxelBuilder.h" +Octree::SolidVoxelBuilder::SolidVoxelBuilder(const Octree::Voxel &voxel) { + +} + +void Octree::SolidVoxelBuilder::build(Octree::Voxel &solidVoxel) { + +} diff --git a/src/voxel/SurfaceVoxelBuilder.cpp b/src/voxel/SurfaceVoxelBuilder.cpp index a6fe438..c147be9 100644 --- a/src/voxel/SurfaceVoxelBuilder.cpp +++ b/src/voxel/SurfaceVoxelBuilder.cpp @@ -19,12 +19,8 @@ Octree::SurfaceVoxelBuilder::SurfaceVoxelBuilder(BaseOctree &octree, } 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(_x * _y * _z, false); + voxel.create_voxels(_x, _y, _z, 1); BOOST_LOG_TRIVIAL(debug) << "Voxel size: " << _x << " " << _y << " " << _z; diff --git a/src/voxel/Voxel.cpp b/src/voxel/Voxel.cpp index 46c9933..70768f3 100644 --- a/src/voxel/Voxel.cpp +++ b/src/voxel/Voxel.cpp @@ -9,16 +9,36 @@ #include "Octree/voxel/Voxel.h" -Octree::Voxel::Voxel(const std::vector &value, int _x, int _y, int _z): voxels(value), _x(_x), _y(_y), _z(_z) { +Octree::Voxel::Voxel(const std::vector &value, int _x, int _y, int _z, int expand) + : voxels(value), _x(_x), _y(_y), _z(_z), expand(expand), _x_exp(_x + 2 * expand), _y_exp(_y + 2 * expand), _z_exp(_z + 2 * expand) { } -Octree::Voxel::Voxel(int _x, int _y, int _z): Voxel(std::vector(_x * _y * _z, false), _x, _y, _z) { +Octree::Voxel::Voxel(int _x, int _y, int _z, int expand) : + Voxel(std::vector((_x + 2 * expand) * (_y + 2 * expand) * (+2 * expand), false), + _x, _y, _z, expand) { } + int Octree::Voxel::id_at(int x, int y, int z) const { - return ((z * _y) + y) * _x + x; + x += expand; + y += expand; + z += expand; + + return ((z * _y_exp) + y) * _x_exp + x; +// return ((z * _y) + y) * _x + x; } bool Octree::Voxel::at(int x, int y, int z) const { - return voxels[id_at(x,y,z)]; + return voxels[id_at(x, y, z)]; +} + +void Octree::Voxel::create_voxels(int _x, int _y, int _z, int expand) { + this->_x = _x; + this->_y = _y; + this->_z = _z; + this->_x_exp = _x + 2 * expand; + this->_y_exp = _y + 2 * expand; + this->_z_exp = _z + 2 * expand; + this->expand = expand; + voxels = std::vector(_x_exp * _y_exp * _z_exp, false); }