gmio_stl: add gmio_stl_write() and gmio_stl_write_file()
This commit is contained in:
parent
9ee0abfdc6
commit
38c444e7b0
@ -80,3 +80,68 @@ int gmio_stl_read(gmio_transfer_t *trsf, gmio_stl_mesh_creator_t *creator)
|
|||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gmio_stl_write_file(
|
||||||
|
gmio_stl_format_t format,
|
||||||
|
const char *filepath,
|
||||||
|
gmio_stl_mesh_t *mesh,
|
||||||
|
gmio_task_iface_t *task_iface)
|
||||||
|
{
|
||||||
|
int error = GMIO_ERROR_OK;
|
||||||
|
FILE* file = NULL;
|
||||||
|
|
||||||
|
file = fopen(filepath, "wb");
|
||||||
|
if (file != NULL) {
|
||||||
|
gmio_transfer_t trsf = { 0 };
|
||||||
|
trsf.stream = gmio_stream_stdio(file);
|
||||||
|
trsf.buffer = gmio_buffer_default();
|
||||||
|
if (task_iface != NULL)
|
||||||
|
trsf.task_iface = *task_iface;
|
||||||
|
|
||||||
|
error = gmio_stl_write(format, &trsf, mesh);
|
||||||
|
fclose(file);
|
||||||
|
gmio_buffer_deallocate(&trsf.buffer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = GMIO_ERROR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gmio_stl_write(
|
||||||
|
gmio_stl_format_t format,
|
||||||
|
gmio_transfer_t *trsf,
|
||||||
|
gmio_stl_mesh_t *mesh)
|
||||||
|
{
|
||||||
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
|
if (trsf != NULL) {
|
||||||
|
switch (format) {
|
||||||
|
case GMIO_STL_FORMAT_ASCII: {
|
||||||
|
error = gmio_stla_write(trsf, mesh, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GMIO_STL_FORMAT_BINARY_BE: {
|
||||||
|
const gmio_stlb_write_options_t opts = { NULL,
|
||||||
|
GMIO_ENDIANNESS_BIG };
|
||||||
|
error = gmio_stlb_write(trsf, mesh, &opts);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GMIO_STL_FORMAT_BINARY_LE: {
|
||||||
|
const gmio_stlb_write_options_t opts = { NULL,
|
||||||
|
GMIO_ENDIANNESS_LITTLE };
|
||||||
|
error = gmio_stlb_write(trsf, mesh, &opts);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GMIO_STL_FORMAT_UNKNOWN: {
|
||||||
|
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
||||||
|
}
|
||||||
|
} /* end switch() */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = GMIO_ERROR_NULL_TRANSFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
GMIO_C_LINKAGE_BEGIN
|
GMIO_C_LINKAGE_BEGIN
|
||||||
|
|
||||||
/*! Reads STL file, format is automatically guessed
|
/*! Reads STL mesh from file, format is automatically guessed
|
||||||
*
|
*
|
||||||
* \param filepath Path to the STL file. A stream is opened with fopen() so
|
* \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)
|
* the string has to be encoded using the system's charset (locale-8bit)
|
||||||
@ -51,7 +51,7 @@ int gmio_stl_read_file(
|
|||||||
gmio_stl_mesh_creator_t* creator,
|
gmio_stl_mesh_creator_t* creator,
|
||||||
gmio_task_iface_t* task_iface);
|
gmio_task_iface_t* task_iface);
|
||||||
|
|
||||||
/*! Reads STL data from stream, format is automatically guessed
|
/*! Reads STL mesh from stream, format is automatically guessed
|
||||||
*
|
*
|
||||||
* \param trsf Defines needed objects for the read operation
|
* \param trsf Defines needed objects for the read operation
|
||||||
* \param creator Defines the callbacks for the mesh creation
|
* \param creator Defines the callbacks for the mesh creation
|
||||||
@ -63,6 +63,43 @@ int gmio_stl_read(
|
|||||||
gmio_transfer_t* trsf,
|
gmio_transfer_t* trsf,
|
||||||
gmio_stl_mesh_creator_t* creator);
|
gmio_stl_mesh_creator_t* creator);
|
||||||
|
|
||||||
|
/*! Writes STL mesh to file
|
||||||
|
*
|
||||||
|
* \param format STL format of the output file
|
||||||
|
* \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 mesh Defines the mesh to output
|
||||||
|
* \param task_iface The interface object by which the write operation can be
|
||||||
|
* controlled. Optional, can be safely set to NULL
|
||||||
|
*
|
||||||
|
* 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())
|
||||||
|
*
|
||||||
|
* \return Error code (see error.h and stl_error.h)
|
||||||
|
*/
|
||||||
|
GMIO_LIBSTL_EXPORT
|
||||||
|
int gmio_stl_write_file(
|
||||||
|
gmio_stl_format_t format,
|
||||||
|
const char* filepath,
|
||||||
|
gmio_stl_mesh_t* mesh,
|
||||||
|
gmio_task_iface_t* task_iface);
|
||||||
|
|
||||||
|
/*! Writes STL mesh to stream
|
||||||
|
*
|
||||||
|
* \param format STL format of the output
|
||||||
|
* \param trsf Defines needed objects for the write operation
|
||||||
|
* \param mesh Defines the mesh to output
|
||||||
|
*
|
||||||
|
* \return Error code (see error.h and stl_error.h)
|
||||||
|
*/
|
||||||
|
GMIO_LIBSTL_EXPORT
|
||||||
|
int gmio_stl_write(
|
||||||
|
gmio_stl_format_t format,
|
||||||
|
gmio_transfer_t* trsf,
|
||||||
|
gmio_stl_mesh_t* mesh);
|
||||||
|
|
||||||
/* ========================================================================
|
/* ========================================================================
|
||||||
* STL ascii
|
* STL ascii
|
||||||
* ======================================================================== */
|
* ======================================================================== */
|
||||||
|
Loading…
Reference in New Issue
Block a user