2014-01-30 00:51:04 +08:00
|
|
|
#include <datax/libstl/stla_read.h>
|
|
|
|
#include <datax/libstl/stlb_read.h>
|
|
|
|
#include <datax/error.h>
|
2013-02-20 21:39:23 +08:00
|
|
|
|
|
|
|
#include "../commons/bench_tools.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
typedef struct my_igeom
|
|
|
|
{
|
|
|
|
uint32_t facet_count;
|
|
|
|
} my_igeom_t;
|
|
|
|
|
2014-01-30 00:51:04 +08:00
|
|
|
static void dummy_process_triangle(void* cookie,
|
|
|
|
uint32_t triangle_id,
|
|
|
|
const foug_stl_triangle_t* triangle)
|
2013-02-20 21:39:23 +08:00
|
|
|
{
|
2014-01-30 00:51:04 +08:00
|
|
|
my_igeom_t* my_igeom = (my_igeom_t*)(cookie);
|
2013-02-20 21:39:23 +08:00
|
|
|
if (my_igeom != NULL)
|
|
|
|
++(my_igeom->facet_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void libstl_foug_stlb_read(const char* filepath)
|
|
|
|
{
|
2014-01-30 00:51:04 +08:00
|
|
|
my_igeom_t cookie;
|
|
|
|
foug_transfer_t trsf;
|
|
|
|
foug_stlb_geom_input_t geom;
|
|
|
|
int result;
|
|
|
|
|
2013-04-27 06:23:00 +08:00
|
|
|
FILE* file = fopen(filepath, "rb");
|
2013-02-20 21:39:23 +08:00
|
|
|
if (file == NULL) {
|
2013-04-27 06:23:00 +08:00
|
|
|
fprintf(stderr, "Failed to open binary STL file %s\n", filepath);
|
2013-02-20 21:39:23 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-27 06:23:00 +08:00
|
|
|
cookie.facet_count = 0;
|
|
|
|
memset(&geom, 0, sizeof(foug_stlb_geom_input_t));
|
|
|
|
geom.cookie = &cookie;
|
2014-01-30 00:51:04 +08:00
|
|
|
geom.process_triangle_func = (foug_stlb_process_triangle_func_t)dummy_process_triangle;
|
2013-02-20 21:39:23 +08:00
|
|
|
|
2013-04-27 06:23:00 +08:00
|
|
|
memset(&trsf, 0, sizeof(foug_transfer_t));
|
|
|
|
foug_stream_set_stdio(&trsf.stream, file);
|
|
|
|
trsf.buffer = (uint8_t*)malloc(512 * 1024);
|
|
|
|
trsf.buffer_size = 512 * 1024;
|
2013-02-20 21:39:23 +08:00
|
|
|
|
2014-01-30 00:51:04 +08:00
|
|
|
result = foug_stlb_read(&geom, &trsf, FOUG_LITTLE_ENDIAN);
|
2013-04-27 06:23:00 +08:00
|
|
|
if (foug_datax_error(result))
|
|
|
|
fprintf(stderr, "foug_stlb_read() error %i", result);
|
2013-02-20 21:39:23 +08:00
|
|
|
|
2013-04-27 06:23:00 +08:00
|
|
|
fprintf(stdout, "Facet count: %i\n", cookie.facet_count);
|
2013-02-20 21:39:23 +08:00
|
|
|
|
2013-04-27 06:23:00 +08:00
|
|
|
free(trsf.buffer);
|
|
|
|
fclose(file);
|
|
|
|
}
|
2013-02-20 21:39:23 +08:00
|
|
|
|
2013-04-27 06:23:00 +08:00
|
|
|
static void libstl_foug_stla_read(const char* filepath)
|
|
|
|
{
|
2014-01-30 00:51:04 +08:00
|
|
|
foug_transfer_t trsf;
|
|
|
|
int result;
|
|
|
|
FILE* file;
|
|
|
|
|
|
|
|
file = fopen(filepath, "r");
|
2013-04-27 06:23:00 +08:00
|
|
|
if (file == NULL) {
|
|
|
|
fprintf(stderr, "Failed to open ascii STL file %s\n", filepath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&trsf, 0, sizeof(foug_transfer_t));
|
|
|
|
foug_stream_set_stdio(&trsf.stream, file);
|
|
|
|
trsf.buffer = (char*)malloc(512 * 1024);
|
|
|
|
trsf.buffer_size = 512 * 1024;
|
|
|
|
|
2014-01-30 00:51:04 +08:00
|
|
|
result = foug_stla_read(NULL, &trsf, 0);
|
2013-04-27 06:23:00 +08:00
|
|
|
if (foug_datax_error(result))
|
|
|
|
fprintf(stderr, "foug_stla_read() error %i", result);
|
|
|
|
|
|
|
|
/* fprintf(stdout, "Facet count: %i\n", igeom.facet_count); */
|
2013-02-20 21:39:23 +08:00
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-04-27 06:23:00 +08:00
|
|
|
if (argc < 3)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "--stla") == 0)
|
|
|
|
benchmark(&libstl_foug_stla_read, "foug_stla_read()", argc - 2, argv + 2);
|
|
|
|
else if (strcmp(argv[1], "--stlb") == 0)
|
|
|
|
benchmark(&libstl_foug_stlb_read, "foug_stlb_read()", argc - 2, argv + 2);
|
|
|
|
|
2013-02-20 21:39:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|