gmio_stl: simplify façade API for stl_io.h

This commit is contained in:
Hugues Delorme 2015-04-02 15:36:57 +02:00
parent 692c2d7f58
commit 69d68a4ba9
5 changed files with 11 additions and 19 deletions

View File

@ -145,8 +145,6 @@ static void gmio_assimp_end_solid(void* cookie)
static void bench_gmio_stl_read(const char* filepath) static void bench_gmio_stl_read(const char* filepath)
{ {
gmio_buffer_t buffer = gmio_buffer_malloc(256 * 1024);
aiScene* scene = new aiScene; aiScene* scene = new aiScene;
gmio_stl_mesh_creator_t mesh_creator = { 0 }; gmio_stl_mesh_creator_t mesh_creator = { 0 };
mesh_creator.cookie = scene; mesh_creator.cookie = scene;
@ -155,11 +153,9 @@ static void bench_gmio_stl_read(const char* filepath)
mesh_creator.add_triangle_func = gmio_assimp_add_triangle; mesh_creator.add_triangle_func = gmio_assimp_add_triangle;
mesh_creator.end_solid_func = gmio_assimp_end_solid; mesh_creator.end_solid_func = gmio_assimp_end_solid;
int error = gmio_stl_read_file(filepath, &buffer, &mesh_creator); int error = gmio_stl_read_file(filepath, &mesh_creator);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("GeomIO error: 0x%X\n", error); printf("GeomIO error: 0x%X\n", error);
gmio_buffer_deallocate(&buffer);
} }
int main(int argc, char** argv) int main(int argc, char** argv)

View File

@ -19,19 +19,15 @@ static void dummy_process_triangle(void* cookie,
static void bench_gmio_stl_read(const char* filepath) static void bench_gmio_stl_read(const char* filepath)
{ {
gmio_buffer_t buffer = gmio_buffer_malloc(512 * 1024);
my_igeom_t cookie = { 0 }; my_igeom_t cookie = { 0 };
gmio_stl_mesh_creator_t mesh_creator = { 0 }; gmio_stl_mesh_creator_t mesh_creator = { 0 };
int error = GMIO_ERROR_OK; int error = GMIO_ERROR_OK;
mesh_creator.cookie = &cookie; mesh_creator.cookie = &cookie;
mesh_creator.add_triangle_func = dummy_process_triangle; mesh_creator.add_triangle_func = dummy_process_triangle;
error = gmio_stl_read_file(filepath, &mesh_creator);
error = gmio_stl_read_file(filepath, &buffer, &mesh_creator);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("GeomIO error: 0x%X\n", error); printf("GeomIO error: 0x%X\n", error);
gmio_buffer_deallocate(&buffer);
} }
int main(int argc, char** argv) int main(int argc, char** argv)

View File

@ -15,13 +15,11 @@ static void bench_occ_RWStl_ReadFile(const char* filepath)
static void bench_gmio_stl_read(const char* filepath) static void bench_gmio_stl_read(const char* filepath)
{ {
gmio_buffer_t buffer = gmio_buffer_malloc(256 * 1024);
Handle_StlMesh_Mesh mesh = new StlMesh_Mesh; Handle_StlMesh_Mesh mesh = new StlMesh_Mesh;
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_occmesh_creator(mesh); gmio_stl_mesh_creator_t mesh_creator = gmio_stl_occmesh_creator(mesh);
int error = gmio_stl_read_file(filepath, &buffer, &mesh_creator); int error = gmio_stl_read_file(filepath, &mesh_creator);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("GeomIO error: 0x%X\n", error); printf("GeomIO error: 0x%X\n", error);
gmio_buffer_deallocate(&buffer);
} }
int main(int argc, char** argv) int main(int argc, char** argv)

View File

@ -24,7 +24,6 @@
int gmio_stl_read_file( int gmio_stl_read_file(
const char* filepath, const char* filepath,
gmio_buffer_t* buffer,
gmio_stl_mesh_creator_t* creator) gmio_stl_mesh_creator_t* creator)
{ {
int error = GMIO_ERROR_OK; int error = GMIO_ERROR_OK;
@ -33,13 +32,12 @@ int gmio_stl_read_file(
file = fopen(filepath, "rb"); file = fopen(filepath, "rb");
if (file != NULL) { if (file != NULL) {
gmio_transfer_t trsf = { 0 }; gmio_transfer_t trsf = { 0 };
trsf.stream = gmio_stream_stdio(file); trsf.stream = gmio_stream_stdio(file);
if (buffer != NULL) trsf.buffer = gmio_buffer_default();
trsf.buffer = *buffer;
error = gmio_stl_read(&trsf, creator); error = gmio_stl_read(&trsf, creator);
fclose(file); fclose(file);
gmio_buffer_deallocate(&trsf.buffer);
} }
else { else {
error = GMIO_ERROR_UNKNOWN; error = GMIO_ERROR_UNKNOWN;

View File

@ -21,6 +21,7 @@
#define GMIO_STL_IO_H #define GMIO_STL_IO_H
#include "stl_global.h" #include "stl_global.h"
#include "stl_format.h"
#include "stl_mesh.h" #include "stl_mesh.h"
#include "stl_mesh_creator.h" #include "stl_mesh_creator.h"
#include "../gmio_core/buffer.h" #include "../gmio_core/buffer.h"
@ -34,14 +35,17 @@ GMIO_C_LINKAGE_BEGIN
* \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)
* \param creator Defines the callbacks for the mesh creation * \param creator Defines the callbacks for the mesh creation
* \param buffer The memory block used by stream operations *
* 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) * \return Error code (see error.h and stl_error.h)
*/ */
GMIO_LIBSTL_EXPORT GMIO_LIBSTL_EXPORT
int gmio_stl_read_file( int gmio_stl_read_file(
const char* filepath, const char* filepath,
gmio_buffer_t* buffer,
gmio_stl_mesh_creator_t* creator); gmio_stl_mesh_creator_t* creator);
/*! Reads STL data from stream, format is automatically guessed /*! Reads STL data from stream, format is automatically guessed