Browse Source

add voxel expand

master
lab pc 3 years ago
parent
commit
68ead4a90f
  1. 3
      include/Octree/voxel/SolidVoxelBuilder.h
  2. 8
      include/Octree/voxel/Voxel.h
  3. 7
      src/voxel/SolidVoxelBuilder.cpp
  4. 6
      src/voxel/SurfaceVoxelBuilder.cpp
  5. 28
      src/voxel/Voxel.cpp

3
include/Octree/voxel/SolidVoxelBuilder.h

@ -14,7 +14,10 @@
namespace Octree {
class SolidVoxelBuilder {
public:
explicit SolidVoxelBuilder(const Voxel& surfVoxel);
void build(Voxel& solidVoxel);
};
}

8
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<bool> voxels;
int expand;
public:
Voxel() = default;
Voxel(int _x, int _y, int _z);
Voxel(const std::vector<bool> &value, int _x, int _y, int _z);
Voxel(int _x, int _y, int _z, int expand=0);
Voxel(const std::vector<bool> &value, int _x, int _y, int _z, int expand=0);
void create_voxels(int _x, int _y, int _z, int expand=0);
public:
/**

7
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) {
}

6
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<bool>(_x * _y * _z, false);
voxel.create_voxels(_x, _y, _z, 1);
BOOST_LOG_TRIVIAL(debug) << "Voxel size: " << _x << " " << _y << " " << _z;

28
src/voxel/Voxel.cpp

@ -9,16 +9,36 @@
#include "Octree/voxel/Voxel.h"
Octree::Voxel::Voxel(const std::vector<bool> &value, int _x, int _y, int _z): voxels(value), _x(_x), _y(_y), _z(_z) {
Octree::Voxel::Voxel(const std::vector<bool> &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<bool>(_x * _y * _z, false), _x, _y, _z) {
Octree::Voxel::Voxel(int _x, int _y, int _z, int expand) :
Voxel(std::vector<bool>((_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<bool>(_x_exp * _y_exp * _z_exp, false);
}

Loading…
Cancel
Save