Add target for "examples"

This commit is contained in:
Hugues Delorme 2016-03-07 17:48:33 +01:00
parent b6c9518e97
commit f99983b3fa
9 changed files with 72 additions and 15 deletions

View File

@ -61,6 +61,7 @@ cmake_dependent_option(
cmake_dependent_option(
GMIO_BUILD_BENCHMARK_OPENCASCADE "Build benchmark for OpenCascade" ON
"GMIO_BUILD_BENCHMARKS" OFF)
option(GMIO_BUILD_EXAMPLES "Build gmio examples" OFF)
option(GMIO_BUILD_TESTS_FAKE_SUPPORT "Build tests/fake_support target" OFF)
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
option(GMIO_BUILD_TESTS_COVERAGE "Instrument testing code with code coverage" OFF)
@ -279,6 +280,9 @@ add_subdirectory(doc)
if(GMIO_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(GMIO_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Examples:
# cmake -DCMAKE_INSTALL_PREFIX=gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=_d

38
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,38 @@
#############################################################################
## gmio
## Copyright Fougue (2 Mar. 2015)
## contact@fougue.pro
##
## This software is a reusable library whose purpose is to provide complete
## I/O support for various CAD file formats (eg. STL)
##
## This software is governed by the CeCILL-B license under French law and
## abiding by the rules of distribution of free software. You can use,
## modify and/ or redistribute the software under the terms of the CeCILL-B
## license as circulated by CEA, CNRS and INRIA at the following URL
## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
#############################################################################
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For cmake generated headers
include_directories(${CMAKE_SOURCE_DIR}/tests/fake_support/opencascade)
link_libraries(gmio)
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
link_libraries(m) # -lm
endif()
file(GLOB SUPPORT_STL_OCC_FILES ${CMAKE_SOURCE_DIR}/src/gmio_support/stl_occ.*)
set(SUPPORT_STL_OCC_FILES_FILES ${SUPPORT_STL_OCC_FILES_FILES})
# gmio OpenCascade/STL support
add_executable(occstl_read_file
occstl_read_file.cpp ${SUPPORT_STL_OCC_FILES})
add_executable(occstl_write_file
occstl_write_file.cpp ${SUPPORT_STL_OCC_FILES})
add_executable(occstl_redefine_mesh_creator
occstl_redefine_mesh_creator.cpp ${SUPPORT_STL_OCC_FILES})
# gmio STL
add_executable(stl_get_infos stl_get_infos.c)
add_executable(stl_read_file stl_read_file.c)
add_executable(stl_write_file stl_write_file.c)

View File

@ -16,6 +16,7 @@
#include <gmio_core/error.h>
#include <gmio_stl/stl_io.h>
#include <gmio_support/stl_occ.h>
#include <StlMesh_Mesh.hxx>
#include <iostream>
int main(int argc, char** argv)

View File

@ -7,6 +7,7 @@
#include <gmio_core/error.h>
#include <gmio_stl/stl_io.h>
#include <gmio_support/stl_occ.h>
#include <StlMesh_Mesh.hxx>
#include <iostream>
// Redefine func_begin_solid of some gmio_stl_mesh_creator object

View File

@ -15,6 +15,7 @@
#include <gmio_core/error.h>
#include <gmio_stl/stl_io.h>
#include <gmio_support/stl_occ.h>
#include <StlMesh_Mesh.hxx>
#include <iostream>
int main(int argc, char** argv)

View File

@ -27,15 +27,14 @@ static const char* gmio_stl_format_to_str(enum gmio_stl_format format)
case GMIO_STL_FORMAT_BINARY_LE: return "STL BINARY LITTLE-ENDIAN";
case GMIO_STL_FORMAT_BINARY_BE: return "STL BINARY BIG-ENDIAN";
}
return NULL;
}
static void print_stl_infos(const struct gmio_stl_infos* infos)
{
printf("File: %s\n"
"Format: %s\n"
printf("Format: %s\n"
"Size: %uKo\n"
"Facets: %u\n",
filepath,
gmio_stl_format_to_str(infos->format),
infos->size / 1024,
infos->facet_count);
@ -66,6 +65,7 @@ int main(int argc, char** argv)
/* Retrieve STL informations */
error = gmio_stl_infos_get(
&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL);
printf("File: %s\n", filepath);
if (error == GMIO_ERROR_OK)
print_stl_infos(&infos);
else

View File

@ -63,10 +63,11 @@ static void my_3d_mesh__copy_triangle(
{ /* Copy new triangle */
struct my_3d_triangle* my_tri = &my_mesh->triangle_array[triangle_id];
const struct gmio_stl_coords* tri_vertices = &triangle->v1;
for (int i = 0; i < 3; ++i) {
my_tri->vertex[i][0] = tri_vertices[i].x;
my_tri->vertex[i][1] = tri_vertices[i].y;
my_tri->vertex[i][2] = tri_vertices[i].z;
int i;
for (i = 0; i < 3; ++i) {
my_tri->vertex[i].coords[0] = tri_vertices[i].x;
my_tri->vertex[i].coords[1] = tri_vertices[i].y;
my_tri->vertex[i].coords[2] = tri_vertices[i].z;
}
}
my_mesh->triangle_array_count = triangle_id + 1;
@ -87,9 +88,9 @@ int main(int argc, char** argv)
/* -- Cookie object passed to callbacks of gmio_stl_mesh_creator */
mesh_creator.cookie = &my_mesh;
/* -- Function called initially at the beginning of a STL solid(mesh) */
mesh_creator.func_begin_solid = &my_stl_mesh__begin_solid;
mesh_creator.func_begin_solid = my_3d_mesh__begin_solid;
/* -- Function called for each triangle in the STL mesh */
mesh_creator.func_add_triangle = &my_stl_mesh__copy_triangle;
mesh_creator.func_add_triangle = my_3d_mesh__copy_triangle;
/* Read, using default options(NULL) */
error = gmio_stl_read_file(filepath, &mesh_creator, NULL);

View File

@ -15,6 +15,7 @@
#include <gmio_core/error.h>
#include <gmio_stl/stl_io.h>
#include <stdio.h>
#include <stdlib.h>
#include "3d_mesh.h"
/* Callback invoked sequentially for each triangle in the STL mesh
@ -25,10 +26,11 @@ static void my_3d_mesh__get_triangle(
const struct my_3d_mesh* my_mesh = (const struct my_3d_mesh*)cookie;
const struct my_3d_triangle* my_tri = &my_mesh->triangle_array[tri_id];
struct gmio_stl_coords* tri_vertices = &triangle->v1;
for (int i = 0; i < 3; ++i) {
tri_vertices[i].x = my_tri[i][0];
tri_vertices[i].y = my_tri[i][1];
tri_vertices[i].z = my_tri[i][2];
int i;
for (i = 0; i < 3; ++i) {
tri_vertices[i].x = my_tri->vertex[i].coords[0];
tri_vertices[i].y = my_tri->vertex[i].coords[1];
tri_vertices[i].z = my_tri->vertex[i].coords[2];
}
gmio_stl_triangle_compute_normal(triangle);
}
@ -51,9 +53,9 @@ int main(int argc, char** argv)
/* -- Cookie object passed to callbacks of gmio_stl_mesh */
mesh.cookie = &my_mesh;
/* -- Count of triangles in the mesh */
mesh.triangle_count = my_mesh.facet_count;
mesh.triangle_count = my_mesh.triangle_array_count;
/* -- Pointer on a function that retrieves a triangle from the mesh */
mesh.func_get_triangle = &my_3d_mesh__get_triangle;
mesh.func_get_triangle = my_3d_mesh__get_triangle;
/* Write binary STL little-endian, using default options(NULL) */
error = gmio_stl_write_file(

View File

@ -8,6 +8,15 @@ class StlMesh_Mesh;
class Handle_StlMesh_Mesh
{
public:
Handle_StlMesh_Mesh()
{ }
Handle_StlMesh_Mesh(const Handle_StlMesh_Mesh&)
{ }
Handle_StlMesh_Mesh(const StlMesh_Mesh*)
{ }
StlMesh_Mesh* operator->() const
{ return NULL; }