Skip to content

Commit

Permalink
Add create volume example showing how to create a hex volume
Browse files Browse the repository at this point in the history
  • Loading branch information
lbinria committed Jan 4, 2024
1 parent 46f4d08 commit b25ac1a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_executable(create_fill_attributes create_fill_attributes.cpp)
add_executable(create_tri_mesh create_tri_mesh.cpp)
add_executable(edit_mesh edit_mesh.cpp)
add_executable(algebra algebra.cpp)
add_executable(create_volume_mesh create_volume_mesh.cpp)

target_link_libraries(hello ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
target_link_libraries(vertex_distances ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
Expand All @@ -33,6 +34,7 @@ target_link_libraries(create_fill_attributes ${CMAKE_DL_LIBS} ultimaille $<$<BO
target_link_libraries(create_tri_mesh ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
target_link_libraries(edit_mesh ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
target_link_libraries(algebra ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
target_link_libraries(create_volume_mesh ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)

IF (NOT WIN32)
target_link_libraries(hello m)
Expand All @@ -48,6 +50,7 @@ IF (NOT WIN32)
target_link_libraries(create_tri_mesh m)
target_link_libraries(edit_mesh m)
target_link_libraries(algebra m)
target_link_libraries(create_volume_mesh m)
ENDIF()

# Copy asset files to build directory
Expand Down
64 changes: 64 additions & 0 deletions examples/create_volume_mesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* This example shows how to create tet/hex volumetric mesh from scratch
*/
#include "helpers.h"
#include <ultimaille/all.h>


using namespace UM;

int main(int argc, char** argv) {

// --- LOAD ---

// Declare a mesh with hex cells
Hexahedra m;

// --- CREATE ---

// Create and place 8 points
// /!\ There is a vertex numbering convention (https://github.com/ultimaille/ultimaille/tree/master/notes/mesh_vertex_numbering_convention.pdf),
// it gives a specific order of vertex to be able to rely them correctly
// Here, this order is given by following points declaration
// Therefore, we just have to associate vertex i with point i (m.vert(0,i) = i)
// Note that we could have declared them in any order, but if we did, we'd have to link them in the right order
m.points.create_points(8);
m.points[0] = vec3(-0.5,-0.5,-0.5);
m.points[1] = vec3(0.5,-0.5,-0.5);
m.points[2] = vec3(-0.5,0.5,-0.5);
m.points[3] = vec3(0.5,0.5,-0.5);
m.points[4] = vec3(-0.5,-0.5,0.5);
m.points[5] = vec3(0.5,-0.5,0.5);
m.points[6] = vec3(-0.5,0.5,0.5);
m.points[7] = vec3(0.5,0.5,0.5);

// Create 1 cell
m.create_cells(1);
// Link cell 0, vertex 0 with point 0
m.vert(0, 0) = 0;
// Link cell 0, vertex 1 with point 1
m.vert(0, 1) = 1;
// ...
m.vert(0, 2) = 2;
m.vert(0, 3) = 3;
m.vert(0, 4) = 4;
m.vert(0, 5) = 5;
m.vert(0, 6) = 6;
m.vert(0, 7) = 7;

// --- SAVE ---

// Save mesh
write_by_extension("hex_mesh.geogram", m, {{}, {}, {}});

// --- END ---

// --- RUN ---

#ifdef _WIN32
// Open the generated mesh with Graphite
int result = system((getGraphitePath() + " hex_mesh.geogram").c_str());
#endif

return 0;
}

0 comments on commit b25ac1a

Please sign in to comment.