From 71bc14b6dc503fc6e50b96a6df4d7961e8be9b24 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 17 Dec 2015 12:31:30 +0100 Subject: [PATCH] gmio_stl: API change in stl_io --- benchmarks/benchmark_assimp/main.cpp | 3 +-- benchmarks/benchmark_gmio/main.c | 3 +-- benchmarks/benchmark_opencascade/main.cpp | 5 ++--- src/gmio_stl/stl_io.c | 15 ++++++++----- src/gmio_stl/stl_io.h | 8 +++++-- src/gmio_stl/stl_rwargs.h | 3 --- tests/CMakeLists.txt | 2 ++ tests/test_stl_io.c | 27 ++++++++++++++--------- 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/benchmarks/benchmark_assimp/main.cpp b/benchmarks/benchmark_assimp/main.cpp index 4ecbc28..250e1d3 100644 --- a/benchmarks/benchmark_assimp/main.cpp +++ b/benchmarks/benchmark_assimp/main.cpp @@ -305,13 +305,12 @@ static void stl_write(const char* filepath, gmio_stl_format format) const aiMesh* sceneMesh = globalSceneHelper.scene->mMeshes[0]; gmio_stl_write_args write = {}; - write.format = format; write.mesh.cookie = sceneMesh; write.mesh.triangle_count = sceneMesh->mNumFaces; write.mesh.func_get_triangle = get_triangle; write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE; write.options.stla_float32_prec = 7; - const int error = gmio_stl_write_file(&write, filepath); + const int error = gmio_stl_write_file(&write, format, filepath); if (error != GMIO_ERROR_OK) printf("gmio error: 0x%X\n", error); } diff --git a/benchmarks/benchmark_gmio/main.c b/benchmarks/benchmark_gmio/main.c index 0934ecc..dd3ec84 100644 --- a/benchmarks/benchmark_gmio/main.c +++ b/benchmarks/benchmark_gmio/main.c @@ -130,14 +130,13 @@ static void stl_readwrite_flush_triangles(struct stl_readwrite_conv* rw_conv) { struct gmio_stl_write_args write = {0}; write.core = rw_conv->rwargs; - write.format = rw_conv->out_format; write.mesh.cookie = &rw_conv->triangle_array[0]; write.mesh.triangle_count = rw_conv->triangle_pos; write.mesh.func_get_triangle = &readwrite_get_triangle; write.options.stl_write_triangles_only = GMIO_TRUE; write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SCIENTIFIC_LOWERCASE; write.options.stla_float32_prec = 6; - gmio_stl_write(&write); + gmio_stl_write(&write, rw_conv->out_format); rw_conv->triangle_pos = 0; } diff --git a/benchmarks/benchmark_opencascade/main.cpp b/benchmarks/benchmark_opencascade/main.cpp index 63443a9..359fe2e 100644 --- a/benchmarks/benchmark_opencascade/main.cpp +++ b/benchmarks/benchmark_opencascade/main.cpp @@ -60,7 +60,7 @@ static void stl_read(const char* filepath) { stlMesh = new StlMesh_Mesh; gmio_stl_read_args read = {}; - args.mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh); + read.mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh); int error = gmio_stl_read_file(&read, filepath); if (error != GMIO_ERROR_OK) printf("gmio error: 0x%X\n", error); @@ -70,11 +70,10 @@ static void stl_write(const char* filepath, gmio_stl_format format) { const gmio_occ_stl_mesh_domain occ_mesh_domain(stlMesh); gmio_stl_write_args write = {}; - write.format = format; write.mesh = gmio_stl_occmesh(&occ_mesh_domain); write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE; write.options.stla_float32_prec = 7; - const int error = gmio_stl_write_file(&write, filepath); + const int error = gmio_stl_write_file(&write, format, filepath); if (error != GMIO_ERROR_OK) printf("gmio error: 0x%X\n", error); } diff --git a/src/gmio_stl/stl_io.c b/src/gmio_stl/stl_io.c index f3bf99f..6ecebbb 100644 --- a/src/gmio_stl/stl_io.c +++ b/src/gmio_stl/stl_io.c @@ -27,10 +27,10 @@ int gmio_stl_read(struct gmio_stl_read_args* args) { int error = GMIO_ERROR_OK; if (args != NULL) { - const enum gmio_stl_format stl_format = + const enum gmio_stl_format format = gmio_stl_get_format(&args->core.stream); - switch (stl_format) { + switch (format) { case GMIO_STL_FORMAT_ASCII: { error = gmio_stla_read(args); break; @@ -76,13 +76,14 @@ int gmio_stl_read_file( return error; } -int gmio_stl_write(struct gmio_stl_write_args* args) +int gmio_stl_write( + struct gmio_stl_write_args* args, enum gmio_stl_format format) { int error = GMIO_ERROR_OK; if (args != NULL) { struct gmio_memblock_helper mblock_helper = gmio_memblock_helper(&args->core.memblock); - switch (args->format) { + switch (format) { case GMIO_STL_FORMAT_ASCII: { error = gmio_stla_write(args); break; @@ -108,14 +109,16 @@ int gmio_stl_write(struct gmio_stl_write_args* args) } int gmio_stl_write_file( - struct gmio_stl_write_args* args, const char* filepath) + struct gmio_stl_write_args* args, + enum gmio_stl_format format, + const char* filepath) { int error = GMIO_ERROR_OK; if (args != NULL) { FILE* file = fopen(filepath, "wb"); if (file != NULL) { args->core.stream = gmio_stream_stdio(file); - error = gmio_stl_write(args); + error = gmio_stl_write(args, format); fclose(file); } else { diff --git a/src/gmio_stl/stl_io.h b/src/gmio_stl/stl_io.h index 70f1c82..218d291 100644 --- a/src/gmio_stl/stl_io.h +++ b/src/gmio_stl/stl_io.h @@ -70,7 +70,8 @@ int gmio_stlb_read( * \return Error code (see gmio_core/error.h and stl_error.h) */ GMIO_LIBSTL_EXPORT -int gmio_stl_write(struct gmio_stl_write_args* args); +int gmio_stl_write( + struct gmio_stl_write_args* args, enum gmio_stl_format format); /*! Writes STL mesh to stream * @@ -84,7 +85,10 @@ int gmio_stl_write(struct gmio_stl_write_args* args); * \return Error code (see gmio_core/error.h and stl_error.h) */ GMIO_LIBSTL_EXPORT -int gmio_stl_write_file(struct gmio_stl_write_args* args, const char* filepath); +int gmio_stl_write_file( + struct gmio_stl_write_args* args, + enum gmio_stl_format format, + const char* filepath); /*! Writes STL binary header data to stream * diff --git a/src/gmio_stl/stl_rwargs.h b/src/gmio_stl/stl_rwargs.h index 7ff7aa2..4f1cdf1 100644 --- a/src/gmio_stl/stl_rwargs.h +++ b/src/gmio_stl/stl_rwargs.h @@ -62,9 +62,6 @@ struct gmio_stl_write_args /*! Defines the mesh to output */ struct gmio_stl_mesh mesh; - /*! STL format of the output */ - enum gmio_stl_format format; - /*! Options for the write operation, can be safely set to \c {0} to use * default values */ struct gmio_stl_write_options options; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2b31ed6..ecbc0d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,6 +38,7 @@ if(GMIO_BUILD_SHARED_LIBS) # exports all symbols) set(GMIO_TEST_CORE_SRC ${GMIO_TEST_CORE_SRC} + ../src/gmio_core/internal/numeric_utils.c ../src/gmio_core/internal/stringstream.c) endif() @@ -59,6 +60,7 @@ if(GMIO_BUILD_SHARED_LIBS) # See Note_1 set(GMIO_TEST_STL_SRC ${GMIO_TEST_STL_SRC} + ../src/gmio_core/internal/numeric_utils.c ../src/gmio_stl/internal/stl_rw_common.c) endif() diff --git a/tests/test_stl_io.c b/tests/test_stl_io.c index 3d71c9a..a2ea3d5 100644 --- a/tests/test_stl_io.c +++ b/tests/test_stl_io.c @@ -245,13 +245,13 @@ const char* test_stlb_write() struct gmio_stl_write_args write = {0}; write.mesh = gmio_stl_data_mesh(&data); write.options.stlb_header_data = &data.header; - write.format = GMIO_STL_FORMAT_BINARY_LE; - error = gmio_stl_write_file(&write, model_filepath_out); + error = gmio_stl_write_file( + &write, GMIO_STL_FORMAT_BINARY_LE, model_filepath_out); UTEST_ASSERT(error == GMIO_ERROR_OK); /* Big-endian version */ - write.format = GMIO_STL_FORMAT_BINARY_BE; - error = gmio_stl_write_file(&write, model_filepath_out_be); + error = gmio_stl_write_file( + &write, GMIO_STL_FORMAT_BINARY_BE, model_filepath_out_be); } /* Check input and output models are equal */ @@ -324,13 +324,14 @@ const char* test_stla_write() /* Write the model to STL ascii format */ { struct gmio_stl_write_args write = {0}; - write.format = GMIO_STL_FORMAT_ASCII; write.mesh = gmio_stl_data_mesh(&data); gmio_stlb_header_to_printable_string(&data.header, &header_str[0], '_'); write.options.stla_solid_name = &header_str[0]; write.options.stla_float32_prec = 7; - write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE; - error = gmio_stl_write_file(&write, model_filepath_out); + write.options.stla_float32_format = + GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE; + error = gmio_stl_write_file( + &write, GMIO_STL_FORMAT_ASCII, model_filepath_out); UTEST_ASSERT(error == GMIO_ERROR_OK); } @@ -382,9 +383,13 @@ void generate_stlb_tests_models() data.tri_array.count = 1; write.mesh = gmio_stl_data_mesh(&data); - write.format = GMIO_STL_FORMAT_BINARY_LE; - gmio_stl_write_file(&write, "models/solid_one_facet.le_stlb"); - write.format = GMIO_STL_FORMAT_BINARY_BE; - gmio_stl_write_file(&write, "models/solid_one_facet.be_stlb"); + gmio_stl_write_file( + &write, + GMIO_STL_FORMAT_BINARY_LE, + "models/solid_one_facet.le_stlb"); + gmio_stl_write_file( + &write, + GMIO_STL_FORMAT_BINARY_BE, + "models/solid_one_facet.be_stlb"); } }