gmio_stl: improve API
This commit is contained in:
parent
9ae18d1b9e
commit
75cd51398e
@ -285,15 +285,15 @@ static void get_triangle(
|
|||||||
|
|
||||||
static void stl_read(const void* filepath)
|
static void stl_read(const void* filepath)
|
||||||
{
|
{
|
||||||
gmio_stl_read_args read = {};
|
const char* str_filepath = static_cast<const char*>(filepath);
|
||||||
read.mesh_creator.cookie = &globalSceneHelper;
|
gmio_stl_mesh_creator mesh_creator = {};
|
||||||
read.mesh_creator.func_ascii_begin_solid = func_ascii_begin_solid;
|
mesh_creator.cookie = &globalSceneHelper;
|
||||||
read.mesh_creator.func_binary_begin_solid = binary_begin_solid;
|
mesh_creator.func_ascii_begin_solid = func_ascii_begin_solid;
|
||||||
read.mesh_creator.func_add_triangle = add_triangle;
|
mesh_creator.func_binary_begin_solid = binary_begin_solid;
|
||||||
read.mesh_creator.func_end_solid = end_solid;
|
mesh_creator.func_add_triangle = add_triangle;
|
||||||
|
mesh_creator.func_end_solid = end_solid;
|
||||||
|
|
||||||
const int error =
|
const int error = gmio_stl_read_file(str_filepath, mesh_creator, NULL);
|
||||||
gmio_stl_read_file(&read, static_cast<const char*>(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);
|
||||||
|
|
||||||
@ -306,13 +306,15 @@ 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_mesh mesh = {};
|
||||||
write.mesh.cookie = sceneMesh;
|
mesh.cookie = sceneMesh;
|
||||||
write.mesh.triangle_count = sceneMesh->mNumFaces;
|
mesh.triangle_count = sceneMesh->mNumFaces;
|
||||||
write.mesh.func_get_triangle = get_triangle;
|
mesh.func_get_triangle = get_triangle;
|
||||||
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
|
|
||||||
write.options.stla_float32_prec = 7;
|
gmio_stl_write_options opts = {};
|
||||||
const int error = gmio_stl_write_file(&write, format, filepath);
|
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);
|
||||||
if (error != GMIO_ERROR_OK)
|
if (error != GMIO_ERROR_OK)
|
||||||
printf("gmio error: 0x%X\n", error);
|
printf("gmio error: 0x%X\n", error);
|
||||||
}
|
}
|
||||||
@ -376,7 +378,7 @@ int main(int argc, char** argv)
|
|||||||
std::vector<benchmark_cmp_result> cmp_res_vec;
|
std::vector<benchmark_cmp_result> cmp_res_vec;
|
||||||
cmp_res_vec.resize(GMIO_ARRAY_SIZE(cmp_args) - 1);
|
cmp_res_vec.resize(GMIO_ARRAY_SIZE(cmp_args) - 1);
|
||||||
benchmark_cmp_batch(
|
benchmark_cmp_batch(
|
||||||
5, &cmp_args[0], &cmp_res_vec[0], bmk_init, bmk_cleanup);
|
5, cmp_args, &cmp_res_vec[0], bmk_init, bmk_cleanup);
|
||||||
|
|
||||||
/* Print results */
|
/* Print results */
|
||||||
const benchmark_cmp_result_array res_array = {
|
const benchmark_cmp_result_array res_array = {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <gmio_core/error.h>
|
#include <gmio_core/error.h>
|
||||||
#include <gmio_core/rwargs.h>
|
|
||||||
#include <gmio_stl/stl_io.h>
|
#include <gmio_stl/stl_io.h>
|
||||||
#include <gmio_stl/stl_io_options.h>
|
#include <gmio_stl/stl_io_options.h>
|
||||||
#include <gmio_stl/stl_mesh.h>
|
#include <gmio_stl/stl_mesh.h>
|
||||||
@ -48,12 +47,12 @@ static void dummy_process_triangle(
|
|||||||
static void bmk_gmio_stl_read(const void* filepath)
|
static void bmk_gmio_stl_read(const void* filepath)
|
||||||
{
|
{
|
||||||
struct my_igeom cookie = {0};
|
struct my_igeom cookie = {0};
|
||||||
struct gmio_stl_read_args read = {0};
|
struct gmio_stl_mesh_creator mesh_creator = {0};
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
read.mesh_creator.cookie = &cookie;
|
mesh_creator.cookie = &cookie;
|
||||||
read.mesh_creator.func_add_triangle = dummy_process_triangle;
|
mesh_creator.func_add_triangle = dummy_process_triangle;
|
||||||
error = gmio_stl_read_file(&read, filepath);
|
error = gmio_stl_read_file(filepath, mesh_creator, NULL);
|
||||||
if (error != GMIO_ERROR_OK)
|
if (error != GMIO_ERROR_OK)
|
||||||
printf("gmio error: 0x%X\n", error);
|
printf("gmio error: 0x%X\n", error);
|
||||||
}
|
}
|
||||||
@ -75,7 +74,7 @@ static enum gmio_endianness to_byte_order(enum gmio_stl_format format)
|
|||||||
enum { STL_TRIANGLE_ARRAY_SIZE = 512 };
|
enum { STL_TRIANGLE_ARRAY_SIZE = 512 };
|
||||||
struct stl_readwrite_conv
|
struct stl_readwrite_conv
|
||||||
{
|
{
|
||||||
struct gmio_rwargs rwargs;
|
struct gmio_stream stream;
|
||||||
struct gmio_streampos out_stream_pos_begin;
|
struct gmio_streampos out_stream_pos_begin;
|
||||||
enum gmio_stl_format in_format;
|
enum gmio_stl_format in_format;
|
||||||
enum gmio_stl_format out_format;
|
enum gmio_stl_format out_format;
|
||||||
@ -88,7 +87,7 @@ static void readwrite_ascii_begin_solid(
|
|||||||
void* cookie, gmio_streamsize_t stream_size, const char* solid_name)
|
void* cookie, gmio_streamsize_t stream_size, const char* solid_name)
|
||||||
{
|
{
|
||||||
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
|
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
|
||||||
struct gmio_stream* stream = &rw_conv->rwargs.stream;
|
struct gmio_stream* stream = &rw_conv->stream;
|
||||||
GMIO_UNUSED(stream_size);
|
GMIO_UNUSED(stream_size);
|
||||||
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
||||||
stream->func_write(stream->cookie, "solid ", 1, 6);
|
stream->func_write(stream->cookie, "solid ", 1, 6);
|
||||||
@ -109,7 +108,7 @@ static void readwrite_binary_begin_solid(
|
|||||||
void* cookie, uint32_t tri_count, const struct gmio_stlb_header* header)
|
void* cookie, uint32_t tri_count, const struct gmio_stlb_header* header)
|
||||||
{
|
{
|
||||||
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
|
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
|
||||||
struct gmio_stream* stream = &rw_conv->rwargs.stream;
|
struct gmio_stream* stream = &rw_conv->stream;
|
||||||
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
||||||
stream->func_write(stream->cookie, "solid\n", 1, 6);
|
stream->func_write(stream->cookie, "solid\n", 1, 6);
|
||||||
}
|
}
|
||||||
@ -129,15 +128,18 @@ static void readwrite_get_triangle(
|
|||||||
|
|
||||||
static void stl_readwrite_flush_triangles(struct stl_readwrite_conv* rw_conv)
|
static void stl_readwrite_flush_triangles(struct stl_readwrite_conv* rw_conv)
|
||||||
{
|
{
|
||||||
struct gmio_stl_write_args write = {0};
|
struct gmio_stl_mesh mesh = {0};
|
||||||
write.core = rw_conv->rwargs;
|
struct gmio_stl_write_options options = {0};
|
||||||
write.mesh.cookie = &rw_conv->triangle_array[0];
|
|
||||||
write.mesh.triangle_count = rw_conv->triangle_pos;
|
mesh.cookie = &rw_conv->triangle_array[0];
|
||||||
write.mesh.func_get_triangle = &readwrite_get_triangle;
|
mesh.triangle_count = rw_conv->triangle_pos;
|
||||||
write.options.stl_write_triangles_only = true;
|
mesh.func_get_triangle = &readwrite_get_triangle;
|
||||||
write.options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SCIENTIFIC_LOWERCASE;
|
|
||||||
write.options.stla_float32_prec = 6;
|
options.stl_write_triangles_only = true;
|
||||||
gmio_stl_write(&write, rw_conv->out_format);
|
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);
|
||||||
rw_conv->triangle_pos = 0;
|
rw_conv->triangle_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ static void readwrite_add_triangle(
|
|||||||
static void readwrite_end_solid(void* cookie)
|
static void readwrite_end_solid(void* cookie)
|
||||||
{
|
{
|
||||||
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
|
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
|
||||||
struct gmio_stream* stream = &rw_conv->rwargs.stream;
|
struct gmio_stream* stream = &rw_conv->stream;
|
||||||
if (rw_conv->triangle_pos != 0)
|
if (rw_conv->triangle_pos != 0)
|
||||||
stl_readwrite_flush_triangles(rw_conv);
|
stl_readwrite_flush_triangles(rw_conv);
|
||||||
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
|
||||||
@ -175,36 +177,32 @@ static void bmk_gmio_stl_readwrite_conv(const void* filepath)
|
|||||||
{
|
{
|
||||||
FILE* infile = fopen(filepath, "rb");
|
FILE* infile = fopen(filepath, "rb");
|
||||||
FILE* outfile = fopen("_readwrite_conv.stl", "wb");
|
FILE* outfile = fopen("_readwrite_conv.stl", "wb");
|
||||||
struct gmio_stl_read_args read = {0};
|
struct gmio_stream instream = {0};
|
||||||
struct stl_readwrite_conv rw_conv = {0};
|
struct stl_readwrite_conv rw_conv = {0};
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator = {0};
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
/* rw_conv.out_format = GMIO_STL_FORMAT_BINARY_LE; */
|
/* rw_conv.out_format = GMIO_STL_FORMAT_BINARY_LE; */
|
||||||
rw_conv.out_format = GMIO_STL_FORMAT_ASCII;
|
rw_conv.out_format = GMIO_STL_FORMAT_ASCII;
|
||||||
|
|
||||||
if (infile != NULL) {
|
if (infile != NULL) {
|
||||||
read.core.stream_memblock = gmio_memblock_malloc(512 * 1024);
|
instream = gmio_stream_stdio(infile);
|
||||||
read.core.stream = gmio_stream_stdio(infile);
|
rw_conv.in_format = gmio_stl_get_format(&instream);
|
||||||
rw_conv.in_format = gmio_stl_get_format(&read.core.stream);
|
|
||||||
}
|
}
|
||||||
if (outfile != NULL) {
|
if (outfile != NULL) {
|
||||||
rw_conv.rwargs.stream_memblock = gmio_memblock_malloc(512 * 1024);
|
rw_conv.stream = gmio_stream_stdio(outfile);
|
||||||
rw_conv.rwargs.stream = gmio_stream_stdio(outfile);
|
rw_conv.stream.func_get_pos(
|
||||||
rw_conv.rwargs.stream.func_get_pos(
|
rw_conv.stream.cookie,
|
||||||
rw_conv.rwargs.stream.cookie,
|
|
||||||
&rw_conv.out_stream_pos_begin);
|
&rw_conv.out_stream_pos_begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
read.mesh_creator.cookie = &rw_conv;
|
mesh_creator.cookie = &rw_conv;
|
||||||
read.mesh_creator.func_ascii_begin_solid = &readwrite_ascii_begin_solid;
|
mesh_creator.func_ascii_begin_solid = &readwrite_ascii_begin_solid;
|
||||||
read.mesh_creator.func_binary_begin_solid = &readwrite_binary_begin_solid;
|
mesh_creator.func_binary_begin_solid = &readwrite_binary_begin_solid;
|
||||||
read.mesh_creator.func_add_triangle = &readwrite_add_triangle;
|
mesh_creator.func_add_triangle = &readwrite_add_triangle;
|
||||||
read.mesh_creator.func_end_solid = &readwrite_end_solid;
|
mesh_creator.func_end_solid = &readwrite_end_solid;
|
||||||
|
|
||||||
error = gmio_stl_read(&read);
|
error = gmio_stl_read(instream, mesh_creator, NULL);
|
||||||
|
|
||||||
gmio_memblock_deallocate(&read.core.stream_memblock);
|
|
||||||
gmio_memblock_deallocate(&rw_conv.rwargs.stream_memblock);
|
|
||||||
|
|
||||||
if (error != GMIO_ERROR_OK)
|
if (error != GMIO_ERROR_OK)
|
||||||
printf("gmio error: 0x%X\n", error);
|
printf("gmio error: 0x%X\n", error);
|
||||||
@ -219,29 +217,25 @@ void bmk_gmio_stl_infos_get(const void* filepath)
|
|||||||
FILE* file = fopen(filepath, "rb");
|
FILE* file = fopen(filepath, "rb");
|
||||||
|
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
struct gmio_stream stream = gmio_stream_stdio(file);
|
const struct gmio_stream stream = gmio_stream_stdio(file);
|
||||||
struct gmio_stl_infos_get_args args = {0};
|
struct gmio_stl_infos infos = {0};
|
||||||
const enum gmio_stl_format format = gmio_stl_get_format(&stream);
|
gmio_stl_infos_get(&infos, stream, GMIO_STL_INFO_FLAG_ALL, NULL);
|
||||||
|
|
||||||
args.stream = stream;
|
|
||||||
gmio_stl_infos_get(&args, format, GMIO_STL_INFO_FLAG_ALL);
|
|
||||||
if (!already_exec) {
|
if (!already_exec) {
|
||||||
printf("stl_infos_get()\n"
|
printf("stl_infos_get()\n"
|
||||||
" File: %s\n"
|
" File: %s\n"
|
||||||
" Size: %uKo\n"
|
" Size: %uKo\n"
|
||||||
" Facets: %u\n",
|
" Facets: %u\n",
|
||||||
(const char*)filepath,
|
(const char*)filepath,
|
||||||
args.infos.size / 1024,
|
infos.size / 1024,
|
||||||
args.infos.facet_count);
|
infos.facet_count);
|
||||||
if (format == GMIO_STL_FORMAT_ASCII) {
|
if (infos.format == GMIO_STL_FORMAT_ASCII) {
|
||||||
printf(" [STLA]Solid name: %s\n",
|
printf(" [STLA]Solid name: %s\n", infos.stla_solidname);
|
||||||
args.infos.stla_solidname);
|
|
||||||
}
|
}
|
||||||
else if (format == GMIO_STL_FORMAT_BINARY_LE
|
else if (infos.format == GMIO_STL_FORMAT_BINARY_LE
|
||||||
|| format == GMIO_STL_FORMAT_BINARY_BE)
|
|| infos.format == GMIO_STL_FORMAT_BINARY_BE)
|
||||||
{
|
{
|
||||||
printf(" [STLB]Header: %80.80s\n",
|
printf(" [STLB]Header: %80.80s\n", infos.stlb_header.data);
|
||||||
args.infos.stlb_header.data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
already_exec = true;
|
already_exec = true;
|
||||||
|
@ -122,7 +122,7 @@ int main(int argc, char** argv)
|
|||||||
/* Execute benchmarks */
|
/* Execute benchmarks */
|
||||||
std::vector<benchmark_cmp_result> cmp_res_vec;
|
std::vector<benchmark_cmp_result> cmp_res_vec;
|
||||||
cmp_res_vec.resize(GMIO_ARRAY_SIZE(cmp_args) - 1);
|
cmp_res_vec.resize(GMIO_ARRAY_SIZE(cmp_args) - 1);
|
||||||
benchmark_cmp_batch(5, &cmp_args[0], &cmp_res_vec[0], NULL, NULL);
|
benchmark_cmp_batch(5, cmp_args, &cmp_res_vec[0], NULL, NULL);
|
||||||
|
|
||||||
/* Print results */
|
/* Print results */
|
||||||
const benchmark_cmp_result_array res_array = {
|
const benchmark_cmp_result_array res_array = {
|
||||||
|
@ -31,9 +31,6 @@ enum gmio_error
|
|||||||
/*! No error occurred, success */
|
/*! No error occurred, success */
|
||||||
GMIO_ERROR_OK = 0,
|
GMIO_ERROR_OK = 0,
|
||||||
|
|
||||||
/*! Pointer on argument gmio_rwargs is NULL */
|
|
||||||
GMIO_ERROR_NULL_RWARGS,
|
|
||||||
|
|
||||||
/*! Pointer on argument memory block is NULL */
|
/*! Pointer on argument memory block is NULL */
|
||||||
GMIO_ERROR_NULL_MEMBLOCK,
|
GMIO_ERROR_NULL_MEMBLOCK,
|
||||||
|
|
||||||
|
@ -22,12 +22,13 @@
|
|||||||
|
|
||||||
struct gmio_memblock_helper
|
struct gmio_memblock_helper
|
||||||
{
|
{
|
||||||
struct gmio_memblock* memblock;
|
struct gmio_memblock memblock;
|
||||||
bool was_allocated;
|
bool was_allocated;
|
||||||
};
|
};
|
||||||
|
|
||||||
GMIO_INLINE
|
GMIO_INLINE
|
||||||
struct gmio_memblock_helper gmio_memblock_helper(struct gmio_memblock* mblock);
|
struct gmio_memblock_helper gmio_memblock_helper(
|
||||||
|
const struct gmio_memblock* mblock);
|
||||||
|
|
||||||
GMIO_INLINE
|
GMIO_INLINE
|
||||||
void gmio_memblock_helper_release(struct gmio_memblock_helper* helper);
|
void gmio_memblock_helper_release(struct gmio_memblock_helper* helper);
|
||||||
@ -38,22 +39,26 @@ void gmio_memblock_helper_release(struct gmio_memblock_helper* helper);
|
|||||||
* Implementation
|
* Implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct gmio_memblock_helper gmio_memblock_helper(struct gmio_memblock* mblock)
|
struct gmio_memblock_helper gmio_memblock_helper(
|
||||||
|
const struct gmio_memblock* mblock)
|
||||||
{
|
{
|
||||||
struct gmio_memblock_helper helper = {0};
|
struct gmio_memblock_helper helper = {0};
|
||||||
helper.memblock = mblock;
|
if (gmio_memblock_isnull(mblock)) {
|
||||||
if (mblock != NULL && (mblock->ptr == NULL || mblock->size == 0)) {
|
helper.memblock = gmio_memblock_default();
|
||||||
*(helper.memblock) = gmio_memblock_default();
|
|
||||||
helper.was_allocated = true;
|
helper.was_allocated = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
helper.memblock = *mblock;
|
||||||
|
}
|
||||||
return helper;
|
return helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gmio_memblock_helper_release(struct gmio_memblock_helper* helper)
|
void gmio_memblock_helper_release(struct gmio_memblock_helper* helper)
|
||||||
{
|
{
|
||||||
if (helper != NULL && helper->was_allocated) {
|
if (helper != NULL && helper->was_allocated) {
|
||||||
gmio_memblock_deallocate(helper->memblock);
|
const struct gmio_memblock mblock_null = {0};
|
||||||
helper->memblock = NULL;
|
gmio_memblock_deallocate(&helper->memblock);
|
||||||
|
helper->memblock = mblock_null;
|
||||||
helper->was_allocated = false;
|
helper->was_allocated = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
** gmio
|
|
||||||
** Copyright Fougue (2 Mar. 2015)
|
|
||||||
** contact@fougue.pro
|
|
||||||
**
|
|
||||||
** 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
|
|
||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef GMIO_INTERNAL_HELPER_RWARGS_H
|
|
||||||
#define GMIO_INTERNAL_HELPER_RWARGS_H
|
|
||||||
|
|
||||||
#include "../rwargs.h"
|
|
||||||
#include "helper_task_iface.h"
|
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_task_iface::func_is_stop_requested()
|
|
||||||
* through gmio_transfer::task_iface
|
|
||||||
*/
|
|
||||||
GMIO_INLINE bool gmio_rwargs_is_stop_requested(
|
|
||||||
const struct gmio_rwargs* args)
|
|
||||||
{
|
|
||||||
if (args != NULL)
|
|
||||||
return gmio_task_iface_is_stop_requested(&args->task_iface);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_task_iface::func_handle_progress()
|
|
||||||
* through gmio_transfer::task_iface
|
|
||||||
*/
|
|
||||||
GMIO_INLINE void gmio_rwargs_handle_progress(
|
|
||||||
const struct gmio_rwargs* args, size_t value, size_t max_value)
|
|
||||||
{
|
|
||||||
if (args != NULL)
|
|
||||||
gmio_task_iface_handle_progress(&args->task_iface, value, max_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_HELPER_RWARGS_H */
|
|
@ -17,6 +17,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
bool gmio_memblock_isnull(const struct gmio_memblock *mblock)
|
||||||
|
{
|
||||||
|
return mblock == NULL || mblock->ptr == NULL || mblock->size == 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct gmio_memblock gmio_memblock(
|
struct gmio_memblock gmio_memblock(
|
||||||
void* ptr, size_t size, void (*func_deallocate)(void*))
|
void* ptr, size_t size, void (*func_deallocate)(void*))
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,9 @@ struct gmio_memblock
|
|||||||
|
|
||||||
GMIO_C_LINKAGE_BEGIN
|
GMIO_C_LINKAGE_BEGIN
|
||||||
|
|
||||||
|
/*! Returns true if \p mblock is NULL or points to null/void memory */
|
||||||
|
GMIO_LIB_EXPORT bool gmio_memblock_isnull(const struct gmio_memblock* mblock);
|
||||||
|
|
||||||
/*! Returns an initialized gmio_memblock object
|
/*! Returns an initialized gmio_memblock object
|
||||||
*
|
*
|
||||||
* If \p ptr is NULL then gmio_memblock::size is forced to \c 0
|
* If \p ptr is NULL then gmio_memblock::size is forced to \c 0
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
** gmio
|
|
||||||
** Copyright Fougue (2 Mar. 2015)
|
|
||||||
** contact@fougue.pro
|
|
||||||
**
|
|
||||||
** 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
|
|
||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/*! \file rwargs.h
|
|
||||||
* Declares structures for the common arguments of read/write operations
|
|
||||||
*
|
|
||||||
* \addtogroup gmio_core
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GMIO_RWARGS_H
|
|
||||||
#define GMIO_RWARGS_H
|
|
||||||
|
|
||||||
#include "stream.h"
|
|
||||||
#include "memblock.h"
|
|
||||||
#include "task_iface.h"
|
|
||||||
|
|
||||||
/*! Common arguments for read or write functions */
|
|
||||||
struct gmio_rwargs
|
|
||||||
{
|
|
||||||
/*! The stream object to be used for I/O */
|
|
||||||
struct gmio_stream stream;
|
|
||||||
|
|
||||||
/*! Optional memory block used by the stream to bufferize I/O device
|
|
||||||
* operations
|
|
||||||
*
|
|
||||||
* If passed null to a read/write function, then a temporary memblock
|
|
||||||
* is created with the global default constructor function (see
|
|
||||||
* gmio_memblock_default())
|
|
||||||
*/
|
|
||||||
struct gmio_memblock stream_memblock;
|
|
||||||
|
|
||||||
/*! Optional interface by which the I/O operation can be controlled */
|
|
||||||
struct gmio_task_iface task_iface;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* GMIO_RWARGS_H */
|
|
@ -16,30 +16,22 @@
|
|||||||
#include "stl_rw_common.h"
|
#include "stl_rw_common.h"
|
||||||
|
|
||||||
#include "../../gmio_core/error.h"
|
#include "../../gmio_core/error.h"
|
||||||
#include "../../gmio_core/rwargs.h"
|
|
||||||
#include "../stl_error.h"
|
#include "../stl_error.h"
|
||||||
#include "../stl_io.h"
|
#include "../stl_io.h"
|
||||||
|
|
||||||
bool gmio_check_rwargs(int *error, const struct gmio_rwargs* args)
|
bool gmio_check_memblock(int *error, const struct gmio_memblock* mblock)
|
||||||
{
|
{
|
||||||
if (args == NULL) {
|
if (mblock == NULL || mblock->ptr == NULL)
|
||||||
*error = GMIO_ERROR_NULL_RWARGS;
|
*error = GMIO_ERROR_NULL_MEMBLOCK;
|
||||||
}
|
else if (mblock->size == 0)
|
||||||
else {
|
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
|
||||||
if (args->stream_memblock.ptr == NULL)
|
|
||||||
*error = GMIO_ERROR_NULL_MEMBLOCK;
|
|
||||||
else if (args->stream_memblock.size == 0)
|
|
||||||
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gmio_no_error(*error);
|
return gmio_no_error(*error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gmio_check_memblock(int *error, const struct gmio_memblock* mblock)
|
bool gmio_check_memblock_size(
|
||||||
|
int *error, const struct gmio_memblock *mblock, size_t minsize)
|
||||||
{
|
{
|
||||||
if (mblock->ptr == NULL)
|
if (gmio_check_memblock(error, mblock) && mblock->size < minsize)
|
||||||
*error = GMIO_ERROR_NULL_MEMBLOCK;
|
|
||||||
else if (mblock->size == 0)
|
|
||||||
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
|
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
|
||||||
return gmio_no_error(*error);
|
return gmio_no_error(*error);
|
||||||
}
|
}
|
||||||
@ -51,25 +43,22 @@ bool gmio_stl_check_mesh(int *error, const struct gmio_stl_mesh* mesh)
|
|||||||
{
|
{
|
||||||
*error = GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE;
|
*error = GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gmio_no_error(*error);
|
return gmio_no_error(*error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gmio_stlb_check_params(
|
bool gmio_stlb_check_byteorder(int* error, enum gmio_endianness byte_order)
|
||||||
int *error,
|
|
||||||
const struct gmio_rwargs* args,
|
|
||||||
enum gmio_endianness byte_order)
|
|
||||||
{
|
{
|
||||||
if (!gmio_check_rwargs(error, args))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (args->stream_memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE)
|
|
||||||
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
|
|
||||||
if (byte_order != GMIO_ENDIANNESS_LITTLE
|
if (byte_order != GMIO_ENDIANNESS_LITTLE
|
||||||
&& byte_order != GMIO_ENDIANNESS_BIG)
|
&& byte_order != GMIO_ENDIANNESS_BIG)
|
||||||
{
|
{
|
||||||
*error = GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER;
|
*error = GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER;
|
||||||
}
|
}
|
||||||
|
return gmio_no_error(*error);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gmio_stla_check_float32_precision(int *error, uint8_t prec)
|
||||||
|
{
|
||||||
|
if (prec == 0 || prec > 9)
|
||||||
|
*error = GMIO_STL_ERROR_INVALID_FLOAT32_PREC;
|
||||||
return gmio_no_error(*error);
|
return gmio_no_error(*error);
|
||||||
}
|
}
|
||||||
|
@ -24,17 +24,17 @@
|
|||||||
#include "../../gmio_core/endian.h"
|
#include "../../gmio_core/endian.h"
|
||||||
|
|
||||||
struct gmio_memblock;
|
struct gmio_memblock;
|
||||||
struct gmio_rwargs;
|
|
||||||
struct gmio_stl_mesh;
|
struct gmio_stl_mesh;
|
||||||
|
|
||||||
bool gmio_check_rwargs(int* error, const struct gmio_rwargs* args);
|
|
||||||
bool gmio_check_memblock(int* error, const struct gmio_memblock* mblock);
|
bool gmio_check_memblock(int* error, const struct gmio_memblock* mblock);
|
||||||
|
|
||||||
|
bool gmio_check_memblock_size(
|
||||||
|
int* error, const struct gmio_memblock* mblock, size_t minsize);
|
||||||
|
|
||||||
bool gmio_stl_check_mesh(int* error, const struct gmio_stl_mesh* mesh);
|
bool gmio_stl_check_mesh(int* error, const struct gmio_stl_mesh* mesh);
|
||||||
|
|
||||||
bool gmio_stlb_check_params(
|
bool gmio_stla_check_float32_precision(int* error, uint8_t prec);
|
||||||
int* error,
|
|
||||||
const struct gmio_rwargs* args,
|
bool gmio_stlb_check_byteorder(int* error, enum gmio_endianness byte_order);
|
||||||
enum gmio_endianness byte_order);
|
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STLB_RW_COMMON_H */
|
#endif /* GMIO_INTERNAL_STLB_RW_COMMON_H */
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "stla_infos_get.h"
|
#include "stla_infos_get.h"
|
||||||
|
|
||||||
#include "../../gmio_core/error.h"
|
#include "../../gmio_core/error.h"
|
||||||
|
#include "../../gmio_core/internal/helper_memblock.h"
|
||||||
#include "../../gmio_core/internal/min_max.h"
|
#include "../../gmio_core/internal/min_max.h"
|
||||||
#include "../../gmio_core/internal/stringstream.h"
|
#include "../../gmio_core/internal/stringstream.h"
|
||||||
#include "../stl_error.h"
|
#include "../stl_error.h"
|
||||||
@ -109,7 +110,10 @@ static void gmio_stringstream_stla_read_hook(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stla_infos_get(
|
int gmio_stla_infos_get(
|
||||||
struct gmio_stl_infos_get_args* args, unsigned flags)
|
struct gmio_stl_infos* infos,
|
||||||
|
struct gmio_stream stream,
|
||||||
|
unsigned flags,
|
||||||
|
const struct gmio_stl_infos_get_options* opts)
|
||||||
{
|
{
|
||||||
const bool flag_facet_count =
|
const bool flag_facet_count =
|
||||||
(flags & GMIO_STL_INFO_FLAG_FACET_COUNT) != 0;
|
(flags & GMIO_STL_INFO_FLAG_FACET_COUNT) != 0;
|
||||||
@ -118,10 +122,9 @@ int gmio_stla_infos_get(
|
|||||||
const bool flag_stla_solidname =
|
const bool flag_stla_solidname =
|
||||||
(flags & GMIO_STLA_INFO_FLAG_SOLIDNAME) != 0;
|
(flags & GMIO_STLA_INFO_FLAG_SOLIDNAME) != 0;
|
||||||
|
|
||||||
struct gmio_stl_infos* infos = &args->infos;
|
void* const mblock_ptr = opts->stream_memblock.ptr;
|
||||||
void* const mblock_ptr = args->stream_memblock.ptr;
|
|
||||||
/* Leave one byte to end the string buffer with 0 */
|
/* Leave one byte to end the string buffer with 0 */
|
||||||
const size_t mblock_size = args->stream_memblock.size - 1;
|
const size_t mblock_size = opts->stream_memblock.size - 1;
|
||||||
struct gmio_stla_parse_data parse_data = {0};
|
struct gmio_stla_parse_data parse_data = {0};
|
||||||
struct gmio_stringstream* sstream = &parse_data.strstream;
|
struct gmio_stringstream* sstream = &parse_data.strstream;
|
||||||
struct gmio_string* strbuff = &parse_data.strbuff;
|
struct gmio_string* strbuff = &parse_data.strbuff;
|
||||||
@ -131,13 +134,11 @@ int gmio_stla_infos_get(
|
|||||||
|
|
||||||
if (flags == 0)
|
if (flags == 0)
|
||||||
return err;
|
return err;
|
||||||
if (!gmio_check_memblock(&err, &args->stream_memblock))
|
if (!gmio_check_memblock(&err, &opts->stream_memblock))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
parse_data.strstream =
|
parse_data.strstream =
|
||||||
gmio_stringstream(
|
gmio_stringstream(stream, gmio_string(mblock_ptr, 0, mblock_size));
|
||||||
args->stream,
|
|
||||||
gmio_string(mblock_ptr, 0, mblock_size));
|
|
||||||
parse_data.strstream.func_stream_read_hook = gmio_stringstream_stla_read_hook;
|
parse_data.strstream.func_stream_read_hook = gmio_stringstream_stla_read_hook;
|
||||||
parse_data.strbuff = gmio_string(fixed_buffer, 0, sizeof(fixed_buffer));
|
parse_data.strbuff = gmio_string(fixed_buffer, 0, sizeof(fixed_buffer));
|
||||||
|
|
||||||
@ -190,139 +191,3 @@ int gmio_stla_infos_get(
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include "../../gmio_core/error.h"
|
|
||||||
#include "../../gmio_core/internal/min_max.h"
|
|
||||||
#include "../../gmio_core/internal/string.h"
|
|
||||||
#include "../../gmio_core/internal/string_ascii_utils.h"
|
|
||||||
#include "stl_rw_common.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static uint32_t stla_facet_count(
|
|
||||||
const struct gmio_string* strbuff, const char* end_ptr)
|
|
||||||
{
|
|
||||||
const char* substr_at = NULL;
|
|
||||||
size_t strbuff_pos = 0;
|
|
||||||
uint32_t facet_count = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
substr_at = gmio_ascii_istrstr(strbuff->ptr + strbuff_pos, "endfacet");
|
|
||||||
if (substr_at != NULL && substr_at < end_ptr) {
|
|
||||||
++facet_count;
|
|
||||||
/* Note: strlen("endfacet") == 8 */
|
|
||||||
strbuff_pos = (substr_at - strbuff->ptr) + 8;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
substr_at = NULL;
|
|
||||||
}
|
|
||||||
} while (substr_at != NULL);
|
|
||||||
|
|
||||||
return facet_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum {
|
|
||||||
BUFF_OVERLAP_SIZE = 14,
|
|
||||||
BUFF_OVERLAP_SIZE_DIV2 = BUFF_OVERLAP_SIZE / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
int gmio_stla_infos_get(
|
|
||||||
struct gmio_stl_infos_get_args* args, unsigned flags)
|
|
||||||
{
|
|
||||||
struct gmio_stream* stream = &args->stream;
|
|
||||||
struct gmio_stl_infos* infos = &args->infos;
|
|
||||||
void* mblock_ptr = args->stream_memblock.ptr;
|
|
||||||
/* Leave one byte to end the string buffer with 0 */
|
|
||||||
const size_t mblock_size = args->stream_memblock.size - 1;
|
|
||||||
struct gmio_string strbuff = gmio_string(mblock_ptr, 0, mblock_size);
|
|
||||||
|
|
||||||
const bool flag_facet_count =
|
|
||||||
(flags & GMIO_STL_INFO_FLAG_FACET_COUNT) != 0;
|
|
||||||
const bool flag_size =
|
|
||||||
(flags & GMIO_STL_INFO_FLAG_SIZE) != 0;
|
|
||||||
const bool flag_stla_solidname =
|
|
||||||
(flags & GMIO_STLA_INFO_FLAG_SOLIDNAME) != 0;
|
|
||||||
|
|
||||||
int err = GMIO_ERROR_OK;
|
|
||||||
|
|
||||||
if (!gmio_check_memblock(&err, &args->stream_memblock))
|
|
||||||
return err;
|
|
||||||
|
|
||||||
if (flags != 0) {
|
|
||||||
/* 'overlap' stores the ending/starting bytes of the previous/current
|
|
||||||
* stream buffers(memblock) */
|
|
||||||
char overlap[14] = {0}; /* 14 == 2*(strlen("endfacet") - 1) */
|
|
||||||
bool endsolid_found = false;
|
|
||||||
|
|
||||||
while (!endsolid_found && gmio_no_error(err)) {
|
|
||||||
const char* substr_at = NULL;
|
|
||||||
const size_t read_size =
|
|
||||||
gmio_stream_read(stream, mblock_ptr, 1, mblock_size);
|
|
||||||
const int stream_err = gmio_stream_error(&args->stream);
|
|
||||||
const bool overlap_has_contents = overlap[0] != 0;
|
|
||||||
bool endsolid_in_overlap = false;
|
|
||||||
|
|
||||||
err = stream_err;
|
|
||||||
strbuff.len = read_size;
|
|
||||||
strbuff.ptr[strbuff.len] = 0;
|
|
||||||
|
|
||||||
/* Copy first half of overlap buffer */
|
|
||||||
if (overlap_has_contents) {
|
|
||||||
strncpy(&overlap[BUFF_OVERLAP_SIZE_DIV2],
|
|
||||||
mblock_ptr,
|
|
||||||
GMIO_MIN(BUFF_OVERLAP_SIZE_DIV2, read_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find "endsolid" in overlap */
|
|
||||||
if (overlap_has_contents) {
|
|
||||||
substr_at = strstr(overlap, "endsolid");
|
|
||||||
endsolid_found = substr_at != NULL;
|
|
||||||
endsolid_in_overlap = endsolid_found;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find "endsolid" in memblock */
|
|
||||||
if (!endsolid_found) {
|
|
||||||
substr_at = gmio_ascii_istrstr(strbuff.ptr, "endsolid");
|
|
||||||
endsolid_found = substr_at != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update stream size */
|
|
||||||
if (flag_size) {
|
|
||||||
/* Note: strlen("endsolid") == 8 */
|
|
||||||
if (endsolid_found) {
|
|
||||||
if (!endsolid_in_overlap)
|
|
||||||
infos->size += (substr_at - strbuff.ptr) + 8;
|
|
||||||
/* TODO : gérer le cas où "endsolid" se trouve dans overlap */
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
infos->size += read_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find "endfacet" tokens */
|
|
||||||
if (flag_facet_count && !endsolid_in_overlap) {
|
|
||||||
const char* endsolid_ptr =
|
|
||||||
endsolid_found ? substr_at : gmio_string_end(&strbuff);
|
|
||||||
/* Check in overlap */
|
|
||||||
const bool endfacet_in_overlap =
|
|
||||||
overlap_has_contents
|
|
||||||
&& strstr(overlap, "endfacet") != NULL;
|
|
||||||
infos->facet_count += endfacet_in_overlap ? 1 : 0;
|
|
||||||
/* Check in memblock */
|
|
||||||
infos->facet_count += stla_facet_count(&strbuff, endsolid_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy second half of overlap buffer */
|
|
||||||
if (!endsolid_found && read_size >= BUFF_OVERLAP_SIZE_DIV2) {
|
|
||||||
memset(&overlap, 0, sizeof(overlap));
|
|
||||||
strncpy(overlap,
|
|
||||||
&strbuff.ptr[read_size - BUFF_OVERLAP_SIZE_DIV2],
|
|
||||||
GMIO_MIN(BUFF_OVERLAP_SIZE_DIV2, read_size));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
/*! Find infos from a STL ASCII stream */
|
/*! Find infos from a STL ASCII stream */
|
||||||
int gmio_stla_infos_get(
|
int gmio_stla_infos_get(
|
||||||
struct gmio_stl_infos_get_args* args, unsigned flags);
|
struct gmio_stl_infos* infos,
|
||||||
|
struct gmio_stream stream,
|
||||||
|
unsigned flags,
|
||||||
|
const struct gmio_stl_infos_get_options* opts);
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STLA_INFOS_GET_H */
|
#endif /* GMIO_INTERNAL_STLA_INFOS_GET_H */
|
||||||
|
@ -43,12 +43,12 @@ enum gmio_stla_token
|
|||||||
struct gmio_stringstream_stla_cookie
|
struct gmio_stringstream_stla_cookie
|
||||||
{
|
{
|
||||||
/* Copy of gmio_stla_read() corresponding argument */
|
/* Copy of gmio_stla_read() corresponding argument */
|
||||||
struct gmio_rwargs* rwargs;
|
const struct gmio_task_iface* task;
|
||||||
/* Cache for the input stream size */
|
/* Cache for the input stream size */
|
||||||
gmio_streamsize_t stream_size;
|
gmio_streamsize_t stream_size;
|
||||||
/* Offset (in bytes) from beginning of stream : current position */
|
/* Offset (in bytes) from beginning of stream : current position */
|
||||||
gmio_streamoffset_t stream_offset;
|
gmio_streamoffset_t stream_offset;
|
||||||
/* Cache for gmio_transfer::func_is_stop_requested() */
|
/* Cache for gmio_task_iface::func_is_stop_requested() */
|
||||||
bool is_stop_requested;
|
bool is_stop_requested;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
#include "../stl_error.h"
|
#include "../stl_error.h"
|
||||||
|
|
||||||
#include "../../gmio_core/error.h"
|
#include "../../gmio_core/error.h"
|
||||||
|
#include "../../gmio_core/task_iface.h"
|
||||||
#include "../../gmio_core/text_format.h"
|
#include "../../gmio_core/text_format.h"
|
||||||
#include "../../gmio_core/internal/helper_rwargs.h"
|
#include "../../gmio_core/internal/helper_memblock.h"
|
||||||
#include "../../gmio_core/internal/helper_stream.h"
|
#include "../../gmio_core/internal/helper_stream.h"
|
||||||
|
#include "../../gmio_core/internal/helper_task_iface.h"
|
||||||
#include "../../gmio_core/internal/min_max.h"
|
#include "../../gmio_core/internal/min_max.h"
|
||||||
#include "../../gmio_core/internal/safe_cast.h"
|
#include "../../gmio_core/internal/safe_cast.h"
|
||||||
|
|
||||||
@ -47,9 +49,11 @@
|
|||||||
* Total with EOL(2 chars) = 307 + 7*2 = 321
|
* Total with EOL(2 chars) = 307 + 7*2 = 321
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum { GMIO_STLA_FACET_SIZE = 321 };
|
enum {
|
||||||
enum { GMIO_STLA_FACET_SIZE_P2 = 512 };
|
GMIO_STLA_FACET_SIZE = 321,
|
||||||
enum { GMIO_STLA_SOLID_NAME_MAX_LEN = 512 };
|
GMIO_STLA_FACET_SIZE_P2 = 512,
|
||||||
|
GMIO_STLA_SOLID_NAME_MAX_LEN = 512
|
||||||
|
};
|
||||||
|
|
||||||
/* Fucntions for raw strings(ie. "const char*") */
|
/* Fucntions for raw strings(ie. "const char*") */
|
||||||
|
|
||||||
@ -121,49 +125,52 @@ GMIO_INLINE char* gmio_write_coords(
|
|||||||
coords_format, coords->x, coords->y, coords->z);
|
coords_format, coords->x, coords->y, coords->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE bool gmio_rwargs_flush_buffer(
|
GMIO_INLINE bool gmio_stream_flush_buffer(
|
||||||
struct gmio_rwargs* args, size_t n)
|
struct gmio_stream* stream, char* buffer, const char* buffer_offset)
|
||||||
{
|
{
|
||||||
const size_t write_count =
|
const size_t n = buffer_offset - buffer;
|
||||||
gmio_stream_write(
|
const size_t write_count = gmio_stream_write(stream, buffer, 1, n);
|
||||||
&args->stream, args->stream_memblock.ptr, sizeof(char), n);
|
|
||||||
return write_count == n;
|
return write_count == n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stla_write(struct gmio_stl_write_args* args)
|
int gmio_stla_write(
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* opts)
|
||||||
{
|
{
|
||||||
/* Constants */
|
/* Constants */
|
||||||
const struct gmio_stl_write_options* options = &args->options;
|
const struct gmio_task_iface* task = opts != NULL ? &opts->task_iface : NULL;
|
||||||
const gmio_stl_mesh_func_get_triangle_t func_mesh_get_triangle =
|
struct gmio_memblock_helper mblock_helper =
|
||||||
args->mesh.func_get_triangle;
|
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||||
const void* mesh_cookie = args->mesh.cookie;
|
const size_t mblock_size = mblock_helper.memblock.size;
|
||||||
const uint32_t total_facet_count = args->mesh.triangle_count;
|
const uint32_t total_facet_count = mesh.triangle_count;
|
||||||
const uint32_t buffer_facet_count =
|
const uint32_t buffer_facet_count =
|
||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(mblock_size / GMIO_STLA_FACET_SIZE_P2);
|
||||||
args->core.stream_memblock.size / GMIO_STLA_FACET_SIZE_P2);
|
const char* opt_solid_name = opts != NULL ? opts->stla_solid_name : NULL;
|
||||||
const char* opt_solid_name = options->stla_solid_name;
|
|
||||||
const char* solid_name = opt_solid_name != NULL ? opt_solid_name : "";
|
const char* solid_name = opt_solid_name != NULL ? opt_solid_name : "";
|
||||||
const enum gmio_float_text_format f32_format = options->stla_float32_format;
|
const enum gmio_float_text_format f32_format =
|
||||||
const uint8_t opt_f32_prec = options->stla_float32_prec;
|
opts != NULL ?
|
||||||
|
opts->stla_float32_format :
|
||||||
|
GMIO_FLOAT_TEXT_FORMAT_DECIMAL_LOWERCASE;
|
||||||
|
const uint8_t opt_f32_prec = opts != NULL ? opts->stla_float32_prec : 9;
|
||||||
const uint8_t f32_prec = opt_f32_prec != 0 ? opt_f32_prec : 9;
|
const uint8_t f32_prec = opt_f32_prec != 0 ? opt_f32_prec : 9;
|
||||||
const bool write_triangles_only = options->stl_write_triangles_only;
|
const bool write_triangles_only =
|
||||||
|
opts != NULL ? opts->stl_write_triangles_only : false;
|
||||||
|
|
||||||
/* Variables */
|
/* Variables */
|
||||||
struct gmio_rwargs* core_args = &args->core;
|
struct gmio_memblock* const mblock = &mblock_helper.memblock;
|
||||||
void* const mblock_ptr = core_args->stream_memblock.ptr;
|
void* const mblock_ptr = mblock->ptr;
|
||||||
uint32_t ifacet = 0; /* for-loop counter on facets */
|
uint32_t ifacet = 0; /* for-loop counter on facets */
|
||||||
char coords_format_str[64] = {0}; /* printf-like format for XYZ coords */
|
char coords_format_str[64] = {0}; /* printf-like format for XYZ coords */
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
/* Check validity of input parameters */
|
/* Check validity of input parameters */
|
||||||
if (!gmio_check_rwargs(&error, core_args))
|
if (!gmio_check_memblock_size(&error, mblock, GMIO_STLA_FACET_SIZE_P2))
|
||||||
return error;
|
goto label_end;
|
||||||
if (!gmio_stl_check_mesh(&error, &args->mesh))
|
if (!gmio_stl_check_mesh(&error, &mesh))
|
||||||
return error;
|
goto label_end;
|
||||||
if (f32_prec == 0 || f32_prec > 9)
|
if (!gmio_stla_check_float32_precision(&error, f32_prec))
|
||||||
return GMIO_STL_ERROR_INVALID_FLOAT32_PREC;
|
goto label_end;
|
||||||
if (core_args->stream_memblock.size < GMIO_STLA_FACET_SIZE_P2)
|
|
||||||
return GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
|
|
||||||
|
|
||||||
/* Create XYZ coords format string (for normal and vertex coords) */
|
/* Create XYZ coords format string (for normal and vertex coords) */
|
||||||
{
|
{
|
||||||
@ -182,8 +189,10 @@ int gmio_stla_write(struct gmio_stl_write_args* args)
|
|||||||
char* buffpos = mblock_ptr;
|
char* buffpos = mblock_ptr;
|
||||||
buffpos = gmio_write_rawstr(buffpos, "solid ");
|
buffpos = gmio_write_rawstr(buffpos, "solid ");
|
||||||
buffpos = gmio_write_rawstr_eol(buffpos, solid_name);
|
buffpos = gmio_write_rawstr_eol(buffpos, solid_name);
|
||||||
if (!gmio_rwargs_flush_buffer(core_args, buffpos - (char*)mblock_ptr))
|
if (!gmio_stream_flush_buffer(&stream, mblock_ptr, buffpos)) {
|
||||||
return GMIO_ERROR_STREAM;
|
error = GMIO_ERROR_STREAM;
|
||||||
|
goto label_end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write solid's facets */
|
/* Write solid's facets */
|
||||||
@ -197,14 +206,14 @@ int gmio_stla_write(struct gmio_stl_write_args* args)
|
|||||||
uint32_t ibuffer_facet;
|
uint32_t ibuffer_facet;
|
||||||
char* buffpos = mblock_ptr;
|
char* buffpos = mblock_ptr;
|
||||||
|
|
||||||
gmio_rwargs_handle_progress(core_args, ifacet, total_facet_count);
|
gmio_task_iface_handle_progress(task, ifacet, total_facet_count);
|
||||||
|
|
||||||
/* Writing of facets is buffered */
|
/* Writing of facets is buffered */
|
||||||
for (ibuffer_facet = ifacet;
|
for (ibuffer_facet = ifacet;
|
||||||
ibuffer_facet < clamped_facet_count;
|
ibuffer_facet < clamped_facet_count;
|
||||||
++ibuffer_facet)
|
++ibuffer_facet)
|
||||||
{
|
{
|
||||||
func_mesh_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_rawstr(buffpos, "facet normal ");
|
||||||
buffpos = gmio_write_coords(buffpos, coords_format_str, &tri.n);
|
buffpos = gmio_write_coords(buffpos, coords_format_str, &tri.n);
|
||||||
@ -221,11 +230,11 @@ int gmio_stla_write(struct gmio_stl_write_args* args)
|
|||||||
buffpos = gmio_write_rawstr(buffpos, "\nendfacet\n");
|
buffpos = gmio_write_rawstr(buffpos, "\nendfacet\n");
|
||||||
} /* end for (ibuffer_facet) */
|
} /* end for (ibuffer_facet) */
|
||||||
|
|
||||||
if (!gmio_rwargs_flush_buffer(core_args, buffpos - (char*)mblock_ptr))
|
if (!gmio_stream_flush_buffer(&stream, mblock_ptr, buffpos))
|
||||||
error = GMIO_ERROR_STREAM;
|
error = GMIO_ERROR_STREAM;
|
||||||
|
|
||||||
/* Task control */
|
/* Task control */
|
||||||
if (gmio_no_error(error) && gmio_rwargs_is_stop_requested(core_args))
|
if (gmio_no_error(error) && gmio_task_iface_is_stop_requested(task))
|
||||||
error = GMIO_ERROR_TRANSFER_STOPPED;
|
error = GMIO_ERROR_TRANSFER_STOPPED;
|
||||||
} /* end for (ifacet) */
|
} /* end for (ifacet) */
|
||||||
|
|
||||||
@ -234,9 +243,11 @@ int gmio_stla_write(struct gmio_stl_write_args* args)
|
|||||||
char* buffpos = mblock_ptr;
|
char* buffpos = mblock_ptr;
|
||||||
buffpos = gmio_write_rawstr(buffpos, "endsolid ");
|
buffpos = gmio_write_rawstr(buffpos, "endsolid ");
|
||||||
buffpos = gmio_write_rawstr_eol(buffpos, solid_name);
|
buffpos = gmio_write_rawstr_eol(buffpos, solid_name);
|
||||||
if (!gmio_rwargs_flush_buffer(core_args, buffpos - (char*)mblock_ptr))
|
if (!gmio_stream_flush_buffer(&stream, mblock_ptr, buffpos))
|
||||||
error = GMIO_ERROR_STREAM;
|
error = GMIO_ERROR_STREAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label_end:
|
||||||
|
gmio_memblock_helper_release(&mblock_helper);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,19 @@
|
|||||||
#ifndef GMIO_INTERNAL_STLA_WRITE_H
|
#ifndef GMIO_INTERNAL_STLA_WRITE_H
|
||||||
#define GMIO_INTERNAL_STLA_WRITE_H
|
#define GMIO_INTERNAL_STLA_WRITE_H
|
||||||
|
|
||||||
#include "../stl_rwargs.h"
|
#include "../../gmio_core/stream.h"
|
||||||
|
#include "../stl_io_options.h"
|
||||||
|
#include "../stl_mesh.h"
|
||||||
|
|
||||||
/*! Writes geometry in the STL ascii format
|
/*! Writes geometry in the STL ascii format
|
||||||
*
|
*
|
||||||
* \return Error code (see gmio_core/error.h and stl_error.h)
|
* \return Error code (see gmio_core/error.h and stl_error.h)
|
||||||
* \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE
|
* \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE
|
||||||
* if <tt>args->core.memblock.size < 512</tt>
|
* if <tt>options->stream_memblock.size < 512</tt>
|
||||||
*/
|
*/
|
||||||
int gmio_stla_write(struct gmio_stl_write_args* args);
|
int gmio_stla_write(
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* options);
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STLA_WRITE_H */
|
#endif /* GMIO_INTERNAL_STLA_WRITE_H */
|
||||||
|
@ -20,19 +20,31 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static enum gmio_endianness gmio_stl_format_to_endianness(
|
||||||
|
enum gmio_stl_format format)
|
||||||
|
{
|
||||||
|
if (format == GMIO_STL_FORMAT_BINARY_BE)
|
||||||
|
return GMIO_ENDIANNESS_BIG;
|
||||||
|
else if (format == GMIO_STL_FORMAT_BINARY_LE)
|
||||||
|
return GMIO_ENDIANNESS_LITTLE;
|
||||||
|
return GMIO_ENDIANNESS_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
int gmio_stlb_infos_get(
|
int gmio_stlb_infos_get(
|
||||||
struct gmio_stl_infos_get_args* args,
|
struct gmio_stl_infos* infos,
|
||||||
enum gmio_endianness byte_order,
|
struct gmio_stream stream,
|
||||||
unsigned flags)
|
unsigned flags,
|
||||||
|
const struct gmio_stl_infos_get_options* opts)
|
||||||
{
|
{
|
||||||
if (flags != 0) {
|
if (flags != 0) {
|
||||||
struct gmio_stl_infos* infos = &args->infos;
|
const enum gmio_endianness byte_order =
|
||||||
|
gmio_stl_format_to_endianness(opts->format_hint);
|
||||||
uint32_t facet_count = 0;
|
uint32_t facet_count = 0;
|
||||||
uint8_t buff[GMIO_STLB_HEADER_SIZE + sizeof(uint32_t)];
|
uint8_t buff[GMIO_STLB_HEADER_SIZE + sizeof(uint32_t)];
|
||||||
|
|
||||||
{ /* Read header and facet count into buff */
|
{ /* Read header and facet count into buff */
|
||||||
const size_t read_size =
|
const size_t read_size =
|
||||||
gmio_stream_read(&args->stream, buff, 1, sizeof(buff));
|
gmio_stream_read(&stream, buff, 1, sizeof(buff));
|
||||||
if (read_size != sizeof(buff))
|
if (read_size != sizeof(buff))
|
||||||
return GMIO_ERROR_STREAM;
|
return GMIO_ERROR_STREAM;
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,9 @@
|
|||||||
|
|
||||||
/*! Find infos from a STL binary stream */
|
/*! Find infos from a STL binary stream */
|
||||||
int gmio_stlb_infos_get(
|
int gmio_stlb_infos_get(
|
||||||
struct gmio_stl_infos_get_args* args,
|
struct gmio_stl_infos* infos,
|
||||||
enum gmio_endianness byte_order,
|
struct gmio_stream stream,
|
||||||
unsigned flags);
|
unsigned flags,
|
||||||
|
const struct gmio_stl_infos_get_options* opts);
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STLB_INFOS_GET_H */
|
#endif /* GMIO_INTERNAL_STLB_INFOS_GET_H */
|
||||||
|
@ -24,8 +24,9 @@
|
|||||||
|
|
||||||
#include "../../gmio_core/error.h"
|
#include "../../gmio_core/error.h"
|
||||||
#include "../../gmio_core/internal/byte_codec.h"
|
#include "../../gmio_core/internal/byte_codec.h"
|
||||||
|
#include "../../gmio_core/internal/helper_memblock.h"
|
||||||
|
#include "../../gmio_core/internal/helper_task_iface.h"
|
||||||
#include "../../gmio_core/internal/min_max.h"
|
#include "../../gmio_core/internal/min_max.h"
|
||||||
#include "../../gmio_core/internal/helper_rwargs.h"
|
|
||||||
#include "../../gmio_core/internal/helper_stream.h"
|
#include "../../gmio_core/internal/helper_stream.h"
|
||||||
#include "../../gmio_core/internal/safe_cast.h"
|
#include "../../gmio_core/internal/safe_cast.h"
|
||||||
|
|
||||||
@ -85,39 +86,45 @@ static void gmio_stlb_encode_facets_byteswap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stlb_write(
|
int gmio_stlb_write(
|
||||||
struct gmio_stl_write_args* args, enum gmio_endianness byte_order)
|
enum gmio_endianness byte_order,
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* opts)
|
||||||
{
|
{
|
||||||
/* Constants */
|
/* Constants */
|
||||||
const uint32_t facet_count = args->mesh.triangle_count;
|
const struct gmio_task_iface* task = opts != NULL ? &opts->task_iface : NULL;
|
||||||
|
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 func_gmio_stlb_encode_facets_t func_encode_facets =
|
const func_gmio_stlb_encode_facets_t func_encode_facets =
|
||||||
byte_order != GMIO_ENDIANNESS_HOST ?
|
byte_order != GMIO_ENDIANNESS_HOST ?
|
||||||
gmio_stlb_encode_facets_byteswap :
|
gmio_stlb_encode_facets_byteswap :
|
||||||
gmio_stlb_encode_facets;
|
gmio_stlb_encode_facets;
|
||||||
|
const bool write_triangles_only =
|
||||||
|
opts != NULL ? opts->stl_write_triangles_only : false;
|
||||||
|
const struct gmio_stlb_header* header =
|
||||||
|
opts != NULL ? &opts->stlb_header : NULL;
|
||||||
|
|
||||||
/* Variables */
|
/* Variables */
|
||||||
struct gmio_rwargs* core_args = &args->core;
|
|
||||||
uint32_t i_facet = 0; /* Facet counter */
|
uint32_t i_facet = 0; /* Facet counter */
|
||||||
uint32_t write_facet_count =
|
uint32_t write_facet_count =
|
||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(mblock_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
core_args->stream_memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
void* const mblock_ptr = mblock_helper.memblock.ptr;
|
||||||
void* mblock_ptr = core_args->stream_memblock.ptr;
|
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
/* Check validity of input parameters */
|
/* Check validity of input parameters */
|
||||||
if (!gmio_stl_check_mesh(&error, &args->mesh)
|
if (!gmio_check_memblock(&error, &mblock_helper.memblock))
|
||||||
|| !gmio_stlb_check_params(&error, core_args, byte_order))
|
goto label_end;
|
||||||
{
|
if (!gmio_stl_check_mesh(&error, &mesh))
|
||||||
return error;
|
goto label_end;
|
||||||
}
|
if (!gmio_stlb_check_byteorder(&error, byte_order))
|
||||||
|
goto label_end;
|
||||||
|
|
||||||
if (!args->options.stl_write_triangles_only) {
|
if (!write_triangles_only) {
|
||||||
error = gmio_stlb_write_header(
|
error = gmio_stlb_write_header(&stream, byte_order, header, facet_count);
|
||||||
&core_args->stream,
|
|
||||||
byte_order,
|
|
||||||
args->options.stlb_header,
|
|
||||||
facet_count);
|
|
||||||
if (gmio_error(error))
|
if (gmio_error(error))
|
||||||
return error;
|
goto label_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write triangles */
|
/* Write triangles */
|
||||||
@ -125,16 +132,15 @@ int gmio_stlb_write(
|
|||||||
i_facet < facet_count && gmio_no_error(error);
|
i_facet < facet_count && gmio_no_error(error);
|
||||||
i_facet += write_facet_count)
|
i_facet += write_facet_count)
|
||||||
{
|
{
|
||||||
gmio_rwargs_handle_progress(core_args, i_facet, facet_count);
|
gmio_task_iface_handle_progress(task, i_facet, facet_count);
|
||||||
|
|
||||||
/* Write to memory block */
|
/* Write to memory block */
|
||||||
write_facet_count = GMIO_MIN(write_facet_count, facet_count - i_facet);
|
write_facet_count = GMIO_MIN(write_facet_count, facet_count - i_facet);
|
||||||
func_encode_facets(
|
func_encode_facets(&mesh, mblock_ptr, write_facet_count, i_facet);
|
||||||
&args->mesh, mblock_ptr, write_facet_count, i_facet);
|
|
||||||
|
|
||||||
/* Write memory block to stream */
|
/* Write memory block to stream */
|
||||||
if (gmio_stream_write(
|
if (gmio_stream_write(
|
||||||
&core_args->stream,
|
&stream,
|
||||||
mblock_ptr,
|
mblock_ptr,
|
||||||
GMIO_STLB_TRIANGLE_RAWSIZE,
|
GMIO_STLB_TRIANGLE_RAWSIZE,
|
||||||
write_facet_count)
|
write_facet_count)
|
||||||
@ -144,9 +150,11 @@ int gmio_stlb_write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Handle stop request */
|
/* Handle stop request */
|
||||||
if (gmio_no_error(error) && gmio_rwargs_is_stop_requested(core_args))
|
if (gmio_no_error(error) && gmio_task_iface_is_stop_requested(task))
|
||||||
error = GMIO_ERROR_TRANSFER_STOPPED;
|
error = GMIO_ERROR_TRANSFER_STOPPED;
|
||||||
} /* end for */
|
} /* end for */
|
||||||
|
|
||||||
|
label_end:
|
||||||
|
gmio_memblock_helper_release(&mblock_helper);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,21 @@
|
|||||||
#ifndef GMIO_INTERNAL_STLB_WRITE_H
|
#ifndef GMIO_INTERNAL_STLB_WRITE_H
|
||||||
#define GMIO_INTERNAL_STLB_WRITE_H
|
#define GMIO_INTERNAL_STLB_WRITE_H
|
||||||
|
|
||||||
#include "../stl_rwargs.h"
|
|
||||||
#include "../../gmio_core/endian.h"
|
#include "../../gmio_core/endian.h"
|
||||||
|
#include "../../gmio_core/stream.h"
|
||||||
|
#include "../stl_io_options.h"
|
||||||
|
#include "../stl_mesh.h"
|
||||||
|
|
||||||
/*! Writes geometry in the STL binary format
|
/*! Writes geometry in the STL binary format
|
||||||
*
|
*
|
||||||
* \return Error code (see error.h and stl_error.h)
|
* \return Error code (see error.h and stl_error.h)
|
||||||
* \retval GMIO_INVALID_MEMBLOCK_SIZE_ERROR
|
* \retval GMIO_INVALID_MEMBLOCK_SIZE_ERROR
|
||||||
* if <tt>args->core.memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
|
* if <tt>opts->stream_memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
|
||||||
*/
|
*/
|
||||||
int gmio_stlb_write(
|
int gmio_stlb_write(
|
||||||
struct gmio_stl_write_args* args, enum gmio_endianness byte_order);
|
enum gmio_endianness byte_order,
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* opts);
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STLB_WRITE_H */
|
#endif /* GMIO_INTERNAL_STLB_WRITE_H */
|
||||||
|
@ -45,3 +45,4 @@ enum gmio_stl_constants
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif /* GMIO_STL_CONSTANTS_H */
|
#endif /* GMIO_STL_CONSTANTS_H */
|
||||||
|
/*! @} */
|
||||||
|
@ -19,36 +19,57 @@
|
|||||||
#include "../gmio_core/internal/helper_memblock.h"
|
#include "../gmio_core/internal/helper_memblock.h"
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
#include "stl_error.h"
|
#include "stl_error.h"
|
||||||
|
#include "stl_format.h"
|
||||||
#include "internal/stla_infos_get.h"
|
#include "internal/stla_infos_get.h"
|
||||||
#include "internal/stlb_infos_get.h"
|
#include "internal/stlb_infos_get.h"
|
||||||
|
|
||||||
int gmio_stl_infos_get(
|
int gmio_stl_infos_get(
|
||||||
struct gmio_stl_infos_get_args* args,
|
struct gmio_stl_infos* infos,
|
||||||
enum gmio_stl_format format,
|
struct gmio_stream stream,
|
||||||
unsigned flags)
|
unsigned flags,
|
||||||
|
const struct gmio_stl_infos_get_options* opts)
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
|
const struct gmio_streampos begin_streampos = gmio_streampos(&stream, NULL);
|
||||||
struct gmio_memblock_helper mblock_helper =
|
struct gmio_memblock_helper mblock_helper =
|
||||||
gmio_memblock_helper(&args->stream_memblock);
|
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||||
const struct gmio_streampos begin_streampos =
|
enum gmio_stl_format format =
|
||||||
gmio_streampos(&args->stream, NULL);
|
opts != NULL ? opts->format_hint : GMIO_STL_FORMAT_UNKNOWN;
|
||||||
|
struct gmio_stl_infos_get_options ovrdn_opts = {0};
|
||||||
|
|
||||||
|
if (opts != NULL)
|
||||||
|
ovrdn_opts = *opts;
|
||||||
|
ovrdn_opts.stream_memblock = mblock_helper.memblock;
|
||||||
|
|
||||||
|
/* Guess format when left unspecified */
|
||||||
|
if (format == GMIO_STL_FORMAT_UNKNOWN) {
|
||||||
|
format = gmio_stl_get_format(&stream);
|
||||||
|
if (format == GMIO_STL_FORMAT_UNKNOWN) {
|
||||||
|
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
||||||
|
goto label_end;
|
||||||
|
}
|
||||||
|
ovrdn_opts.format_hint = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & GMIO_STL_INFO_FLAG_FORMAT)
|
||||||
|
infos->format = format;
|
||||||
|
|
||||||
|
/* Dispatch to the sub-function */
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case GMIO_STL_FORMAT_ASCII:
|
case GMIO_STL_FORMAT_ASCII:
|
||||||
error = gmio_stla_infos_get(args, flags);
|
error = gmio_stla_infos_get(infos, stream, flags, &ovrdn_opts);
|
||||||
break;
|
break;
|
||||||
case GMIO_STL_FORMAT_BINARY_LE:
|
case GMIO_STL_FORMAT_BINARY_LE:
|
||||||
error = gmio_stlb_infos_get(args, GMIO_ENDIANNESS_LITTLE, flags);
|
|
||||||
break;
|
|
||||||
case GMIO_STL_FORMAT_BINARY_BE:
|
case GMIO_STL_FORMAT_BINARY_BE:
|
||||||
error = gmio_stlb_infos_get(args, GMIO_ENDIANNESS_BIG, flags);
|
error = gmio_stlb_infos_get(infos, stream, flags, &ovrdn_opts);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gmio_memblock_helper_release(&mblock_helper);
|
|
||||||
gmio_stream_set_pos(&args->stream, &begin_streampos);
|
|
||||||
|
|
||||||
|
label_end:
|
||||||
|
gmio_stream_set_pos(&stream, &begin_streampos);
|
||||||
|
gmio_memblock_helper_release(&mblock_helper);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/*! \file stl_infos.h
|
/*! \file stl_infos.h
|
||||||
* TODO: description
|
* Retrieval of STL infos from input stream
|
||||||
*
|
*
|
||||||
* \addtogroup gmio_stl
|
* \addtogroup gmio_stl
|
||||||
* @{
|
* @{
|
||||||
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "stl_global.h"
|
#include "stl_global.h"
|
||||||
|
|
||||||
#include "../gmio_core/rwargs.h"
|
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -36,6 +35,9 @@
|
|||||||
/*! Informations retrieved by gmio_stl_infos_get() */
|
/*! Informations retrieved by gmio_stl_infos_get() */
|
||||||
struct gmio_stl_infos
|
struct gmio_stl_infos
|
||||||
{
|
{
|
||||||
|
/*! STL format of the input stream */
|
||||||
|
enum stl_format format;
|
||||||
|
|
||||||
/*! Count of facets(triangles) */
|
/*! Count of facets(triangles) */
|
||||||
uint32_t facet_count;
|
uint32_t facet_count;
|
||||||
|
|
||||||
@ -78,24 +80,28 @@ enum gmio_stl_info_flag
|
|||||||
GMIO_STL_INFO_FLAG_SOLIDNAME_OR_HEADER =
|
GMIO_STL_INFO_FLAG_SOLIDNAME_OR_HEADER =
|
||||||
GMIO_STLA_INFO_FLAG_SOLIDNAME | GMIO_STLB_INFO_FLAG_HEADER,
|
GMIO_STLA_INFO_FLAG_SOLIDNAME | GMIO_STLB_INFO_FLAG_HEADER,
|
||||||
|
|
||||||
|
/*! -> gmio_stl_infos::format */
|
||||||
|
GMIO_STL_INFO_FLAG_FORMAT = 0x0010,
|
||||||
|
|
||||||
/*! All infos */
|
/*! All infos */
|
||||||
GMIO_STL_INFO_FLAG_ALL = 0xFFFF
|
GMIO_STL_INFO_FLAG_ALL = 0xFFFF
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Objects to be passed to gmio_stl_infos_get() */
|
/*! Optional parameters of gmio_stl_infos_get() */
|
||||||
struct gmio_stl_infos_get_args
|
struct gmio_stl_infos_get_options
|
||||||
{
|
{
|
||||||
/*! Input stream */
|
/*! See gmio_core_readwrite_options::stream_memblock */
|
||||||
struct gmio_stream stream;
|
|
||||||
|
|
||||||
/*! Optional memory block used by the stream to bufferize read operations
|
|
||||||
*
|
|
||||||
* If null, then a temporary memblock is created with the global default
|
|
||||||
* constructor function (see gmio_memblock_default()) */
|
|
||||||
struct gmio_memblock stream_memblock;
|
struct gmio_memblock stream_memblock;
|
||||||
|
|
||||||
/*! Output informations */
|
/*! Assume STL input format, if GMIO_STL_FORMAT_UNKNOWN then it is
|
||||||
struct gmio_stl_infos infos;
|
* automatically guessed */
|
||||||
|
enum gmio_stl_format format_hint;
|
||||||
|
|
||||||
|
/*! Restrict gmio_stl_infos_get() to not read further this limit
|
||||||
|
*
|
||||||
|
* Not yet supported
|
||||||
|
*/
|
||||||
|
gmio_streamsize_t size_limit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GMIO_C_LINKAGE_BEGIN
|
GMIO_C_LINKAGE_BEGIN
|
||||||
@ -106,9 +112,10 @@ GMIO_C_LINKAGE_BEGIN
|
|||||||
*/
|
*/
|
||||||
GMIO_LIBSTL_EXPORT
|
GMIO_LIBSTL_EXPORT
|
||||||
int gmio_stl_infos_get(
|
int gmio_stl_infos_get(
|
||||||
struct gmio_stl_infos_get_args* args,
|
struct gmio_stl_infos* infos,
|
||||||
enum gmio_stl_format format,
|
struct gmio_stream stream,
|
||||||
unsigned flags);
|
unsigned flags, /*!< Bitor combination of gmio_stl_info_flag values */
|
||||||
|
const struct gmio_stl_infos_get_options* options);
|
||||||
|
|
||||||
GMIO_C_LINKAGE_END
|
GMIO_C_LINKAGE_END
|
||||||
|
|
||||||
|
@ -23,112 +23,75 @@
|
|||||||
#include "../gmio_core/internal/helper_memblock.h"
|
#include "../gmio_core/internal/helper_memblock.h"
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
|
|
||||||
int gmio_stl_read(struct gmio_stl_read_args* args)
|
int gmio_stl_read(
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
const struct gmio_stl_read_options* options)
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
const enum gmio_stl_format format = gmio_stl_get_format(&stream);
|
||||||
if (args != NULL) {
|
switch (format) {
|
||||||
const enum gmio_stl_format format =
|
case GMIO_STL_FORMAT_ASCII:
|
||||||
gmio_stl_get_format(&args->core.stream);
|
return gmio_stla_read(stream, mesh_creator, options);
|
||||||
|
case GMIO_STL_FORMAT_BINARY_BE:
|
||||||
switch (format) {
|
return gmio_stlb_read(
|
||||||
case GMIO_STL_FORMAT_ASCII: {
|
stream, mesh_creator, GMIO_ENDIANNESS_BIG, options);
|
||||||
error = gmio_stla_read(args);
|
case GMIO_STL_FORMAT_BINARY_LE:
|
||||||
break;
|
return gmio_stlb_read(
|
||||||
}
|
stream, mesh_creator, GMIO_ENDIANNESS_LITTLE, options);
|
||||||
case GMIO_STL_FORMAT_BINARY_BE: {
|
case GMIO_STL_FORMAT_UNKNOWN:
|
||||||
error = gmio_stlb_read(args, GMIO_ENDIANNESS_BIG);
|
return GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GMIO_STL_FORMAT_BINARY_LE: {
|
|
||||||
error = gmio_stlb_read(args, GMIO_ENDIANNESS_LITTLE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GMIO_STL_FORMAT_UNKNOWN: {
|
|
||||||
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} /* end switch() */
|
|
||||||
}
|
}
|
||||||
else {
|
return GMIO_ERROR_UNKNOWN;
|
||||||
error = GMIO_ERROR_NULL_RWARGS;
|
|
||||||
}
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stl_read_file(
|
int gmio_stl_read_file(
|
||||||
struct gmio_stl_read_args* args, const char* filepath)
|
const char* filepath,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
const struct gmio_stl_read_options* options)
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
FILE* file = fopen(filepath, "rb");
|
||||||
if (args != NULL) {
|
if (file != NULL) {
|
||||||
FILE* file = fopen(filepath, "rb");
|
const int error =
|
||||||
if (file != NULL) {
|
gmio_stl_read(gmio_stream_stdio(file), mesh_creator, options);
|
||||||
args->core.stream = gmio_stream_stdio(file);
|
fclose(file);
|
||||||
error = gmio_stl_read(args);
|
return error;
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
error = GMIO_ERROR_STDIO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
return GMIO_ERROR_STDIO;
|
||||||
error = GMIO_ERROR_NULL_RWARGS;
|
|
||||||
}
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stl_write(
|
int gmio_stl_write(
|
||||||
struct gmio_stl_write_args* args, enum gmio_stl_format format)
|
enum gmio_stl_format format,
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* options)
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
switch (format) {
|
||||||
if (args != NULL) {
|
case GMIO_STL_FORMAT_ASCII:
|
||||||
struct gmio_memblock_helper mblock_helper =
|
return gmio_stla_write(stream, mesh, options);
|
||||||
gmio_memblock_helper(&args->core.stream_memblock);
|
case GMIO_STL_FORMAT_BINARY_BE:
|
||||||
switch (format) {
|
return gmio_stlb_write(GMIO_ENDIANNESS_BIG, stream, mesh, options);
|
||||||
case GMIO_STL_FORMAT_ASCII: {
|
case GMIO_STL_FORMAT_BINARY_LE:
|
||||||
error = gmio_stla_write(args);
|
return gmio_stlb_write(GMIO_ENDIANNESS_LITTLE, stream, mesh, options);
|
||||||
break;
|
case GMIO_STL_FORMAT_UNKNOWN:
|
||||||
}
|
return GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
||||||
case GMIO_STL_FORMAT_BINARY_BE: {
|
|
||||||
error = gmio_stlb_write(args, GMIO_ENDIANNESS_BIG);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GMIO_STL_FORMAT_BINARY_LE: {
|
|
||||||
error = gmio_stlb_write(args, GMIO_ENDIANNESS_LITTLE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GMIO_STL_FORMAT_UNKNOWN: {
|
|
||||||
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
|
||||||
}
|
|
||||||
} /* end switch() */
|
|
||||||
gmio_memblock_helper_release(&mblock_helper);
|
|
||||||
}
|
}
|
||||||
else {
|
return GMIO_ERROR_UNKNOWN;
|
||||||
error = GMIO_ERROR_NULL_RWARGS;
|
|
||||||
}
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stl_write_file(
|
int gmio_stl_write_file(
|
||||||
struct gmio_stl_write_args* args,
|
|
||||||
enum gmio_stl_format format,
|
enum gmio_stl_format format,
|
||||||
const char* filepath)
|
const char* filepath,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* options)
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
FILE* file = fopen(filepath, "wb");
|
||||||
if (args != NULL) {
|
if (file != NULL) {
|
||||||
FILE* file = fopen(filepath, "wb");
|
const int error =
|
||||||
if (file != NULL) {
|
gmio_stl_write(format, gmio_stream_stdio(file), mesh, options);
|
||||||
args->core.stream = gmio_stream_stdio(file);
|
fclose(file);
|
||||||
error = gmio_stl_write(args, format);
|
return error;
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
error = GMIO_ERROR_STDIO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
return GMIO_ERROR_STDIO;
|
||||||
error = GMIO_ERROR_NULL_RWARGS;
|
|
||||||
}
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct gmio_stlb_header internal_stlb_zero_header = {0};
|
static const struct gmio_stlb_header internal_stlb_zero_header = {0};
|
||||||
|
@ -24,7 +24,12 @@
|
|||||||
#define GMIO_STL_IO_H
|
#define GMIO_STL_IO_H
|
||||||
|
|
||||||
#include "stl_global.h"
|
#include "stl_global.h"
|
||||||
#include "stl_rwargs.h"
|
|
||||||
|
#include "stl_format.h"
|
||||||
|
#include "stl_io_options.h"
|
||||||
|
#include "stl_mesh.h"
|
||||||
|
#include "stl_mesh_creator.h"
|
||||||
|
#include "../gmio_core/stream.h"
|
||||||
#include "../gmio_core/endian.h"
|
#include "../gmio_core/endian.h"
|
||||||
|
|
||||||
GMIO_C_LINKAGE_BEGIN
|
GMIO_C_LINKAGE_BEGIN
|
||||||
@ -33,37 +38,46 @@ GMIO_C_LINKAGE_BEGIN
|
|||||||
*
|
*
|
||||||
* \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_read(
|
||||||
int gmio_stl_read(struct gmio_stl_read_args* args);
|
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
|
/*! Reads STL mesh from a file, format is automatically guessed
|
||||||
*
|
*
|
||||||
* This is just a facility function over gmio_stl_read(). The stream object
|
* This is just a facility function over gmio_stl_read(). The internal stream
|
||||||
* pointed to by \c args->core.stream is automatically initialized to read file
|
* object is created to read file at \p filepath (see gmio_stream_stdio(FILE*))
|
||||||
* at \p filepath (see gmio_stream_stdio(FILE*))
|
|
||||||
*
|
*
|
||||||
* The file is opened with fopen() so \p filepath shall follow the file name
|
* The file is opened with fopen() so \p filepath shall follow the file name
|
||||||
* specifications of the running environment
|
* specifications of the running environment
|
||||||
*/
|
*/
|
||||||
GMIO_LIBSTL_EXPORT
|
GMIO_LIBSTL_EXPORT int gmio_stl_read_file(
|
||||||
int gmio_stl_read_file(struct gmio_stl_read_args* args, const char* filepath);
|
const char* filepath,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
const struct gmio_stl_read_options* options);
|
||||||
|
|
||||||
/*! Reads geometry from STL ascii stream
|
/*! Reads geometry from STL ascii stream
|
||||||
*
|
*
|
||||||
* \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_stla_read(struct gmio_stl_read_args* args);
|
int gmio_stla_read(
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
const struct gmio_stl_read_options* options);
|
||||||
|
|
||||||
/*! Reads geometry from STL binary stream
|
/*! Reads geometry from STL binary stream
|
||||||
*
|
*
|
||||||
* \return Error code (see gmio_core/error.h and stl_error.h)
|
* \return Error code (see gmio_core/error.h and stl_error.h)
|
||||||
* \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE
|
* \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE
|
||||||
* if <tt>args->core.stream_memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
|
* if <tt>options->stream_memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
|
||||||
*/
|
*/
|
||||||
GMIO_LIBSTL_EXPORT
|
GMIO_LIBSTL_EXPORT
|
||||||
int gmio_stlb_read(
|
int gmio_stlb_read(
|
||||||
struct gmio_stl_read_args* args, enum gmio_endianness byte_order);
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
enum gmio_endianness byte_order,
|
||||||
|
const struct gmio_stl_read_options* options);
|
||||||
|
|
||||||
/*! Writes STL mesh to stream
|
/*! Writes STL mesh to stream
|
||||||
*
|
*
|
||||||
@ -71,13 +85,15 @@ int gmio_stlb_read(
|
|||||||
*/
|
*/
|
||||||
GMIO_LIBSTL_EXPORT
|
GMIO_LIBSTL_EXPORT
|
||||||
int gmio_stl_write(
|
int gmio_stl_write(
|
||||||
struct gmio_stl_write_args* args, enum gmio_stl_format format);
|
enum gmio_stl_format format,
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* options);
|
||||||
|
|
||||||
/*! Writes STL mesh to stream
|
/*! Writes STL mesh to stream
|
||||||
*
|
*
|
||||||
* This is just a facility function over gmio_stl_write(). The stream object
|
* This is just a facility function over gmio_stl_write(). The internal stream
|
||||||
* pointed to by \c args->core.stream is automatically initialized to write
|
* object is created to read file at \p filepath (see gmio_stream_stdio(FILE*))
|
||||||
* file to \p filepath (see gmio_stream_stdio(FILE*))
|
|
||||||
*
|
*
|
||||||
* The file is opened with fopen() so \p filepath shall follow the file name
|
* The file is opened with fopen() so \p filepath shall follow the file name
|
||||||
* specifications of the running environment
|
* specifications of the running environment
|
||||||
@ -86,9 +102,10 @@ int gmio_stl_write(
|
|||||||
*/
|
*/
|
||||||
GMIO_LIBSTL_EXPORT
|
GMIO_LIBSTL_EXPORT
|
||||||
int gmio_stl_write_file(
|
int gmio_stl_write_file(
|
||||||
struct gmio_stl_write_args* args,
|
|
||||||
enum gmio_stl_format format,
|
enum gmio_stl_format format,
|
||||||
const char* filepath);
|
const char* filepath,
|
||||||
|
struct gmio_stl_mesh mesh,
|
||||||
|
const struct gmio_stl_write_options* options);
|
||||||
|
|
||||||
/*! Writes STL binary header data to stream
|
/*! Writes STL binary header data to stream
|
||||||
*
|
*
|
||||||
|
@ -26,11 +26,45 @@
|
|||||||
#include "stl_global.h"
|
#include "stl_global.h"
|
||||||
#include "stlb_header.h"
|
#include "stlb_header.h"
|
||||||
#include "../gmio_core/endian.h"
|
#include "../gmio_core/endian.h"
|
||||||
|
#include "../gmio_core/stream.h"
|
||||||
|
#include "../gmio_core/task_iface.h"
|
||||||
#include "../gmio_core/text_format.h"
|
#include "../gmio_core/text_format.h"
|
||||||
|
|
||||||
|
struct gmio_stl_read_options
|
||||||
|
{
|
||||||
|
/*! Used by the stream to bufferize I/O operations
|
||||||
|
*
|
||||||
|
* If null(see gmio_memblock_isnull()), then a temporary memblock is
|
||||||
|
* created with the global default constructor function
|
||||||
|
* (see gmio_memblock_default()) */
|
||||||
|
struct gmio_memblock stream_memblock;
|
||||||
|
|
||||||
|
/*! Optional interface by which the I/O operation can be controlled */
|
||||||
|
struct gmio_task_iface task_iface;
|
||||||
|
|
||||||
|
/*! Optional pointer to a function that returns the size(in bytes) of the
|
||||||
|
* STL ascii data to read
|
||||||
|
*
|
||||||
|
* Useful only with STL ascii format. If set to NULL then by default
|
||||||
|
* gmio_stream::func_size() is called.
|
||||||
|
*
|
||||||
|
* The resulting stream size is passed to
|
||||||
|
* gmio_task_iface::func_handle_progress() as the \p max_value argument.
|
||||||
|
*/
|
||||||
|
gmio_streamsize_t (*func_stla_get_streamsize)(
|
||||||
|
struct gmio_stream* stream,
|
||||||
|
struct gmio_memblock* stream_memblock);
|
||||||
|
};
|
||||||
|
|
||||||
/*! Options for gmio_stl_write() */
|
/*! Options for gmio_stl_write() */
|
||||||
struct gmio_stl_write_options
|
struct gmio_stl_write_options
|
||||||
{
|
{
|
||||||
|
/*! See gmio_stl_read_options::stream_memblock */
|
||||||
|
struct gmio_memblock stream_memblock;
|
||||||
|
|
||||||
|
/*! See gmio_stl_read_options::task_iface */
|
||||||
|
struct gmio_task_iface task_iface;
|
||||||
|
|
||||||
/*! Flag allowing to skip writting of any header/footer data, but just
|
/*! Flag allowing to skip writting of any header/footer data, but just
|
||||||
* triangles
|
* triangles
|
||||||
*
|
*
|
||||||
@ -78,7 +112,7 @@ struct gmio_stl_write_options
|
|||||||
* \li calling gmio_stl_write() with <tt>options == NULL</tt>
|
* \li calling gmio_stl_write() with <tt>options == NULL</tt>
|
||||||
* \li OR <tt>stlb_header_data == NULL</tt>
|
* \li OR <tt>stlb_header_data == NULL</tt>
|
||||||
*/
|
*/
|
||||||
const struct gmio_stlb_header* stlb_header;
|
struct gmio_stlb_header stlb_header;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* GMIO_STL_IO_OPTIONS_H */
|
#endif /* GMIO_STL_IO_OPTIONS_H */
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
** gmio
|
|
||||||
** Copyright Fougue (2 Mar. 2015)
|
|
||||||
** contact@fougue.pro
|
|
||||||
**
|
|
||||||
** 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
|
|
||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/*! \file stl_rwargs.h
|
|
||||||
* Read/write structures for STL
|
|
||||||
*
|
|
||||||
* \addtogroup gmio_stl
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GMIO_STL_RWARGS_H
|
|
||||||
#define GMIO_STL_RWARGS_H
|
|
||||||
|
|
||||||
#include "stl_format.h"
|
|
||||||
#include "stl_global.h"
|
|
||||||
#include "stl_io_options.h"
|
|
||||||
#include "stl_mesh.h"
|
|
||||||
#include "stl_mesh_creator.h"
|
|
||||||
#include "../gmio_core/rwargs.h"
|
|
||||||
|
|
||||||
/*! Arguments for STL read functions */
|
|
||||||
struct gmio_stl_read_args
|
|
||||||
{
|
|
||||||
/*! Common(core) objects needed for the read operation */
|
|
||||||
struct gmio_rwargs core;
|
|
||||||
|
|
||||||
/*! Defines the callbacks for the mesh creation */
|
|
||||||
struct gmio_stl_mesh_creator mesh_creator;
|
|
||||||
|
|
||||||
/*! Optional pointer to a function that returns the size(in bytes) of the
|
|
||||||
* STL ascii data to read
|
|
||||||
*
|
|
||||||
* Useful only with STL ascii format. If set to NULL then by default
|
|
||||||
* gmio_stream::func_size() is called.
|
|
||||||
*
|
|
||||||
* The resulting stream size is passed to
|
|
||||||
* gmio_task_iface::func_handle_progress() as the \p max_value argument.
|
|
||||||
*/
|
|
||||||
gmio_streamsize_t (*func_stla_get_streamsize)(
|
|
||||||
struct gmio_stream* stream,
|
|
||||||
struct gmio_memblock* stream_memblock);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*! Arguments for STL write functions */
|
|
||||||
struct gmio_stl_write_args
|
|
||||||
{
|
|
||||||
/*! Common(core) objects needed for the write operation */
|
|
||||||
struct gmio_rwargs core;
|
|
||||||
|
|
||||||
/*! Defines the mesh to output */
|
|
||||||
struct gmio_stl_mesh mesh;
|
|
||||||
|
|
||||||
/*! Options for the write operation, can be safely set to \c {0} to use
|
|
||||||
* default values */
|
|
||||||
struct gmio_stl_write_options options;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* GMIO_STL_RWARGS_H */
|
|
@ -22,10 +22,9 @@
|
|||||||
#include "internal/stla_parsing.h"
|
#include "internal/stla_parsing.h"
|
||||||
|
|
||||||
#include "../gmio_core/error.h"
|
#include "../gmio_core/error.h"
|
||||||
#include "../gmio_core/rwargs.h"
|
|
||||||
#include "../gmio_core/internal/helper_memblock.h"
|
#include "../gmio_core/internal/helper_memblock.h"
|
||||||
#include "../gmio_core/internal/helper_rwargs.h"
|
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
|
#include "../gmio_core/internal/helper_task_iface.h"
|
||||||
#include "../gmio_core/internal/min_max.h"
|
#include "../gmio_core/internal/min_max.h"
|
||||||
#include "../gmio_core/internal/stringstream.h"
|
#include "../gmio_core/internal/stringstream.h"
|
||||||
#include "../gmio_core/internal/string_ascii_utils.h"
|
#include "../gmio_core/internal/string_ascii_utils.h"
|
||||||
@ -89,51 +88,51 @@ static void gmio_stringstream_stla_read_hook(
|
|||||||
{
|
{
|
||||||
struct gmio_stringstream_stla_cookie* tcookie =
|
struct gmio_stringstream_stla_cookie* tcookie =
|
||||||
(struct gmio_stringstream_stla_cookie*)(cookie);
|
(struct gmio_stringstream_stla_cookie*)(cookie);
|
||||||
const struct gmio_rwargs* rwargs =
|
|
||||||
tcookie != NULL ? tcookie->rwargs : NULL;
|
|
||||||
if (tcookie != NULL) {
|
if (tcookie != NULL) {
|
||||||
|
const struct gmio_task_iface* task = tcookie->task;
|
||||||
tcookie->stream_offset += strbuff->len;
|
tcookie->stream_offset += strbuff->len;
|
||||||
tcookie->is_stop_requested = gmio_rwargs_is_stop_requested(rwargs);
|
tcookie->is_stop_requested = gmio_task_iface_is_stop_requested(task);
|
||||||
gmio_rwargs_handle_progress(
|
gmio_task_iface_handle_progress(
|
||||||
rwargs, tcookie->stream_offset, tcookie->stream_size);
|
task, tcookie->stream_offset, tcookie->stream_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Root function, parses a whole solid */
|
/* Root function, parses a whole solid */
|
||||||
static void parse_solid(struct gmio_stla_parse_data* data);
|
static void parse_solid(struct gmio_stla_parse_data* data);
|
||||||
|
|
||||||
int gmio_stla_read(struct gmio_stl_read_args* args)
|
int gmio_stla_read(
|
||||||
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
const struct gmio_stl_read_options* opts)
|
||||||
{
|
{
|
||||||
struct gmio_rwargs* core_args = &args->core;
|
|
||||||
struct gmio_memblock_helper mblock_helper =
|
struct gmio_memblock_helper mblock_helper =
|
||||||
gmio_memblock_helper(&core_args->stream_memblock);
|
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||||
|
struct gmio_memblock* const mblock = &mblock_helper.memblock;
|
||||||
char fixed_buffer[GMIO_STLA_READ_STRING_MAX_LEN];
|
char fixed_buffer[GMIO_STLA_READ_STRING_MAX_LEN];
|
||||||
struct gmio_stla_parse_data parse_data;
|
struct gmio_stla_parse_data parse_data;
|
||||||
|
|
||||||
parse_data.token = unknown_token;
|
parse_data.token = unknown_token;
|
||||||
parse_data.error = false;
|
parse_data.error = false;
|
||||||
|
|
||||||
parse_data.strstream_cookie.rwargs = core_args;
|
parse_data.strstream_cookie.task = opts != NULL ? &opts->task_iface : NULL;
|
||||||
parse_data.strstream_cookie.stream_offset = 0;
|
parse_data.strstream_cookie.stream_offset = 0;
|
||||||
|
|
||||||
parse_data.strstream_cookie.stream_size =
|
parse_data.strstream_cookie.stream_size =
|
||||||
args->func_stla_get_streamsize != NULL ?
|
opts != NULL && opts->func_stla_get_streamsize != NULL ?
|
||||||
args->func_stla_get_streamsize(
|
opts->func_stla_get_streamsize(&stream, mblock) :
|
||||||
&core_args->stream, &core_args->stream_memblock) :
|
gmio_stream_size(&stream);
|
||||||
gmio_stream_size(&core_args->stream);
|
|
||||||
|
|
||||||
parse_data.strstream_cookie.is_stop_requested = false;
|
parse_data.strstream_cookie.is_stop_requested = false;
|
||||||
|
|
||||||
parse_data.strstream.stream = core_args->stream;
|
parse_data.strstream.stream = stream;
|
||||||
parse_data.strstream.strbuff.ptr = core_args->stream_memblock.ptr;
|
parse_data.strstream.strbuff.ptr = mblock->ptr;
|
||||||
parse_data.strstream.strbuff.max_len = core_args->stream_memblock.size;
|
parse_data.strstream.strbuff.max_len = mblock->size;
|
||||||
parse_data.strstream.cookie = &parse_data.strstream_cookie;
|
parse_data.strstream.cookie = &parse_data.strstream_cookie;
|
||||||
parse_data.strstream.func_stream_read_hook = gmio_stringstream_stla_read_hook;
|
parse_data.strstream.func_stream_read_hook = gmio_stringstream_stla_read_hook;
|
||||||
gmio_stringstream_init_pos(&parse_data.strstream);
|
gmio_stringstream_init_pos(&parse_data.strstream);
|
||||||
|
|
||||||
parse_data.strbuff = gmio_string(fixed_buffer, 0, sizeof(fixed_buffer));
|
parse_data.strbuff = gmio_string(fixed_buffer, 0, sizeof(fixed_buffer));
|
||||||
|
|
||||||
parse_data.creator = &args->mesh_creator;
|
parse_data.creator = &mesh_creator;
|
||||||
|
|
||||||
parse_solid(&parse_data);
|
parse_solid(&parse_data);
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
#include "../gmio_core/internal/byte_swap.h"
|
#include "../gmio_core/internal/byte_swap.h"
|
||||||
#include "../gmio_core/internal/convert.h"
|
#include "../gmio_core/internal/convert.h"
|
||||||
#include "../gmio_core/internal/helper_memblock.h"
|
#include "../gmio_core/internal/helper_memblock.h"
|
||||||
#include "../gmio_core/internal/helper_rwargs.h"
|
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
|
#include "../gmio_core/internal/helper_task_iface.h"
|
||||||
#include "../gmio_core/internal/safe_cast.h"
|
#include "../gmio_core/internal/safe_cast.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -89,14 +89,17 @@ static void gmio_stlb_decode_facets_byteswap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stlb_read(
|
int gmio_stlb_read(
|
||||||
struct gmio_stl_read_args* args, enum gmio_endianness byte_order)
|
struct gmio_stream stream,
|
||||||
|
struct gmio_stl_mesh_creator mesh_creator,
|
||||||
|
enum gmio_endianness byte_order,
|
||||||
|
const struct gmio_stl_read_options* opts)
|
||||||
{
|
{
|
||||||
/* Variables */
|
/* Variables */
|
||||||
struct gmio_memblock_helper mblock_helper =
|
struct gmio_memblock_helper mblock_helper =
|
||||||
gmio_memblock_helper(&args->core.stream_memblock);
|
gmio_memblock_helper(opts != NULL ? &opts->stream_memblock : NULL);
|
||||||
struct gmio_rwargs* core_args = &args->core;
|
struct gmio_memblock* mblock = &mblock_helper.memblock;
|
||||||
struct gmio_stl_mesh_creator* mesh_creator = &args->mesh_creator;
|
void* mblock_ptr = mblock->ptr;
|
||||||
void* mblock_ptr = core_args->stream_memblock.ptr;
|
const struct gmio_task_iface* task = opts != NULL ? &opts->task_iface : NULL;
|
||||||
struct gmio_stlb_header header;
|
struct gmio_stlb_header header;
|
||||||
uint32_t i_facet = 0; /* Facet counter */
|
uint32_t i_facet = 0; /* Facet counter */
|
||||||
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
|
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
|
||||||
@ -107,15 +110,16 @@ int gmio_stlb_read(
|
|||||||
gmio_stlb_decode_facets_byteswap :
|
gmio_stlb_decode_facets_byteswap :
|
||||||
gmio_stlb_decode_facets;
|
gmio_stlb_decode_facets;
|
||||||
const uint32_t max_facet_count_per_read =
|
const uint32_t max_facet_count_per_read =
|
||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(mblock->size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
args->core.stream_memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
|
||||||
|
|
||||||
/* Check validity of input parameters */
|
/* Check validity of input parameters */
|
||||||
if (!gmio_stlb_check_params(&error, core_args, byte_order))
|
if (!gmio_check_memblock_size(&error, mblock, GMIO_STLB_MIN_CONTENTS_SIZE))
|
||||||
|
goto label_end;
|
||||||
|
if (!gmio_stlb_check_byteorder(&error, byte_order))
|
||||||
goto label_end;
|
goto label_end;
|
||||||
|
|
||||||
/* Read header */
|
/* Read header */
|
||||||
if (gmio_stream_read(&core_args->stream, &header, GMIO_STLB_HEADER_SIZE, 1)
|
if (gmio_stream_read(&stream, &header, GMIO_STLB_HEADER_SIZE, 1)
|
||||||
!= 1)
|
!= 1)
|
||||||
{
|
{
|
||||||
error = GMIO_STL_ERROR_HEADER_WRONG_SIZE;
|
error = GMIO_STL_ERROR_HEADER_WRONG_SIZE;
|
||||||
@ -123,7 +127,7 @@ int gmio_stlb_read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read facet count */
|
/* Read facet count */
|
||||||
if (gmio_stream_read(&core_args->stream, mblock_ptr, sizeof(uint32_t), 1)
|
if (gmio_stream_read(&stream, mblock_ptr, sizeof(uint32_t), 1)
|
||||||
!= 1)
|
!= 1)
|
||||||
{
|
{
|
||||||
error = GMIO_STL_ERROR_FACET_COUNT;
|
error = GMIO_STL_ERROR_FACET_COUNT;
|
||||||
@ -136,20 +140,20 @@ int gmio_stlb_read(
|
|||||||
|
|
||||||
/* Callback to notify triangle count and header data */
|
/* Callback to notify triangle count and header data */
|
||||||
gmio_stl_mesh_creator_binary_begin_solid(
|
gmio_stl_mesh_creator_binary_begin_solid(
|
||||||
mesh_creator, total_facet_count, &header);
|
&mesh_creator, total_facet_count, &header);
|
||||||
|
|
||||||
/* Read triangles */
|
/* Read triangles */
|
||||||
gmio_rwargs_handle_progress(core_args, 0, total_facet_count);
|
gmio_task_iface_handle_progress(task, 0, total_facet_count);
|
||||||
while (gmio_no_error(error) && i_facet < total_facet_count) {
|
while (gmio_no_error(error) && i_facet < total_facet_count) {
|
||||||
const uint32_t read_facet_count =
|
const uint32_t read_facet_count =
|
||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(
|
||||||
gmio_stream_read(
|
gmio_stream_read(
|
||||||
&core_args->stream,
|
&stream,
|
||||||
mblock_ptr,
|
mblock_ptr,
|
||||||
GMIO_STLB_TRIANGLE_RAWSIZE,
|
GMIO_STLB_TRIANGLE_RAWSIZE,
|
||||||
max_facet_count_per_read));
|
max_facet_count_per_read));
|
||||||
|
|
||||||
if (gmio_stream_error(&core_args->stream) != 0)
|
if (gmio_stream_error(&stream) != 0)
|
||||||
error = GMIO_ERROR_STREAM;
|
error = GMIO_ERROR_STREAM;
|
||||||
else if (read_facet_count > 0)
|
else if (read_facet_count > 0)
|
||||||
error = GMIO_ERROR_OK;
|
error = GMIO_ERROR_OK;
|
||||||
@ -158,16 +162,16 @@ int gmio_stlb_read(
|
|||||||
|
|
||||||
if (gmio_no_error(error)) {
|
if (gmio_no_error(error)) {
|
||||||
func_decode_facets(
|
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;
|
i_facet += read_facet_count;
|
||||||
if (gmio_rwargs_is_stop_requested(core_args))
|
if (gmio_task_iface_is_stop_requested(task))
|
||||||
error = GMIO_ERROR_TRANSFER_STOPPED;
|
error = GMIO_ERROR_TRANSFER_STOPPED;
|
||||||
}
|
}
|
||||||
gmio_rwargs_handle_progress(core_args, i_facet, total_facet_count);
|
gmio_task_iface_handle_progress(task, i_facet, total_facet_count);
|
||||||
} /* end while */
|
} /* end while */
|
||||||
|
|
||||||
if (gmio_no_error(error))
|
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)
|
if (gmio_no_error(error) && i_facet != total_facet_count)
|
||||||
error = GMIO_STL_ERROR_FACET_COUNT;
|
error = GMIO_STL_ERROR_FACET_COUNT;
|
||||||
|
@ -49,11 +49,11 @@ static void gmio_stl_data__ascii_begin_solid(
|
|||||||
{
|
{
|
||||||
struct gmio_stl_data* data = (struct gmio_stl_data*)cookie;
|
struct gmio_stl_data* data = (struct gmio_stl_data*)cookie;
|
||||||
|
|
||||||
memset(&data->solid_name[0], 0, sizeof(data->solid_name));
|
memset(data->solid_name, 0, sizeof(data->solid_name));
|
||||||
if (solid_name != NULL) {
|
if (solid_name != NULL) {
|
||||||
const size_t len =
|
const size_t len =
|
||||||
GMIO_MIN(sizeof(data->solid_name), strlen(solid_name));
|
GMIO_MIN(sizeof(data->solid_name), strlen(solid_name));
|
||||||
strncpy(&data->solid_name[0], solid_name, len);
|
strncpy(data->solid_name, solid_name, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to guess how many vertices we could have assume we'll need 200 bytes
|
/* Try to guess how many vertices we could have assume we'll need 200 bytes
|
||||||
@ -86,7 +86,7 @@ static void gmio_stl_data__add_triangle(
|
|||||||
data->tri_array.capacity = cap;
|
data->tri_array.capacity = cap;
|
||||||
}
|
}
|
||||||
memcpy(&data->tri_array.ptr[tri_id], triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
memcpy(&data->tri_array.ptr[tri_id], triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
data->tri_array.count = GMIO_MAX(data->tri_array.count, tri_id + 1);
|
data->tri_array.count = tri_id + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gmio_stl_data__get_triangle(
|
static void gmio_stl_data__get_triangle(
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "utest_assert.h"
|
#include "utest_assert.h"
|
||||||
|
|
||||||
#include "../src/gmio_core/global.h"
|
#include "../src/gmio_core/global.h"
|
||||||
#include "../src/gmio_core/rwargs.h"
|
#include "../src/gmio_core/stream.h"
|
||||||
#include "../src/gmio_stl/stl_constants.h"
|
#include "../src/gmio_stl/stl_constants.h"
|
||||||
#include "../src/gmio_stl/stl_triangle.h"
|
#include "../src/gmio_stl/stl_triangle.h"
|
||||||
|
|
||||||
@ -76,21 +76,16 @@ const char* test_platform__compiler()
|
|||||||
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
|
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
const struct gmio_rwargs args_null_bracket0 = {0};
|
const struct gmio_stream null_bracket0 = {0};
|
||||||
struct gmio_rwargs args_null_memset0;
|
struct gmio_stream null_memset0;
|
||||||
|
|
||||||
memset(&args_null_memset0, 0, sizeof(struct gmio_rwargs));
|
memset(&null_memset0, 0, sizeof(struct gmio_stream));
|
||||||
|
|
||||||
UTEST_ASSERT(memcmp(
|
UTEST_ASSERT(memcmp(
|
||||||
&args_null_bracket0,
|
&null_bracket0,
|
||||||
&args_null_memset0,
|
&null_memset0,
|
||||||
sizeof(struct gmio_rwargs))
|
sizeof(struct gmio_stream))
|
||||||
== 0);
|
== 0);
|
||||||
|
|
||||||
UTEST_ASSERT(sizeof(struct gmio_rwargs)
|
|
||||||
>= (sizeof(struct gmio_stream)
|
|
||||||
+ sizeof(struct gmio_memblock)
|
|
||||||
+ sizeof(struct gmio_task_iface)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check sizeof() operator with fixed-size arrays */
|
/* Check sizeof() operator with fixed-size arrays */
|
||||||
|
@ -51,27 +51,27 @@ const char* generic_test_stl_infos(const struct gmio_test_stl_infos* test)
|
|||||||
{
|
{
|
||||||
FILE* file = fopen(test->filepath, "rb");
|
FILE* file = fopen(test->filepath, "rb");
|
||||||
gmio_streamsize_t expected_size = test->expected_size;
|
gmio_streamsize_t expected_size = test->expected_size;
|
||||||
struct gmio_stl_infos_get_args args = {0};
|
struct gmio_stl_infos infos = {0};
|
||||||
|
struct gmio_stream stream = gmio_stream_stdio(file);
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
args.stream = gmio_stream_stdio(file);
|
printf("\n%s\n", test->filepath);
|
||||||
|
|
||||||
error = gmio_stl_infos_get(
|
error = gmio_stl_infos_get(&infos, stream, GMIO_STL_INFO_FLAG_ALL, NULL);
|
||||||
&args, test->format, GMIO_STL_INFO_FLAG_ALL);
|
|
||||||
if (test->format != GMIO_STL_FORMAT_UNKNOWN) {
|
if (test->format != GMIO_STL_FORMAT_UNKNOWN) {
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
UTEST_ASSERT(error == GMIO_STL_ERROR_UNKNOWN_FORMAT);
|
UTEST_COMPARE_INT(GMIO_STL_ERROR_UNKNOWN_FORMAT, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test->expected_size == -1)
|
if (test->expected_size == -1)
|
||||||
expected_size = gmio_stream_size(&args.stream);
|
expected_size = gmio_stream_size(&stream);
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
if (test->expected_size != -2)
|
if (test->expected_size != -2)
|
||||||
UTEST_COMPARE_UINT(expected_size, args.infos.size);
|
UTEST_COMPARE_UINT(expected_size, infos.size);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "stl_utils.h"
|
#include "stl_utils.h"
|
||||||
|
|
||||||
#include "../src/gmio_core/error.h"
|
#include "../src/gmio_core/error.h"
|
||||||
#include "../src/gmio_core/rwargs.h"
|
|
||||||
#include "../src/gmio_stl/internal/stl_rw_common.h"
|
#include "../src/gmio_stl/internal/stl_rw_common.h"
|
||||||
#include "../src/gmio_stl/stl_error.h"
|
#include "../src/gmio_stl/stl_error.h"
|
||||||
#include "../src/gmio_stl/stl_io.h"
|
#include "../src/gmio_stl/stl_io.h"
|
||||||
@ -27,33 +26,45 @@
|
|||||||
|
|
||||||
const char* test_stl_internal__rw_common()
|
const char* test_stl_internal__rw_common()
|
||||||
{
|
{
|
||||||
/* gmio_check_transfer() */
|
/* gmio_check_memblock() */
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
uint8_t buff[128] = {0};
|
uint8_t buff[128] = {0};
|
||||||
struct gmio_rwargs rwargs = {0};
|
struct gmio_memblock mblock = {0};
|
||||||
|
|
||||||
UTEST_ASSERT(!gmio_check_rwargs(&error, NULL));
|
UTEST_ASSERT(!gmio_check_memblock(&error, NULL));
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_NULL_RWARGS);
|
|
||||||
|
|
||||||
UTEST_ASSERT(!gmio_check_rwargs(&error, &rwargs));
|
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_NULL_MEMBLOCK);
|
UTEST_ASSERT(error == GMIO_ERROR_NULL_MEMBLOCK);
|
||||||
|
|
||||||
rwargs.stream_memblock = gmio_memblock(&buff[0], 0, NULL);
|
UTEST_ASSERT(!gmio_check_memblock(&error, &mblock));
|
||||||
UTEST_ASSERT(!gmio_check_rwargs(&error, &rwargs));
|
UTEST_ASSERT(error == GMIO_ERROR_NULL_MEMBLOCK);
|
||||||
|
|
||||||
|
mblock = gmio_memblock(buff, 0, NULL);
|
||||||
|
UTEST_ASSERT(!gmio_check_memblock(&error, &mblock));
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
|
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
|
||||||
|
|
||||||
/* Verify that gmio_check_transfer() doesn't touch error when in case of
|
/* Verify that gmio_check_memblock() doesn't touch error when in case of
|
||||||
* success */
|
* success */
|
||||||
rwargs.stream_memblock = gmio_memblock(&buff[0], sizeof(buff), NULL);
|
mblock = gmio_memblock(buff, sizeof(buff), NULL);
|
||||||
UTEST_ASSERT(!gmio_check_rwargs(&error, &rwargs));
|
UTEST_ASSERT(!gmio_check_memblock(&error, &mblock));
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
|
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
|
||||||
|
|
||||||
error = GMIO_ERROR_OK;
|
error = GMIO_ERROR_OK;
|
||||||
UTEST_ASSERT(gmio_check_rwargs(&error, &rwargs));
|
UTEST_ASSERT(gmio_check_memblock(&error, &mblock));
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* gmio_check_memblock_size() */
|
||||||
|
{
|
||||||
|
uint8_t buff[1024] = {0};
|
||||||
|
struct gmio_memblock mblock =
|
||||||
|
gmio_memblock(buff, GMIO_STLB_MIN_CONTENTS_SIZE / 2, NULL);
|
||||||
|
int error = GMIO_ERROR_OK;
|
||||||
|
|
||||||
|
UTEST_ASSERT(!gmio_check_memblock_size(
|
||||||
|
&error, &mblock, GMIO_STLB_MIN_CONTENTS_SIZE));
|
||||||
|
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
/* gmio_stl_check_mesh() */
|
/* gmio_stl_check_mesh() */
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
@ -78,28 +89,14 @@ const char* test_stl_internal__rw_common()
|
|||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* gmio_stlb_check_params() */
|
/* gmio_stlb_check_byteorder() */
|
||||||
{
|
{
|
||||||
int error = GMIO_ERROR_OK;
|
int error = GMIO_ERROR_OK;
|
||||||
struct gmio_rwargs rwargs = {0};
|
|
||||||
uint8_t buff[1024] = {0};
|
|
||||||
|
|
||||||
UTEST_ASSERT(!gmio_stlb_check_params(&error, NULL, GMIO_ENDIANNESS_HOST));
|
UTEST_ASSERT(gmio_stlb_check_byteorder(&error, GMIO_ENDIANNESS_HOST));
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_NULL_RWARGS);
|
|
||||||
|
|
||||||
error = GMIO_ERROR_OK;
|
|
||||||
rwargs.stream_memblock =
|
|
||||||
gmio_memblock(&buff[0], GMIO_STLB_MIN_CONTENTS_SIZE / 2, NULL);
|
|
||||||
UTEST_ASSERT(!gmio_stlb_check_params(&error, &rwargs, GMIO_ENDIANNESS_HOST));
|
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
|
|
||||||
|
|
||||||
error = GMIO_ERROR_OK;
|
|
||||||
rwargs.stream_memblock =
|
|
||||||
gmio_memblock(&buff[0], sizeof(buff), NULL);
|
|
||||||
UTEST_ASSERT(gmio_stlb_check_params(&error, &rwargs, GMIO_ENDIANNESS_HOST));
|
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
||||||
|
|
||||||
UTEST_ASSERT(!gmio_stlb_check_params(&error, &rwargs, GMIO_ENDIANNESS_UNKNOWN));
|
UTEST_ASSERT(!gmio_stlb_check_byteorder(&error, GMIO_ENDIANNESS_UNKNOWN));
|
||||||
UTEST_ASSERT(error == GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER);
|
UTEST_ASSERT(error == GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ void stl_testcase_result__ascii_begin_solid(
|
|||||||
if (res != NULL) {
|
if (res != NULL) {
|
||||||
res->solid_name[0] = 0;
|
res->solid_name[0] = 0;
|
||||||
if (solid_name != NULL)
|
if (solid_name != NULL)
|
||||||
strcpy(&res->solid_name[0], solid_name);
|
strcpy(res->solid_name, solid_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,18 +127,18 @@ const char* test_stl_read()
|
|||||||
const size_t expected_count =
|
const size_t expected_count =
|
||||||
sizeof(expected) / sizeof(struct stl_testcase);
|
sizeof(expected) / sizeof(struct stl_testcase);
|
||||||
size_t i; /* for loop counter */
|
size_t i; /* for loop counter */
|
||||||
struct gmio_stl_read_args read = {0};
|
struct gmio_stl_mesh_creator mesh_creator = {0};
|
||||||
struct stl_testcase_result result = {0};
|
struct stl_testcase_result result = {0};
|
||||||
|
|
||||||
read.mesh_creator.cookie = &result;
|
mesh_creator.cookie = &result;
|
||||||
read.mesh_creator.func_ascii_begin_solid = &stl_testcase_result__ascii_begin_solid;
|
mesh_creator.func_ascii_begin_solid = &stl_testcase_result__ascii_begin_solid;
|
||||||
read.mesh_creator.func_add_triangle = &gmio_stl_nop_add_triangle;
|
mesh_creator.func_add_triangle = &gmio_stl_nop_add_triangle;
|
||||||
|
|
||||||
for (i = 0; i < expected_count; ++i) {
|
for (i = 0; i < expected_count; ++i) {
|
||||||
const enum gmio_stl_format format =
|
const enum gmio_stl_format format =
|
||||||
gmio_stl_get_format_file(expected[i].filepath);
|
gmio_stl_get_format_file(expected[i].filepath);
|
||||||
const int err =
|
const int err =
|
||||||
gmio_stl_read_file(&read, expected[i].filepath);
|
gmio_stl_read_file(expected[i].filepath, mesh_creator, NULL);
|
||||||
|
|
||||||
/* Check format */
|
/* Check format */
|
||||||
if (format != expected[i].format) {
|
if (format != expected[i].format) {
|
||||||
@ -149,7 +149,7 @@ const char* test_stl_read()
|
|||||||
expected[i].format,
|
expected[i].format,
|
||||||
format);
|
format);
|
||||||
}
|
}
|
||||||
UTEST_ASSERT(format == expected[i].format);
|
UTEST_COMPARE_UINT(expected[i].format, format);
|
||||||
|
|
||||||
/* Check error code */
|
/* Check error code */
|
||||||
if (err != expected[i].errorcode) {
|
if (err != expected[i].errorcode) {
|
||||||
@ -160,7 +160,7 @@ const char* test_stl_read()
|
|||||||
expected[i].errorcode,
|
expected[i].errorcode,
|
||||||
err);
|
err);
|
||||||
}
|
}
|
||||||
UTEST_ASSERT(err == expected[i].errorcode);
|
UTEST_COMPARE_UINT(expected[i].errorcode, err);
|
||||||
|
|
||||||
/* Check solid name */
|
/* Check solid name */
|
||||||
if (expected[i].format == GMIO_STL_FORMAT_ASCII) {
|
if (expected[i].format == GMIO_STL_FORMAT_ASCII) {
|
||||||
@ -174,7 +174,7 @@ const char* test_stl_read()
|
|||||||
expected_name,
|
expected_name,
|
||||||
result.solid_name);
|
result.solid_name);
|
||||||
}
|
}
|
||||||
UTEST_ASSERT(strcmp(result.solid_name, expected_name) == 0);
|
UTEST_COMPARE_CSTR(expected_name, result.solid_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,17 +197,16 @@ const char* test_stlb_write_header()
|
|||||||
error = gmio_stlb_write_header(
|
error = gmio_stlb_write_header(
|
||||||
&stream, GMIO_ENDIANNESS_LITTLE, &header, 0);
|
&stream, GMIO_ENDIANNESS_LITTLE, &header, 0);
|
||||||
fclose(outfile);
|
fclose(outfile);
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
struct gmio_stl_read_args read = {0};
|
|
||||||
struct gmio_stl_data data = {0};
|
struct gmio_stl_data data = {0};
|
||||||
read.mesh_creator = gmio_stl_data_mesh_creator(&data);
|
error = gmio_stl_read_file(
|
||||||
error = gmio_stl_read_file(&read, filepath);
|
filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header));
|
UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header));
|
||||||
UTEST_ASSERT(data.tri_array.count == 0);
|
UTEST_COMPARE_UINT(0, data.tri_array.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -232,26 +231,30 @@ const char* test_stlb_write()
|
|||||||
|
|
||||||
/* Read input model file */
|
/* Read input model file */
|
||||||
{
|
{
|
||||||
struct gmio_stl_read_args read = {0};
|
error = gmio_stl_read_file(
|
||||||
read.mesh_creator = gmio_stl_data_mesh_creator(&data);
|
model_filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
||||||
error = gmio_stl_read_file(&read, model_filepath);
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write back input model file
|
/* Write back input model file
|
||||||
* Write also the model file in big-endian STL format
|
* Write also the model file in big-endian STL format
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
struct gmio_stl_write_args write = {0};
|
struct gmio_stl_write_options opts = {0};
|
||||||
write.mesh = gmio_stl_data_mesh(&data);
|
opts.stlb_header = data.header;
|
||||||
write.options.stlb_header = &data.header;
|
|
||||||
error = gmio_stl_write_file(
|
error = gmio_stl_write_file(
|
||||||
&write, GMIO_STL_FORMAT_BINARY_LE, model_filepath_out);
|
GMIO_STL_FORMAT_BINARY_LE,
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
model_filepath_out,
|
||||||
|
gmio_stl_data_mesh(&data),
|
||||||
|
&opts);
|
||||||
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
|
|
||||||
/* Big-endian version */
|
/* Big-endian version */
|
||||||
error = gmio_stl_write_file(
|
error = gmio_stl_write_file(
|
||||||
&write, GMIO_STL_FORMAT_BINARY_BE, model_filepath_out_be);
|
GMIO_STL_FORMAT_BINARY_BE,
|
||||||
|
model_filepath_out_be,
|
||||||
|
gmio_stl_data_mesh(&data),
|
||||||
|
&opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check input and output models are equal */
|
/* Check input and output models are equal */
|
||||||
@ -269,13 +272,13 @@ const char* test_stlb_write()
|
|||||||
UTEST_FAIL("fopen() error for in/out model files");
|
UTEST_FAIL("fopen() error for in/out model files");
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
bytes_read_in = fread(&buffer_in[0], 1, buff_size, in);
|
bytes_read_in = fread(buffer_in, 1, buff_size, in);
|
||||||
bytes_read_out = fread(&buffer_out[0], 1, buff_size, out);
|
bytes_read_out = fread(buffer_out, 1, buff_size, out);
|
||||||
if (bytes_read_in != bytes_read_out) {
|
if (bytes_read_in != bytes_read_out) {
|
||||||
fclose_2(in, out);
|
fclose_2(in, out);
|
||||||
UTEST_FAIL("Different byte count between in/out");
|
UTEST_FAIL("Different byte count between in/out");
|
||||||
}
|
}
|
||||||
if (memcmp(&buffer_in[0], &buffer_out[0], buff_size) != 0) {
|
if (memcmp(buffer_in, buffer_out, buff_size) != 0) {
|
||||||
fclose_2(in, out);
|
fclose_2(in, out);
|
||||||
UTEST_FAIL("Different buffer contents between in/out");
|
UTEST_FAIL("Different buffer contents between in/out");
|
||||||
}
|
}
|
||||||
@ -287,12 +290,13 @@ const char* test_stlb_write()
|
|||||||
/* Check output LE/BE models are equal */
|
/* Check output LE/BE models are equal */
|
||||||
{
|
{
|
||||||
struct gmio_stl_data data_be = {0};
|
struct gmio_stl_data data_be = {0};
|
||||||
struct gmio_stl_read_args read = {0};
|
error = gmio_stl_read_file(
|
||||||
read.mesh_creator = gmio_stl_data_mesh_creator(&data_be);
|
model_filepath_out_be,
|
||||||
error = gmio_stl_read_file(&read, model_filepath_out_be);
|
gmio_stl_data_mesh_creator(&data_be),
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
NULL);
|
||||||
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header));
|
UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header));
|
||||||
UTEST_ASSERT(data.tri_array.count == data_be.tri_array.count);
|
UTEST_COMPARE_UINT(data.tri_array.count, data_be.tri_array.count);
|
||||||
UTEST_ASSERT(memcmp(data.tri_array.ptr,
|
UTEST_ASSERT(memcmp(data.tri_array.ptr,
|
||||||
data_be.tri_array.ptr,
|
data_be.tri_array.ptr,
|
||||||
data.tri_array.count * sizeof(struct gmio_stl_triangle))
|
data.tri_array.count * sizeof(struct gmio_stl_triangle))
|
||||||
@ -315,39 +319,40 @@ const char* test_stla_write()
|
|||||||
|
|
||||||
/* Read input model file */
|
/* Read input model file */
|
||||||
{
|
{
|
||||||
struct gmio_stl_read_args read = {0};
|
error = gmio_stl_read_file(
|
||||||
read.mesh_creator = gmio_stl_data_mesh_creator(&data);
|
model_filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
||||||
error = gmio_stl_read_file(&read, model_filepath);
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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_options opts = {0};
|
||||||
write.mesh = gmio_stl_data_mesh(&data);
|
gmio_stlb_header_to_printable_str(&data.header, header_str, '_');
|
||||||
gmio_stlb_header_to_printable_str(&data.header, &header_str[0], '_');
|
opts.stla_solid_name = header_str;
|
||||||
write.options.stla_solid_name = &header_str[0];
|
opts.stla_float32_prec = 7;
|
||||||
write.options.stla_float32_prec = 7;
|
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
|
||||||
write.options.stla_float32_format =
|
|
||||||
GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
|
|
||||||
error = gmio_stl_write_file(
|
error = gmio_stl_write_file(
|
||||||
&write, GMIO_STL_FORMAT_ASCII, model_filepath_out);
|
GMIO_STL_FORMAT_ASCII,
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
model_filepath_out,
|
||||||
|
gmio_stl_data_mesh(&data),
|
||||||
|
&opts);
|
||||||
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the output STL ascii model */
|
/* Read the output STL ascii model */
|
||||||
{
|
{
|
||||||
char trim_header_str[sizeof(header_str)] = {0};
|
char trim_header_str[sizeof(header_str)] = {0};
|
||||||
struct gmio_stl_data data_stla = {0};
|
struct gmio_stl_data data_stla = {0};
|
||||||
struct gmio_stl_read_args read = {0};
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
read.mesh_creator = gmio_stl_data_mesh_creator(&data_stla);
|
strncpy(trim_header_str, header_str, sizeof(header_str));
|
||||||
strncpy(&trim_header_str[0], &header_str[0], sizeof(header_str));
|
|
||||||
gmio_string_trim_from_end(trim_header_str, sizeof(header_str));
|
gmio_string_trim_from_end(trim_header_str, sizeof(header_str));
|
||||||
error = gmio_stl_read_file(&read, model_filepath_out);
|
error = gmio_stl_read_file(
|
||||||
UTEST_ASSERT(error == GMIO_ERROR_OK);
|
model_filepath_out,
|
||||||
UTEST_ASSERT(data.tri_array.count == data_stla.tri_array.count);
|
gmio_stl_data_mesh_creator(&data_stla),
|
||||||
UTEST_ASSERT(strcmp(&trim_header_str[0], &data_stla.solid_name[0]) == 0);
|
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);
|
||||||
for (i = 0; i < data.tri_array.count; ++i) {
|
for (i = 0; i < data.tri_array.count; ++i) {
|
||||||
const struct gmio_stl_triangle* lhs = &data.tri_array.ptr[i];
|
const struct gmio_stl_triangle* lhs = &data.tri_array.ptr[i];
|
||||||
const struct gmio_stl_triangle* rhs = &data_stla.tri_array.ptr[i];
|
const struct gmio_stl_triangle* rhs = &data_stla.tri_array.ptr[i];
|
||||||
@ -377,19 +382,19 @@ void generate_stlb_tests_models()
|
|||||||
0 /* attr */
|
0 /* attr */
|
||||||
};
|
};
|
||||||
struct gmio_stl_data data = {0};
|
struct gmio_stl_data data = {0};
|
||||||
struct gmio_stl_write_args write = {0};
|
|
||||||
|
|
||||||
data.tri_array.ptr = &tri;
|
data.tri_array.ptr = &tri;
|
||||||
data.tri_array.count = 1;
|
data.tri_array.count = 1;
|
||||||
write.mesh = gmio_stl_data_mesh(&data);
|
|
||||||
|
|
||||||
gmio_stl_write_file(
|
gmio_stl_write_file(
|
||||||
&write,
|
|
||||||
GMIO_STL_FORMAT_BINARY_LE,
|
GMIO_STL_FORMAT_BINARY_LE,
|
||||||
"models/solid_one_facet.le_stlb");
|
"models/solid_one_facet.le_stlb",
|
||||||
|
gmio_stl_data_mesh(&data),
|
||||||
|
NULL);
|
||||||
gmio_stl_write_file(
|
gmio_stl_write_file(
|
||||||
&write,
|
|
||||||
GMIO_STL_FORMAT_BINARY_BE,
|
GMIO_STL_FORMAT_BINARY_BE,
|
||||||
"models/solid_one_facet.be_stlb");
|
"models/solid_one_facet.be_stlb",
|
||||||
|
gmio_stl_data_mesh(&data),
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user