gmio/benchs/bench_libstl/main.c

97 lines
2.4 KiB
C
Raw Normal View History

2014-04-04 22:01:44 +08:00
#include <gmio_core/error.h>
#include <gmio_stl/stl_io.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,
2014-04-04 22:01:44 +08:00
const gmio_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);
}
2014-04-04 22:01:44 +08:00
static void libstl_gmio_stlb_read(const char* filepath)
2013-02-20 21:39:23 +08:00
{
2014-03-14 17:24:05 +08:00
/* uint8_t stack_buff[30 * 1024]; */
2014-01-30 00:51:04 +08:00
my_igeom_t cookie;
2014-04-04 22:01:44 +08:00
gmio_transfer_t trsf;
gmio_stl_mesh_creator_t mesh_creator;
2014-01-30 00:51:04 +08:00
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;
2014-04-04 22:01:44 +08:00
memset(&mesh_creator, 0, sizeof(gmio_stl_mesh_creator_t));
mesh_creator.cookie = &cookie;
mesh_creator.add_triangle_func = dummy_process_triangle;
2013-02-20 21:39:23 +08:00
2014-04-04 22:01:44 +08:00
memset(&trsf, 0, sizeof(gmio_transfer_t));
gmio_stream_set_stdio(&trsf.stream, file);
2013-04-27 06:23:00 +08:00
trsf.buffer = (uint8_t*)malloc(512 * 1024);
trsf.buffer_size = 512 * 1024;
2014-03-14 17:24:05 +08:00
/* trsf.buffer = stack_buff;
trsf.buffer_size = 24 * 1024; */
2013-02-20 21:39:23 +08:00
2014-04-04 22:01:44 +08:00
result = gmio_stlb_read(&mesh_creator, &trsf, GMIO_LITTLE_ENDIAN);
if (gmio_error(result))
fprintf(stderr, "gmio_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
2014-04-04 22:01:44 +08:00
static void libstl_gmio_stla_read(const char* filepath)
2013-04-27 06:23:00 +08:00
{
2014-04-04 22:01:44 +08:00
gmio_transfer_t trsf;
2014-01-30 00:51:04 +08:00
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;
}
2014-04-04 22:01:44 +08:00
memset(&trsf, 0, sizeof(gmio_transfer_t));
gmio_stream_set_stdio(&trsf.stream, file);
2013-04-27 06:23:00 +08:00
trsf.buffer = (char*)malloc(512 * 1024);
trsf.buffer_size = 512 * 1024;
2014-04-04 22:01:44 +08:00
result = gmio_stla_read(NULL, &trsf, 0);
if (gmio_error(result))
fprintf(stderr, "gmio_stla_read() error %i", result);
2013-04-27 06:23:00 +08:00
/* 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)
2014-04-04 22:01:44 +08:00
benchmark(&libstl_gmio_stla_read, "gmio_stla_read()", argc - 2, argv + 2);
2013-04-27 06:23:00 +08:00
else if (strcmp(argv[1], "--stlb") == 0)
2014-04-04 22:01:44 +08:00
benchmark(&libstl_gmio_stlb_read, "gmio_stlb_read()", argc - 2, argv + 2);
2013-04-27 06:23:00 +08:00
2013-02-20 21:39:23 +08:00
return 0;
}