gmio_stl: API change in stl_io

This commit is contained in:
Hugues Delorme 2015-12-17 12:31:30 +01:00
parent 0f04b296fb
commit 71bc14b6dc
8 changed files with 37 additions and 29 deletions

View File

@ -305,13 +305,12 @@ static void stl_write(const char* filepath, gmio_stl_format format)
const aiMesh* sceneMesh = globalSceneHelper.scene->mMeshes[0]; const aiMesh* sceneMesh = globalSceneHelper.scene->mMeshes[0];
gmio_stl_write_args write = {}; gmio_stl_write_args write = {};
write.format = format;
write.mesh.cookie = sceneMesh; write.mesh.cookie = sceneMesh;
write.mesh.triangle_count = sceneMesh->mNumFaces; write.mesh.triangle_count = sceneMesh->mNumFaces;
write.mesh.func_get_triangle = get_triangle; write.mesh.func_get_triangle = get_triangle;
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE; write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
write.options.stla_float32_prec = 7; write.options.stla_float32_prec = 7;
const int error = gmio_stl_write_file(&write, filepath); const int error = gmio_stl_write_file(&write, format, filepath);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
} }

View File

@ -130,14 +130,13 @@ static void stl_readwrite_flush_triangles(struct stl_readwrite_conv* rw_conv)
{ {
struct gmio_stl_write_args write = {0}; struct gmio_stl_write_args write = {0};
write.core = rw_conv->rwargs; write.core = rw_conv->rwargs;
write.format = rw_conv->out_format;
write.mesh.cookie = &rw_conv->triangle_array[0]; write.mesh.cookie = &rw_conv->triangle_array[0];
write.mesh.triangle_count = rw_conv->triangle_pos; write.mesh.triangle_count = rw_conv->triangle_pos;
write.mesh.func_get_triangle = &readwrite_get_triangle; write.mesh.func_get_triangle = &readwrite_get_triangle;
write.options.stl_write_triangles_only = GMIO_TRUE; write.options.stl_write_triangles_only = GMIO_TRUE;
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SCIENTIFIC_LOWERCASE; write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SCIENTIFIC_LOWERCASE;
write.options.stla_float32_prec = 6; write.options.stla_float32_prec = 6;
gmio_stl_write(&write); gmio_stl_write(&write, rw_conv->out_format);
rw_conv->triangle_pos = 0; rw_conv->triangle_pos = 0;
} }

View File

@ -60,7 +60,7 @@ static void stl_read(const char* filepath)
{ {
stlMesh = new StlMesh_Mesh; stlMesh = new StlMesh_Mesh;
gmio_stl_read_args read = {}; gmio_stl_read_args read = {};
args.mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh); read.mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh);
int error = gmio_stl_read_file(&read, filepath); int error = gmio_stl_read_file(&read, filepath);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
@ -70,11 +70,10 @@ static void stl_write(const char* filepath, gmio_stl_format format)
{ {
const gmio_occ_stl_mesh_domain occ_mesh_domain(stlMesh); const gmio_occ_stl_mesh_domain occ_mesh_domain(stlMesh);
gmio_stl_write_args write = {}; gmio_stl_write_args write = {};
write.format = format;
write.mesh = gmio_stl_occmesh(&occ_mesh_domain); write.mesh = gmio_stl_occmesh(&occ_mesh_domain);
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE; write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
write.options.stla_float32_prec = 7; write.options.stla_float32_prec = 7;
const int error = gmio_stl_write_file(&write, filepath); const int error = gmio_stl_write_file(&write, format, filepath);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
} }

View File

