diff --git a/src/gmio_stl/internal/helper_stl_mesh_creator.h b/src/gmio_stl/internal/helper_stl_mesh_creator.h new file mode 100644 index 0000000..23e4e67 --- /dev/null +++ b/src/gmio_stl/internal/helper_stl_mesh_creator.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** GeomIO Library +** Copyright FougSys (2 Mar. 2015) +** contact@fougsys.fr +** +** 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". +****************************************************************************/ + +/* WARNING : + * this header has no multi-inclusion guard. It must be included only once + * in the translation unit of use. The reason is that all functions + * defined here are meant to be inlined for performance purpose + */ + +#include "../stl_mesh_creator.h" + +/*! Safe and convenient function for + * gmio_stl_mesh_creator::ascii_begin_solid_func() */ +GMIO_INLINE void gmio_stl_mesh_creator_ascii_begin_solid( + gmio_stl_mesh_creator_t* creator, + size_t stream_size, + const char* solid_name) +{ + if (creator != NULL && creator->ascii_begin_solid_func != NULL) { + creator->ascii_begin_solid_func( + creator->cookie, stream_size, solid_name); + } +} + +/*! Safe and convenient function for + * gmio_stl_mesh_creator::binary_begin_solid_func() */ +GMIO_INLINE void gmio_stl_mesh_creator_binary_begin_solid( + gmio_stl_mesh_creator_t* creator, + uint32_t tri_count, + const uint8_t* header) +{ + if (creator != NULL && creator->binary_begin_solid_func != NULL) + creator->binary_begin_solid_func(creator->cookie, tri_count, header); +} + +/*! Safe and convenient function for + * gmio_stl_mesh_creator::add_triangle_func() */ +GMIO_INLINE void gmio_stl_mesh_creator_add_triangle( + gmio_stl_mesh_creator_t* creator, + uint32_t tri_id, + const gmio_stl_triangle_t* triangle) +{ + if (creator != NULL && creator->add_triangle_func != NULL) + creator->add_triangle_func(creator->cookie, tri_id, triangle); +} + +/*! Safe and convenient function for + * gmio_stl_mesh_creator::end_solid_func() */ +GMIO_INLINE void gmio_stl_mesh_creator_end_solid( + gmio_stl_mesh_creator_t* creator) +{ + if (creator != NULL && creator->end_solid_func != NULL) + creator->end_solid_func(creator->cookie); +} diff --git a/src/gmio_stl/stla_read.c b/src/gmio_stl/stla_read.c index 608aee9..44383d0 100644 --- a/src/gmio_stl/stla_read.c +++ b/src/gmio_stl/stla_read.c @@ -18,6 +18,7 @@ #include "stl_io.h" #include "stl_error.h" +#include "internal/helper_stl_mesh_creator.h" #include "internal/stl_rw_common.h" #include "../gmio_core/error.h" @@ -303,12 +304,9 @@ static void parse_beginsolid(gmio_stla_parse_data_t* data) case SOLID_token: { parsing_eat_token(SOLID_token, data); parse_solidname_beg(data); - if (parsing_can_continue(data) - && data->creator != NULL - && data->creator->ascii_begin_solid_func != NULL) - { - data->creator->ascii_begin_solid_func( - data->creator->cookie, + if (parsing_can_continue(data)) { + gmio_stl_mesh_creator_ascii_begin_solid( + data->creator, data->stream_iterator_cookie.stream_size, current_token_as_identifier(data)); } @@ -330,12 +328,8 @@ static void parse_endsolid(gmio_stla_parse_data_t* data) case ENDSOLID_token: { parsing_eat_token(ENDSOLID_token, data); parse_solidname_end(data); - if (parsing_can_continue(data) - && data->creator != NULL - && data->creator->end_solid_func != NULL) - { - data->creator->end_solid_func(data->creator->cookie/*, current_token_as_identifier(data)*/); - } + if (parsing_can_continue(data)) + gmio_stl_mesh_creator_end_solid(data->creator); if (data->token == ID_token) parsing_eat_token(ID_token, data); break; @@ -392,18 +386,13 @@ static void parse_facet( static void parse_facets(gmio_stla_parse_data_t* data) { - uint32_t i_facet_offset = 0; + uint32_t i_facet = 0; gmio_stl_triangle_t facet; - const gmio_bool_t is_add_triangle_available = - data->creator != NULL && data->creator->add_triangle_func != NULL; while (data->token == FACET_token && parsing_can_continue(data)) { parse_facet(data, &facet); - if (is_add_triangle_available) { - data->creator->add_triangle_func( - data->creator->cookie, i_facet_offset, &facet); - } - ++i_facet_offset; + gmio_stl_mesh_creator_add_triangle(data->creator, i_facet, &facet); + ++i_facet; } } diff --git a/src/gmio_stl/stlb_read.c b/src/gmio_stl/stlb_read.c index 71aa529..39a5131 100644 --- a/src/gmio_stl/stlb_read.c +++ b/src/gmio_stl/stlb_read.c @@ -18,6 +18,7 @@ #include "stl_io.h" #include "stl_error.h" +#include "internal/helper_stl_mesh_creator.h" #include "internal/stl_rw_common.h" #include "internal/stlb_byte_swap.h" @@ -111,10 +112,8 @@ int gmio_stlb_read( total_facet_count = gmio_uint32_bswap(total_facet_count); /* Callback to notify triangle count and header data */ - if (creator != NULL && creator->binary_begin_solid_func != NULL) { - creator->binary_begin_solid_func( - creator->cookie, total_facet_count, header_data); - } + gmio_stl_mesh_creator_binary_begin_solid( + creator, total_facet_count, header_data); /* Read triangles */ while (gmio_no_error(error) @@ -145,12 +144,8 @@ int gmio_stlb_read( } } /* end while */ - if (gmio_no_error(error) - && creator != NULL - && creator->end_solid_func != NULL) - { - creator->end_solid_func(creator->cookie); - } + if (gmio_no_error(error)) + gmio_stl_mesh_creator_end_solid(creator); if (gmio_no_error(error) && rparams.i_facet_offset != total_facet_count) error = GMIO_STLB_READ_FACET_COUNT_ERROR;