libstl: use field instead of function pointer where possible
This commit is contained in:
parent
6f7d8c4121
commit
5720614cdc
@ -429,7 +429,7 @@ static void parse_xyz_coords(foug_stla_parse_data_t* data, foug_stl_coords_t* co
|
||||
} /* end switch */
|
||||
}
|
||||
|
||||
static void parse_facets(foug_stla_parse_data_t* data)
|
||||
static void parse_facets(foug_stla_parse_data_t* data, size_t i_facet_offset)
|
||||
{
|
||||
if (!parsing_can_continue(data))
|
||||
return;
|
||||
@ -458,12 +458,13 @@ static void parse_facets(foug_stla_parse_data_t* data)
|
||||
parsing_eat_token(ENDFACET_token, data);
|
||||
|
||||
if (parsing_can_continue(data)
|
||||
&& data->geom != NULL && data->geom->process_next_triangle_func != NULL)
|
||||
&& data->geom != NULL
|
||||
&& data->geom->process_triangle_func != NULL)
|
||||
{
|
||||
data->geom->process_next_triangle_func(data->geom, &facet);
|
||||
data->geom->process_triangle_func(data->geom, &facet, i_facet_offset);
|
||||
}
|
||||
|
||||
parse_facets(data);
|
||||
parse_facets(data, i_facet_offset + 1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -479,7 +480,7 @@ static void parse_solid(foug_stla_parse_data_t* data)
|
||||
switch (data->token) {
|
||||
case SOLID_token:
|
||||
parse_beginsolid(data);
|
||||
parse_facets(data);
|
||||
parse_facets(data, 0);
|
||||
parse_endsolid(data);
|
||||
break;
|
||||
default:
|
||||
|
@ -11,7 +11,7 @@ struct foug_stla_geom_input
|
||||
{
|
||||
void* cookie;
|
||||
void (*begin_solid_func) (foug_stla_geom_input_t*, const char*); /* Optional */
|
||||
void (*process_next_triangle_func)(foug_stla_geom_input_t*, const foug_stl_triangle_t*);
|
||||
void (*process_triangle_func)(foug_stla_geom_input_t*, const foug_stl_triangle_t*, uint32_t);
|
||||
void (*end_solid_func) (foug_stla_geom_input_t*, const char*); /* Optional */
|
||||
};
|
||||
|
||||
|
@ -109,7 +109,7 @@ int foug_stla_write(foug_stla_geom_output_t* geom,
|
||||
foug_transfer_t* trsf,
|
||||
uint8_t real32_prec)
|
||||
{
|
||||
size_t solid_count = 0;
|
||||
const size_t solid_count = geom != NULL ? geom->solid_count : 0;
|
||||
size_t total_facet_count = 0;
|
||||
size_t written_facet_count = 0;
|
||||
size_t isolid = 0;
|
||||
@ -139,12 +139,6 @@ int foug_stla_write(foug_stla_geom_output_t* geom,
|
||||
/* TODO: check the "format" string can contain the given precision */
|
||||
}
|
||||
|
||||
/* Get solid count */
|
||||
if (geom->get_solid_count_func != NULL)
|
||||
solid_count = geom->get_solid_count_func(geom);
|
||||
else
|
||||
solid_count = 1;
|
||||
|
||||
/* Compute total facet count */
|
||||
if (trsf->task_control.handle_progress_func != NULL) {
|
||||
for (isolid = 0; isolid < solid_count; ++isolid)
|
||||
|
@ -11,10 +11,10 @@ struct foug_stla_geom_output
|
||||
{
|
||||
void* cookie;
|
||||
|
||||
size_t (*get_solid_count_func) (foug_stla_geom_output_t*); /* Optional (if NULL solid_count == 1) */
|
||||
void (*get_solid_name) (foug_stla_geom_output_t*, size_t, char*); /* Optional */
|
||||
size_t (*get_triangle_count_func)(foug_stla_geom_output_t*, size_t);
|
||||
void (*get_triangle_func) (foug_stla_geom_output_t*, size_t, size_t, foug_stl_triangle_t*);
|
||||
size_t solid_count;
|
||||
void (*get_solid_name) (const foug_stla_geom_output_t*, size_t, char*); /* Optional */
|
||||
size_t (*get_triangle_count_func)(const foug_stla_geom_output_t*, size_t);
|
||||
void (*get_triangle_func) (const foug_stla_geom_output_t*, size_t, size_t, foug_stl_triangle_t*);
|
||||
};
|
||||
|
||||
/* Write geometry in the STL ascii format */
|
||||
|
@ -28,13 +28,14 @@ static void read_triangle_alignsafe(const uint8_t* buffer, foug_stlb_triangle_t*
|
||||
|
||||
static void foug_stlb_read_facets(foug_stlb_geom_input_t* geom,
|
||||
uint8_t* buffer,
|
||||
uint32_t facet_count)
|
||||
uint32_t facet_count,
|
||||
uint32_t i_facet_offset)
|
||||
{
|
||||
foug_stlb_triangle_t triangle;
|
||||
uint32_t buffer_offset;
|
||||
uint32_t i_facet;
|
||||
|
||||
if (geom == NULL || geom->process_next_triangle_func == NULL)
|
||||
if (geom == NULL || geom->process_triangle_func == NULL)
|
||||
return;
|
||||
|
||||
buffer_offset = 0;
|
||||
@ -48,7 +49,7 @@ static void foug_stlb_read_facets(foug_stlb_geom_input_t* geom,
|
||||
buffer_offset += FOUG_STLB_TRIANGLE_RAWSIZE;
|
||||
|
||||
/* Declare triangle */
|
||||
geom->process_next_triangle_func(geom, &triangle);
|
||||
geom->process_triangle_func(geom, &triangle, i_facet_offset + i_facet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +106,7 @@ int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
||||
if (foug_datax_no_error(error)) {
|
||||
uint8_t progress_pc;
|
||||
|
||||
foug_stlb_read_facets(geom, trsf->buffer, facet_count_read);
|
||||
foug_stlb_read_facets(geom, trsf->buffer, facet_count_read, accum_facet_count_read);
|
||||
accum_facet_count_read += facet_count_read;
|
||||
progress_pc = foug_percentage(0, total_facet_count, accum_facet_count_read);
|
||||
if (!foug_task_control_handle_progress(&trsf->task_control, progress_pc))
|
||||
|
@ -13,7 +13,7 @@ struct foug_stlb_geom_input
|
||||
void* cookie;
|
||||
void (*process_header_func) (foug_stlb_geom_input_t*, const uint8_t*); /* Optional */
|
||||
void (*begin_triangles_func) (foug_stlb_geom_input_t*, uint32_t); /* Optional */
|
||||
void (*process_next_triangle_func)(foug_stlb_geom_input_t*, const foug_stlb_triangle_t*);
|
||||
void (*process_triangle_func)(foug_stlb_geom_input_t*, const foug_stlb_triangle_t*, uint32_t);
|
||||
void (*end_triangles_func) (foug_stlb_geom_input_t*); /* Optional */
|
||||
};
|
||||
|
||||
|
@ -53,7 +53,7 @@ int foug_stlb_write(const foug_stlb_geom_output_t* geom,
|
||||
foug_transfer_t* trsf,
|
||||
foug_endianness_t byte_order)
|
||||
{
|
||||
uint32_t facet_count;
|
||||
const uint32_t facet_count = geom != NULL ? geom->triangle_count : 0;
|
||||
uint32_t i_facet;
|
||||
uint32_t buffer_facet_count;
|
||||
uint32_t ifacet_start;
|
||||
@ -63,8 +63,6 @@ int foug_stlb_write(const foug_stlb_geom_output_t* geom,
|
||||
return FOUG_DATAX_NULL_BUFFER_ERROR;
|
||||
if (trsf->buffer_size < FOUG_STLB_MIN_CONTENTS_SIZE)
|
||||
return FOUG_DATAX_INVALID_BUFFER_SIZE_ERROR;
|
||||
if (geom == NULL || geom->get_triangle_count_func == NULL)
|
||||
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_COUNT_FUNC;
|
||||
if (geom == NULL || geom->get_triangle_func == NULL)
|
||||
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC;
|
||||
if (byte_order != FOUG_LITTLE_ENDIAN/* && byte_order != FOUG_BIG_ENDIAN*/)
|
||||
@ -72,18 +70,20 @@ int foug_stlb_write(const foug_stlb_geom_output_t* geom,
|
||||
|
||||
/* Write header */
|
||||
{
|
||||
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
||||
if (geom->get_header_func != NULL)
|
||||
geom->get_header_func(geom, header_data);
|
||||
else
|
||||
memset(header_data, 0, FOUG_STLB_HEADER_SIZE);
|
||||
|
||||
const uint8_t* header_data = NULL;
|
||||
if (geom->header != NULL) {
|
||||
header_data = geom->header;
|
||||
}
|
||||
else {
|
||||
/* Use buffer to store an empty header (filled with zeroes) */
|
||||
memset(trsf->buffer, 0, FOUG_STLB_HEADER_SIZE);
|
||||
header_data = (const uint8_t*)trsf->buffer;
|
||||
}
|
||||
if (foug_stream_write(&trsf->stream, header_data, FOUG_STLB_HEADER_SIZE, 1) != 1)
|
||||
return FOUG_DATAX_STREAM_ERROR;
|
||||
}
|
||||
|
||||
/* Write facet count */
|
||||
facet_count = geom->get_triangle_count_func(geom);
|
||||
if (byte_order == FOUG_LITTLE_ENDIAN)
|
||||
foug_encode_uint32_le(facet_count, trsf->buffer);
|
||||
else
|
||||
|
@ -11,8 +11,8 @@ typedef struct foug_stlb_geom_output foug_stlb_geom_output_t;
|
||||
struct foug_stlb_geom_output
|
||||
{
|
||||
void* cookie;
|
||||
void (*get_header_func) (const foug_stlb_geom_output_t*, uint8_t*); /* Optional */
|
||||
uint32_t (*get_triangle_count_func)(const foug_stlb_geom_output_t*);
|
||||
uint8_t* header; /* May be NULL if empty header*/
|
||||
uint32_t triangle_count;
|
||||
void (*get_triangle_func)(const foug_stlb_geom_output_t*, uint32_t, foug_stlb_triangle_t*);
|
||||
};
|
||||
|
||||
@ -22,8 +22,7 @@ FOUG_DATAX_LIBSTL_EXPORT int foug_stlb_write(const foug_stlb_geom_output_t* geom
|
||||
foug_endianness_t byte_order);
|
||||
|
||||
/* Specific error codes returned by foug_stlb_write() */
|
||||
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_COUNT_FUNC 1
|
||||
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC 2
|
||||
#define FOUG_STLB_WRITE_UNSUPPORTED_BYTE_ORDER 3
|
||||
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC 1
|
||||
#define FOUG_STLB_WRITE_UNSUPPORTED_BYTE_ORDER 2
|
||||
|
||||
#endif /* FOUG_DATAX_C_LIBSTL_STLB_WRITE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user