gmio_stl: change API to use pointer arguments instead of confusing value
This commit is contained in:
parent
77c65947bb
commit
74ae9ba752
@ -284,7 +284,7 @@ static void stl_read(const void* filepath)
|
||||
mesh_creator.func_add_triangle = add_triangle;
|
||||
mesh_creator.func_end_solid = end_solid;
|
||||
|
||||
const int error = gmio_stl_read_file(str_filepath, mesh_creator, NULL);
|
||||
const int error = gmio_stl_read_file(str_filepath, &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
|
||||
@ -305,7 +305,7 @@ static void stl_write(const char* filepath, gmio_stl_format format)
|
||||
gmio_stl_write_options opts = {};
|
||||
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
|
||||
opts.stla_float32_prec = 7;
|
||||
const int error = gmio_stl_write_file(format, filepath, mesh, NULL);
|
||||
const int error = gmio_stl_write_file(format, filepath, &mesh, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ static void bmk_gmio_stl_read(const void* filepath)
|
||||
|
||||
mesh_creator.cookie = &cookie;
|
||||
mesh_creator.func_add_triangle = dummy_process_triangle;
|
||||
error = gmio_stl_read_file(filepath, mesh_creator, NULL);
|
||||
error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
@ -143,7 +143,7 @@ static void stl_readwrite_flush_triangles(struct stl_readwrite_conv* rw_conv)
|
||||
options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SCIENTIFIC_LOWERCASE;
|
||||
options.stla_float32_prec = 6;
|
||||
|
||||
gmio_stl_write(rw_conv->out_format, rw_conv->stream, mesh, &options);
|
||||
gmio_stl_write(rw_conv->out_format, &rw_conv->stream, &mesh, &options);
|
||||
rw_conv->triangle_pos = 0;
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ static void bmk_gmio_stl_readwrite_conv(const void* filepath)
|
||||
mesh_creator.func_add_triangle = &readwrite_add_triangle;
|
||||
mesh_creator.func_end_solid = &readwrite_end_solid;
|
||||
|
||||
error = gmio_stl_read(instream, mesh_creator, NULL);
|
||||
error = gmio_stl_read(&instream, &mesh_creator, NULL);
|
||||
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
@ -220,9 +220,9 @@ void bmk_gmio_stl_infos_get_all(const void* filepath)
|
||||
FILE* file = fopen(filepath, "rb");
|
||||
|
||||
if (file != NULL) {
|
||||
const struct gmio_stream stream = gmio_stream_stdio(file);
|
||||
struct gmio_stream stream = gmio_stream_stdio(file);
|
||||
struct gmio_stl_infos infos = {0};
|
||||
gmio_stl_infos_get(&infos, stream, GMIO_STL_INFO_FLAG_ALL, NULL);
|
||||
gmio_stl_infos_get(&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL);
|
||||
|
||||
if (!already_exec) {
|
||||
printf("stl_infos_get(ALL)\n"
|
||||
@ -253,9 +253,9 @@ void bmk_gmio_stl_infos_get_size(const void* filepath)
|
||||
FILE* file = fopen(filepath, "rb");
|
||||
|
||||
if (file != NULL) {
|
||||
const struct gmio_stream stream = gmio_stream_stdio(file);
|
||||
struct gmio_stream stream = gmio_stream_stdio(file);
|
||||
struct gmio_stl_infos infos = {0};
|
||||
gmio_stl_infos_get(&infos, stream, GMIO_STL_INFO_FLAG_SIZE, NULL);
|
||||
gmio_stl_infos_get(&infos, &stream, GMIO_STL_INFO_FLAG_SIZE, NULL);
|
||||
|
||||
if (!already_exec) {
|
||||
printf("stl_infos_get(SIZE)\n"
|
||||
|
@ -58,11 +58,10 @@ Handle_StlMesh_Mesh stlMesh;
|
||||
|
||||
static void stl_read(const void* filepath)
|
||||
{
|
||||
gmio_stl_mesh_creator mesh_creator = gmio_stl_occmesh_creator(stlMesh);
|
||||
stlMesh = new StlMesh_Mesh;
|
||||
const int error = gmio_stl_read_file(
|
||||
static_cast<const char*>(filepath),
|
||||
gmio_stl_occmesh_creator(stlMesh),
|
||||
NULL);
|
||||
static_cast<const char*>(filepath), &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
@ -72,12 +71,9 @@ static void stl_write(const char* filepath, gmio_stl_format format)
|
||||
gmio_stl_write_options options = {};
|
||||
options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
|
||||
options.stla_float32_prec = 7;
|
||||
const int error =
|
||||
gmio_stl_write_file(
|
||||
format,
|
||||
static_cast<const char*>(filepath),
|
||||
gmio_stl_occmesh(stlMesh),
|
||||
&options);
|
||||
gmio_stl_occmesh_iterator occ_itmesh(stlMesh);
|
||||
const gmio_stl_mesh occmesh = gmio_stl_occmesh(occ_itmesh);
|
||||
const int error = gmio_stl_write_file(format, filepath, &occmesh, &options);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ static size_t gmio_stringstream_read(
|
||||
|
||||
int gmio_stla_infos_get(
|
||||
struct gmio_stl_infos* infos,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stream* stream,
|
||||
unsigned flags,
|
||||
const struct gmio_stl_infos_get_options* opts)
|
||||
{
|
||||
@ -85,7 +85,7 @@ int gmio_stla_infos_get(
|
||||
return err;
|
||||
|
||||
/* Initialize string stream */
|
||||
sstream.stream = stream;
|
||||
sstream.stream = *stream;
|
||||
sstream.strbuff = gmio_string(mblock_ptr, 0, mblock_size);
|
||||
if (flag_size) {
|
||||
infos->size = 0;
|
||||
|
@ -21,7 +21,7 @@
|
||||
/*! Find infos from a STL ASCII stream */
|
||||
int gmio_stla_infos_get(
|
||||
struct gmio_stl_infos* infos,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stream* stream,
|
||||
unsigned flags,
|
||||
const struct gmio_stl_infos_get_options* opts);
|
||||
|
||||
|
@ -134,8 +134,8 @@ GMIO_INLINE bool gmio_stream_flush_buffer(
|
||||
}
|
||||
|
||||
int gmio_stla_write(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh mesh,
|
||||
struct gmio_stream* stream,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* opts)
|
||||
{
|
||||
/* Constants */
|
||||
@ -143,7 +143,7 @@ int gmio_stla_write(
|
||||
struct gmio_memblock_helper mblock_helper =
|
||||
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||
const size_t mblock_size = mblock_helper.memblock.size;
|
||||
const uint32_t total_facet_count = mesh.triangle_count;
|
||||
const uint32_t total_facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
||||
const uint32_t buffer_facet_count =
|
||||
gmio_size_to_uint32(mblock_size / GMIO_STLA_FACET_SIZE_P2);
|
||||
const char* opt_solid_name = opts != NULL ? opts->stla_solid_name : NULL;
|
||||
@ -167,7 +167,7 @@ int gmio_stla_write(
|
||||
/* Check validity of input parameters */
|
||||
if (!gmio_check_memblock_size(&error, mblock, GMIO_STLA_FACET_SIZE_P2))
|
||||
goto label_end;
|
||||
if (!gmio_stl_check_mesh(&error, &mesh))
|
||||
if (!gmio_stl_check_mesh(&error, mesh))
|
||||
goto label_end;
|
||||
if (!gmio_stla_check_float32_precision(&error, f32_prec))
|
||||
goto label_end;
|
||||
@ -189,7 +189,7 @@ int gmio_stla_write(
|
||||
char* buffpos = mblock_ptr;
|
||||
buffpos = gmio_write_rawstr(buffpos, "solid ");
|
||||
buffpos = gmio_write_rawstr_eol(buffpos, solid_name);
|
||||
if (!gmio_stream_flush_buffer(&stream, mblock_ptr, buffpos)) {
|
||||
if (!gmio_stream_flush_buffer(stream, mblock_ptr, buffpos)) {
|
||||
error = GMIO_ERROR_STREAM;
|
||||
goto label_end;
|
||||
}
|
||||
@ -213,7 +213,7 @@ int gmio_stla_write(
|
||||
ibuffer_facet < clamped_facet_count;
|
||||
++ibuffer_facet)
|
||||
{
|
||||
mesh.func_get_triangle(mesh.cookie, ibuffer_facet, &tri);
|
||||
mesh->func_get_triangle(mesh->cookie, ibuffer_facet, &tri);
|
||||
|
||||
buffpos = gmio_write_rawstr(buffpos, "facet normal ");
|
||||
buffpos = gmio_write_coords(buffpos, coords_format_str, &tri.n);
|
||||
@ -230,7 +230,7 @@ int gmio_stla_write(
|
||||
buffpos = gmio_write_rawstr(buffpos, "\nendfacet\n");
|
||||
} /* end for (ibuffer_facet) */
|
||||
|
||||
if (!gmio_stream_flush_buffer(&stream, mblock_ptr, buffpos))
|
||||
if (!gmio_stream_flush_buffer(stream, mblock_ptr, buffpos))
|
||||
error = GMIO_ERROR_STREAM;
|
||||
|
||||
/* Task control */
|
||||
@ -243,7 +243,7 @@ int gmio_stla_write(
|
||||
char* buffpos = mblock_ptr;
|
||||
buffpos = gmio_write_rawstr(buffpos, "endsolid ");
|
||||
buffpos = gmio_write_rawstr_eol(buffpos, solid_name);
|
||||
if (!gmio_stream_flush_buffer(&stream, mblock_ptr, buffpos))
|
||||
if (!gmio_stream_flush_buffer(stream, mblock_ptr, buffpos))
|
||||
error = GMIO_ERROR_STREAM;
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@
|
||||
* if <tt>options->stream_memblock.size < 512</tt>
|
||||
*/
|
||||
int gmio_stla_write(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh mesh,
|
||||
struct gmio_stream* stream,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* options);
|
||||
|
||||
#endif /* GMIO_INTERNAL_STLA_WRITE_H */
|
||||
|
@ -32,7 +32,7 @@ static enum gmio_endianness gmio_stl_format_to_endianness(
|
||||
|
||||
int gmio_stlb_infos_get(
|
||||
struct gmio_stl_infos* infos,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stream* stream,
|
||||
unsigned flags,
|
||||
const struct gmio_stl_infos_get_options* opts)
|
||||
{
|
||||
@ -44,7 +44,7 @@ int gmio_stlb_infos_get(
|
||||
|
||||
{ /* Read header and facet count into buff */
|
||||
const size_t read_size =
|
||||
gmio_stream_read(&stream, buff, 1, sizeof(buff));
|
||||
gmio_stream_read_bytes(stream, buff, sizeof(buff));
|
||||
if (read_size != sizeof(buff))
|
||||
return GMIO_ERROR_STREAM;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
/*! Finds infos from a STL binary stream */
|
||||
int gmio_stlb_infos_get(
|
||||
struct gmio_stl_infos* infos,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stream* stream,
|
||||
unsigned flags,
|
||||
const struct gmio_stl_infos_get_options* opts);
|
||||
|
||||
|
@ -87,8 +87,8 @@ static void gmio_stlb_encode_facets_byteswap(
|
||||
|
||||
int gmio_stlb_write(
|
||||
enum gmio_endianness byte_order,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh mesh,
|
||||
struct gmio_stream* stream,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* opts)
|
||||
{
|
||||
/* Constants */
|
||||
@ -96,7 +96,7 @@ int gmio_stlb_write(
|
||||
struct gmio_memblock_helper mblock_helper =
|
||||
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||
const size_t mblock_size = mblock_helper.memblock.size;
|
||||
const uint32_t facet_count = mesh.triangle_count;
|
||||
const uint32_t facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
||||
const func_gmio_stlb_encode_facets_t func_encode_facets =
|
||||
byte_order != GMIO_ENDIANNESS_HOST ?
|
||||
gmio_stlb_encode_facets_byteswap :
|
||||
@ -116,13 +116,13 @@ int gmio_stlb_write(
|
||||
/* Check validity of input parameters */
|
||||
if (!gmio_check_memblock(&error, &mblock_helper.memblock))
|
||||
goto label_end;
|
||||
if (!gmio_stl_check_mesh(&error, &mesh))
|
||||
if (!gmio_stl_check_mesh(&error, mesh))
|
||||
goto label_end;
|
||||
if (!gmio_stlb_check_byteorder(&error, byte_order))
|
||||
goto label_end;
|
||||
|
||||
if (!write_triangles_only) {
|
||||
error = gmio_stlb_write_header(&stream, byte_order, header, facet_count);
|
||||
error = gmio_stlb_write_header(stream, byte_order, header, facet_count);
|
||||
if (gmio_error(error))
|
||||
goto label_end;
|
||||
}
|
||||
@ -136,11 +136,11 @@ int gmio_stlb_write(
|
||||
|
||||
/* Write to memory block */
|
||||
write_facet_count = GMIO_MIN(write_facet_count, facet_count - i_facet);
|
||||
func_encode_facets(&mesh, mblock_ptr, write_facet_count, i_facet);
|
||||
func_encode_facets(mesh, mblock_ptr, write_facet_count, i_facet);
|
||||
|
||||
/* Write memory block to stream */
|
||||
if (gmio_stream_write(
|
||||
&stream,
|
||||
stream,
|
||||
mblock_ptr,
|
||||
GMIO_STLB_TRIANGLE_RAWSIZE,
|
||||
write_facet_count)
|
||||
|
@ -29,8 +29,8 @@
|
||||
*/
|
||||
int gmio_stlb_write(
|
||||
enum gmio_endianness byte_order,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh mesh,
|
||||
struct gmio_stream* stream,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* opts);
|
||||
|
||||
#endif /* GMIO_INTERNAL_STLB_WRITE_H */
|
||||
|
@ -25,12 +25,12 @@
|
||||
|
||||
int gmio_stl_infos_get(
|
||||
struct gmio_stl_infos* infos,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stream* stream,
|
||||
unsigned flags,
|
||||
const struct gmio_stl_infos_get_options* opts)
|
||||
{
|
||||
int error = GMIO_ERROR_OK;
|
||||
const struct gmio_streampos begin_streampos = gmio_streampos(&stream, NULL);
|
||||
const struct gmio_streampos begin_streampos = gmio_streampos(stream, NULL);
|
||||
struct gmio_memblock_helper mblock_helper =
|
||||
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||
enum gmio_stl_format format =
|
||||
@ -43,7 +43,7 @@ int gmio_stl_infos_get(
|
||||
|
||||
/* Guess format when left unspecified */
|
||||
if (format == GMIO_STL_FORMAT_UNKNOWN) {
|
||||
format = gmio_stl_get_format(&stream);
|
||||
format = gmio_stl_get_format(stream);
|
||||
if (format == GMIO_STL_FORMAT_UNKNOWN) {
|
||||
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
||||
goto label_end;
|
||||
@ -69,7 +69,7 @@ int gmio_stl_infos_get(
|
||||
}
|
||||
|
||||
label_end:
|
||||
gmio_stream_set_pos(&stream, &begin_streampos);
|
||||
gmio_stream_set_pos(stream, &begin_streampos);
|
||||
gmio_memblock_helper_release(&mblock_helper);
|
||||
return error;
|
||||
}
|
||||
@ -81,6 +81,6 @@ gmio_streamsize_t gmio_stla_infos_get_streamsize(
|
||||
struct gmio_stl_infos_get_options options = {0};
|
||||
options.stream_memblock = *stream_memblock;
|
||||
options.format_hint = GMIO_STL_FORMAT_ASCII;
|
||||
gmio_stl_infos_get(&infos, *stream, GMIO_STL_INFO_FLAG_SIZE, &options);
|
||||
gmio_stl_infos_get(&infos, stream, GMIO_STL_INFO_FLAG_SIZE, &options);
|
||||
return infos.size;
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ GMIO_C_LINKAGE_BEGIN
|
||||
GMIO_LIBSTL_EXPORT
|
||||
int gmio_stl_infos_get(
|
||||
struct gmio_stl_infos* infos,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stream* stream,
|
||||
unsigned flags, /*!< Bitor combination of gmio_stl_info_flag values */
|
||||
const struct gmio_stl_infos_get_options* options);
|
||||
|
||||
|
@ -24,11 +24,11 @@
|
||||
#include "../gmio_core/internal/helper_stream.h"
|
||||
|
||||
int gmio_stl_read(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stream* stream,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
const struct gmio_stl_read_options* options)
|
||||
{
|
||||
const enum gmio_stl_format format = gmio_stl_get_format(&stream);
|
||||
const enum gmio_stl_format format = gmio_stl_get_format(stream);
|
||||
switch (format) {
|
||||
case GMIO_STL_FORMAT_ASCII:
|
||||
return gmio_stla_read(stream, mesh_creator, options);
|
||||
@ -46,13 +46,13 @@ int gmio_stl_read(
|
||||
|
||||
int gmio_stl_read_file(
|
||||
const char* filepath,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
const struct gmio_stl_read_options* options)
|
||||
{
|
||||
FILE* file = fopen(filepath, "rb");
|
||||
if (file != NULL) {
|
||||
const int error =
|
||||
gmio_stl_read(gmio_stream_stdio(file), mesh_creator, options);
|
||||
struct gmio_stream stream = gmio_stream_stdio(file);
|
||||
const int error = gmio_stl_read(&stream, mesh_creator, options);
|
||||
fclose(file);
|
||||
return error;
|
||||
}
|
||||
@ -61,8 +61,8 @@ int gmio_stl_read_file(
|
||||
|
||||
int gmio_stl_write(
|
||||
enum gmio_stl_format format,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh mesh,
|
||||
struct gmio_stream* stream,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* options)
|
||||
{
|
||||
switch (format) {
|
||||
@ -81,13 +81,13 @@ int gmio_stl_write(
|
||||
int gmio_stl_write_file(
|
||||
enum gmio_stl_format format,
|
||||
const char* filepath,
|
||||
struct gmio_stl_mesh mesh,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* options)
|
||||
{
|
||||
FILE* file = fopen(filepath, "wb");
|
||||
if (file != NULL) {
|
||||
const int error =
|
||||
gmio_stl_write(format, gmio_stream_stdio(file), mesh, options);
|
||||
struct gmio_stream stream = gmio_stream_stdio(file);
|
||||
const int error = gmio_stl_write(format, &stream, mesh, options);
|
||||
fclose(file);
|
||||
return error;
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ GMIO_C_LINKAGE_BEGIN
|
||||
* \return Error code (see gmio_core/error.h and stl_error.h)
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT int gmio_stl_read(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stream* stream,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
const struct gmio_stl_read_options* options);
|
||||
|
||||
/*! Reads STL mesh from a file, format is automatically guessed
|
||||
@ -53,7 +53,7 @@ GMIO_LIBSTL_EXPORT int gmio_stl_read(
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT int gmio_stl_read_file(
|
||||
const char* filepath,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
const struct gmio_stl_read_options* options);
|
||||
|
||||
/*! Reads geometry from STL ascii stream
|
||||
@ -62,8 +62,8 @@ GMIO_LIBSTL_EXPORT int gmio_stl_read_file(
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT
|
||||
int gmio_stla_read(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stream* stream,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
const struct gmio_stl_read_options* options);
|
||||
|
||||
/*! Reads geometry from STL binary stream
|
||||
@ -74,8 +74,8 @@ int gmio_stla_read(
|
||||
*/
|
||||
GMIO_LIBSTL_EXPORT
|
||||
int gmio_stlb_read(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stream* stream,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
enum gmio_endianness byte_order,
|
||||
const struct gmio_stl_read_options* options);
|
||||
|
||||
@ -86,8 +86,8 @@ int gmio_stlb_read(
|
||||
GMIO_LIBSTL_EXPORT
|
||||
int gmio_stl_write(
|
||||
enum gmio_stl_format format,
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh mesh,
|
||||
struct gmio_stream* stream,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* options);
|
||||
|
||||
/*! Writes STL mesh to stream
|
||||
@ -104,7 +104,7 @@ GMIO_LIBSTL_EXPORT
|
||||
int gmio_stl_write_file(
|
||||
enum gmio_stl_format format,
|
||||
const char* filepath,
|
||||
struct gmio_stl_mesh mesh,
|
||||
const struct gmio_stl_mesh* mesh,
|
||||
const struct gmio_stl_write_options* options);
|
||||
|
||||
/*! Writes STL binary header data to stream
|
||||
|
@ -106,8 +106,8 @@ static size_t gmio_stringstream_stla_read(
|
||||
static void parse_solid(struct gmio_stla_parse_data* data);
|
||||
|
||||
int gmio_stla_read(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stream* stream,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
const struct gmio_stl_read_options* opts)
|
||||
{
|
||||
struct gmio_memblock_helper mblock_helper =
|
||||
@ -124,11 +124,11 @@ int gmio_stla_read(
|
||||
|
||||
parse_data.strstream_cookie.stream_size =
|
||||
opts != NULL && opts->func_stla_get_streamsize != NULL ?
|
||||
opts->func_stla_get_streamsize(&stream, mblock) :
|
||||
gmio_stream_size(&stream);
|
||||
opts->func_stla_get_streamsize(stream, mblock) :
|
||||
gmio_stream_size(stream);
|
||||
parse_data.strstream_cookie.is_stop_requested = false;
|
||||
|
||||
parse_data.strstream.stream = stream;
|
||||
parse_data.strstream.stream = *stream;
|
||||
parse_data.strstream.strbuff.ptr = mblock->ptr;
|
||||
parse_data.strstream.strbuff.max_len = mblock->size;
|
||||
parse_data.strstream.cookie = &parse_data.strstream_cookie;
|
||||
@ -137,7 +137,7 @@ int gmio_stla_read(
|
||||
|
||||
parse_data.token_str = gmio_string(fixed_buffer, 0, sizeof(fixed_buffer));
|
||||
|
||||
parse_data.creator = &mesh_creator;
|
||||
parse_data.creator = mesh_creator;
|
||||
|
||||
parse_solid(&parse_data);
|
||||
|
||||
|
@ -90,8 +90,8 @@ static void gmio_stlb_decode_facets_byteswap(
|
||||
}
|
||||
|
||||
int gmio_stlb_read(
|
||||
struct gmio_stream stream,
|
||||
struct gmio_stl_mesh_creator mesh_creator,
|
||||
struct gmio_stream* stream,
|
||||
struct gmio_stl_mesh_creator* mesh_creator,
|
||||
enum gmio_endianness byte_order,
|
||||
const struct gmio_stl_read_options* opts)
|
||||
{
|
||||
@ -119,13 +119,13 @@ int gmio_stlb_read(
|
||||
goto label_end;
|
||||
|
||||
/* Read header */
|
||||
if (gmio_stream_read(&stream, &header, GMIO_STLB_HEADER_SIZE, 1) != 1) {
|
||||
if (gmio_stream_read(stream, &header, GMIO_STLB_HEADER_SIZE, 1) != 1) {
|
||||
error = GMIO_STL_ERROR_HEADER_WRONG_SIZE;
|
||||
goto label_end;
|
||||
}
|
||||
|
||||
/* Read facet count */
|
||||
if (gmio_stream_read(&stream, mblock->ptr, sizeof(uint32_t), 1) != 1) {
|
||||
if (gmio_stream_read(stream, mblock->ptr, sizeof(uint32_t), 1) != 1) {
|
||||
error = GMIO_STL_ERROR_FACET_COUNT;
|
||||
goto label_end;
|
||||
}
|
||||
@ -142,7 +142,7 @@ int gmio_stlb_read(
|
||||
GMIO_STL_FORMAT_BINARY_BE;
|
||||
infos.stlb_header = &header;
|
||||
infos.stlb_triangle_count = total_facet_count;
|
||||
gmio_stl_mesh_creator_begin_solid(&mesh_creator, &infos);
|
||||
gmio_stl_mesh_creator_begin_solid(mesh_creator, &infos);
|
||||
}
|
||||
|
||||
/* Read triangles */
|
||||
@ -154,12 +154,12 @@ int gmio_stlb_read(
|
||||
const uint32_t read_facet_count =
|
||||
gmio_size_to_uint32(
|
||||
gmio_stream_read(
|
||||
&stream,
|
||||
stream,
|
||||
mblock->ptr,
|
||||
GMIO_STLB_TRIANGLE_RAWSIZE,
|
||||
facet_count_to_read));
|
||||
|
||||
if (gmio_stream_error(&stream) != 0)
|
||||
if (gmio_stream_error(stream) != 0)
|
||||
error = GMIO_ERROR_STREAM;
|
||||
else if (read_facet_count > 0)
|
||||
error = GMIO_ERROR_OK;
|
||||
@ -168,7 +168,7 @@ int gmio_stlb_read(
|
||||
|
||||
if (gmio_no_error(error)) {
|
||||
func_decode_facets(
|
||||
&mesh_creator, mblock->ptr, read_facet_count, i_facet);
|
||||
mesh_creator, mblock->ptr, read_facet_count, i_facet);
|
||||
i_facet += read_facet_count;
|
||||
if (gmio_task_iface_is_stop_requested(task))
|
||||
error = GMIO_ERROR_TRANSFER_STOPPED;
|
||||
@ -177,7 +177,7 @@ int gmio_stlb_read(
|
||||
} /* end while */
|
||||
|
||||
if (gmio_no_error(error))
|
||||
gmio_stl_mesh_creator_end_solid(&mesh_creator);
|
||||
gmio_stl_mesh_creator_end_solid(mesh_creator);
|
||||
|
||||
if (gmio_no_error(error) && i_facet != total_facet_count)
|
||||
error = GMIO_STL_ERROR_FACET_COUNT;
|
||||
|
@ -48,8 +48,8 @@ class TColgp_SequenceOfXYZ;
|
||||
struct GMIO_LIBSUPPORT_EXPORT gmio_stl_occmesh_iterator
|
||||
{
|
||||
gmio_stl_occmesh_iterator();
|
||||
gmio_stl_occmesh_iterator(const StlMesh_Mesh* mesh);
|
||||
gmio_stl_occmesh_iterator(const Handle_StlMesh_Mesh& hnd);
|
||||
explicit gmio_stl_occmesh_iterator(const StlMesh_Mesh* mesh);
|
||||
explicit gmio_stl_occmesh_iterator(const Handle_StlMesh_Mesh& hnd);
|
||||
|
||||
bool move_to_next_tri(uint32_t tri_id);
|
||||
inline const Handle_StlMesh_MeshTriangle& domain_tri(uint32_t tri_id) const;
|
||||
@ -76,21 +76,9 @@ private:
|
||||
* Example of use:
|
||||
* \code
|
||||
* Handle_StlMesh_Mesh occmesh = ...;
|
||||
* gmio_stl_write_file(
|
||||
* stl_format,
|
||||
* filepath,
|
||||
* gmio_stl_occmesh(occmesh), // Implicit temporary iterator
|
||||
* &options);
|
||||
* \endcode
|
||||
*
|
||||
* Dangerous use:
|
||||
* \code
|
||||
* Handle_StlMesh_Mesh occmesh = ...;
|
||||
* const gmio_stl_mesh mesh =
|
||||
* gmio_stl_occmesh(gmio_stl_occmesh_iterator(occmesh));
|
||||
* // At this point the iterator object is destroyed, mesh.cookie points to
|
||||
* // some garbage. The following line may cause a crash.
|
||||
* gmio_stl_write_file(stl_format, filepath, mesh, &options);
|
||||
* const gmio_stl_occmesh_iterator it(occmesh);
|
||||
* const gmio_stl_mesh mesh = gmio_stl_occmesh(it);
|
||||
* gmio_stl_write_file(stl_format, filepath, &mesh, &options);
|
||||
* \endcode
|
||||
*/
|
||||
GMIO_LIBSUPPORT_EXPORT
|
||||
|
@ -58,7 +58,7 @@ const char* generic_test_stl_infos(const struct gmio_test_stl_infos* test)
|
||||
|
||||
infos.stla_solidname = stla_solid_name;
|
||||
infos.stla_solidname_maxlen = sizeof(stla_solid_name) - 1;
|
||||
error = gmio_stl_infos_get(&infos, stream, GMIO_STL_INFO_FLAG_ALL, NULL);
|
||||
error = gmio_stl_infos_get(&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL);
|
||||
if (test->format != GMIO_STL_FORMAT_UNKNOWN) {
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ const char* test_stl_read()
|
||||
const enum gmio_stl_format format =
|
||||
gmio_stl_get_format_file(expected[i].filepath);
|
||||
const int err =
|
||||
gmio_stl_read_file(expected[i].filepath, mesh_creator, NULL);
|
||||
gmio_stl_read_file(expected[i].filepath, &mesh_creator, NULL);
|
||||
|
||||
/* Check format */
|
||||
if (format != expected[i].format) {
|
||||
@ -209,8 +209,8 @@ const char* test_stlb_write_header()
|
||||
|
||||
{
|
||||
struct gmio_stl_data data = {0};
|
||||
error = gmio_stl_read_file(
|
||||
filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
||||
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
|
||||
error = gmio_stl_read_file(filepath, &creator, NULL);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header));
|
||||
UTEST_COMPARE_UINT(0, data.tri_array.count);
|
||||
@ -230,16 +230,16 @@ static void fclose_2(FILE* f1, FILE* f2)
|
||||
|
||||
const char* test_stlb_write()
|
||||
{
|
||||
const char* model_filepath = stl_grabcad_arm11_filepath;
|
||||
const char* model_filepath_out = "temp/solid.le_stlb";
|
||||
const char* model_filepath_out_be = "temp/solid.be_stlb";
|
||||
const char* model_fpath = stl_grabcad_arm11_filepath;
|
||||
const char* model_fpath_out = "temp/solid.le_stlb";
|
||||
const char* model_fpath_out_be = "temp/solid.be_stlb";
|
||||
struct gmio_stl_data data = {0};
|
||||
int error = GMIO_ERROR_OK;
|
||||
|
||||
/* Read input model file */
|
||||
{
|
||||
error = gmio_stl_read_file(
|
||||
model_filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
||||
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
|
||||
error = gmio_stl_read_file(model_fpath, &creator, NULL);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
}
|
||||
|
||||
@ -247,21 +247,16 @@ const char* test_stlb_write()
|
||||
* Write also the model file in big-endian STL format
|
||||
*/
|
||||
{
|
||||
const struct gmio_stl_mesh mesh = gmio_stl_data_mesh(&data);
|
||||
struct gmio_stl_write_options opts = {0};
|
||||
opts.stlb_header = data.header;
|
||||
error = gmio_stl_write_file(
|
||||
GMIO_STL_FORMAT_BINARY_LE,
|
||||
model_filepath_out,
|
||||
gmio_stl_data_mesh(&data),
|
||||
&opts);
|
||||
GMIO_STL_FORMAT_BINARY_LE, model_fpath_out, &mesh, &opts);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
|
||||
/* Big-endian version */
|
||||
error = gmio_stl_write_file(
|
||||
GMIO_STL_FORMAT_BINARY_BE,
|
||||
model_filepath_out_be,
|
||||
gmio_stl_data_mesh(&data),
|
||||
&opts);
|
||||
GMIO_STL_FORMAT_BINARY_BE, model_fpath_out_be, &mesh, &opts);
|
||||
}
|
||||
|
||||
/* Check input and output models are equal */
|
||||
@ -271,8 +266,8 @@ const char* test_stlb_write()
|
||||
const size_t buff_size = 2048;
|
||||
size_t bytes_read_in = 0;
|
||||
size_t bytes_read_out = 0;
|
||||
FILE* in = fopen(model_filepath, "rb");
|
||||
FILE* out = fopen(model_filepath_out, "rb");
|
||||
FILE* in = fopen(model_fpath, "rb");
|
||||
FILE* out = fopen(model_fpath_out, "rb");
|
||||
if (in == NULL || out == NULL) {
|
||||
fclose_2(in, out);
|
||||
perror("test_stlb_write()");
|
||||
@ -297,10 +292,8 @@ const char* test_stlb_write()
|
||||
/* Check output LE/BE models are equal */
|
||||
{
|
||||
struct gmio_stl_data data_be = {0};
|
||||
error = gmio_stl_read_file(
|
||||
model_filepath_out_be,
|
||||
gmio_stl_data_mesh_creator(&data_be),
|
||||
NULL);
|
||||
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data_be);
|
||||
error = gmio_stl_read_file(model_fpath_out_be, &creator, NULL);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header));
|
||||
UTEST_COMPARE_UINT(data.tri_array.count, data_be.tri_array.count);
|
||||
@ -326,23 +319,21 @@ const char* test_stla_write()
|
||||
|
||||
/* Read input model file */
|
||||
{
|
||||
error = gmio_stl_read_file(
|
||||
model_filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
||||
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
|
||||
error = gmio_stl_read_file(model_filepath, &creator, NULL);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
}
|
||||
|
||||
/* Write the model to STL ascii format */
|
||||
{
|
||||
struct gmio_stl_write_options opts = {0};
|
||||
const struct gmio_stl_mesh mesh = gmio_stl_data_mesh(&data);
|
||||
gmio_stlb_header_to_printable_str(&data.header, header_str, '_');
|
||||
opts.stla_solid_name = header_str;
|
||||
opts.stla_float32_prec = 7;
|
||||
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
|
||||
error = gmio_stl_write_file(
|
||||
GMIO_STL_FORMAT_ASCII,
|
||||
model_filepath_out,
|
||||
gmio_stl_data_mesh(&data),
|
||||
&opts);
|
||||
GMIO_STL_FORMAT_ASCII, model_filepath_out, &mesh, &opts);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
}
|
||||
|
||||
@ -350,13 +341,12 @@ const char* test_stla_write()
|
||||
{
|
||||
char trim_header_str[sizeof(header_str)] = {0};
|
||||
struct gmio_stl_data data_stla = {0};
|
||||
struct gmio_stl_mesh_creator creator =
|
||||
gmio_stl_data_mesh_creator(&data_stla);
|
||||
size_t i = 0;
|
||||
strncpy(trim_header_str, header_str, sizeof(header_str));
|
||||
gmio_string_trim_from_end(trim_header_str, sizeof(header_str));
|
||||
error = gmio_stl_read_file(
|
||||
model_filepath_out,
|
||||
gmio_stl_data_mesh_creator(&data_stla),
|
||||
NULL);
|
||||
error = gmio_stl_read_file(model_filepath_out, &creator, NULL);
|
||||
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||
UTEST_COMPARE_UINT(data.tri_array.count, data_stla.tri_array.count);
|
||||
UTEST_COMPARE_CSTR(trim_header_str, data_stla.solid_name);
|
||||
@ -378,12 +368,12 @@ const char* generic_test_stl_read_multi_solid(
|
||||
if (infile != NULL) {
|
||||
unsigned solid_count = 0;
|
||||
int error = GMIO_ERROR_OK;
|
||||
struct gmio_stream stream = gmio_stream_stdio(infile);
|
||||
struct gmio_stl_read_options roptions = {0};
|
||||
struct gmio_stl_mesh_creator null_creator = {0};
|
||||
roptions.func_stla_get_streamsize = gmio_stla_infos_get_streamsize;
|
||||
while (gmio_no_error(error)) {
|
||||
const struct gmio_stl_mesh_creator null_creator = {0};
|
||||
error = gmio_stl_read(
|
||||
gmio_stream_stdio(infile), null_creator, &roptions);
|
||||
error = gmio_stl_read(&stream, &null_creator, &roptions);
|
||||
if (gmio_no_error(error))
|
||||
++solid_count;
|
||||
}
|
||||
@ -417,6 +407,8 @@ void generate_stlb_tests_models()
|
||||
}
|
||||
|
||||
{
|
||||
const char model_fpath_le[] = "models/solid_one_facet.le_stlb";
|
||||
const char model_fpath_be[] = "models/solid_one_facet.be_stlb";
|
||||
struct gmio_stl_triangle tri = {
|
||||
{ 0.f, 0.f, 1.f }, /* normal */
|
||||
{ 0.f, 0.f, 0.f }, /* v1 */
|
||||
@ -425,41 +417,35 @@ void generate_stlb_tests_models()
|
||||
0 /* attr */
|
||||
};
|
||||
struct gmio_stl_data data = {0};
|
||||
struct gmio_stl_mesh mesh = {0};
|
||||
|
||||
data.tri_array.ptr = &tri;
|
||||
data.tri_array.count = 1;
|
||||
mesh = gmio_stl_data_mesh(&data);
|
||||
|
||||
gmio_stl_write_file(
|
||||
GMIO_STL_FORMAT_BINARY_LE,
|
||||
"models/solid_one_facet.le_stlb",
|
||||
gmio_stl_data_mesh(&data),
|
||||
NULL);
|
||||
GMIO_STL_FORMAT_BINARY_LE, model_fpath_le, &mesh, NULL);
|
||||
gmio_stl_write_file(
|
||||
GMIO_STL_FORMAT_BINARY_BE,
|
||||
"models/solid_one_facet.be_stlb",
|
||||
gmio_stl_data_mesh(&data),
|
||||
NULL);
|
||||
GMIO_STL_FORMAT_BINARY_BE, model_fpath_be, &mesh, NULL);
|
||||
}
|
||||
|
||||
{
|
||||
FILE* infile = fopen("models/solid_4meshs.stla", "rb");
|
||||
FILE* outfile = fopen("models/solid_4meshs.le_stlb", "wb");
|
||||
int read_error = GMIO_ERROR_OK;
|
||||
struct gmio_stl_read_options roptions = {0};
|
||||
roptions.func_stla_get_streamsize = gmio_stla_infos_get_streamsize;
|
||||
struct gmio_stream istream = gmio_stream_stdio(infile);
|
||||
struct gmio_stream ostream = gmio_stream_stdio(outfile);
|
||||
struct gmio_stl_read_options ropts = {0};
|
||||
ropts.func_stla_get_streamsize = gmio_stla_infos_get_streamsize;
|
||||
while (gmio_no_error(read_error)) {
|
||||
struct gmio_stl_data data = {0};
|
||||
struct gmio_stl_write_options woptions = {0};
|
||||
read_error = gmio_stla_read(
|
||||
gmio_stream_stdio(infile),
|
||||
gmio_stl_data_mesh_creator(&data),
|
||||
&roptions);
|
||||
woptions.stlb_header = gmio_stlb_header_str(data.solid_name);
|
||||
gmio_stl_write(
|
||||
GMIO_STL_FORMAT_BINARY_LE,
|
||||
gmio_stream_stdio(outfile),
|
||||
gmio_stl_data_mesh(&data),
|
||||
&woptions);
|
||||
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
|
||||
struct gmio_stl_mesh mesh = {0};
|
||||
struct gmio_stl_write_options wopts = {0};
|
||||
read_error = gmio_stla_read(&istream, &creator, &ropts);
|
||||
mesh = gmio_stl_data_mesh(&data);
|
||||
wopts.stlb_header = gmio_stlb_header_str(data.solid_name);
|
||||
gmio_stl_write(GMIO_STL_FORMAT_BINARY_LE, &ostream, &mesh, &wopts);
|
||||
gmio_stl_triangle_array_free(&data.tri_array);
|
||||
}
|
||||
fclose(infile);
|
||||
|
Loading…
Reference in New Issue
Block a user