gmio_stl: new API for read/write functions
This commit is contained in:
parent
e284d9c7c8
commit
72228a82dc
@ -9,35 +9,94 @@
|
||||
|
||||
GMIO_C_LINKAGE_BEGIN
|
||||
|
||||
/*
|
||||
/* ============================================================================
|
||||
* STL ascii
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/*! Read geometry from STL ascii stream */
|
||||
GMIO_LIBSTL_EXPORT int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
size_t data_size_hint);
|
||||
/*! \brief Options for gmio_stla_read()
|
||||
*
|
||||
* No options yet, it just exists for future needs
|
||||
*/
|
||||
struct gmio_stla_read_options
|
||||
{
|
||||
void* dummy; /*!< Structs must have at least one member ... */
|
||||
/* Flag to force locale ? */
|
||||
};
|
||||
typedef struct gmio_stla_read_options gmio_stla_read_options_t;
|
||||
|
||||
/*! Write geometry in the STL ascii format */
|
||||
/*! \brief Read geometry from STL ascii stream
|
||||
*
|
||||
* \p options should be always set to NULL (not used for the moment)
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stla_read_options_t* options); /* NULL */
|
||||
|
||||
/*! \brief Options for gmio_stla_write()
|
||||
*/
|
||||
struct gmio_stla_write_options
|
||||
{
|
||||
/*! May be NULL to generate default name */
|
||||
const char* solid_name;
|
||||
|
||||
/*! The maximum number of significant digits(set to 9 if options == NULL) */
|
||||
uint8_t real32_prec;
|
||||
};
|
||||
typedef struct gmio_stla_write_options gmio_stla_write_options_t;
|
||||
|
||||
/*! \brief Write geometry in the STL ascii format
|
||||
*
|
||||
* \param mesh Defines the mesh to write
|
||||
* \param trsf Defines needed objects (stream, buffer, ...) for the writing
|
||||
* operation
|
||||
* \param options Options for the writing operation
|
||||
*
|
||||
* \return Error code
|
||||
* \retval GMIO_NO_ERROR If operation successful
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const char* solid_name,
|
||||
uint8_t real32_prec);
|
||||
const gmio_stla_write_options_t* options);
|
||||
|
||||
/*
|
||||
/* ============================================================================
|
||||
* STL binary
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/*! Read geometry from STL binary stream */
|
||||
GMIO_LIBSTL_EXPORT int gmio_stlb_read(gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
gmio_endianness_t byte_order);
|
||||
/*! \brief Options for gmio_stlb_read()
|
||||
*/
|
||||
struct gmio_stlb_read_options
|
||||
{
|
||||
/*! Set to host byte order if not specified (ie. options == NULL) */
|
||||
gmio_endianness_t byte_order;
|
||||
};
|
||||
typedef struct gmio_stlb_read_options gmio_stlb_read_options_t;
|
||||
|
||||
/*! Write geometry in the STL binary format */
|
||||
/*! \brief Read geometry from STL binary stream
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT int gmio_stlb_read(gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stlb_read_options_t* options);
|
||||
|
||||
|
||||
/*! \brief Options for gmio_stlb_write()
|
||||
*/
|
||||
struct gmio_stlb_write_options
|
||||
{
|
||||
/*! Header data consisting of 80 bytes */
|
||||
const uint8_t* header_data;
|
||||
|
||||
/*! Set to host byte order if not specified (ie. options == NULL) */
|
||||
gmio_endianness_t byte_order;
|
||||
};
|
||||
typedef struct gmio_stlb_write_options gmio_stlb_write_options_t;
|
||||
|
||||
/*! \brief Write geometry in the STL binary format
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const uint8_t* header_data,
|
||||
gmio_endianness_t byte_order);
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stlb_write_options_t* options);
|
||||
|
||||
GMIO_C_LINKAGE_END
|
||||
|
||||
|
@ -62,7 +62,6 @@
|
||||
typedef struct
|
||||
{
|
||||
gmio_task_control_t* task_control;
|
||||
size_t stream_data_size;
|
||||
size_t stream_offset;
|
||||
gmio_bool_t is_stop_requested;
|
||||
} _internal_gmio_fwd_iterator_cookie_t;
|
||||
@ -102,7 +101,7 @@ static void gmio_stream_fwd_iterator_stla_read_hook(void* cookie,
|
||||
_internal_gmio_fwd_iterator_cookie_t* tcookie = (_internal_gmio_fwd_iterator_cookie_t*)(cookie);
|
||||
const gmio_task_control_t* ctrl = tcookie != NULL ? tcookie->task_control : NULL;
|
||||
if (ctrl != NULL)
|
||||
tcookie->is_stop_requested = !gmio_task_control_is_stop_requested(ctrl);
|
||||
tcookie->is_stop_requested = gmio_task_control_is_stop_requested(ctrl);
|
||||
if (tcookie != NULL)
|
||||
tcookie->stream_offset += buffer->len;
|
||||
}
|
||||
@ -393,12 +392,13 @@ static void parse_solid(gmio_stla_parse_data_t* data)
|
||||
|
||||
#define GMIO_STLA_READ_STRING_BUFFER_LEN 512
|
||||
|
||||
int gmio_stla_read(gmio_stl_mesh_creator_t *creator,
|
||||
gmio_transfer_t *trsf,
|
||||
size_t data_size_hint)
|
||||
int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stla_read_options_t* options)
|
||||
{
|
||||
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;
|
||||
@ -410,9 +410,8 @@ int gmio_stla_read(gmio_stl_mesh_creator_t *creator,
|
||||
parse_data.error = GMIO_FALSE;
|
||||
|
||||
parse_data.stream_iterator_cookie.task_control = &trsf->task_control;
|
||||
parse_data.stream_iterator_cookie.stream_data_size = data_size_hint;
|
||||
parse_data.stream_iterator_cookie.stream_offset = 0;
|
||||
parse_data.stream_iterator_cookie.is_stop_requested = 0;
|
||||
parse_data.stream_iterator_cookie.is_stop_requested = GMIO_FALSE;
|
||||
|
||||
parse_data.stream_iterator.stream = &trsf->stream;
|
||||
parse_data.stream_iterator.buffer.ptr = trsf->buffer;
|
||||
|
@ -96,20 +96,12 @@ static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n)
|
||||
|
||||
#define _GMIO_INTERNAL_MIN(v1, v2) ((v1) < (v2) ? (v1) : (v2))
|
||||
|
||||
/*! \param mesh Defines the mesh to write
|
||||
* \param trsf Defines needed objects (stream, buffer, ...) for the writing operation
|
||||
* \param solid_name May be NULL to generate default name
|
||||
* \param real32_prec The maximum number of significant digits
|
||||
*
|
||||
* \return Error code
|
||||
*
|
||||
* \retval GMIO_NO_ERROR If operation successful
|
||||
*/
|
||||
int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const char* solid_name,
|
||||
uint8_t real32_prec)
|
||||
const gmio_stla_write_options_t* options)
|
||||
{
|
||||
const char* solid_name = options != NULL ? options->solid_name : NULL;
|
||||
const uint8_t real32_prec = options != NULL ? options->real32_prec : 9;
|
||||
const uint32_t total_facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
||||
const uint32_t buffer_facet_count = trsf != NULL ? trsf->buffer_size / GMIO_STLA_FACET_SIZE_P2 : 0;
|
||||
uint32_t ifacet = 0;
|
||||
|
@ -46,9 +46,10 @@ static void gmio_stlb_read_facets(gmio_stl_mesh_creator_t* creator,
|
||||
|
||||
int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
||||
gmio_transfer_t* trsf,
|
||||
gmio_endianness_t byte_order)
|
||||
const gmio_stlb_read_options_t* options)
|
||||
{
|
||||
const gmio_endianness_t host_byte_order = gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order = options != NULL ? options->byte_order : host_byte_order;
|
||||
gmio_stlb_readwrite_helper_t rparams = {0};
|
||||
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
||||
uint32_t total_facet_count = 0; /* Count of facets as declared in the stream */
|
||||
|
@ -42,11 +42,13 @@ static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
||||
} /* end for */
|
||||
}
|
||||
|
||||
int gmio_stlb_write(const gmio_stl_mesh_t *mesh,
|
||||
int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const uint8_t *header_data,
|
||||
gmio_endianness_t byte_order)
|
||||
const gmio_stlb_write_options_t* options)
|
||||
{
|
||||
const gmio_endianness_t host_byte_order = gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order = options != NULL ? options->byte_order : host_byte_order;
|
||||
const uint8_t* header_data = options != NULL ? options->header_data : NULL;
|
||||
gmio_stlb_readwrite_helper_t wparams = {0};
|
||||
const uint32_t facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
||||
uint32_t i_facet = 0;
|
||||
@ -59,7 +61,7 @@ int gmio_stlb_write(const gmio_stl_mesh_t *mesh,
|
||||
return error;
|
||||
|
||||
/* Initialize wparams */
|
||||
if (gmio_host_endianness() != byte_order)
|
||||
if (host_byte_order != byte_order)
|
||||
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||
wparams.facet_count = trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user