commit f92bdf0c35353861377ff6209c2f93fe7e325402
parent 0bd40758ecdebec80ca453607d902a1b6ac0fa1b
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 31 Oct 2019 15:22:01 +0100
Add missing file
Diffstat:
1 file changed, 202 insertions(+), 0 deletions(-)
diff --git a/src/test_senc2d_undefined_medium.c b/src/test_senc2d_undefined_medium.c
@@ -0,0 +1,202 @@
+/* Copyright (C) |Meso|Star> 2016-2018 (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 "senc2d.h"
+#include "senc2d_s2d_wrapper.h"
+#include "test_senc2d_utils.h"
+
+#include <rsys/double2.h>
+
+static void
+test(enum senc2d_convention convention)
+{
+ struct mem_allocator allocator;
+ struct senc2d_descriptor* desc = NULL;
+ struct senc2d_device* dev = NULL;
+ struct senc2d_scene* scn = NULL;
+ struct senc2d_enclosure* enclosure;
+ struct senc2d_enclosure_header header;
+ unsigned medium;
+ unsigned gid;
+ struct context ctx;
+ unsigned i, s, ecount, vcount, scount;
+ int is_front, is_in;
+ unsigned media[4];
+ unsigned rev_box_indices[sizeof(box_indices) / sizeof(*box_indices)];
+
+ /* Create the box with reversed segments */
+ FOR_EACH(i, 0, sizeof(rev_box_indices) / sizeof(*rev_box_indices)) {
+ switch (i % 2) {
+ case 0: rev_box_indices[i] = box_indices[i + 1]; break;
+ case 1: rev_box_indices[i] = box_indices[i - 1]; break;
+ }
+ }
+ OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
+ OK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev));
+
+ OK(senc2d_scene_create(dev, convention, &scn));
+ is_front = (convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0;
+ is_in = (convention & SENC2D_CONVENTION_NORMAL_INSIDE) != 0;
+
+ /* A 2D square.
+ * 2 enclosures (inside, outside) sharing the same segments,
+ * but opposite sides */
+ ctx.positions = box_vertices;
+ ctx.indices = box_indices;
+ ctx.scale = 1;
+ ctx.reverse_vrtx = 0;
+ ctx.reverse_med = 0;
+ d2(ctx.offset, 0, 0);
+ ctx.front_media = media;
+ ctx.back_media = medium1;
+
+ /* Can add the same segments again defined/undefined media in any order */
+
+ /* Add geometry with no media information */
+ for (i = 0; i < sizeof(media) / sizeof(*media); i++)
+ media[i] = SENC2D_UNDEFINED_MEDIUM;
+ OK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
+ NULL, nvertices, get_position, &ctx));
+
+ /* Cannot run analyze with undefined media */
+ BA(senc2d_scene_analyze(scn, &desc));
+
+ /* Same geometry, front media are defined for odd segments */
+ for (i = 0; i < sizeof(media) / sizeof(*media); i++)
+ media[i] = (i % 2) ? 0 : SENC2D_UNDEFINED_MEDIUM;
+ OK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
+ NULL, nvertices, get_position, &ctx));
+
+ /* Cannot run analyze with undefined media */
+ BA(senc2d_scene_analyze(scn, &desc));
+
+ /* Get the deduplicated geometry without (successful) analyze */
+ OK(senc2d_scene_get_unique_vertices_count(scn, &vcount));
+ CHK(vcount == nvertices);
+ OK(senc2d_scene_get_unique_segments_count(scn, &scount));
+ CHK(vcount == nsegments);
+ FOR_EACH(i, 0, vcount) {
+ int j;
+ unsigned med[2], ids[2];
+ OK(senc2d_scene_get_unique_segment(scn, i, ids));
+ OK(senc2d_scene_get_unique_segment_media(scn, i, med));
+ CHK(med[0] == ((i % 2) ? 0 : SENC2D_UNDEFINED_MEDIUM) && med[1] == 1);
+ FOR_EACH(j, 0, 2) {
+ double pos[2];
+ CHK(ids[j] < vcount);
+ OK(senc2d_scene_get_unique_vertex(scn, ids[j], pos));
+ }
+ }
+
+ /* Same information again, using a reversed box */
+ ctx.indices = rev_box_indices;
+ SWAP(const unsigned*, ctx.front_media, ctx.back_media);
+ OK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
+ NULL, nvertices, get_position, &ctx));
+
+ /* Cannot run analyze with undefined media */
+ BA(senc2d_scene_analyze(scn, &desc));
+
+ /* Define media for remaining segments, using reversed box */
+ for (i = 0; i < sizeof(media) / sizeof(*media); i++)
+ media[i] = (i % 2) ? SENC2D_UNDEFINED_MEDIUM : 0;
+ OK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
+ NULL, nvertices, get_position, &ctx));
+
+ /* Get the deduplicated geometry without (successful) analyze */
+ OK(senc2d_scene_get_unique_vertices_count(scn, &vcount));
+ CHK(vcount == nvertices);
+ OK(senc2d_scene_get_unique_segments_count(scn, &scount));
+ CHK(scount == nsegments);
+ FOR_EACH(i, 0, scount) {
+ int j;
+ unsigned med[2], ids[2];
+ OK(senc2d_scene_get_unique_segment(scn, i, ids));
+ OK(senc2d_scene_get_unique_segment_media(scn, i, med));
+ CHK(med[0] == 0 && med[1] == 1);
+ FOR_EACH(j, 0, 2) {
+ double pos[2];
+ CHK(ids[j] < vcount);
+ OK(senc2d_scene_get_unique_vertex(scn, ids[j], pos));
+ }
+ }
+
+ /* Can run analyze */
+ OK(senc2d_scene_analyze(scn, &desc));
+ OK(senc2d_descriptor_ref_put(desc));
+
+ /* Define media for all segments, nothing new here */
+ for (i = 0; i < sizeof(media) / sizeof(*media); i++)
+ media[i] = 0;
+ OK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
+ NULL, nvertices, get_position, &ctx));
+
+ /* Define incoherent media for some segments */
+ for (i = 0; i < sizeof(media) / sizeof(*media); i++)
+ media[i] = (i % 2);
+ BA(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
+ NULL, nvertices, get_position, &ctx));
+
+ /* Scene is still OK and can be analyzed */
+ OK(senc2d_scene_analyze(scn, &desc));
+
+ OK(senc2d_descriptor_get_global_segments_count(desc, &scount));
+ CHK(scount == sizeof(media) / sizeof(*media));
+
+ OK(senc2d_descriptor_get_enclosure_count(desc, &ecount));
+ CHK(ecount == 2);
+
+ FOR_EACH(i, 0, ecount) {
+ OK(senc2d_descriptor_get_enclosure(desc, i, &enclosure));
+ OK(senc2d_enclosure_get_header(enclosure, &header));
+
+ CHK(header.enclosure_id == i);
+ CHK(header.enclosed_media_count == 1);
+ OK(senc2d_enclosure_get_medium(enclosure, 0, &medium));
+ /* Geometrical normals point outside the cube in input segments:
+ * if convention is front, front medium (0) is outside,
+ * that is medium 0's enclosure is infinite */
+ CHK(is_front == ((medium == 0) == header.is_infinite));
+ CHK(header.segment_count == nsegments);
+ CHK(header.unique_segment_count == nsegments);
+ CHK(header.vertices_count == nvertices);
+ CHK(header.is_infinite == (i == 0));
+
+ FOR_EACH(s, 0, header.segment_count) {
+ OK(senc2d_enclosure_get_segment_global_id(enclosure, s, &gid));
+ CHK(gid == s);
+ }
+ OK(senc2d_enclosure_ref_put(enclosure));
+ }
+
+ SENC2D(scene_ref_put(scn));
+ SENC2D(device_ref_put(dev));
+ SENC2D(descriptor_ref_put(desc));
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+}
+
+int
+main(int argc, char** argv)
+{
+ (void)argc, (void)argv;
+ test(SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE);
+ test(SENC2D_CONVENTION_NORMAL_BACK | SENC2D_CONVENTION_NORMAL_INSIDE);
+ test(SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_OUTSIDE);
+ test(SENC2D_CONVENTION_NORMAL_BACK | SENC2D_CONVENTION_NORMAL_OUTSIDE);
+ return 0;
+}