From ae8213446309a1e1b37f30cc8f8fe546cdf4b71a Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Mon, 30 Mar 2015 09:30:55 +0200 Subject: [PATCH] gmio_stl: simplify options in stl_io.h --- benchs/bench_assimp/main.cpp | 2 +- benchs/bench_occ/main.cpp | 3 +- src/gmio_stl/stl_io.c | 12 +++--- src/gmio_stl/stl_io.h | 74 ++++++++++++++---------------------- src/gmio_stl/stla_read.c | 6 +-- src/gmio_stl/stlb_read.c | 4 +- 6 files changed, 38 insertions(+), 63 deletions(-) diff --git a/benchs/bench_assimp/main.cpp b/benchs/bench_assimp/main.cpp index ed60d9e..a46122d 100644 --- a/benchs/bench_assimp/main.cpp +++ b/benchs/bench_assimp/main.cpp @@ -155,7 +155,7 @@ static void bench_gmio_stl_read(const char* filepath) mesh_creator.add_triangle_func = gmio_assimp_add_triangle; mesh_creator.end_solid_func = gmio_assimp_end_solid; - int error = gmio_stl_read_file(filepath, &mesh_creator, &buffer); + int error = gmio_stl_read_file(filepath, &buffer, &mesh_creator); if (error != GMIO_NO_ERROR) printf("GeomIO error: 0x%X\n", error); diff --git a/benchs/bench_occ/main.cpp b/benchs/bench_occ/main.cpp index 680175c..7a5e524 100644 --- a/benchs/bench_occ/main.cpp +++ b/benchs/bench_occ/main.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include @@ -24,7 +23,7 @@ static void bench_gmio_stl_read(const char* filepath) Handle_StlMesh_Mesh mesh = new StlMesh_Mesh; gmio_stl_mesh_creator_t mesh_creator = gmio_stl_occmesh_creator(mesh); - int error = gmio_stl_read_file(filepath, &mesh_creator, &buffer); + int error = gmio_stl_read_file(filepath, &buffer, &mesh_creator); if (error != GMIO_NO_ERROR) printf("GeomIO error: 0x%X\n", error); diff --git a/src/gmio_stl/stl_io.c b/src/gmio_stl/stl_io.c index c014ce9..a890c04 100644 --- a/src/gmio_stl/stl_io.c +++ b/src/gmio_stl/stl_io.c @@ -24,8 +24,8 @@ int gmio_stl_read_file( const char* filepath, - gmio_stl_mesh_creator_t* creator, - gmio_buffer_t* buffer) + gmio_buffer_t* buffer, + gmio_stl_mesh_creator_t* creator) { int error = GMIO_NO_ERROR; FILE* file = NULL; @@ -57,17 +57,15 @@ int gmio_stl_read(gmio_transfer_t *trsf, gmio_stl_mesh_creator_t *creator) switch (stl_format) { case GMIO_STL_ASCII_FORMAT: { - error = gmio_stla_read(trsf, creator, NULL); + error = gmio_stla_read(trsf, creator); break; } case GMIO_STL_BINARY_BE_FORMAT: { - const gmio_stlb_read_options_t opts = { GMIO_BIG_ENDIAN }; - error = gmio_stlb_read(trsf, creator, &opts); + error = gmio_stlb_read(trsf, creator, GMIO_BIG_ENDIAN); break; } case GMIO_STL_BINARY_LE_FORMAT: { - const gmio_stlb_read_options_t opts = { GMIO_LITTLE_ENDIAN }; - error = gmio_stlb_read(trsf, creator, &opts); + error = gmio_stlb_read(trsf, creator, GMIO_LITTLE_ENDIAN); break; } case GMIO_STL_UNKNOWN_FORMAT: { diff --git a/src/gmio_stl/stl_io.h b/src/gmio_stl/stl_io.h index e195bc9..58de379 100644 --- a/src/gmio_stl/stl_io.h +++ b/src/gmio_stl/stl_io.h @@ -38,19 +38,21 @@ GMIO_C_LINKAGE_BEGIN * * \return Error code (see error.h and stl_error.h) */ -GMIO_LIBSTL_EXPORT int gmio_stl_read_file( +GMIO_LIBSTL_EXPORT +int gmio_stl_read_file( const char* filepath, - gmio_stl_mesh_creator_t* creator, - gmio_buffer_t* buffer); + gmio_buffer_t* buffer, + gmio_stl_mesh_creator_t* creator); -/*! Reads STL file, format is automatically guessed +/*! Reads STL data from stream, format is automatically guessed * * \param trsf Defines needed objects for the read operation * \param creator Defines the callbacks for the mesh creation * * \return Error code (see error.h and stl_error.h) */ -GMIO_LIBSTL_EXPORT int gmio_stl_read( +GMIO_LIBSTL_EXPORT +int gmio_stl_read( gmio_transfer_t* trsf, gmio_stl_mesh_creator_t* creator); @@ -58,18 +60,6 @@ GMIO_LIBSTL_EXPORT int gmio_stl_read( * STL ascii * ======================================================================== */ -/*! Options for gmio_stla_read() - * - * Possible other options in the future: - * - flag to force locale ? - * - case sensitive/insensitive ? - */ -struct gmio_stla_read_options -{ - void* dummy; /* Empty structs are forbidden with ISO-C90 */ -}; -typedef struct gmio_stla_read_options gmio_stla_read_options_t; - /*! Reads geometry from STL ascii stream * * \param creator Defines the callbacks for the mesh creation @@ -80,12 +70,16 @@ typedef struct gmio_stla_read_options gmio_stla_read_options_t; * Stream size is passed to gmio_transfer::handle_progress_func() as the * \p max_value argument. * + * Possible options in a future version could be: + * - flag to force locale ? + * - case sensitive/insensitive ? + * * \return Error code (see error.h and stl_error.h) */ GMIO_LIBSTL_EXPORT -int gmio_stla_read(gmio_transfer_t* trsf, - gmio_stl_mesh_creator_t* creator, - const gmio_stla_read_options_t* options); +int gmio_stla_read( + gmio_transfer_t* trsf, + gmio_stl_mesh_creator_t* creator); /*! Options for gmio_stla_write() */ @@ -103,7 +97,7 @@ struct gmio_stla_write_options * * Defaulted to \c 9 when calling gmio_stla_write() with \c options==NULL */ - uint8_t float32_prec; + uint8_t float32_prec; }; typedef struct gmio_stla_write_options gmio_stla_write_options_t; @@ -118,41 +112,30 @@ typedef struct gmio_stla_write_options gmio_stla_write_options_t; * \retval GMIO_INVALID_BUFFER_SIZE_ERROR if \c trs->buffer_size < 512 */ GMIO_LIBSTL_EXPORT -int gmio_stla_write(gmio_transfer_t* trsf, - const gmio_stl_mesh_t* mesh, - const gmio_stla_write_options_t* options); +int gmio_stla_write( + gmio_transfer_t* trsf, + const gmio_stl_mesh_t* mesh, + const gmio_stla_write_options_t* options); /* ======================================================================== * STL binary * ======================================================================== */ -/*! Options for gmio_stlb_read() */ -struct gmio_stlb_read_options -{ - /*! Byte order of the input STL binary data - * - * Defaulted to host's endianness when calling gmio_stlb_read() - * with \c options==NULL - */ - gmio_endianness_t byte_order; -}; -typedef struct gmio_stlb_read_options gmio_stlb_read_options_t; - /*! Reads geometry from STL binary stream * * \param mesh Defines the callbacks for the mesh creation * \param trsf Defines needed objects for the read operation - * \param options Options for the operation, can be \c NULL to use default - * values + * \param options Byte order of the input STL binary data * * \return Error code (see error.h and stl_error.h) * \retval GMIO_INVALID_BUFFER_SIZE_ERRO * if \c trs->buffer_size < GMIO_STLB_MIN_CONTENTS_SIZE */ GMIO_LIBSTL_EXPORT -int gmio_stlb_read(gmio_transfer_t* trsf, - gmio_stl_mesh_creator_t* creator, - const gmio_stlb_read_options_t* options); +int gmio_stlb_read( + gmio_transfer_t* trsf, + gmio_stl_mesh_creator_t* creator, + gmio_endianness_t byte_order); /*! Options for gmio_stlb_write() */ @@ -183,13 +166,14 @@ typedef struct gmio_stlb_write_options gmio_stlb_write_options_t; * values * * \return Error code (see error.h and stl_error.h) - * \retval GMIO_INVALID_BUFFER_SIZE_ERRO + * \retval GMIO_INVALID_BUFFER_SIZE_ERROR * if \c trs->buffer_size < GMIO_STLB_MIN_CONTENTS_SIZE */ GMIO_LIBSTL_EXPORT -int gmio_stlb_write(gmio_transfer_t* trsf, - const gmio_stl_mesh_t* mesh, - const gmio_stlb_write_options_t* options); +int gmio_stlb_write( + gmio_transfer_t* trsf, + const gmio_stl_mesh_t* mesh, + const gmio_stlb_write_options_t* options); GMIO_C_LINKAGE_END diff --git a/src/gmio_stl/stla_read.c b/src/gmio_stl/stla_read.c index b9a5fa7..608aee9 100644 --- a/src/gmio_stl/stla_read.c +++ b/src/gmio_stl/stla_read.c @@ -424,15 +424,11 @@ static void parse_solid(gmio_stla_parse_data_t* data) enum { GMIO_STLA_READ_STRING_BUFFER_LEN = 512 }; -int gmio_stla_read( - gmio_transfer_t* trsf, - gmio_stl_mesh_creator_t* creator, - const gmio_stla_read_options_t* options) +int gmio_stla_read(gmio_transfer_t* trsf, gmio_stl_mesh_creator_t* creator) { char fixed_buffer[GMIO_STLA_READ_STRING_BUFFER_LEN]; gmio_stla_parse_data_t parse_data; - GMIO_UNUSED(options); { /* Check validity of input parameters */ int error = GMIO_NO_ERROR; if (!gmio_check_transfer(&error, trsf)) diff --git a/src/gmio_stl/stlb_read.c b/src/gmio_stl/stlb_read.c index 9df1aa1..0384bdb 100644 --- a/src/gmio_stl/stlb_read.c +++ b/src/gmio_stl/stlb_read.c @@ -69,11 +69,9 @@ static void gmio_stlb_read_facets( int gmio_stlb_read( gmio_transfer_t* trsf, gmio_stl_mesh_creator_t *creator, - const gmio_stlb_read_options_t* options) + gmio_endianness_t byte_order) { /* Constants */ - const gmio_endianness_t byte_order = - options != NULL ? options->byte_order : GMIO_HOST_ENDIANNESS; const uint32_t max_facet_count_per_read = trsf != NULL ? gmio_size_to_uint32(