star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

commit f575562b53d37e452db8df6054a89f0ac64ce54e
parent 94fc4340b6fe54977cf9ee1b057ddaae161fa3c7
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 25 Sep 2020 12:42:04 +0200

Merge branch 'release_0.1.0'

Diffstat:
MREADME.md | 6+++---
Mcmake/CMakeLists.txt | 3+++
Msrc/test_sg3d_cube_behind_cube.c | 4++--
Msrc/test_sg3d_cube_in_cube.c | 4++--
Msrc/test_sg3d_cube_on_cube.c | 2+-
Asrc/test_sg3d_invalid_models.c | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sg3d_many_enclosures.c | 2+-
Asrc/test_sg3d_multi_media.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sg3d_some_enclosures.c | 2+-
Msrc/test_sg3d_utils.h | 11++++++-----
Msrc/test_sg3d_utils2.h | 2+-
11 files changed, 209 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md @@ -14,7 +14,7 @@ How to build Star-geometry-3d relies on the [CMake](http://www.cmake.org) and the [RCMake](https://gitlab.com/vaplv/rcmake/) package to build and depends on the [RSys](https://gitlab.com/vaplv/rsys/) library. Some tests -also depends on the [SD3UT](https://gitlab.com/meso-star/star-3dut/) +also depend on the [SD3UT](https://gitlab.com/meso-star/star-3dut/) library. First ensure that CMake and a C compiler that is compliant with C89 are @@ -31,9 +31,9 @@ Release notes First version and implementation of the star-geometry-3d API. - Creation of geometries in multiple steps, allowing advanced - deduplication and application-data management; + deduplication and application-data management -- Dump of geometries as OBJ or VTK files or as C code chunks; +- Dump of geometries as OBJ or VTK files or as C code chunks License ------- diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -150,6 +150,7 @@ if(NOT NO_TEST) build_test(test_sg3d_cube_in_cube) build_test(test_sg3d_cube_on_cube) build_test(test_sg3d_invalid_models) + build_test(test_sg3d_multi_media) build_test(test_sg3d_some_enclosures test_sg3d_utils2.h) build_test(test_sg3d_some_triangles test_sg3d_utils2.h) build_test(test_sg3d_unspecified_properties) @@ -170,6 +171,7 @@ if(NOT NO_TEST) rcmake_copy_runtime_libraries(test_sg3d_cube_in_cube) rcmake_copy_runtime_libraries(test_sg3d_cube_on_cube) rcmake_copy_runtime_libraries(test_sg3d_invalid_models) + rcmake_copy_runtime_libraries(test_sg3d_multi_media) rcmake_copy_runtime_libraries(test_sg3d_some_enclosures) rcmake_copy_runtime_libraries(test_sg3d_some_triangles) rcmake_copy_runtime_libraries(test_sg3d_unspecified_properties) @@ -182,6 +184,7 @@ if(NOT NO_TEST) add_test(test_sg3d_cube_in_cube test_sg3d_cube_in_cube) add_test(test_sg3d_cube_on_cube test_sg3d_cube_on_cube) add_test(test_sg3d_invalid_models test_sg3d_invalid_models) + add_test(test_sg3d_multi_media test_sg3d_multi_media) add_test(test_sg3d_some_enclosures test_sg3d_some_enclosures) add_test(test_sg3d_some_triangles test_sg3d_some_triangles) add_test(test_sg3d_unspecified_properties test_sg3d_unspecified_properties) diff --git a/src/test_sg3d_cube_behind_cube.c b/src/test_sg3d_cube_behind_cube.c @@ -77,7 +77,7 @@ main(int argc, char** argv) OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); d3(ctx.offset, -2, -2, 20); - ctx.scale = 5; + d3_splat(ctx.scale, 5); /* Second cube (front: 0, back: 1), right-handed normal outside */ OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); @@ -92,7 +92,7 @@ main(int argc, char** argv) SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); d3(ctx.offset, -3, -3, 30); - ctx.scale = 7; + d3_splat(ctx.scale, 7); ctx.front_media = medium1; ctx.back_media = medium0; diff --git a/src/test_sg3d_cube_in_cube.c b/src/test_sg3d_cube_in_cube.c @@ -67,7 +67,7 @@ main(int argc, char** argv) OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); d3(ctx.offset, -1, -1, -1); - ctx.scale = 3; + d3_splat(ctx.scale, 3); ctx.reverse_vrtx = 1; /* Second cube (front: 0, back: 1), right-handed normal inside */ @@ -83,7 +83,7 @@ main(int argc, char** argv) SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); d3(ctx.offset, -4, -4, -4); - ctx.scale = 10; + d3_splat(ctx.scale, 10); ctx.reverse_vrtx = 1; ctx.reverse_med = 1; ctx.front_media = medium1; diff --git a/src/test_sg3d_cube_on_cube.c b/src/test_sg3d_cube_on_cube.c @@ -74,7 +74,7 @@ main(int argc, char** argv) ctx.positions = box_vertices; /* Can use distorded cube for cube #3 */ d3(ctx.offset, 0, 0, 0); - ctx.scale = 4; + d3_splat(ctx.scale, 4); ctx.reverse_vrtx = 1; ctx.reverse_med = 1; ctx.front_media = medium2; diff --git a/src/test_sg3d_invalid_models.c b/src/test_sg3d_invalid_models.c @@ -0,0 +1,116 @@ +/* Copyright (C) 2019-2020 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "sg3d.h" +#include "test_sg3d_utils.h" + +#include <rsys/double3.h> + +#include <stdio.h> + + /* The following array lists the indices toward the 3D vertices of each + * triangle. + * ,2---,3 ,2----3 + * ,' | ,'/| ,'/| \ | + * 6----7' / | 6' / | \ | Y + * |', | / ,1 | / ,0---,1 | + * | ',|/,' |/,' | ,' o--X + * 4----5' 4----5' / + * Front, right Back, left and Z + * and Top faces bottom faces + * + * The right-handed geometrical normal is outside the cube */ +static const unsigned +cube_indices2[12/*#triangles*/ * 3/*#indices per triangle*/] = { + 0, 3, 1, 0, 2, 3, /* Front face */ + 0, 6, 2, 0, 4, 6, /* Left face*/ + 4, 5, 7, 6, 4, 7, /* Back face */ + 3, 7, 5, 1, 3, 5, /* Right face */ + 2, 6, 7, 3, 2, 7, /* Top face */ + 0, 1, 5, 4, 0, 5 /* Bottom face */ +}; + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sg3d_device* dev; + struct sg3d_geometry* geom; + struct context ctx = CONTEXT_NULL__; + struct sg3d_geometry_add_callbacks callbacks = SG3D_ADD_CALLBACKS_NULL__; + unsigned count; + (void)argc, (void)argv; + + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sg3d_device_create(NULL, &allocator, 1, &dev)); + OK(sg3d_geometry_create(dev, &geom)); + SG3D(device_ref_put(dev)); + + callbacks.get_indices = get_indices; + callbacks.get_properties = get_properties; + callbacks.get_position = get_position; + + ctx.positions = cube_vertices; + ctx.indices = cube_indices; + ctx.front_media = medium0; + ctx.back_media = medium1; + ctx.intface = intface0; + + /* First cube (front: 0, back: 1), right-handed normal outside */ + OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); + + ctx.indices = cube_indices2; + + /* Second cube (front: 0, back: 1), right-handed normal outside + * Same cube location, but opposite diagonals on sides than first cube */ + OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); + + OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_dump_as_c_code(geom, stdout, "invalid_1", + SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); + + d3(ctx.offset, -4, -4, -4); + d3_splat(ctx.scale, 10); + ctx.reverse_vrtx = 1; + ctx.reverse_med = 1; + ctx.front_media = medium1; + ctx.back_media = medium0; + + /* Third cube (front: 0, back: 1), right-handed normal inside */ + OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); + + OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_dump_as_c_code(geom, stdout, "invalid_2", + SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); + + OK(sg3d_geometry_dump_as_vtk(geom, stdout)); + + SG3D(geometry_ref_put(geom)); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} +\ No newline at end of file diff --git a/src/test_sg3d_many_enclosures.c b/src/test_sg3d_many_enclosures.c @@ -74,7 +74,7 @@ main(int argc, char** argv) double center_y = 2 * (1 + NB_CYL_Z) * (j - NB_CYL_Y / 2); m_in = (unsigned)k; m_out = (unsigned)(k + 1); - ctx.ctx.scale = k + 1; + d3_splat(ctx.ctx.scale, k + 1); #ifdef MITIGATE_EMBREE_181 /* Mitigate Embree issue #181 * We cannot keep perfect alignment of cylinders diff --git a/src/test_sg3d_multi_media.c b/src/test_sg3d_multi_media.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2019-2020 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "sg3d.h" +#include "test_sg3d_utils.h" + +#include <rsys/double3.h> + +#include <stdio.h> + +static const unsigned multi_media[12] = { 4, 4, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1 }; +static const unsigned multi_intface[12] = { 4, 4, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1 }; + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sg3d_device* dev; + struct sg3d_geometry* geom; + struct context ctx = CONTEXT_NULL__; + struct sg3d_geometry_add_callbacks callbacks = SG3D_ADD_CALLBACKS_NULL__; + unsigned count; + (void)argc, (void)argv; + + OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); + OK(sg3d_device_create(NULL, &allocator, 1, &dev)); + OK(sg3d_geometry_create(dev, &geom)); + SG3D(device_ref_put(dev)); + + callbacks.get_indices = get_indices; + callbacks.get_properties = get_properties; + callbacks.get_position = get_position; + + ctx.positions = cube_vertices; + ctx.indices = cube_indices; + ctx.front_media = medium0; + ctx.back_media = multi_media; + ctx.intface = multi_intface; + + OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx)); + + OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count)); + CHK(count == 0); + OK(sg3d_geometry_dump_as_c_code(geom, stdout, "multi_media", + SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC)); + + OK(sg3d_geometry_dump_as_vtk(geom, stdout)); + + SG3D(geometry_ref_put(geom)); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} +\ No newline at end of file diff --git a/src/test_sg3d_some_enclosures.c b/src/test_sg3d_some_enclosures.c @@ -74,7 +74,7 @@ main(int argc, char** argv) double center_y = 2 * (1 + NB_CYL_Z) * (j - NB_CYL_Y / 2); m_in = (unsigned)k; m_out = (unsigned)(k + 1); - ctx.ctx.scale = k + 1; + d3_splat(ctx.ctx.scale, k + 1); #ifdef MITIGATE_EMBREE_181 /* Mitigate Embree issue #181 * We cannot keep perfect alignment of cylinders diff --git a/src/test_sg3d_utils.h b/src/test_sg3d_utils.h @@ -17,6 +17,8 @@ #define TEST_SG3D_UTILS_H #include <rsys/mem_allocator.h> +#include <rsys/double3.h> + #include <stdio.h> #define OK(Cond) CHK((Cond) == RES_OK) @@ -97,11 +99,11 @@ struct context { const unsigned* intface; void* custom; double offset[3]; - double scale; + double scale[3]; char reverse_vrtx, reverse_med; }; #define CONTEXT_NULL__ {\ - NULL, NULL, NULL, NULL, NULL, NULL, {0,0,0}, 1, 0, 0\ + NULL, NULL, NULL, NULL, NULL, NULL, {0,0,0}, {1, 1, 1}, 0, 0\ } static const unsigned medium0[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -128,10 +130,9 @@ static INLINE void get_position(const unsigned ivert, double pos[3], void* context) { const struct context* ctx = context; + double tmp[3]; ASSERT(pos && ctx); - pos[0] = ctx->positions[ivert * 3 + 0] * ctx->scale + ctx->offset[0]; - pos[1] = ctx->positions[ivert * 3 + 1] * ctx->scale + ctx->offset[1]; - pos[2] = ctx->positions[ivert * 3 + 2] * ctx->scale + ctx->offset[2]; + d3_add(pos, d3_mul(tmp, ctx->positions + ivert * 3, ctx->scale), ctx->offset); } static INLINE void diff --git a/src/test_sg3d_utils2.h b/src/test_sg3d_utils2.h @@ -48,7 +48,7 @@ get_s3dut_position(const unsigned ivert, double pos[3], void* context) ASSERT(pos && ctx); ASSERT(ivert < ctx->data.nvertices); (void)ivert; - d3_add(pos, d3_muld(tmp, ctx->data.positions + ivert * 3, ctx->ctx.scale), + d3_add(pos, d3_mul(tmp, ctx->data.positions + ivert * 3, ctx->ctx.scale), ctx->ctx.offset); }