gmio_stl: for passing STL binary header data, replace uint8_t* with new gmio_stlb_header

This commit is contained in:
Hugues Delorme 2015-05-28 16:19:07 +02:00
parent 3bd7ec8782
commit 742de300fe
10 changed files with 54 additions and 22 deletions

View File

@ -36,7 +36,7 @@ GMIO_INLINE void gmio_stl_mesh_creator_ascii_begin_solid(
GMIO_INLINE void gmio_stl_mesh_creator_binary_begin_solid(
gmio_stl_mesh_creator_t* creator,
uint32_t tri_count,
const uint8_t* header)
const gmio_stlb_header_t* header)
{
if (creator != NULL && creator->binary_begin_solid_func != NULL)
creator->binary_begin_solid_func(creator->cookie, tri_count, header);

View File

@ -17,6 +17,7 @@
#include "../../gmio_core/error.h"
#include "../stl_error.h"
#include "../stl_io.h"
gmio_bool_t gmio_check_transfer(int *error, const gmio_transfer_t* trsf)
{

View File

@ -16,6 +16,7 @@
#include "stl_format.h"
#include "stl_triangle.h"
#include "stlb_header.h"
#include "../gmio_core/endian.h"
#include "../gmio_core/internal/byte_codec.h"

View File

@ -34,14 +34,4 @@
# define GMIO_LIBSTL_EXPORT
#endif /* GMIO_LIBSTL_DLL */
/*! Constants for the STL binary format */
enum {
/*! Size(in bytes) of the header data for STL binary */
GMIO_STLB_HEADER_SIZE = 80,
/*! Size(in bytes) of the minimum contents possible with the STL binary
* format */
GMIO_STLB_MIN_CONTENTS_SIZE = 284
};
#endif /* GMIO_STL_GLOBAL_H */

View File

@ -147,17 +147,17 @@ int gmio_stl_write(
return error;
}
static const uint8_t internal_stlb_zero_header[GMIO_STLB_HEADER_SIZE] = { 0 };
static const gmio_stlb_header_t internal_stlb_zero_header = {0};
int gmio_stlb_write_header(
gmio_stream_t *stream,
gmio_endianness_t byte_order,
const uint8_t *header,
const gmio_stlb_header_t *header,
uint32_t facet_count)
{
uint8_t facet_count_bytes[sizeof(uint32_t)];
const uint8_t* non_null_header =
header != NULL ? header : &internal_stlb_zero_header[0];
const gmio_stlb_header_t* non_null_header =
header != NULL ? header : &internal_stlb_zero_header;
/* Write 80-byte header */
if (gmio_stream_write(stream, non_null_header, GMIO_STLB_HEADER_SIZE, 1)

View File

@ -125,6 +125,9 @@ int gmio_stla_read(
gmio_transfer_t* trsf,
gmio_stl_mesh_creator_t* creator);
/*! Size(in bytes) of the minimum contents possible with the STL binary format */
enum { GMIO_STLB_MIN_CONTENTS_SIZE = 284 };
/*! Reads geometry from STL binary stream
*
* \param trsf Defines needed objects for the read operation
@ -159,7 +162,7 @@ GMIO_LIBSTL_EXPORT
int gmio_stlb_write_header(
gmio_stream_t* stream,
gmio_endianness_t byte_order,
const uint8_t* header,
const gmio_stlb_header_t* header,
uint32_t facet_count);
GMIO_C_LINKAGE_END

View File

@ -21,6 +21,7 @@
#define GMIO_STL_IO_OPTIONS_H
#include "stl_global.h"
#include "stlb_header.h"
#include "../gmio_core/endian.h"
#include "../gmio_core/text_format.h"
@ -65,7 +66,7 @@ struct gmio_stl_write_options
*/
uint8_t stla_float32_prec;
/*! Header data whose first 80 bytes have to be written
/*! Header data(80-bytes)
*
* Option useful only with STL binary formats (GMIO_STL_FORMAT_BINARY_LE
* or GMIO_STL_FORMAT_BINARY_BE).
@ -74,7 +75,7 @@ struct gmio_stl_write_options
* \li calling gmio_stl_write() with <tt>options == NULL</tt>
* \li OR <tt>stlb_header_data == NULL</tt>
*/
const uint8_t* stlb_header_data;
const gmio_stlb_header_t* stlb_header_data;
};
typedef struct gmio_stl_write_options gmio_stl_write_options_t;

View File

@ -22,6 +22,7 @@
#include "stl_global.h"
#include "stl_triangle.h"
#include "stlb_header.h"
#include <stddef.h>
@ -54,7 +55,7 @@ struct gmio_stl_mesh_creator
* The argument \p header contains the header data(80 bytes)
*/
void (*binary_begin_solid_func)(
void* cookie, uint32_t tri_count, const uint8_t* header);
void* cookie, uint32_t tri_count, const gmio_stlb_header_t* header);
/*! Pointer on a function that adds a triangle to the user mesh
*

View File

@ -0,0 +1,35 @@
/****************************************************************************
** gmio
** Copyright Fougue (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".
****************************************************************************/
/*! \file stlb_header.h
* Declaration of gmio_stlb_header
*/
#ifndef GMIO_STLB_HEADER_H
#define GMIO_STLB_HEADER_H
#include "stl_global.h"
/*! Size(in bytes) of the header data for STL binary */
enum { GMIO_STLB_HEADER_SIZE = 80 };
/*! 80-byte data at the beginning of any STL binary file */
struct gmio_stlb_header
{
uint8_t data[GMIO_STLB_HEADER_SIZE];
};
typedef struct gmio_stlb_header gmio_stlb_header_t;
#endif /* GMIO_STLB_HEADER_H */

View File

@ -79,7 +79,7 @@ int gmio_stlb_read(
/* Variables */
void* buffer_ptr = trsf != NULL ? trsf->buffer.ptr : NULL;
gmio_stlb_readwrite_helper_t rparams = {0};
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
gmio_stlb_header_t header;
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
int error = GMIO_ERROR_OK; /* Helper to store function result error code */
@ -92,7 +92,7 @@ int gmio_stlb_read(
rparams.fix_endian_func = gmio_stl_triangle_bswap;
/* Read header */
if (gmio_stream_read(&trsf->stream, header_data, 1, GMIO_STLB_HEADER_SIZE)
if (gmio_stream_read(&trsf->stream, &header, GMIO_STLB_HEADER_SIZE, 1)
!= GMIO_STLB_HEADER_SIZE)
{
return GMIO_STL_ERROR_HEADER_WRONG_SIZE;
@ -111,7 +111,7 @@ int gmio_stlb_read(
/* Callback to notify triangle count and header data */
gmio_stl_mesh_creator_binary_begin_solid(
creator, total_facet_count, header_data);
creator, total_facet_count, &header);
/* Read triangles */
while (gmio_no_error(error)