2015-05-28 23:33:42 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** gmio
|
|
|
|
** Copyright Fougue (2 Mar. 2015)
|
2015-07-13 17:42:03 +08:00
|
|
|
** contact@fougue.pro
|
2015-05-28 23:33:42 +08:00
|
|
|
**
|
|
|
|
** 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".
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-09-14 17:09:12 +08:00
|
|
|
#include "utest_assert.h"
|
|
|
|
|
2015-09-14 17:25:29 +08:00
|
|
|
#include "core_utils.h"
|
2015-09-11 16:51:25 +08:00
|
|
|
#include "stl_utils.h"
|
2015-05-28 23:33:42 +08:00
|
|
|
|
|
|
|
#include "../src/gmio_core/error.h"
|
2015-09-11 00:03:12 +08:00
|
|
|
#include "../src/gmio_core/internal/min_max.h"
|
2015-05-28 23:33:42 +08:00
|
|
|
#include "../src/gmio_stl/stl_error.h"
|
|
|
|
#include "../src/gmio_stl/stl_io.h"
|
2015-12-04 01:00:25 +08:00
|
|
|
#include "../src/gmio_stl/stl_io_options.h"
|
2015-05-28 23:33:42 +08:00
|
|
|
|
|
|
|
#include <stddef.h>
|
2015-09-14 17:09:12 +08:00
|
|
|
#include <stdlib.h>
|
2015-09-11 00:03:12 +08:00
|
|
|
|
2015-12-04 01:00:25 +08:00
|
|
|
static const char stl_grabcad_arm11_filepath[] =
|
2015-09-11 22:36:03 +08:00
|
|
|
"models/solid_grabcad_arm11_link0_hb.le_stlb";
|
|
|
|
|
2015-07-10 16:55:02 +08:00
|
|
|
struct stl_testcase_result
|
|
|
|
{
|
|
|
|
char solid_name[2048];
|
|
|
|
};
|
|
|
|
|
2016-02-01 23:53:45 +08:00
|
|
|
void stl_testcase_result__begin_solid(
|
|
|
|
void* cookie, const struct gmio_stl_mesh_creator_infos* infos)
|
2015-07-10 16:55:02 +08:00
|
|
|
{
|
2016-02-01 23:53:45 +08:00
|
|
|
if (infos->format == GMIO_STL_FORMAT_ASCII) {
|
|
|
|
struct stl_testcase_result* res = (struct stl_testcase_result*)cookie;
|
|
|
|
if (res != NULL) {
|
|
|
|
res->solid_name[0] = 0;
|
|
|
|
if (infos->stla_solid_name != NULL)
|
|
|
|
strcpy(res->solid_name, infos->stla_solid_name);
|
|
|
|
}
|
2015-07-10 16:55:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stl_testcase
|
2015-05-28 23:33:42 +08:00
|
|
|
{
|
|
|
|
const char* filepath;
|
|
|
|
int errorcode;
|
2015-12-04 01:00:25 +08:00
|
|
|
enum gmio_stl_format format;
|
2015-07-10 16:55:02 +08:00
|
|
|
const char* solid_name;
|
2015-05-28 23:33:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const char* test_stl_read()
|
|
|
|
{
|
2015-12-10 01:51:03 +08:00
|
|
|
const struct stl_testcase expected[] = {
|
2016-01-26 18:50:55 +08:00
|
|
|
{ "models/file_empty",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_STL_ERROR_UNKNOWN_FORMAT,
|
|
|
|
GMIO_STL_FORMAT_UNKNOWN,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_4vertex.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_STL_ERROR_PARSING,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_anonymous_empty.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_empty.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
"emptysolid"
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_empty.stlb",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_BINARY_LE,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_empty_name_many_words.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
"name with multiple words"
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_empty_name_many_words_single_letters.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
"a b c d e f\t\tg h"
|
2016-01-26 18:50:55 +08:00
|
|
|
},
|
2015-09-11 00:03:12 +08:00
|
|
|
{ "models/solid_grabcad_arm11_link0_hb.le_stlb",
|
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_BINARY_LE,
|
|
|
|
NULL
|
|
|
|
},
|
2016-02-23 00:15:30 +08:00
|
|
|
{ "models/solid_jburkardt_sphere.stla",
|
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
"sphere"
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_lack_z.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_STL_ERROR_PARSING,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_one_facet.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_one_facet.le_stlb",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_BINARY_LE,
|
|
|
|
NULL
|
|
|
|
},
|
2015-09-10 22:12:05 +08:00
|
|
|
{ "models/solid_one_facet.be_stlb",
|
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_BINARY_BE,
|
|
|
|
NULL
|
|
|
|
},
|
2015-08-12 05:57:57 +08:00
|
|
|
{ "models/solid_one_facet_uppercase.stla",
|
2015-07-10 16:55:02 +08:00
|
|
|
GMIO_ERROR_OK,
|
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
NULL
|
|
|
|
}
|
2015-05-28 23:33:42 +08:00
|
|
|
};
|
|
|
|
const size_t expected_count =
|
2015-12-10 01:51:03 +08:00
|
|
|
sizeof(expected) / sizeof(struct stl_testcase);
|
2015-05-29 00:02:26 +08:00
|
|
|
size_t i; /* for loop counter */
|
2016-01-29 19:47:01 +08:00
|
|
|
struct gmio_stl_mesh_creator mesh_creator = {0};
|
2015-12-10 01:51:03 +08:00
|
|
|
struct stl_testcase_result result = {0};
|
2015-05-28 23:33:42 +08:00
|
|
|
|
2016-01-29 19:47:01 +08:00
|
|
|
mesh_creator.cookie = &result;
|
2016-02-01 23:53:45 +08:00
|
|
|
mesh_creator.func_begin_solid = &stl_testcase_result__begin_solid;
|
2016-01-29 19:47:01 +08:00
|
|
|
mesh_creator.func_add_triangle = &gmio_stl_nop_add_triangle;
|
2015-05-28 23:33:42 +08:00
|
|
|
|
2015-05-29 00:02:26 +08:00
|
|
|
for (i = 0; i < expected_count; ++i) {
|
2015-12-04 01:00:25 +08:00
|
|
|
const enum gmio_stl_format format =
|
2015-07-10 16:55:02 +08:00
|
|
|
gmio_stl_get_format_file(expected[i].filepath);
|
|
|
|
const int err =
|
2016-01-29 19:47:01 +08:00
|
|
|
gmio_stl_read_file(expected[i].filepath, mesh_creator, NULL);
|
2015-07-10 16:55:02 +08:00
|
|
|
|
|
|
|
/* Check format */
|
|
|
|
if (format != expected[i].format) {
|
|
|
|
printf("\nfilepath : %s\n"
|
|
|
|
"expected format : %d\n"
|
|
|
|
"actual format : %d\n",
|
|
|
|
expected[i].filepath,
|
|
|
|
expected[i].format,
|
|
|
|
format);
|
|
|
|
}
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_UINT(expected[i].format, format);
|
2015-07-10 16:55:02 +08:00
|
|
|
|
|
|
|
/* Check error code */
|
2015-05-28 23:33:42 +08:00
|
|
|
if (err != expected[i].errorcode) {
|
|
|
|
printf("\nfilepath : %s\n"
|
|
|
|
"expected error : 0x%x\n"
|
|
|
|
"actual error : 0x%x\n",
|
|
|
|
expected[i].filepath,
|
|
|
|
expected[i].errorcode,
|
|
|
|
err);
|
|
|
|
}
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_UINT(expected[i].errorcode, err);
|
2015-07-10 16:55:02 +08:00
|
|
|
|
|
|
|
/* Check solid name */
|
|
|
|
if (expected[i].format == GMIO_STL_FORMAT_ASCII) {
|
|
|
|
const char* expected_name =
|
|
|
|
expected[i].solid_name != NULL ? expected[i].solid_name : "";
|
|
|
|
if (strcmp(result.solid_name, expected_name) != 0) {
|
|
|
|
printf("\nfilepath : %s\n"
|
|
|
|
"expected solidname : %s\n"
|
|
|
|
"actual solidname : %s\n",
|
|
|
|
expected[i].filepath,
|
|
|
|
expected_name,
|
|
|
|
result.solid_name);
|
|
|
|
}
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_CSTR(expected_name, result.solid_name);
|
2015-07-10 16:55:02 +08:00
|
|
|
}
|
2015-05-28 23:33:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-11 00:03:12 +08:00
|
|
|
const char* test_stlb_write_header()
|
|
|
|
{
|
|
|
|
const char* filepath = "temp/solid.stlb";
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stlb_header header = {0};
|
2015-09-11 00:03:12 +08:00
|
|
|
const char* header_str = "temp/solid.stlb generated with gmio library";
|
|
|
|
int error = GMIO_ERROR_OK;
|
|
|
|
|
|
|
|
{
|
|
|
|
FILE* outfile = fopen(filepath, "wb");
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stream stream = gmio_stream_stdio(outfile);
|
2015-09-11 00:03:12 +08:00
|
|
|
memcpy(&header,
|
|
|
|
header_str,
|
|
|
|
GMIO_MIN(GMIO_STLB_HEADER_SIZE, strlen(header_str)));
|
|
|
|
error = gmio_stlb_write_header(
|
|
|
|
&stream, GMIO_ENDIANNESS_LITTLE, &header, 0);
|
|
|
|
fclose(outfile);
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 00:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_data data = {0};
|
2016-01-29 19:47:01 +08:00
|
|
|
error = gmio_stl_read_file(
|
|
|
|
filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 16:51:25 +08:00
|
|
|
UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header));
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_UINT(0, data.tri_array.count);
|
2015-09-11 00:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-06 22:29:29 +08:00
|
|
|
/* Safely closes the two files \p f1 and \p f2 */
|
|
|
|
static void fclose_2(FILE* f1, FILE* f2)
|
|
|
|
{
|
|
|
|
if (f1 != NULL)
|
|
|
|
fclose(f1);
|
|
|
|
if (f2 != NULL)
|
|
|
|
fclose(f2);
|
|
|
|
}
|
|
|
|
|
2015-09-11 00:03:12 +08:00
|
|
|
const char* test_stlb_write()
|
|
|
|
{
|
2015-09-11 22:36:03 +08:00
|
|
|
const char* model_filepath = stl_grabcad_arm11_filepath;
|
|
|
|
const char* model_filepath_out = "temp/solid.le_stlb";
|
|
|
|
const char* model_filepath_out_be = "temp/solid.be_stlb";
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_data data = {0};
|
2015-09-11 00:03:12 +08:00
|
|
|
int error = GMIO_ERROR_OK;
|
|
|
|
|
|
|
|
/* Read input model file */
|
|
|
|
{
|
2016-01-29 19:47:01 +08:00
|
|
|
error = gmio_stl_read_file(
|
|
|
|
model_filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 00:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write back input model file
|
|
|
|
* Write also the model file in big-endian STL format
|
|
|
|
*/
|
|
|
|
{
|
2016-01-29 19:47:01 +08:00
|
|
|
struct gmio_stl_write_options opts = {0};
|
|
|
|
opts.stlb_header = data.header;
|
2015-12-17 19:31:30 +08:00
|
|
|
error = gmio_stl_write_file(
|
2016-01-29 19:47:01 +08:00
|
|
|
GMIO_STL_FORMAT_BINARY_LE,
|
|
|
|
model_filepath_out,
|
|
|
|
gmio_stl_data_mesh(&data),
|
|
|
|
&opts);
|
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 00:03:12 +08:00
|
|
|
|
|
|
|
/* Big-endian version */
|
2015-12-17 19:31:30 +08:00
|
|
|
error = gmio_stl_write_file(
|
2016-01-29 19:47:01 +08:00
|
|
|
GMIO_STL_FORMAT_BINARY_BE,
|
|
|
|
model_filepath_out_be,
|
|
|
|
gmio_stl_data_mesh(&data),
|
|
|
|
&opts);
|
2015-09-11 00:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check input and output models are equal */
|
|
|
|
{
|
|
|
|
uint8_t buffer_in[2048] = {0};
|
|
|
|
uint8_t buffer_out[2048] = {0};
|
|
|
|
const size_t buff_size = 2048;
|
|
|
|
size_t bytes_read_in = 0;
|
|
|
|
size_t bytes_read_out = 0;
|
|
|
|
FILE* in = fopen(model_filepath, "rb");
|
|
|
|
FILE* out = fopen(model_filepath_out, "rb");
|
2015-11-06 22:29:29 +08:00
|
|
|
if (in == NULL || out == NULL) {
|
|
|
|
fclose_2(in, out);
|
|
|
|
perror("test_stlb_write()");
|
|
|
|
UTEST_FAIL("fopen() error for in/out model files");
|
|
|
|
}
|
2015-09-11 00:03:12 +08:00
|
|
|
do {
|
2016-01-29 19:47:01 +08:00
|
|
|
bytes_read_in = fread(buffer_in, 1, buff_size, in);
|
|
|
|
bytes_read_out = fread(buffer_out, 1, buff_size, out);
|
2015-11-06 22:29:29 +08:00
|
|
|
if (bytes_read_in != bytes_read_out) {
|
|
|
|
fclose_2(in, out);
|
|
|
|
UTEST_FAIL("Different byte count between in/out");
|
|
|
|
}
|
2016-01-29 19:47:01 +08:00
|
|
|
if (memcmp(buffer_in, buffer_out, buff_size) != 0) {
|
2015-11-06 22:29:29 +08:00
|
|
|
fclose_2(in, out);
|
|
|
|
UTEST_FAIL("Different buffer contents between in/out");
|
|
|
|
}
|
2015-09-11 00:03:12 +08:00
|
|
|
} while (!feof(in) && !feof(out)
|
|
|
|
&& bytes_read_in > 0 && bytes_read_out > 0);
|
2015-11-06 22:29:29 +08:00
|
|
|
fclose_2(in, out);
|
2015-09-11 00:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check output LE/BE models are equal */
|
|
|
|
{
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_data data_be = {0};
|
2016-01-29 19:47:01 +08:00
|
|
|
error = gmio_stl_read_file(
|
|
|
|
model_filepath_out_be,
|
|
|
|
gmio_stl_data_mesh_creator(&data_be),
|
|
|
|
NULL);
|
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 16:51:25 +08:00
|
|
|
UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header));
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_UINT(data.tri_array.count, data_be.tri_array.count);
|
2015-09-14 23:30:22 +08:00
|
|
|
UTEST_ASSERT(memcmp(data.tri_array.ptr,
|
|
|
|
data_be.tri_array.ptr,
|
2015-12-04 01:00:25 +08:00
|
|
|
data.tri_array.count * sizeof(struct gmio_stl_triangle))
|
2015-09-14 23:30:22 +08:00
|
|
|
== 0);
|
2015-09-11 16:51:25 +08:00
|
|
|
free(data_be.tri_array.ptr);
|
2015-09-11 00:03:12 +08:00
|
|
|
}
|
|
|
|
|
2015-09-11 16:51:25 +08:00
|
|
|
free(data.tri_array.ptr);
|
2015-09-11 00:03:12 +08:00
|
|
|
|
|
|
|
return NULL;
|
2015-05-28 23:33:42 +08:00
|
|
|
}
|
|
|
|
|
2015-09-11 22:36:03 +08:00
|
|
|
const char* test_stla_write()
|
|
|
|
{
|
|
|
|
const char* model_filepath = stl_grabcad_arm11_filepath;
|
|
|
|
const char* model_filepath_out = "temp/solid.stla";
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_data data = {0};
|
2015-09-11 22:36:03 +08:00
|
|
|
char header_str[GMIO_STLB_HEADER_SIZE + 1] = {0};
|
|
|
|
int error = GMIO_ERROR_OK;
|
|
|
|
|
|
|
|
/* Read input model file */
|
|
|
|
{
|
2016-01-29 19:47:01 +08:00
|
|
|
error = gmio_stl_read_file(
|
|
|
|
model_filepath, gmio_stl_data_mesh_creator(&data), NULL);
|
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 22:36:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the model to STL ascii format */
|
|
|
|
{
|
2016-01-29 19:47:01 +08:00
|
|
|
struct gmio_stl_write_options opts = {0};
|
|
|
|
gmio_stlb_header_to_printable_str(&data.header, header_str, '_');
|
|
|
|
opts.stla_solid_name = header_str;
|
|
|
|
opts.stla_float32_prec = 7;
|
|
|
|
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
|
2015-12-17 19:31:30 +08:00
|
|
|
error = gmio_stl_write_file(
|
2016-01-29 19:47:01 +08:00
|
|
|
GMIO_STL_FORMAT_ASCII,
|
|
|
|
model_filepath_out,
|
|
|
|
gmio_stl_data_mesh(&data),
|
|
|
|
&opts);
|
|
|
|
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
|
2015-09-11 22:36:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the output STL ascii model */
|
|
|
|
{
|
|
|
|
char trim_header_str[sizeof(header_str)] = {0};
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_data data_stla = {0};
|
2015-09-11 22:36:03 +08:00
|
|
|
size_t i = 0;
|
2016-01-29 19:47:01 +08:00
|
|
|
strncpy(trim_header_str, header_str, sizeof(header_str));
|
2015-09-11 22:36:03 +08:00
|
|
|
gmio_string_trim_from_end(trim_header_str, sizeof(header_str));
|
2016-01-29 19:47:01 +08:00
|
|
|
error = gmio_stl_read_file(
|
|
|
|
model_filepath_out,
|
|
|
|
gmio_stl_data_mesh_creator(&data_stla),
|
|
|
|
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);
|
2015-09-11 22:36:03 +08:00
|
|
|
for (i = 0; i < data.tri_array.count; ++i) {
|
2015-12-04 01:00:25 +08:00
|
|
|
const struct gmio_stl_triangle* lhs = &data.tri_array.ptr[i];
|
|
|
|
const struct gmio_stl_triangle* rhs = &data_stla.tri_array.ptr[i];
|
2016-01-27 00:03:58 +08:00
|
|
|
const bool tri_equal = gmio_stl_triangle_equal(lhs, rhs, 5);
|
2015-09-11 22:36:03 +08:00
|
|
|
UTEST_ASSERT(tri_equal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-28 23:33:42 +08:00
|
|
|
void generate_stlb_tests_models()
|
|
|
|
{
|
|
|
|
{
|
2015-08-12 05:57:57 +08:00
|
|
|
FILE* outfile = fopen("models/solid_empty.stlb", "wb");
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stream stream = gmio_stream_stdio(outfile);
|
2015-05-28 23:33:42 +08:00
|
|
|
gmio_stlb_write_header(&stream, GMIO_ENDIANNESS_LITTLE, NULL, 0);
|
|
|
|
fclose(outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-12-10 01:51:03 +08:00
|
|
|
struct gmio_stl_triangle tri = {
|
|
|
|
{ 0.f, 0.f, 1.f }, /* normal */
|
|
|
|
{ 0.f, 0.f, 0.f }, /* v1 */
|
|
|
|
{ 10.f, 0.f, 0.f }, /* v2 */
|
|
|
|
{ 5.f, 10.f, 0.f }, /* v3 */
|
|
|
|
0 /* attr */
|
|
|
|
};
|
|
|
|
struct gmio_stl_data data = {0};
|
|
|
|
|
|
|
|
data.tri_array.ptr = &tri;
|
|
|
|
data.tri_array.count = 1;
|
|
|
|
|
2015-12-17 19:31:30 +08:00
|
|
|
gmio_stl_write_file(
|
|
|
|
GMIO_STL_FORMAT_BINARY_LE,
|
2016-01-29 19:47:01 +08:00
|
|
|
"models/solid_one_facet.le_stlb",
|
|
|
|
gmio_stl_data_mesh(&data),
|
|
|
|
NULL);
|
2015-12-17 19:31:30 +08:00
|
|
|
gmio_stl_write_file(
|
|
|
|
GMIO_STL_FORMAT_BINARY_BE,
|
2016-01-29 19:47:01 +08:00
|
|
|
"models/solid_one_facet.be_stlb",
|
|
|
|
gmio_stl_data_mesh(&data),
|
|
|
|
NULL);
|
2015-05-28 23:33:42 +08:00
|
|
|
}
|
|
|
|
}
|