Skip to content

Commit

Permalink
feat: add create polyline example
Browse files Browse the repository at this point in the history
  • Loading branch information
lbinria committed Jul 8, 2024
1 parent 055eba9 commit fbf6c2e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12...3.26)

project( playground LANGUAGES C CXX )
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
Expand All @@ -24,7 +24,7 @@ include(FetchContent)
FetchContent_Declare(
ultimaille
GIT_REPOSITORY https://github.com/ssloy/ultimaille
GIT_TAG v1.0.0
GIT_TAG v1.1.1
)
FetchContent_MakeAvailable(ultimaille)
include_directories(${ultimaille_SOURCE_DIR})
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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)
add_executable(create_polyline create_polyline.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 @@ -37,6 +38,7 @@ target_link_libraries(create_tri_mesh ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${Ope
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>)
target_link_libraries(create_polyline ${CMAKE_DL_LIBS} ultimaille $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)

IF (NOT WIN32)
target_link_libraries(hello m)
Expand All @@ -54,6 +56,7 @@ IF (NOT WIN32)
target_link_libraries(algebra m)
target_link_libraries(create_volume_mesh m)
target_link_libraries(quad_subdivision m)
target_link_libraries(create_polyline m)
ENDIF()

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


using namespace UM;

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

// --- LOAD ---

// Declare a polyline
PolyLine p;

// --- CREATE ---

// Create 3 points in polyline
p.points.create_points(3);
p.points[0] = {0,0,0};
p.points[1] = {1,0,0};
p.points[2] = {1,1,0};

// Create edges
p.create_edges(2);

// Link segment 0 with point 0
p.vert(0, 0) = 0;
// Link segment 0 with point 1
p.vert(0, 1) = 1;
// Link segment 1 with point 0
p.vert(1, 0) = 0;
// ...
p.vert(1, 1) = 2;

EdgeAttribute<int> edge_attr(p);

edge_attr[0] = 0;
edge_attr[1] = 1;

// --- SAVE ---

// Save mesh
write_by_extension("simple_polyline.geogram", p, {{}, {{"my_edge_attr", edge_attr.ptr}}});

// --- END ---

// --- RUN ---

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

return 0;
}

0 comments on commit fbf6c2e

Please sign in to comment.