Skip to content

Commit

Permalink
voxel grid initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mlivesu committed Jan 13, 2025
1 parent 8a1e2c2 commit 553a31a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
23 changes: 23 additions & 0 deletions include/cinolib/voxel_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@
namespace cinolib
{

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CINO_INLINE
void voxel_grid_init( VoxelGrid & g,
const uint dim[3],
const AABB & bbox)
{
assert(g.voxels==nullptr);

g.dim[0] = dim[0];
g.dim[1] = dim[1];
g.dim[2] = dim[2];
g.bbox = bbox;

uint max_voxels_per_side = std::max(dim[0],std::max(dim[1],dim[2]));
g.len = g.bbox.delta().max_entry() / max_voxels_per_side;

uint size = dim[0]*dim[1]*dim[2];
g.voxels = new int[size](); // https://stackoverflow.com/questions/12553154/initial-value-of-dynamically-allocated-memory-in-c
}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CINO_INLINE
uint voxel_corner_index(const uint dim[3],
const uint ijk[3],
Expand Down
8 changes: 8 additions & 0 deletions include/cinolib/voxel_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@ enum
VOXEL_OUTSIDE = 0x00000001,
VOXEL_INSIDE = 0x00000010,
VOXEL_BOUNDARY = 0x00000100,
VOXEL_ANY = 0x11111111,
};

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CINO_INLINE
void voxel_grid_init( VoxelGrid & g,
const uint dim[3],
const AABB & bbox);

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CINO_INLINE
uint voxel_corner_index(const uint dim[3],
const uint ijk[3],
Expand Down
3 changes: 2 additions & 1 deletion include/cinolib/voxel_grid_to_hexmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ void voxel_grid_to_hexmesh(const VoxelGrid & g,
std::vector<int> vert_map(n_verts,-1); // to keep track of already existing vertices
for(uint id=0; id<n_voxel; ++id)
{
if(g.voxels[id] & voxel_types)
if(voxel_types==VOXEL_ANY || g.voxels[id] & voxel_types)
{

vec3u ijk = deserialize_3D_index(id,g.dim[1],g.dim[2]);

std::vector<uint> verts(8);
Expand Down

0 comments on commit 553a31a

Please sign in to comment.