2015-03-03 00:38:33 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** 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
|
2015-03-30 15:05:25 +08:00
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
2015-03-03 00:38:33 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! \file stl_io.h
|
|
|
|
* STL read/write functions
|
|
|
|
*/
|
|
|
|
|
2015-04-02 16:41:41 +08:00
|
|
|
#ifndef GMIO_STL_IO_H
|
|
|
|
#define GMIO_STL_IO_H
|
2014-03-28 23:33:35 +08:00
|
|
|
|
|
|
|
#include "stl_global.h"
|
2015-04-02 21:36:57 +08:00
|
|
|
#include "stl_format.h"
|
2014-03-31 21:52:04 +08:00
|
|
|
#include "stl_mesh.h"
|
|
|
|
#include "stl_mesh_creator.h"
|
2015-03-24 01:21:04 +08:00
|
|
|
#include "../gmio_core/buffer.h"
|
2014-03-28 23:33:35 +08:00
|
|
|
#include "../gmio_core/endian.h"
|
|
|
|
#include "../gmio_core/transfer.h"
|
|
|
|
|
|
|
|
GMIO_C_LINKAGE_BEGIN
|
|
|
|
|
2015-03-24 01:21:04 +08:00
|
|
|
/*! Reads STL file, format is automatically guessed
|
|
|
|
*
|
|
|
|
* \param filepath Path to the STL file. A stream is opened with fopen() so
|
|
|
|
* the string has to be encoded using the system's charset (locale-8bit)
|
|
|
|
* \param creator Defines the callbacks for the mesh creation
|
2015-04-02 22:09:08 +08:00
|
|
|
* \param task_iface The interface object by which the read operation can be
|
|
|
|
* controlled. Optional, can be safely set to NULL
|
2015-04-02 21:36:57 +08:00
|
|
|
*
|
|
|
|
* Internally, it uses:
|
|
|
|
* \li the builtin stream wrapper around FILE* (see gmio_stream_stdio())
|
|
|
|
* \li the global default function to construct a temporary gmio_buffer
|
|
|
|
* object (see gmio_buffer_default())
|
2015-03-24 01:21:04 +08:00
|
|
|
*
|
|
|
|
* \return Error code (see error.h and stl_error.h)
|
|
|
|
*/
|
2015-03-30 15:30:55 +08:00
|
|
|
GMIO_LIBSTL_EXPORT
|
|
|
|
int gmio_stl_read_file(
|
2015-03-24 01:21:04 +08:00
|
|
|
const char* filepath,
|
2015-04-02 22:09:08 +08:00
|
|
|
gmio_stl_mesh_creator_t* creator,
|
|
|
|
gmio_task_iface_t* task_iface);
|
2015-03-24 01:21:04 +08:00
|
|
|
|
2015-03-30 15:30:55 +08:00
|
|
|
/*! Reads STL data from stream, format is automatically guessed
|
2015-03-24 01:21:04 +08:00
|
|
|
*
|
|
|
|
* \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)
|
|
|
|
*/
|
2015-03-30 15:30:55 +08:00
|
|
|
GMIO_LIBSTL_EXPORT
|
|
|
|
int gmio_stl_read(
|
2015-03-24 01:21:04 +08:00
|
|
|
gmio_transfer_t* trsf,
|
|
|
|
gmio_stl_mesh_creator_t* creator);
|
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/* ========================================================================
|
2014-03-28 23:33:35 +08:00
|
|
|
* STL ascii
|
2015-03-03 18:35:15 +08:00
|
|
|
* ======================================================================== */
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Reads geometry from STL ascii stream
|
2014-11-21 18:41:29 +08:00
|
|
|
*
|
2015-03-13 19:19:19 +08:00
|
|
|
* \param trsf Defines needed objects for the read operation
|
2015-04-02 16:30:09 +08:00
|
|
|
* \param creator Defines the callbacks for the mesh creation
|
2015-03-24 01:21:04 +08:00
|
|
|
*
|
|
|
|
* Stream size is passed to gmio_transfer::handle_progress_func() as the
|
|
|
|
* \p max_value argument.
|
2015-03-13 19:19:19 +08:00
|
|
|
*
|
2015-03-30 15:30:55 +08:00
|
|
|
* Possible options in a future version could be:
|
|
|
|
* - flag to force locale ?
|
|
|
|
* - case sensitive/insensitive ?
|
|
|
|
*
|
2015-03-13 19:19:19 +08:00
|
|
|
* \return Error code (see error.h and stl_error.h)
|
2014-11-21 18:41:29 +08:00
|
|
|
*/
|
2015-01-29 05:39:03 +08:00
|
|
|
GMIO_LIBSTL_EXPORT
|
2015-03-30 15:30:55 +08:00
|
|
|
int gmio_stla_read(
|
|
|
|
gmio_transfer_t* trsf,
|
|
|
|
gmio_stl_mesh_creator_t* creator);
|
2014-11-21 18:41:29 +08:00
|
|
|
|
2015-03-13 19:19:19 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Options for gmio_stla_write() */
|
2014-11-21 18:41:29 +08:00
|
|
|
struct gmio_stla_write_options
|
|
|
|
{
|
2015-03-13 19:19:19 +08:00
|
|
|
/*! Name of the solid to appear in "solid <name> \n facet normal ..."
|
|
|
|
*
|
|
|
|
* Defaulted to an empty string "" when :
|
|
|
|
* \li calling gmio_stla_write() with <tt>options == NULL</tt>
|
|
|
|
* \li OR <tt>solid_name == NULL</tt>
|
|
|
|
*/
|
2015-03-03 17:35:36 +08:00
|
|
|
const char* solid_name;
|
2014-11-21 18:41:29 +08:00
|
|
|
|
2015-03-13 19:19:19 +08:00
|
|
|
/*! The maximum number of significant digits to write float values
|
|
|
|
*
|
|
|
|
* Defaulted to \c 9 when calling gmio_stla_write() with \c options==NULL
|
|
|
|
*/
|
2015-03-30 15:30:55 +08:00
|
|
|
uint8_t float32_prec;
|
2014-11-21 18:41:29 +08:00
|
|
|
};
|
|
|
|
typedef struct gmio_stla_write_options gmio_stla_write_options_t;
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Writes geometry in the STL ascii format
|
2014-11-21 18:41:29 +08:00
|
|
|
*
|
|
|
|
* \param mesh Defines the mesh to write
|
2015-03-13 19:19:19 +08:00
|
|
|
* \param trsf Defines needed objects for the write operation
|
|
|
|
* \param options Options for the operation, can be \c NULL to use default
|
|
|
|
* values
|
2014-11-21 18:41:29 +08:00
|
|
|
*
|
2015-03-13 19:19:19 +08:00
|
|
|
* \return Error code (see error.h and stl_error.h)
|
2015-04-02 16:04:24 +08:00
|
|
|
* \retval GMIO_ERROR_INVALID_BUFFER_SIZE
|
2015-03-30 23:26:38 +08:00
|
|
|
* if <tt>trsf->buffer.size < 512</tt>
|
2014-11-21 18:41:29 +08:00
|
|
|
*/
|
2015-01-29 05:39:03 +08:00
|
|
|
GMIO_LIBSTL_EXPORT
|
2015-03-30 15:30:55 +08:00
|
|
|
int gmio_stla_write(
|
|
|
|
gmio_transfer_t* trsf,
|
|
|
|
const gmio_stl_mesh_t* mesh,
|
|
|
|
const gmio_stla_write_options_t* options);
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/* ========================================================================
|
2014-03-28 23:33:35 +08:00
|
|
|
* STL binary
|
2015-03-03 18:35:15 +08:00
|
|
|
* ======================================================================== */
|
2014-11-21 18:41:29 +08:00
|
|
|
|
2015-03-13 19:19:19 +08:00
|
|
|
/*! Reads geometry from STL binary stream
|
|
|
|
*
|
|
|
|
* \param trsf Defines needed objects for the read operation
|
2015-04-02 16:30:09 +08:00
|
|
|
* \param creator Defines the callbacks for the mesh creation
|
|
|
|
* \param byte_order Byte order of the input STL binary data
|
2015-03-13 19:19:19 +08:00
|
|
|
*
|
|
|
|
* \return Error code (see error.h and stl_error.h)
|
2015-04-02 16:04:24 +08:00
|
|
|
* \retval GMIO_ERROR_INVALID_BUFFER_SIZE
|
2015-03-30 23:26:38 +08:00
|
|
|
* if <tt>trsf->buffer.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
|
2015-03-13 19:19:19 +08:00
|
|
|
*/
|
2015-01-29 05:39:03 +08:00
|
|
|
GMIO_LIBSTL_EXPORT
|
2015-03-30 15:30:55 +08:00
|
|
|
int gmio_stlb_read(
|
|
|
|
gmio_transfer_t* trsf,
|
|
|
|
gmio_stl_mesh_creator_t* creator,
|
|
|
|
gmio_endianness_t byte_order);
|
2014-11-21 18:41:29 +08:00
|
|
|
|
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Options for gmio_stlb_write() */
|
2014-11-21 18:41:29 +08:00
|
|
|
struct gmio_stlb_write_options
|
|
|
|
{
|
2015-03-13 19:19:19 +08:00
|
|
|
/*! Header data consisting of 80 bytes
|
|
|
|
*
|
|
|
|
* Defaulted to an array containing 0 when :
|
|
|
|
* \li calling gmio_stlb_write() with <tt>options == NULL</tt>
|
|
|
|
* \li OR <tt>header_data == NULL</tt>
|
|
|
|
*/
|
2015-03-03 17:35:36 +08:00
|
|
|
const uint8_t* header_data;
|
2014-11-21 18:41:29 +08:00
|
|
|
|
2015-03-13 19:19:19 +08:00
|
|
|
/*! Byte order of the output STL binary data
|
|
|
|
*
|
|
|
|
* Defaulted to host's endianness when calling gmio_stlb_write()
|
|
|
|
* with \c options==NULL
|
|
|
|
*/
|
2015-03-03 17:35:36 +08:00
|
|
|
gmio_endianness_t byte_order;
|
2014-11-21 18:41:29 +08:00
|
|
|
};
|
|
|
|
typedef struct gmio_stlb_write_options gmio_stlb_write_options_t;
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-13 19:19:19 +08:00
|
|
|
/*! Writes geometry in the STL binary format
|
|
|
|
*
|
|
|
|
* \param mesh Defines the mesh to write
|
|
|
|
* \param trsf Defines needed objects for the write operation
|
|
|
|
* \param options Options for the operation, can be \c NULL to use default
|
|
|
|
* values
|
|
|
|
*
|
|
|
|
* \return Error code (see error.h and stl_error.h)
|
2015-03-30 15:30:55 +08:00
|
|
|
* \retval GMIO_INVALID_BUFFER_SIZE_ERROR
|
2015-03-30 23:26:38 +08:00
|
|
|
* if <tt>trsf->buffer.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
|
2015-03-13 19:19:19 +08:00
|
|
|
*/
|
2015-01-29 05:39:03 +08:00
|
|
|
GMIO_LIBSTL_EXPORT
|
2015-03-30 15:30:55 +08:00
|
|
|
int gmio_stlb_write(
|
|
|
|
gmio_transfer_t* trsf,
|
|
|
|
const gmio_stl_mesh_t* mesh,
|
|
|
|
const gmio_stlb_write_options_t* options);
|
2014-03-28 23:33:35 +08:00
|
|
|
|
|
|
|
GMIO_C_LINKAGE_END
|
|
|
|
|
2015-04-02 16:41:41 +08:00
|
|
|
#endif /* GMIO_STL_IO_H */
|