Skip to content

Commit

Permalink
grid mesh also for volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlivesu committed Jul 2, 2024
1 parent c1c1035 commit ded3213
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
53 changes: 40 additions & 13 deletions include/cinolib/grid_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,53 @@ namespace cinolib

template<class M, class V, class E, class P>
CINO_INLINE
void grid_mesh(const uint quads_per_row,
const uint quads_per_col,
Quadmesh<M,V,E,P> & m)
void grid_mesh(const uint nx, const uint ny, Quadmesh<M,V,E,P> & m)
{
std::vector<vec3d> points;
std::vector<vec3d> verts;
std::vector<uint> polys;
for(uint r=0; r<=quads_per_row; ++r)
for(uint c=0; c<=quads_per_col; ++c)
for(uint x=0; x<=nx; ++x)
for(uint y=0; y<=ny; ++y)
{
points.push_back(vec3d(c,r,0));
verts.push_back(vec3d(x,y,0));

if (r<quads_per_row && c<quads_per_col)
if(x<nx && y<ny)
{
polys.push_back(serialize_2D_index(r , c, quads_per_col+1));
polys.push_back(serialize_2D_index(r , c+1, quads_per_col+1));
polys.push_back(serialize_2D_index(r+1, c+1, quads_per_col+1));
polys.push_back(serialize_2D_index(r+1, c, quads_per_col+1));
polys.push_back(serialize_2D_index(x , y, ny+1));
polys.push_back(serialize_2D_index(x , y+1, ny+1));
polys.push_back(serialize_2D_index(x+1, y+1, ny+1));
polys.push_back(serialize_2D_index(x+1, y, ny+1));
}
}
m = Quadmesh<M,V,E,P>(points, polys);
m = Quadmesh<M,V,E,P>(verts, polys);
}

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

template<class M, class V, class E, class F, class P>
CINO_INLINE
void grid_mesh(const uint nx, const uint ny, const uint nz, Hexmesh<M,V,E,F,P> & m)
{
std::vector<vec3d> verts;
std::vector<uint> polys;
for(uint x=0; x<=nx; ++x)
for(uint y=0; y<=ny; ++y)
for(uint z=0; z<=nz; ++z)
{
verts.push_back(vec3d(x,y,z));

if(x<nx && y<ny && z<nz)
{
polys.push_back(serialize_3D_index(x , y, z , ny+1, nz+1));
polys.push_back(serialize_3D_index(x , y+1, z , ny+1, nz+1));
polys.push_back(serialize_3D_index(x+1, y+1, z , ny+1, nz+1));
polys.push_back(serialize_3D_index(x+1, y, z , ny+1, nz+1));
polys.push_back(serialize_3D_index(x , y, z+1, ny+1, nz+1));
polys.push_back(serialize_3D_index(x , y+1, z+1, ny+1, nz+1));
polys.push_back(serialize_3D_index(x+1, y+1, z+1, ny+1, nz+1));
polys.push_back(serialize_3D_index(x+1, y, z+1, ny+1, nz+1));
}
}
m = Hexmesh<M,V,E,F,P>(verts, polys);
}

}
11 changes: 8 additions & 3 deletions include/cinolib/grid_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <sys/types.h>
#include <cinolib/cino_inline.h>
#include <cinolib/meshes/quadmesh.h>
#include <cinolib/meshes/hexmesh.h>

namespace cinolib
{
Expand All @@ -47,9 +48,13 @@ namespace cinolib

template<class M, class V, class E, class P>
CINO_INLINE
void grid_mesh(const uint quads_per_row,
const uint quads_per_col,
Quadmesh<M,V,E,P> & m);
void grid_mesh(const uint nx, const uint ny, Quadmesh<M,V,E,P> & m);

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

template<class M, class V, class E, class F, class P>
CINO_INLINE
void grid_mesh(const uint nx, const uint ny, const uint nz, Hexmesh<M,V,E,F,P> & m);

}

Expand Down

0 comments on commit ded3213

Please sign in to comment.