@ -27,10 +27,10 @@ int gmio_stl_read(struct gmio_stl_read_args* args)
{ {
int error = GMIO_ERROR_OK; int error = GMIO_ERROR_OK;
if (args != NULL) { if (args != NULL) {
const enum gmio_stl_format stl_format = const enum gmio_stl_format format =
gmio_stl_get_format(&args->core.stream); gmio_stl_get_format(&args->core.stream);
switch (stl_format) { switch (format) {
case GMIO_STL_FORMAT_ASCII: { case GMIO_STL_FORMAT_ASCII: {
error = gmio_stla_read(args); error = gmio_stla_read(args);
break; break;
@ -76,13 +76,14 @@ int gmio_stl_read_file(
return error; return error;
} }
int gmio_stl_write(struct gmio_stl_write_args* args) int gmio_stl_write(
struct gmio_stl_write_args* args, enum gmio_stl_format format)
{ {
int error = GMIO_ERROR_OK; int error = GMIO_ERROR_OK;
if (args != NULL) { if (args != NULL) {
struct gmio_memblock_helper mblock_helper = struct gmio_memblock_helper mblock_helper =
gmio_memblock_helper(&args->core.memblock); gmio_memblock_helper(&args->core.memblock);
switch (args->format) { switch (format) {
case GMIO_STL_FORMAT_ASCII: { case GMIO_STL_FORMAT_ASCII: {
error = gmio_stla_write(args); error = gmio_stla_write(args);
break; break;
@ -108,14 +109,16 @@ int gmio_stl_write(struct gmio_stl_write_args* args)
} }
int gmio_stl_write_file( int gmio_stl_write_file(
struct gmio_stl_write_args* args, const char* filepath) struct gmio_stl_write_args* args,
enum gmio_stl_format format,
const char* filepath)
{ {
int error = GMIO_ERROR_OK; int error = GMIO_ERROR_OK;
if (args != NULL) { if (args != NULL) {
FILE* file = fopen(filepath, "wb"); FILE* file = fopen(filepath, "wb");
if (file != NULL) { if (file != NULL) {
args->core.stream = gmio_stream_stdio(file); args->core.stream = gmio_stream_stdio(file);
error = gmio_stl_write(args); error = gmio_stl_write(args, format);
fclose(file); fclose(file);
} }
else { else {

View File

@ -70,7 +70,8 @@ int gmio_stlb_read(
* \return Error code (see gmio_core/error.h and stl_error.h) * \return Error code (see gmio_core/error.h and stl_error.h)
*/ */
GMIO_LIBSTL_EXPORT GMIO_LIBSTL_EXPORT
int gmio_stl_write(struct gmio_stl_write_args* args); int gmio_stl_write(
struct gmio_stl_write_args* args, enum gmio_stl_format format);
/*! Writes STL mesh to stream /*! Writes STL mesh to stream
* *
@ -84,7 +85,10 @@ int gmio_stl_write(struct gmio_stl_write_args* args);
* \return Error code (see gmio_core/error.h and stl_error.h) * \return Error code (see gmio_core/error.h and stl_error.h)
*/ */
GMIO_LIBSTL_EXPORT GMIO_LIBSTL_EXPORT
int gmio_stl_write_file(struct gmio_stl_write_args* args, const char* filepath); int gmio_stl_write_file(
struct gmio_stl_write_args* args,
enum gmio_stl_format format,
const char* filepath);
/*! Writes STL binary header data to stream /*! Writes STL binary header data to stream
* *

View File

@ -62,9 +62,6 @@ struct gmio_stl_write_args
/*! Defines the mesh to output */ /*! Defines the mesh to output */
struct gmio_stl_mesh mesh; struct gmio_stl_mesh mesh;
/*! STL format of the output */
enum gmio_stl_format format;
/*! Options for the write operation, can be safely set to \c {0} to use /*! Options for the write operation, can be safely set to \c {0} to use
* default values */ * default values */
struct gmio_stl_write_options options; struct gmio_stl_write_options options;

View File

@ -38,6 +38,7 @@ if(GMIO_BUILD_SHARED_LIBS)
# exports all symbols) # exports all symbols)
set(GMIO_TEST_CORE_SRC set(GMIO_TEST_CORE_SRC
${GMIO_TEST_CORE_SRC} ${GMIO_TEST_CORE_SRC}
../src/gmio_core/internal/numeric_utils.c
../src/gmio_core/internal/stringstream.c) ../src/gmio_core/internal/stringstream.c)
endif() endif()
@ -59,6 +60,7 @@ if(GMIO_BUILD_SHARED_LIBS)
# See Note_1 # See Note_1
set(GMIO_TEST_STL_SRC set(GMIO_TEST_STL_SRC
${GMIO_TEST_STL_SRC} ${GMIO_TEST_STL_SRC}
../src/gmio_core/internal/numeric_utils.c
../src/gmio_stl/internal/stl_rw_common.c) ../src/gmio_stl/internal/stl_rw_common.c)
endif() endif()

View File

@ -245,13 +245,13 @@ const char* test_stlb_write()
struct gmio_stl_write_args write = {0}; struct gmio_stl_write_args write = {0};
write.mesh = gmio_stl_data_mesh(&data); write.mesh = gmio_stl_data_mesh(&data);
write.options.stlb_header_data = &data.header; write.options.stlb_header_data = &data.header;
write.format = GMIO_STL_FORMAT_BINARY_LE; error = gmio_stl_write_file(
error = gmio_stl_write_file(&write, model_filepath_out); &write, GMIO_STL_FORMAT_BINARY_LE, model_filepath_out);
UTEST_ASSERT(error == GMIO_ERROR_OK); UTEST_ASSERT(error == GMIO_ERROR_OK);
/* Big-endian version */ /* Big-endian version */
write.format = GMIO_STL_FORMAT_BINARY_BE; error = gmio_stl_write_file(
error = gmio_stl_write_file(&write, model_filepath_out_be); &write, GMIO_STL_FORMAT_BINARY_BE, model_filepath_out_be);
} }
/* Check input and output models are equal */ /* Check input and output models are equal */
@ -324,13 +324,14 @@ const char* test_stla_write()
/* Write the model to STL ascii format */ /* Write the model to STL ascii format */
{ {
struct gmio_stl_write_args write = {0}; struct gmio_stl_write_args write = {0};
write.format = GMIO_STL_FORMAT_ASCII;
write.mesh = gmio_stl_data_mesh(&data); write.mesh = gmio_stl_data_mesh(&data);
gmio_stlb_header_to_printable_string(&data.header, &header_str[0], '_'); gmio_stlb_header_to_printable_string(&data.header, &header_str[0], '_');
write.options.stla_solid_name = &header_str[0]; write.options.stla_solid_name = &header_str[0];
write.options.stla_float32_prec = 7; write.options.stla_float32_prec = 7;
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE; write.options.stla_float32_format =
error = gmio_stl_write_file(&write, model_filepath_out); GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
error = gmio_stl_write_file(
&write, GMIO_STL_FORMAT_ASCII, model_filepath_out);
UTEST_ASSERT(error == GMIO_ERROR_OK); UTEST_ASSERT(error == GMIO_ERROR_OK);
} }
@ -382,9 +383,13 @@ void generate_stlb_tests_models()
data.tri_array.count = 1; data.tri_array.count = 1;
write.mesh = gmio_stl_data_mesh(&data); write.mesh = gmio_stl_data_mesh(&data);
write.format = GMIO_STL_FORMAT_BINARY_LE; gmio_stl_write_file(
gmio_stl_write_file(&write, "models/solid_one_facet.le_stlb"); &write,
write.format = GMIO_STL_FORMAT_BINARY_BE; GMIO_STL_FORMAT_BINARY_LE,
gmio_stl_write_file(&write, "models/solid_one_facet.be_stlb"); "models/solid_one_facet.le_stlb");
gmio_stl_write_file(
&write,
GMIO_STL_FORMAT_BINARY_BE,
"models/solid_one_facet.be_stlb");
} }
} }