gmio_stl: add helper functions for gmio_stl_mesh_creator
This commit is contained in:
parent
762ca148cb
commit
922367f3b1
66
src/gmio_stl/internal/helper_stl_mesh_creator.h
Normal file
66
src/gmio_stl/internal/helper_stl_mesh_creator.h
Normal file
@ -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);
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
#include "stl_io.h"
|
#include "stl_io.h"
|
||||||
|
|
||||||
#include "stl_error.h"
|
#include "stl_error.h"
|
||||||
|
#include "internal/helper_stl_mesh_creator.h"
|
||||||
#include "internal/stl_rw_common.h"
|
#include "internal/stl_rw_common.h"
|
||||||
|
|
||||||
#include "../gmio_core/error.h"
|
#include "../gmio_core/error.h"
|
||||||
@ -303,12 +304,9 @@ static void parse_beginsolid(gmio_stla_parse_data_t* data)
|
|||||||
case SOLID_token: {
|
case SOLID_token: {
|
||||||
parsing_eat_token(SOLID_token, data);
|
parsing_eat_token(SOLID_token, data);
|
||||||
parse_solidname_beg(data);
|
parse_solidname_beg(data);
|
||||||
if (parsing_can_continue(data)
|
if (parsing_can_continue(data)) {
|
||||||
&& data->creator != NULL
|
gmio_stl_mesh_creator_ascii_begin_solid(
|
||||||
&& data->creator->ascii_begin_solid_func != NULL)
|
data->creator,
|
||||||
{
|
|
||||||
data->creator->ascii_begin_solid_func(
|
|
||||||
data->creator->cookie,
|
|
||||||
data->stream_iterator_cookie.stream_size,
|
data->stream_iterator_cookie.stream_size,
|
||||||
current_token_as_identifier(data));
|
current_token_as_identifier(data));
|
||||||
}
|
}
|
||||||
@ -330,12 +328,8 @@ static void parse_endsolid(gmio_stla_parse_data_t* data)
|
|||||||
case ENDSOLID_token: {
|
case ENDSOLID_token: {
|
||||||
parsing_eat_token(ENDSOLID_token, data);
|
parsing_eat_token(ENDSOLID_token, data);
|
||||||
parse_solidname_end(data);
|
parse_solidname_end(data);
|
||||||
if (parsing_can_continue(data)
|
if (parsing_can_continue(data))
|
||||||
&& data->creator != NULL
|
gmio_stl_mesh_creator_end_solid(data->creator);
|
||||||
&& data->creator->end_solid_func != NULL)
|
|
||||||
{
|
|
||||||
data->creator->end_solid_func(data->creator->cookie/*, current_token_as_identifier(data)*/);
|
|
||||||
}
|
|
||||||
if (data->token == ID_token)
|
if (data->token == ID_token)
|
||||||
parsing_eat_token(ID_token, data);
|
parsing_eat_token(ID_token, data);
|
||||||
break;
|
break;
|
||||||
@ -392,18 +386,13 @@ static void parse_facet(
|
|||||||
|
|
||||||
static void parse_facets(gmio_stla_parse_data_t* data)
|
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;
|
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)) {
|
while (data->token == FACET_token && parsing_can_continue(data)) {
|
||||||
parse_facet(data, &facet);
|
parse_facet(data, &facet);
|
||||||
if (is_add_triangle_available) {
|
gmio_stl_mesh_creator_add_triangle(data->creator, i_facet, &facet);
|
||||||
data->creator->add_triangle_func(
|
++i_facet;
|
||||||
data->creator->cookie, i_facet_offset, &facet);
|
|
||||||
}
|
|
||||||
++i_facet_offset;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "stl_io.h"
|
#include "stl_io.h"
|
||||||
|
|
||||||
#include "stl_error.h"
|
#include "stl_error.h"
|
||||||
|
#include "internal/helper_stl_mesh_creator.h"
|
||||||
#include "internal/stl_rw_common.h"
|
#include "internal/stl_rw_common.h"
|
||||||
#include "internal/stlb_byte_swap.h"
|
#include "internal/stlb_byte_swap.h"
|
||||||
|
|
||||||
@ -111,10 +112,8 @@ int gmio_stlb_read(
|
|||||||
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
||||||
|
|
||||||
/* Callback to notify triangle count and header data */
|
/* Callback to notify triangle count and header data */
|
||||||
if (creator != NULL && creator->binary_begin_solid_func != NULL) {
|
gmio_stl_mesh_creator_binary_begin_solid(
|
||||||
creator->binary_begin_solid_func(
|
creator, total_facet_count, header_data);
|
||||||
creator->cookie, total_facet_count, header_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read triangles */
|
/* Read triangles */
|
||||||
while (gmio_no_error(error)
|
while (gmio_no_error(error)
|
||||||
@ -145,12 +144,8 @@ int gmio_stlb_read(
|
|||||||
}
|
}
|
||||||
} /* end while */
|
} /* end while */
|
||||||
|
|
||||||
if (gmio_no_error(error)
|
if (gmio_no_error(error))
|
||||||
&& creator != NULL
|
gmio_stl_mesh_creator_end_solid(creator);
|
||||||
&& creator->end_solid_func != NULL)
|
|
||||||
{
|
|
||||||
creator->end_solid_func(creator->cookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gmio_no_error(error) && rparams.i_facet_offset != total_facet_count)
|
if (gmio_no_error(error) && rparams.i_facet_offset != total_facet_count)
|
||||||
error = GMIO_STLB_READ_FACET_COUNT_ERROR;
|
error = GMIO_STLB_READ_FACET_COUNT_ERROR;
|
||||||
|
Loading…
Reference in New Issue
Block a user