Improve indentation
This commit is contained in:
parent
e78c398026
commit
6b7ead1f24
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
/*! This enum defines common errors */
|
/*! This enum defines common errors */
|
||||||
enum gmio_error
|
enum gmio_error
|
||||||
{
|
{
|
||||||
|
@ -48,8 +48,11 @@ const char *gmio_next_char(gmio_string_stream_fwd_iterator_t *it)
|
|||||||
return it->buffer.ptr + it->buffer_pos;
|
return it->buffer.ptr + it->buffer_pos;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (gmio_stream_error(it->stream) != 0 || gmio_stream_at_end(it->stream))
|
if (gmio_stream_error(it->stream) != 0
|
||||||
|
|| gmio_stream_at_end(it->stream))
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Read next chunk of data */
|
/* Read next chunk of data */
|
||||||
it->buffer_pos = 0;
|
it->buffer_pos = 0;
|
||||||
@ -73,7 +76,8 @@ void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t *it)
|
|||||||
curr_char = gmio_next_char(it);
|
curr_char = gmio_next_char(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_eat_word(gmio_string_stream_fwd_iterator_t *it, gmio_string_buffer_t *buffer)
|
int gmio_eat_word(
|
||||||
|
gmio_string_stream_fwd_iterator_t *it, gmio_string_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
const char* stream_curr_char = NULL;
|
const char* stream_curr_char = NULL;
|
||||||
int isspace_res = 0;
|
int isspace_res = 0;
|
||||||
@ -86,7 +90,10 @@ int gmio_eat_word(gmio_string_stream_fwd_iterator_t *it, gmio_string_buffer_t *b
|
|||||||
gmio_skip_spaces(it);
|
gmio_skip_spaces(it);
|
||||||
stream_curr_char = gmio_current_char(it);
|
stream_curr_char = gmio_current_char(it);
|
||||||
|
|
||||||
while (i < buffer->max_len && stream_curr_char != NULL && isspace_res == 0) {
|
while (i < buffer->max_len
|
||||||
|
&& stream_curr_char != NULL
|
||||||
|
&& isspace_res == 0)
|
||||||
|
{
|
||||||
isspace_res = isspace(*stream_curr_char);
|
isspace_res = isspace(*stream_curr_char);
|
||||||
if (isspace_res == 0) {
|
if (isspace_res == 0) {
|
||||||
buffer->ptr[i] = *stream_curr_char;
|
buffer->ptr[i] = *stream_curr_char;
|
||||||
@ -121,7 +128,8 @@ int gmio_get_float32(const char *str, gmio_float32_t *value_ptr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gmio_bool_t gmio_checked_next_chars(gmio_string_stream_fwd_iterator_t *it, const char *str)
|
gmio_bool_t gmio_checked_next_chars(
|
||||||
|
gmio_string_stream_fwd_iterator_t *it, const char *str)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
const char* curr_char = gmio_current_char(it);
|
const char* curr_char = gmio_current_char(it);
|
||||||
|
@ -46,15 +46,24 @@ struct gmio_string_stream_fwd_iterator
|
|||||||
size_t buffer_pos; /*!< Position indicator in buffer */
|
size_t buffer_pos; /*!< Position indicator in buffer */
|
||||||
|
|
||||||
void* cookie;
|
void* cookie;
|
||||||
void (*stream_read_hook)(void* cookie, const gmio_string_buffer_t* str_buffer);
|
void (*stream_read_hook)(void* cookie,
|
||||||
|
const gmio_string_buffer_t* str_buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct gmio_string_stream_fwd_iterator gmio_string_stream_fwd_iterator_t;
|
typedef struct gmio_string_stream_fwd_iterator
|
||||||
|
gmio_string_stream_fwd_iterator_t;
|
||||||
|
|
||||||
void gmio_string_stream_fwd_iterator_init(gmio_string_stream_fwd_iterator_t* it);
|
void gmio_string_stream_fwd_iterator_init(
|
||||||
const char* gmio_current_char(const gmio_string_stream_fwd_iterator_t* it);
|
gmio_string_stream_fwd_iterator_t* it);
|
||||||
void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t* it);
|
|
||||||
int gmio_eat_word(gmio_string_stream_fwd_iterator_t* it, gmio_string_buffer_t* buffer);
|
const char* gmio_current_char(
|
||||||
|
const gmio_string_stream_fwd_iterator_t* it);
|
||||||
|
|
||||||
|
void gmio_skip_spaces(
|
||||||
|
gmio_string_stream_fwd_iterator_t* it);
|
||||||
|
|
||||||
|
int gmio_eat_word(
|
||||||
|
gmio_string_stream_fwd_iterator_t* it, gmio_string_buffer_t* buffer);
|
||||||
|
|
||||||
/*! Move on next char in stream */
|
/*! Move on next char in stream */
|
||||||
const char* gmio_next_char(gmio_string_stream_fwd_iterator_t* it);
|
const char* gmio_next_char(gmio_string_stream_fwd_iterator_t* it);
|
||||||
@ -63,7 +72,8 @@ const char* gmio_next_char(gmio_string_stream_fwd_iterator_t* it);
|
|||||||
*
|
*
|
||||||
* Returns GMIO_TRUE if \p str was fully matched
|
* Returns GMIO_TRUE if \p str was fully matched
|
||||||
*/
|
*/
|
||||||
gmio_bool_t gmio_checked_next_chars(gmio_string_stream_fwd_iterator_t* it, const char* str);
|
gmio_bool_t gmio_checked_next_chars(
|
||||||
|
gmio_string_stream_fwd_iterator_t* it, const char* str);
|
||||||
|
|
||||||
/*! Converts the string pointed to by \p str to gmio_float32_t representation
|
/*! Converts the string pointed to by \p str to gmio_float32_t representation
|
||||||
*
|
*
|
||||||
|
@ -44,16 +44,23 @@ gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream, size_t data_size)
|
|||||||
/* Binary STL ? */
|
/* Binary STL ? */
|
||||||
if (read_size >= (GMIO_STLB_HEADER_SIZE + 4)) {
|
if (read_size >= (GMIO_STLB_HEADER_SIZE + 4)) {
|
||||||
/* Try with little-endian format */
|
/* Try with little-endian format */
|
||||||
uint32_t facet_count = gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80);
|
uint32_t facet_count =
|
||||||
|
gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80);
|
||||||
|
|
||||||
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) == data_size)
|
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||||
|
== data_size)
|
||||||
|
{
|
||||||
return GMIO_STL_BINARY_LE_FORMAT;
|
return GMIO_STL_BINARY_LE_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try with byte-reverted facet count */
|
/* Try with byte-reverted facet count */
|
||||||
facet_count = gmio_uint32_bswap(facet_count);
|
facet_count = gmio_uint32_bswap(facet_count);
|
||||||
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) == data_size)
|
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||||
|
== data_size)
|
||||||
|
{
|
||||||
return GMIO_STL_BINARY_BE_FORMAT;
|
return GMIO_STL_BINARY_BE_FORMAT;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ASCII STL ? */
|
/* ASCII STL ? */
|
||||||
{
|
{
|
||||||
|
@ -35,9 +35,8 @@ struct gmio_stl_mesh
|
|||||||
|
|
||||||
/*! Pointer on a function that stores the mesh triangle of index \p tri_id
|
/*! Pointer on a function that stores the mesh triangle of index \p tri_id
|
||||||
* into \p triangle */
|
* into \p triangle */
|
||||||
void (*get_triangle_func)(const void* cookie,
|
void (*get_triangle_func)(
|
||||||
uint32_t tri_id,
|
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle);
|
||||||
gmio_stl_triangle_t* triangle);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct gmio_stl_mesh gmio_stl_mesh_t;
|
typedef struct gmio_stl_mesh gmio_stl_mesh_t;
|
||||||
|
@ -47,9 +47,8 @@ struct gmio_stl_mesh_creator
|
|||||||
*
|
*
|
||||||
* The argument \p header contains the header data(80 bytes)
|
* The argument \p header contains the header data(80 bytes)
|
||||||
*/
|
*/
|
||||||
void (*binary_begin_solid_func)(void* cookie,
|
void (*binary_begin_solid_func)(
|
||||||
uint32_t tri_count,
|
void* cookie, uint32_t tri_count, const uint8_t* header);
|
||||||
const uint8_t* header);
|
|
||||||
|
|
||||||
/*! Pointer on a function that adds a triangle to the user mesh
|
/*! Pointer on a function that adds a triangle to the user mesh
|
||||||
*
|
*
|
||||||
@ -58,9 +57,8 @@ struct gmio_stl_mesh_creator
|
|||||||
*
|
*
|
||||||
* The argument \p tri_id is the index of the mesh triangle
|
* The argument \p tri_id is the index of the mesh triangle
|
||||||
*/
|
*/
|
||||||
void (*add_triangle_func)(void* cookie,
|
void (*add_triangle_func)(
|
||||||
uint32_t tri_id,
|
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle);
|
||||||
const gmio_stl_triangle_t* triangle);
|
|
||||||
|
|
||||||
/*! Pointer on a function that finalizes creation of the user mesh
|
/*! Pointer on a function that finalizes creation of the user mesh
|
||||||
*
|
*
|
||||||
|
@ -118,8 +118,8 @@ typedef struct
|
|||||||
gmio_stl_mesh_creator_t* creator;
|
gmio_stl_mesh_creator_t* creator;
|
||||||
} gmio_stla_parse_data_t;
|
} gmio_stla_parse_data_t;
|
||||||
|
|
||||||
static void gmio_stream_fwd_iterator_stla_read_hook(void* cookie,
|
static void gmio_stream_fwd_iterator_stla_read_hook(
|
||||||
const gmio_string_buffer_t* buffer)
|
void* cookie, const gmio_string_buffer_t* buffer)
|
||||||
{
|
{
|
||||||
gmio_string_stream_fwd_iterator_cookie_t* tcookie =
|
gmio_string_stream_fwd_iterator_cookie_t* tcookie =
|
||||||
(gmio_string_stream_fwd_iterator_cookie_t*)(cookie);
|
(gmio_string_stream_fwd_iterator_cookie_t*)(cookie);
|
||||||
@ -132,20 +132,22 @@ static void gmio_stream_fwd_iterator_stla_read_hook(void* cookie,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static gmio_bool_t parsing_can_continue(const gmio_stla_parse_data_t* data)
|
GMIO_INLINE static gmio_bool_t parsing_can_continue(
|
||||||
|
const gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
if (!data->error && !data->stream_iterator_cookie.is_stop_requested)
|
if (!data->error && !data->stream_iterator_cookie.is_stop_requested)
|
||||||
return GMIO_TRUE;
|
return GMIO_TRUE;
|
||||||
return GMIO_FALSE;
|
return GMIO_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static const char* current_token_as_identifier(const gmio_stla_parse_data_t* data)
|
GMIO_INLINE static const char* current_token_as_identifier(
|
||||||
|
const gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
return data->token == ID_token ? data->string_buffer.ptr : "";
|
return data->token == ID_token ? data->string_buffer.ptr : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static int get_current_token_as_float32(const gmio_stla_parse_data_t* data,
|
GMIO_INLINE static int get_current_token_as_float32(
|
||||||
gmio_float32_t* value_ptr)
|
const gmio_stla_parse_data_t* data, gmio_float32_t* value_ptr)
|
||||||
{
|
{
|
||||||
if (data->token == FLOAT_token)
|
if (data->token == FLOAT_token)
|
||||||
return gmio_get_float32(data->string_buffer.ptr, value_ptr);
|
return gmio_get_float32(data->string_buffer.ptr, value_ptr);
|
||||||
@ -161,7 +163,8 @@ GMIO_INLINE static void parsing_error(gmio_stla_parse_data_t* data)
|
|||||||
data->string_buffer.ptr);
|
data->string_buffer.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gmio_stla_token_t parsing_find_token(const gmio_string_buffer_t* str_buffer)
|
static gmio_stla_token_t parsing_find_token(
|
||||||
|
const gmio_string_buffer_t* str_buffer)
|
||||||
{
|
{
|
||||||
const char* word = str_buffer->ptr;
|
const char* word = str_buffer->ptr;
|
||||||
const size_t word_len = str_buffer->len;
|
const size_t word_len = str_buffer->len;
|
||||||
@ -248,7 +251,8 @@ static void parsing_advance(gmio_stla_parse_data_t* data)
|
|||||||
parsing_error(data);
|
parsing_error(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parsing_eat_token(gmio_stla_token_t token, gmio_stla_parse_data_t* data)
|
static void parsing_eat_token(
|
||||||
|
gmio_stla_token_t token, gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
if (!parsing_can_continue(data))
|
if (!parsing_can_continue(data))
|
||||||
return;
|
return;
|
||||||
@ -339,7 +343,8 @@ static void parse_endsolid(gmio_stla_parse_data_t* data)
|
|||||||
} /* end switch */
|
} /* end switch */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
|
static void parse_xyz_coords(
|
||||||
|
gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
|
||||||
{
|
{
|
||||||
if (!parsing_can_continue(data))
|
if (!parsing_can_continue(data))
|
||||||
return;
|
return;
|
||||||
@ -362,7 +367,8 @@ static void parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* co
|
|||||||
} /* end switch */
|
} /* end switch */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_facet(gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet)
|
static void parse_facet(
|
||||||
|
gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet)
|
||||||
{
|
{
|
||||||
parsing_eat_token(FACET_token, data);
|
parsing_eat_token(FACET_token, data);
|
||||||
parsing_eat_token(NORMAL_token, data);
|
parsing_eat_token(NORMAL_token, data);
|
||||||
@ -391,8 +397,10 @@ static void parse_facets(gmio_stla_parse_data_t* data)
|
|||||||
|
|
||||||
while (data->token == FACET_token && parsing_can_continue(data)) {
|
while (data->token == FACET_token && parsing_can_continue(data)) {
|
||||||
parse_facet(data, &facet);
|
parse_facet(data, &facet);
|
||||||
if (is_add_triangle_available)
|
if (is_add_triangle_available) {
|
||||||
data->creator->add_triangle_func(data->creator->cookie, i_facet_offset, &facet);
|
data->creator->add_triangle_func(
|
||||||
|
data->creator->cookie, i_facet_offset, &facet);
|
||||||
|
}
|
||||||
++i_facet_offset;
|
++i_facet_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,7 +422,8 @@ static void parse_solid(gmio_stla_parse_data_t* data)
|
|||||||
|
|
||||||
enum { GMIO_STLA_READ_STRING_BUFFER_LEN = 512 };
|
enum { GMIO_STLA_READ_STRING_BUFFER_LEN = 512 };
|
||||||
|
|
||||||
int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
int gmio_stla_read(
|
||||||
|
gmio_stl_mesh_creator_t* creator,
|
||||||
gmio_transfer_t* trsf,
|
gmio_transfer_t* trsf,
|
||||||
const gmio_stla_read_options_t* options)
|
const gmio_stla_read_options_t* options)
|
||||||
{
|
{
|
||||||
@ -439,7 +448,8 @@ int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
|||||||
parse_data.stream_iterator.buffer.ptr = trsf->buffer;
|
parse_data.stream_iterator.buffer.ptr = trsf->buffer;
|
||||||
parse_data.stream_iterator.buffer.max_len = trsf->buffer_size;
|
parse_data.stream_iterator.buffer.max_len = trsf->buffer_size;
|
||||||
parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie;
|
parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie;
|
||||||
parse_data.stream_iterator.stream_read_hook = gmio_stream_fwd_iterator_stla_read_hook;
|
parse_data.stream_iterator.stream_read_hook =
|
||||||
|
gmio_stream_fwd_iterator_stla_read_hook;
|
||||||
gmio_string_stream_fwd_iterator_init(&parse_data.stream_iterator);
|
gmio_string_stream_fwd_iterator_init(&parse_data.stream_iterator);
|
||||||
|
|
||||||
parse_data.string_buffer.ptr = &fixed_buffer[0];
|
parse_data.string_buffer.ptr = &fixed_buffer[0];
|
||||||
|
@ -98,16 +98,13 @@ static char* gmio_write_stdio_format(char* buffer, uint8_t prec)
|
|||||||
return buffer + 3 + prec_len;
|
return buffer + 3 + prec_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static char* gmio_write_float32_string(char* buffer, const char* format, gmio_float32_t val)
|
static char* gmio_write_coords(
|
||||||
{
|
char* buffer,
|
||||||
return buffer + sprintf(buffer, format, val);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
static char* gmio_write_coords(char* buffer,
|
|
||||||
const char* coords_format,
|
const char* coords_format,
|
||||||
const gmio_stl_coords_t* coords)
|
const gmio_stl_coords_t* coords)
|
||||||
{
|
{
|
||||||
return buffer + sprintf(buffer, coords_format, coords->x, coords->y, coords->z);
|
return buffer + sprintf(buffer,
|
||||||
|
coords_format, coords->x, coords->y, coords->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n)
|
static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n)
|
||||||
@ -115,18 +112,22 @@ static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n)
|
|||||||
return gmio_stream_write(&trsf->stream, trsf->buffer, sizeof(char), n) == n;
|
return gmio_stream_write(&trsf->stream, trsf->buffer, sizeof(char), n) == n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
int gmio_stla_write(
|
||||||
|
const gmio_stl_mesh_t* mesh,
|
||||||
gmio_transfer_t* trsf,
|
gmio_transfer_t* trsf,
|
||||||
const gmio_stla_write_options_t* options)
|
const gmio_stla_write_options_t* options)
|
||||||
{
|
{
|
||||||
|
/* Constants */
|
||||||
const char* solid_name = options != NULL ? options->solid_name : NULL;
|
const char* solid_name = options != NULL ? options->solid_name : NULL;
|
||||||
const uint8_t float32_prec = options != NULL ? options->float32_prec : 9;
|
const uint8_t float32_prec = options != NULL ? options->float32_prec : 9;
|
||||||
const uint32_t total_facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
const uint32_t total_facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
||||||
const uint32_t buffer_facet_count =
|
const uint32_t buffer_facet_count =
|
||||||
trsf != NULL ?
|
trsf != NULL ?
|
||||||
gmio_size_to_uint32(trsf->buffer_size / GMIO_STLA_FACET_SIZE_P2) : 0;
|
gmio_size_to_uint32(trsf->buffer_size / GMIO_STLA_FACET_SIZE_P2)
|
||||||
|
: 0;
|
||||||
|
/* Variables */
|
||||||
uint32_t ifacet = 0;
|
uint32_t ifacet = 0;
|
||||||
char* buffer_iterator = trsf != NULL ? trsf->buffer : NULL;
|
char* buff_it = trsf != NULL ? trsf->buffer : NULL;
|
||||||
char coords_format[64];
|
char coords_format[64];
|
||||||
int error = GMIO_NO_ERROR;
|
int error = GMIO_NO_ERROR;
|
||||||
|
|
||||||
@ -141,21 +142,21 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
|||||||
return GMIO_INVALID_BUFFER_SIZE_ERROR;
|
return GMIO_INVALID_BUFFER_SIZE_ERROR;
|
||||||
|
|
||||||
{ /* Create XYZ coords format string (for normal and vertex coords) */
|
{ /* Create XYZ coords format string (for normal and vertex coords) */
|
||||||
char* coords_format_iterator = coords_format;
|
char* it = coords_format;
|
||||||
coords_format_iterator = gmio_write_stdio_format(coords_format_iterator, float32_prec);
|
it = gmio_write_stdio_format(it, float32_prec);
|
||||||
coords_format_iterator = gmio_write_nspaces(coords_format_iterator, 2);
|
it = gmio_write_nspaces(it, 2);
|
||||||
coords_format_iterator = gmio_write_stdio_format(coords_format_iterator, float32_prec);
|
it = gmio_write_stdio_format(it, float32_prec);
|
||||||
coords_format_iterator = gmio_write_nspaces(coords_format_iterator, 2);
|
it = gmio_write_nspaces(it, 2);
|
||||||
coords_format_iterator = gmio_write_stdio_format(coords_format_iterator, float32_prec);
|
it = gmio_write_stdio_format(it, float32_prec);
|
||||||
*coords_format_iterator = 0; /* Write terminating null byte */
|
*it = 0; /* Write terminating null byte */
|
||||||
/* TODO: check the "format" string can contain the given precision */
|
/* TODO: check the "format" string can contain the given precision */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write solid declaration */
|
/* Write solid declaration */
|
||||||
{
|
{
|
||||||
buffer_iterator = gmio_write_string(buffer_iterator, "solid ");
|
buff_it = gmio_write_string(buff_it, "solid ");
|
||||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, solid_name);
|
buff_it = gmio_write_string_eol(buff_it, solid_name);
|
||||||
if (!gmio_transfer_flush_buffer(trsf, buffer_iterator - (char*)trsf->buffer))
|
if (!gmio_transfer_flush_buffer(trsf, buff_it - (char*)trsf->buffer))
|
||||||
return GMIO_STREAM_ERROR;
|
return GMIO_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,37 +165,40 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
|||||||
ifacet < total_facet_count && gmio_no_error(error);
|
ifacet < total_facet_count && gmio_no_error(error);
|
||||||
ifacet += buffer_facet_count)
|
ifacet += buffer_facet_count)
|
||||||
{
|
{
|
||||||
const uint32_t clamped_facet_count = GMIO_MIN(ifacet + buffer_facet_count,
|
const uint32_t clamped_facet_count =
|
||||||
total_facet_count);
|
GMIO_MIN(ifacet + buffer_facet_count, total_facet_count);
|
||||||
gmio_stl_triangle_t tri;
|
gmio_stl_triangle_t tri;
|
||||||
uint32_t ibuffer_facet;
|
uint32_t ibuffer_facet;
|
||||||
|
|
||||||
gmio_transfer_handle_progress(trsf, ifacet, total_facet_count);
|
gmio_transfer_handle_progress(trsf, ifacet, total_facet_count);
|
||||||
|
|
||||||
/* Writing of facets is buffered */
|
/* Writing of facets is buffered */
|
||||||
buffer_iterator = trsf->buffer;
|
buff_it = trsf->buffer;
|
||||||
for (ibuffer_facet = ifacet; ibuffer_facet < clamped_facet_count; ++ibuffer_facet) {
|
for (ibuffer_facet = ifacet;
|
||||||
|
ibuffer_facet < clamped_facet_count;
|
||||||
|
++ibuffer_facet)
|
||||||
|
{
|
||||||
mesh->get_triangle_func(mesh->cookie, ibuffer_facet, &tri);
|
mesh->get_triangle_func(mesh->cookie, ibuffer_facet, &tri);
|
||||||
buffer_iterator = gmio_write_string(buffer_iterator, "facet normal ");
|
buff_it = gmio_write_string(buff_it, "facet normal ");
|
||||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.normal);
|
buff_it = gmio_write_coords(buff_it, coords_format, &tri.normal);
|
||||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
buff_it = gmio_write_eol(buff_it);
|
||||||
|
|
||||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, " outer loop");
|
buff_it = gmio_write_string_eol(buff_it, " outer loop");
|
||||||
buffer_iterator = gmio_write_string(buffer_iterator, " vertex ");
|
buff_it = gmio_write_string(buff_it, " vertex ");
|
||||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.v1);
|
buff_it = gmio_write_coords(buff_it, coords_format, &tri.v1);
|
||||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
buff_it = gmio_write_eol(buff_it);
|
||||||
buffer_iterator = gmio_write_string(buffer_iterator, " vertex ");
|
buff_it = gmio_write_string(buff_it, " vertex ");
|
||||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.v2);
|
buff_it = gmio_write_coords(buff_it, coords_format, &tri.v2);
|
||||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
buff_it = gmio_write_eol(buff_it);
|
||||||
buffer_iterator = gmio_write_string(buffer_iterator, " vertex ");
|
buff_it = gmio_write_string(buff_it, " vertex ");
|
||||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.v3);
|
buff_it = gmio_write_coords(buff_it, coords_format, &tri.v3);
|
||||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
buff_it = gmio_write_eol(buff_it);
|
||||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, " endloop");
|
buff_it = gmio_write_string_eol(buff_it, " endloop");
|
||||||
|
|
||||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, "endfacet");
|
buff_it = gmio_write_string_eol(buff_it, "endfacet");
|
||||||
} /* end for (ibuffer_facet) */
|
} /* end for (ibuffer_facet) */
|
||||||
|
|
||||||
if (!gmio_transfer_flush_buffer(trsf, buffer_iterator - (char*)trsf->buffer))
|
if (!gmio_transfer_flush_buffer(trsf, buff_it - (char*)trsf->buffer))
|
||||||
error = GMIO_STREAM_ERROR;
|
error = GMIO_STREAM_ERROR;
|
||||||
|
|
||||||
/* Task control */
|
/* Task control */
|
||||||
@ -204,9 +208,9 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
|||||||
|
|
||||||
/* Write end of solid */
|
/* Write end of solid */
|
||||||
if (gmio_no_error(error)) {
|
if (gmio_no_error(error)) {
|
||||||
buffer_iterator = gmio_write_string(trsf->buffer, "endsolid ");
|
buff_it = gmio_write_string(trsf->buffer, "endsolid ");
|
||||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, solid_name);
|
buff_it = gmio_write_string_eol(buff_it, solid_name);
|
||||||
if (!gmio_transfer_flush_buffer(trsf, buffer_iterator - (char*)trsf->buffer))
|
if (!gmio_transfer_flush_buffer(trsf, buff_it - (char*)trsf->buffer))
|
||||||
error = GMIO_STREAM_ERROR;
|
error = GMIO_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,14 +31,15 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
GMIO_INLINE static void read_triangle_memcpy(const uint8_t* buffer,
|
GMIO_INLINE static void read_triangle_memcpy(
|
||||||
gmio_stl_triangle_t* triangle)
|
const uint8_t* buffer, gmio_stl_triangle_t* triangle)
|
||||||
{
|
{
|
||||||
/* *triangle = *((gmio_stl_triangle_t*)(buffer)); */
|
/* *triangle = *((gmio_stl_triangle_t*)(buffer)); */
|
||||||
memcpy(triangle, buffer, GMIO_STLB_TRIANGLE_RAWSIZE);
|
memcpy(triangle, buffer, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gmio_stlb_read_facets(gmio_stl_mesh_creator_t* creator,
|
static void gmio_stlb_read_facets(
|
||||||
|
gmio_stl_mesh_creator_t* creator,
|
||||||
const uint8_t* buffer,
|
const uint8_t* buffer,
|
||||||
const gmio_stlb_readwrite_helper_t* rparams)
|
const gmio_stlb_readwrite_helper_t* rparams)
|
||||||
{
|
{
|
||||||
@ -60,15 +61,19 @@ static void gmio_stlb_read_facets(gmio_stl_mesh_creator_t* creator,
|
|||||||
rparams->fix_endian_func(&triangle);
|
rparams->fix_endian_func(&triangle);
|
||||||
|
|
||||||
/* Declare triangle */
|
/* Declare triangle */
|
||||||
creator->add_triangle_func(creator->cookie, i_facet_offset + i_facet, &triangle);
|
creator->add_triangle_func(
|
||||||
|
creator->cookie, i_facet_offset + i_facet, &triangle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
int gmio_stlb_read(
|
||||||
|
gmio_stl_mesh_creator_t *creator,
|
||||||
gmio_transfer_t* trsf,
|
gmio_transfer_t* trsf,
|
||||||
const gmio_stlb_read_options_t* options)
|
const gmio_stlb_read_options_t* options)
|
||||||
{
|
{
|
||||||
const gmio_endianness_t host_byte_order = gmio_host_endianness();
|
/* Constants */
|
||||||
|
const gmio_endianness_t host_byte_order =
|
||||||
|
gmio_host_endianness();
|
||||||
const gmio_endianness_t byte_order =
|
const gmio_endianness_t byte_order =
|
||||||
options != NULL ? options->byte_order : host_byte_order;
|
options != NULL ? options->byte_order : host_byte_order;
|
||||||
const uint32_t max_facet_count_per_read =
|
const uint32_t max_facet_count_per_read =
|
||||||
@ -76,10 +81,11 @@ int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
|||||||
gmio_size_to_uint32(
|
gmio_size_to_uint32(
|
||||||
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE)
|
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||||
: 0;
|
: 0;
|
||||||
|
/* Variables */
|
||||||
gmio_stlb_readwrite_helper_t rparams = {0};
|
gmio_stlb_readwrite_helper_t rparams = {0};
|
||||||
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
||||||
uint32_t total_facet_count = 0; /* Count of facets as declared in the stream */
|
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
|
||||||
int error = GMIO_NO_ERROR; /* Helper variable to store function result error code */
|
int error = GMIO_NO_ERROR; /* Helper to store function result error code */
|
||||||
|
|
||||||
/* Check validity of input parameters */
|
/* Check validity of input parameters */
|
||||||
if (!gmio_stlb_check_params(&error, trsf, byte_order))
|
if (!gmio_stlb_check_params(&error, trsf, byte_order))
|
||||||
@ -105,8 +111,10 @@ int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
|||||||
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
||||||
|
|
||||||
/* Callback to notify triangle count and header data */
|
/* Callback to notify triangle count and header data */
|
||||||
if (creator != NULL && creator->binary_begin_solid_func != NULL)
|
if (creator != NULL && creator->binary_begin_solid_func != NULL) {
|
||||||
creator->binary_begin_solid_func(creator->cookie, total_facet_count, header_data);
|
creator->binary_begin_solid_func(
|
||||||
|
creator->cookie, total_facet_count, header_data);
|
||||||
|
}
|
||||||
|
|
||||||
/* Read triangles */
|
/* Read triangles */
|
||||||
while (gmio_no_error(error)
|
while (gmio_no_error(error)
|
||||||
|
@ -31,13 +31,14 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
GMIO_INLINE static void write_triangle_memcpy(const gmio_stl_triangle_t* triangle,
|
GMIO_INLINE static void write_triangle_memcpy(
|
||||||
uint8_t* buffer)
|
const gmio_stl_triangle_t* triangle, uint8_t* buffer)
|
||||||
{
|
{
|
||||||
memcpy(buffer, triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
memcpy(buffer, triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
static void gmio_stlb_write_facets(
|
||||||
|
const gmio_stl_mesh_t* mesh,
|
||||||
uint8_t* buffer,
|
uint8_t* buffer,
|
||||||
const gmio_stlb_readwrite_helper_t* wparams)
|
const gmio_stlb_readwrite_helper_t* wparams)
|
||||||
{
|
{
|
||||||
@ -51,7 +52,10 @@ static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
triangle.attribute_byte_count = 0;
|
triangle.attribute_byte_count = 0;
|
||||||
for (i_facet = i_facet_offset; i_facet < (i_facet_offset + facet_count); ++i_facet) {
|
for (i_facet = i_facet_offset;
|
||||||
|
i_facet < (i_facet_offset + facet_count);
|
||||||
|
++i_facet)
|
||||||
|
{
|
||||||
mesh->get_triangle_func(mesh->cookie, i_facet, &triangle);
|
mesh->get_triangle_func(mesh->cookie, i_facet, &triangle);
|
||||||
|
|
||||||
if (wparams->fix_endian_func != NULL)
|
if (wparams->fix_endian_func != NULL)
|
||||||
@ -63,15 +67,22 @@ static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
|||||||
} /* end for */
|
} /* end for */
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
int gmio_stlb_write(
|
||||||
|
const gmio_stl_mesh_t* mesh,
|
||||||
gmio_transfer_t* trsf,
|
gmio_transfer_t* trsf,
|
||||||
const gmio_stlb_write_options_t* options)
|
const gmio_stlb_write_options_t* options)
|
||||||
{
|
{
|
||||||
const gmio_endianness_t host_byte_order = gmio_host_endianness();
|
/* Constants */
|
||||||
const gmio_endianness_t byte_order = options != NULL ? options->byte_order : host_byte_order;
|
const gmio_endianness_t host_byte_order =
|
||||||
const uint8_t* header_data = options != NULL ? options->header_data : NULL;
|
gmio_host_endianness();
|
||||||
|
const gmio_endianness_t byte_order =
|
||||||
|
options != NULL ? options->byte_order : host_byte_order;
|
||||||
|
const uint8_t* header_data =
|
||||||
|
options != NULL ? options->header_data : NULL;
|
||||||
|
const uint32_t facet_count =
|
||||||
|
mesh != NULL ? mesh->triangle_count : 0;
|
||||||
|
/* Variables */
|
||||||
gmio_stlb_readwrite_helper_t wparams = {0};
|
gmio_stlb_readwrite_helper_t wparams = {0};
|
||||||
const uint32_t facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
|
||||||
uint32_t i_facet = 0;
|
uint32_t i_facet = 0;
|
||||||
int error = GMIO_NO_ERROR;
|
int error = GMIO_NO_ERROR;
|
||||||
|
|
||||||
@ -84,7 +95,8 @@ int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
|||||||
/* Initialize wparams */
|
/* Initialize wparams */
|
||||||
if (host_byte_order != byte_order)
|
if (host_byte_order != byte_order)
|
||||||
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||||
wparams.facet_count = gmio_size_to_uint32(trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
wparams.facet_count = gmio_size_to_uint32(
|
||||||
|
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
|
|
||||||
/* Write header */
|
/* Write header */
|
||||||
if (header_data == NULL) {
|
if (header_data == NULL) {
|
||||||
@ -92,8 +104,11 @@ int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
|||||||
memset(trsf->buffer, 0, GMIO_STLB_HEADER_SIZE);
|
memset(trsf->buffer, 0, GMIO_STLB_HEADER_SIZE);
|
||||||
header_data = (const uint8_t*)trsf->buffer;
|
header_data = (const uint8_t*)trsf->buffer;
|
||||||
}
|
}
|
||||||
if (gmio_stream_write(&trsf->stream, header_data, GMIO_STLB_HEADER_SIZE, 1) != 1)
|
if (gmio_stream_write(&trsf->stream, header_data, GMIO_STLB_HEADER_SIZE, 1)
|
||||||
|
!= 1)
|
||||||
|
{
|
||||||
return GMIO_STREAM_ERROR;
|
return GMIO_STREAM_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* Write facet count */
|
/* Write facet count */
|
||||||
if (byte_order == GMIO_LITTLE_ENDIAN)
|
if (byte_order == GMIO_LITTLE_ENDIAN)
|
||||||
|
@ -43,9 +43,8 @@ static void occmesh_add_triangle(void* cookie,
|
|||||||
tri->normal.x, tri->normal.y, tri->normal.z);
|
tri->normal.x, tri->normal.y, tri->normal.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void occmesh_get_triangle(const void* cookie,
|
static void occmesh_get_triangle(
|
||||||
uint32_t tri_id,
|
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
|
||||||
gmio_stl_triangle_t* triangle)
|
|
||||||
{
|
{
|
||||||
const gmio_OccStlMeshDomain* meshCookie =
|
const gmio_OccStlMeshDomain* meshCookie =
|
||||||
static_cast<const gmio_OccStlMeshDomain*>(cookie);
|
static_cast<const gmio_OccStlMeshDomain*>(cookie);
|
||||||
@ -64,7 +63,8 @@ static void occmesh_get_triangle(const void* cookie,
|
|||||||
triangle->normal.y = float(yN);
|
triangle->normal.y = float(yN);
|
||||||
triangle->normal.z = float(zN);
|
triangle->normal.z = float(zN);
|
||||||
|
|
||||||
const TColgp_SequenceOfXYZ& vertices = meshCookie->mesh()->Vertices(meshCookie->domainId());
|
const TColgp_SequenceOfXYZ& vertices =
|
||||||
|
meshCookie->mesh()->Vertices(meshCookie->domainId());
|
||||||
const gp_XYZ& coordsV1 = vertices.Value(v1);
|
const gp_XYZ& coordsV1 = vertices.Value(v1);
|
||||||
const gp_XYZ& coordsV2 = vertices.Value(v2);
|
const gp_XYZ& coordsV2 = vertices.Value(v2);
|
||||||
const gp_XYZ& coordsV3 = vertices.Value(v3);
|
const gp_XYZ& coordsV3 = vertices.Value(v3);
|
||||||
@ -83,7 +83,8 @@ static void occmesh_get_triangle(const void* cookie,
|
|||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
void gmio_stl_set_occmesh(gmio_stl_mesh_t *mesh, const gmio_OccStlMeshDomain &meshCookie)
|
void gmio_stl_set_occmesh(
|
||||||
|
gmio_stl_mesh_t *mesh, const gmio_OccStlMeshDomain &meshCookie)
|
||||||
{
|
{
|
||||||
std::memset(mesh, 0, sizeof(gmio_stl_mesh_t));
|
std::memset(mesh, 0, sizeof(gmio_stl_mesh_t));
|
||||||
mesh->cookie = &meshCookie;
|
mesh->cookie = &meshCookie;
|
||||||
@ -98,7 +99,8 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain &meshCookie)
|
|||||||
return occmesh;
|
return occmesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gmio_stl_set_occmesh_creator(gmio_stl_mesh_creator_t *creator, const Handle_StlMesh_Mesh &mesh)
|
void gmio_stl_set_occmesh_creator(
|
||||||
|
gmio_stl_mesh_creator_t *creator, const Handle_StlMesh_Mesh &mesh)
|
||||||
{
|
{
|
||||||
std::memset(creator, 0, sizeof(gmio_stl_mesh_creator_t));
|
std::memset(creator, 0, sizeof(gmio_stl_mesh_creator_t));
|
||||||
creator->cookie = internal::occMeshPtr(mesh);
|
creator->cookie = internal::occMeshPtr(mesh);
|
||||||
@ -112,7 +114,8 @@ gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh &mesh)
|
|||||||
return occ_creator;
|
return occ_creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh &stlMesh, int domId)
|
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(
|
||||||
|
const Handle_StlMesh_Mesh &stlMesh, int domId)
|
||||||
: m_mesh(stlMesh),
|
: m_mesh(stlMesh),
|
||||||
m_domainId(domId)
|
m_domainId(domId)
|
||||||
{
|
{
|
||||||
|
@ -39,23 +39,20 @@ static int gmio_stream_qiodevice_error(void* cookie)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t gmio_stream_qiodevice_read(void* cookie,
|
static size_t gmio_stream_qiodevice_read(
|
||||||
void* ptr,
|
void* cookie, void* ptr, size_t item_size, size_t item_count)
|
||||||
size_t item_size,
|
|
||||||
size_t item_count)
|
|
||||||
{
|
{
|
||||||
QIODevice* device = static_cast<QIODevice*>(cookie);
|
QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||||
const qint64 c = device->read(static_cast<char*>(ptr), item_size * item_count);
|
const qint64 c = device->read(static_cast<char*>(ptr), item_size * item_count);
|
||||||
return c / item_size;
|
return c / item_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t gmio_stream_qiodevice_write(void* cookie,
|
static size_t gmio_stream_qiodevice_write(
|
||||||
const void* ptr,
|
void* cookie, const void* ptr, size_t item_size, size_t item_count)
|
||||||
size_t item_size,
|
|
||||||
size_t item_count)
|
|
||||||
{
|
{
|
||||||
QIODevice* device = static_cast<QIODevice*>(cookie);
|
QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||||
const qint64 c = device->write(static_cast<const char*>(ptr), item_size * item_count);
|
const qint64 c = device->write(
|
||||||
|
static_cast<const char*>(ptr), item_size * item_count);
|
||||||
return c / item_size;
|
return c / item_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user