commit 20335d659475e245f61017ef1d5858f2f1749188
parent b5c3b1d88a08b50eb22015ac3b8313644fbbd782
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 24 Sep 2018 13:35:26 +0200
Add a convention for normals' orientation in output
Diffstat:
14 files changed, 204 insertions(+), 89 deletions(-)
diff --git a/src/senc2d.h b/src/senc2d.h
@@ -73,12 +73,46 @@ struct senc2d_enclosure_header {
char is_infinite;
};
-/* Type used to define the convention for Front / Back sides.
- * When looking at the Front side, vertices (in the order they are given in
- * segment definitions) can be seen either CW or CCW. */
-enum senc2d_side_convention {
- SENC2D_CONVENTION_CW, /* Order is ClockWise */
- SENC2D_CONVENTION_CCW /* Order is CounterClockWise */
+/* We consider the geometrical normal Ng to a segment V0 V1
+ * that verifies "(V0, V0V1, Ng) is a direct system".
+ *
+ * The user can set the convention used to determine which side of
+ * a segment is to be considered front/back by using the flags :
+ * SENC2D_CONVENTION_NORMAL_FRONT => Ng points toward the front side,
+ * SENC2D_CONVENTION_NORMAL_BACK => Ng points toward the back side.
+ *
+ * Additionaly the user can set the convention used to output enclosures
+ * so that Ng points toward the enclosure or on the opposite direction
+ * (for a closed enclosure Ng points toward the inside or toward the outside)
+ * by using the flags :
+ * SENC2D_CONVENTION_NORMAL_INSIDE => Ng points toward the enclosure,
+ * SENC2D_CONVENTION_NORMAL_OUTSIDE => Ng points to the opposite of the enclosure.
+ *
+ * Note that normals in output data can be opposite to normals in input data
+ * (vertices are then given in reverse order).
+ *
+ * Also note that both sides of a segment can be part of the same enclosure;
+ * in this case the 2 sides will be given with opposite Ng (meaning they
+ * will be given with opposite vertices order).
+ */
+enum senc2d_convention {
+ /*
+ * Convention regarding FRONT/BACK sides in input data
+ */
+
+ /* Geometrical normals point toward the front side */
+ SENC2D_CONVENTION_NORMAL_FRONT = BIT(0),
+ /* Geometrical normals point toward the back side */
+ SENC2D_CONVENTION_NORMAL_BACK = BIT(1),
+
+ /*
+ * Convention regarding geometrical normals in output data
+ */
+
+ /* Geometrical normals point toward the enclosure */
+ SENC2D_CONVENTION_NORMAL_INSIDE = BIT(2),
+ /* Geometrical normals point to the opposite of the enclosure */
+ SENC2D_CONVENTION_NORMAL_OUTSIDE = BIT(3)
};
BEGIN_DECLS
@@ -112,7 +146,7 @@ senc2d_device_ref_put
SENC2D_API res_T
senc2d_scene_create
(struct senc2d_device* device,
- const enum senc2d_side_convention front_side_convention,
+ const enum senc2d_convention convention,
struct senc2d_scene** scene);
/* Add a new set of vertices and segments to the scene.
@@ -141,7 +175,7 @@ senc2d_scene_analyze
SENC2D_API res_T
senc2d_scene_get_convention
(const struct senc2d_scene* scene,
- enum senc2d_side_convention* front_side_convention);
+ enum senc2d_convention* convention);
SENC2D_API res_T
senc2d_scene_get_segments_count
diff --git a/src/senc2d_scene.c b/src/senc2d_scene.c
@@ -48,14 +48,16 @@ scene_release(ref_T * ref)
res_T
senc2d_scene_create
(struct senc2d_device* dev,
- const enum senc2d_side_convention conv,
+ const enum senc2d_convention conv,
struct senc2d_scene** out_scn)
{
struct senc2d_scene* scn = NULL;
res_T res = RES_OK;
if(!dev || !out_scn
- || (conv != SENC2D_CONVENTION_CW && conv != SENC2D_CONVENTION_CCW))
+ /* Convention must be set both regarding FRONT/BACK and INSIDE/OUTSIDE */
+ || !(conv & (SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_BACK))
+ || !(conv & (SENC2D_CONVENTION_NORMAL_INSIDE | SENC2D_CONVENTION_NORMAL_OUTSIDE)))
return RES_BAD_ARG;
scn = MEM_CALLOC(dev->allocator, 1, sizeof(struct senc2d_scene));
@@ -283,10 +285,10 @@ error:
res_T
senc2d_scene_get_convention
(const struct senc2d_scene* scn,
- enum senc2d_side_convention* front_side_convention)
+ enum senc2d_convention* convention)
{
- if(!scn || !front_side_convention) return RES_BAD_ARG;
- *front_side_convention = scn->convention;
+ if(!scn || !convention) return RES_BAD_ARG;
+ *convention = scn->convention;
return RES_OK;
}
diff --git a/src/senc2d_scene_analyze.c b/src/senc2d_scene_analyze.c
@@ -396,9 +396,9 @@ canceled:
norm = d2_normalize(normal, normal);
ASSERT(norm); (void)norm;
- /* Geometrical normal points toward the front side
- * if convention is CW, toward back side if CCW */
- if(SEGSIDE_IS_FRONT(side_id) == (scn->convention == SENC2D_CONVENTION_CW)) {
+ /* Orient the geometrical normal according to the convention */
+ if(SEGSIDE_IS_FRONT(side_id)
+ == ((scn->convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0)) {
max_y_ny += normal[1];
} else {
max_y_ny -= normal[1];
@@ -791,11 +791,11 @@ collect_and_link_neighbours
const seg_id_t crt_id = current->seg_id;
const seg_id_t ccw_id = ccw_neighbour->seg_id;
/* Facing sides of segments */
- const int cw = (scn->convention == SENC2D_CONVENTION_CW);
+ const int front = ((scn->convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0);
const enum side_id crt_side
- = current->normal_toward_next_neighbour == cw ? SIDE_FRONT : SIDE_BACK;
+ = current->normal_toward_next_neighbour == front ? SIDE_FRONT : SIDE_BACK;
const enum side_id ccw_side
- = ccw_neighbour->normal_toward_next_neighbour == cw ?
+ = ccw_neighbour->normal_toward_next_neighbour == front ?
SIDE_BACK : SIDE_FRONT;
/* Index of sides in segsides */
const side_id_t crt_side_idx = SEGIDxSIDE_2_SEGSIDE(crt_id, crt_side);
@@ -834,22 +834,32 @@ build_result
struct segment_enc* segments_enc;
const struct segment_comp* segments_comp;
struct htable_vrtx_id vtable;
+ struct senc2d_scene* scn;
+ enum senc2d_convention convention;
+ int output_normal_in, normals_front, normals_back;
int64_t sg;
int64_t ee;
ASSERT(desc && connex_components && segments_comp_array && res);
alloc = descriptor_get_allocator(desc);
+ scn = desc->scene;
+ convention = scn->convention;
+ output_normal_in = (scn->convention & SENC2D_CONVENTION_NORMAL_INSIDE) != 0;
+ normals_front = (scn->convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0;
+ normals_back = (scn->convention & SENC2D_CONVENTION_NORMAL_BACK) != 0;
+ ASSERT(normals_back != normals_front);
+ ASSERT(output_normal_in != ((scn->convention & SENC2D_CONVENTION_NORMAL_OUTSIDE) != 0));
ASSERT(darray_ptr_component_descriptor_size_get(connex_components)
<= COMPONENT_MAX__);
cc_descriptors = darray_ptr_component_descriptor_cdata_get(connex_components);
enclosures = darray_enclosure_data_get(&desc->enclosures);
- segments_in = darray_segment_in_cdata_get(&desc->scene->segments_in);
+ segments_in = darray_segment_in_cdata_get(&scn->segments_in);
segments_comp = darray_segment_comp_cdata_get(segments_comp_array);
#pragma omp single
{
res_T tmp_res =
- darray_segment_enc_resize(&desc->segments_enc, desc->scene->nusegs);
+ darray_segment_enc_resize(&desc->segments_enc, scn->nusegs);
if(tmp_res != RES_OK) *res = tmp_res;
}/* Implicit barrier here. */
if(*res != RES_OK) return;
@@ -857,7 +867,7 @@ build_result
/* Build global enclosure information */
#pragma omp for
- for(sg = 0; sg < (int64_t)desc->scene->nusegs; sg++) {
+ for(sg = 0; sg < (int64_t)scn->nusegs; sg++) {
seg_id_t s = (seg_id_t)sg;
const component_id_t cf_id = segments_comp[s].component[SIDE_FRONT];
const component_id_t cb_id = segments_comp[s].component[SIDE_BACK];
@@ -899,7 +909,7 @@ build_result
enc->header.is_infinite = (e == 0);
ASSERT(darray_uchar_size_get(&enc->tmp_enclosed_media) <= UINT_MAX);
- ASSERT(enc->header.enclosed_media_count <= desc->scene->nmeds);
+ ASSERT(enc->header.enclosed_media_count <= scn->nmeds);
OK2(bool_array_of_media_to_darray_media
(&enc->enclosed_media, &enc->tmp_enclosed_media));
enc->header.enclosed_media_count
@@ -928,8 +938,7 @@ build_result
OK2(darray_vrtx_id_reserve(&enc->vertices, enc->side_count + 1));
/* New vertex numbering scheme local to the enclosure */
htable_vrtx_id_clear(&vtable);
- ASSERT(desc->scene->nusegs
- == darray_segment_in_size_get(&desc->scene->segments_in));
+ ASSERT(scn->nusegs == darray_segment_in_size_get(&scn->segments_in));
/* Put at the end the back-faces of segments that also have their
* front-face in the list. */
for(s = SEGSIDE_2_SEG(enc->side_range.first);
@@ -964,21 +973,38 @@ build_result
ASSERT(segments_enc[s].enclosure[SIDE_FRONT] == e
|| segments_enc[s].enclosure[SIDE_BACK] == e);
if(segments_enc[s].enclosure[SIDE_FRONT] == e) {
+ /* Front side of the original triangle is member of the enclosure */
+ int input_normal_in = normals_front;
+ int revert_segment = (input_normal_in != output_normal_in);
++enc->header.segment_count;
seg = darray_segment_in_data_get(&enc->sides) + fst_idx++;
-
- FOR_EACH(i, 0, 2) seg->medium[i] = seg_in->medium[i];
+ FOR_EACH(i, 0, 2) {
+ int ii = revert_segment ? 1 - i : i;
+ seg->medium[i] = seg_in->medium[ii];
+ }
seg->global_id = seg_in->global_id;
- FOR_EACH(i, 0, 2) seg->vertice_id[i] = vertice_id[i];
+ FOR_EACH(i, 0, 2) {
+ int ii = revert_segment ? 1 - i : i;
+ seg->vertice_id[i] = vertice_id[ii];
+ }
}
if(segments_enc[s].enclosure[SIDE_BACK] == e) {
+ /* Back side of the original triangle is member of the enclosure */
+ int input_normal_in = normals_back;
+ int revert_segment = (input_normal_in != output_normal_in);
++enc->header.segment_count;
+ /* If both sides are in the enclosure, put the second side at the end */
seg = darray_segment_in_data_get(&enc->sides) +
((segments_enc[s].enclosure[SIDE_FRONT] == e) ? --sgd_idx : fst_idx++);
-
- FOR_EACH(i, 0, 2) seg->medium[i] = seg_in->medium[1 - i];
+ FOR_EACH(i, 0, 2) {
+ int ii = revert_segment ? 1 - i : i;
+ seg->medium[i] = seg_in->medium[ii];
+ }
seg->global_id = seg_in->global_id;
- FOR_EACH(i, 0, 2) seg->vertice_id[i] = vertice_id[1 - i];
+ FOR_EACH(i, 0, 2) {
+ int ii = revert_segment ? 1 - i : i;
+ seg->vertice_id[i] = vertice_id[ii];
+ }
}
if(fst_idx == sgd_idx) break;
}
diff --git a/src/senc2d_scene_c.h b/src/senc2d_scene_c.h
@@ -155,7 +155,7 @@ side_range_init(struct mem_allocator* alloc, struct side_range* data)
struct senc2d_scene {
/* Front / Back sides convention */
- enum senc2d_side_convention convention;
+ enum senc2d_convention convention;
/* Segment information as given by user; no duplicates here */
struct darray_segment_in segments_in;
diff --git a/src/test_senc2d_descriptor.c b/src/test_senc2d_descriptor.c
@@ -39,7 +39,9 @@ main(int argc, char** argv)
CHK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)
== RES_OK);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
/* A 2D square */
ctx.positions = box_vertices;
@@ -75,14 +77,22 @@ main(int argc, char** argv)
CHK(count == 2);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 0, &count) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 9, &count) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 0, NULL) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 9, &count) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 0, NULL) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 9, NULL) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 9, NULL) == RES_BAD_ARG);
- CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 0, &count) == RES_OK);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 0, &count)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 9, &count)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 0, NULL)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 9, &count)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 0, NULL)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 9, NULL)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(NULL, 9, NULL)
+ == RES_BAD_ARG);
+ CHK(senc2d_descriptor_get_enclosure_count_by_medium(desc, 0, &count)
+ == RES_OK);
CHK(count == 1);
diff --git a/src/test_senc2d_enclosure.c b/src/test_senc2d_enclosure.c
@@ -47,7 +47,9 @@ main(int argc, char** argv)
CHK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)
== RES_OK);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
s2d_attribs.type = S2D_FLOAT2;
s2d_attribs.usage = S2D_POSITION;
@@ -185,7 +187,9 @@ main(int argc, char** argv)
/* Same 2D square, but with a hole (incomplete).
* 1 single enclosure including both sides of segments */
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CCW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_BACK | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
ctx.positions = box_vertices;
ctx.indices = box_indices;
diff --git a/src/test_senc2d_inconsistant_square.c b/src/test_senc2d_inconsistant_square.c
@@ -59,6 +59,7 @@ cmp_seg
unsigned i, j;
ASSERT(enclosure && seg2 && vertices2 && seg_eq && seg_reversed);
+
CHK(senc2d_enclosure_get_segment(enclosure, iseg, seg1) == RES_OK);
FOR_EACH(i, 0, 2) {
CHK(senc2d_enclosure_get_vertex(enclosure, seg1[i], s1[i]) == RES_OK);
@@ -90,7 +91,7 @@ cmp_seg
}
void
-test(enum senc2d_side_convention convention)
+test(enum senc2d_convention convention)
{
struct mem_allocator allocator;
struct senc2d_descriptor* desc = NULL;
@@ -98,12 +99,13 @@ test(enum senc2d_side_convention convention)
struct senc2d_scene* scn = NULL;
struct senc2d_enclosure* enclosure;
struct senc2d_enclosure_header header;
- enum senc2d_side_convention conv;
+ enum senc2d_convention conv;
+ int conv_front, conv_in;
struct context ctx;
unsigned i, e, ecount;
CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
- CHK(senc2d_device_create(NULL, &allocator, 1, 1, &dev)
+ CHK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)
== RES_OK);
CHK(senc2d_scene_create(dev, convention, &scn) == RES_OK);
@@ -132,41 +134,48 @@ test(enum senc2d_side_convention convention)
CHK(senc2d_scene_get_convention(scn, &conv) == RES_OK);
CHK(conv == convention);
+ conv_front = (conv & SENC2D_CONVENTION_NORMAL_FRONT) != 0;
+ conv_in = (conv & SENC2D_CONVENTION_NORMAL_INSIDE) != 0;
FOR_EACH(e, 0, ecount) {
- unsigned medium, expected_external_medium;
+ unsigned medium, expected_external_medium, expected_medium;
char name[128];
- int common;
+ int front_inside;
+ int expected_side;
CHK(senc2d_descriptor_get_enclosure(desc, e, &enclosure) == RES_OK);
CHK(senc2d_enclosure_get_header(enclosure, &header) == RES_OK);
CHK(header.enclosed_media_count == 1);
CHK(senc2d_enclosure_get_medium(enclosure, 0, &medium) == RES_OK);
- /* If CW the external enclosure's medium should be 0, 1 if CCW */
- expected_external_medium = conv == SENC2D_CONVENTION_CW ? 0 : 1;
- CHK(header.is_infinite == (medium == expected_external_medium));
- /* Common media, for non reversed segments */
- common = (conv == SENC2D_CONVENTION_CW)
- ? !header.is_infinite : header.is_infinite;
-
- snprintf(name, sizeof(name), "test_inconsistant_square_%s_%u.obj",
- (conv == SENC2D_CONVENTION_CW) ? "cw" : "ccw", e);
+ /* If NORMAL_FRONT the external enclosure's medium should be 0,
+ * 1 if NORMAL_BACK */
+ expected_external_medium = conv_front ? 0 : 1;
+ expected_medium = (header.is_infinite ?
+ expected_external_medium : !expected_external_medium);
+ CHK(medium == expected_medium);
+ /* Common media, for non input triangles */
+ front_inside = (conv_front == conv_in);
+ expected_side = front_inside ? 0 : 1;
+
+ snprintf(name, sizeof(name), "test_inconsistant_square_%s_%s_%u.obj",
+ conv_front ? "front" : "back", conv_in ? "in" : "out", e);
dump_enclosure(desc, e, name);
FOR_EACH(i, 0, header.segment_count) {
- int same, reversed;
+ int same, reversed, fst_reversed;
+ unsigned med[2];
+ fst_reversed = (e == 0) == conv_in;
+ CHK(senc2d_enclosure_get_segment_media(enclosure, i, med) == RES_OK);
+ CHK(med[expected_side] == medium);
cmp_seg(i, enclosure,
inconsistant_box_indices + (2 * i), box_vertices,
&same, &reversed);
/* Should be made of the same segments */
CHK(same);
- /* Segment #0 always differs because it was given in the opposite order
- * Depending on the convention, it is the only one to be/not to be reversed */
- CHK(reversed == (i == 0 ? !common : common));
+ CHK(i ? reversed != fst_reversed : reversed == fst_reversed);
}
SENC2D(enclosure_ref_put(enclosure));
}
-
SENC2D(scene_ref_put(scn));
SENC2D(device_ref_put(dev));
SENC2D(descriptor_ref_put(desc));
@@ -180,7 +189,9 @@ int main(int argc, char** argv)
{
(void) argc, (void) argv;
- test(SENC2D_CONVENTION_CW);
- test(SENC2D_CONVENTION_CCW);
+ 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;
}
\ No newline at end of file
diff --git a/src/test_senc2d_many_enclosures.c b/src/test_senc2d_many_enclosures.c
@@ -76,7 +76,9 @@ main(int argc, char** argv)
/* 64^3 = 262144 circles */
#define NB_CIRC (NB_CIRC_1 * NB_CIRC_1 * NB_CIRC_1)
/* Create the scene */
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
ctx.positions = NULL;
ctx.indices = NULL;
diff --git a/src/test_senc2d_many_segments.c b/src/test_senc2d_many_segments.c
@@ -73,7 +73,9 @@ main(int argc, char** argv)
#define NB_CIRC 4
/* Create the scene */
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
ctx.positions = NULL;
ctx.indices = NULL;
diff --git a/src/test_senc2d_sample_enclosure.c b/src/test_senc2d_sample_enclosure.c
@@ -48,7 +48,9 @@ main(int argc, char** argv)
CHK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)
== RES_OK);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
vrtx_get.type = S2D_FLOAT2;
vrtx_get.usage = S2D_POSITION;
diff --git a/src/test_senc2d_scene.c b/src/test_senc2d_scene.c
@@ -29,7 +29,7 @@ main(int argc, char** argv)
struct senc2d_enclosure* enc = NULL;
struct senc2d_enclosure_header header;
struct context ctx;
- unsigned medcw[2], medccw[2];
+ unsigned medfront[2], medback[2];
unsigned count, i, maxm;
enum senc2d_side_convention convention;
(void)argc, (void)argv;
@@ -38,20 +38,29 @@ main(int argc, char** argv)
CHK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)
== RES_OK);
- CHK(senc2d_scene_create(NULL, SENC2D_CONVENTION_CW, &scn) == RES_BAD_ARG);
- CHK(senc2d_scene_create(dev, 5, &scn) == RES_BAD_ARG);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, NULL) == RES_BAD_ARG);
- CHK(senc2d_scene_create(NULL, 5, &scn) == RES_BAD_ARG);
- CHK(senc2d_scene_create(NULL, SENC2D_CONVENTION_CW, NULL) == RES_BAD_ARG);
- CHK(senc2d_scene_create(dev, 5, NULL) == RES_BAD_ARG);
- CHK(senc2d_scene_create(NULL, 5, NULL) == RES_BAD_ARG);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(NULL,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_BAD_ARG);
+ CHK(senc2d_scene_create(dev, 0, &scn) == RES_BAD_ARG);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, NULL)
+ == RES_BAD_ARG);
+ CHK(senc2d_scene_create(NULL, 0, &scn) == RES_BAD_ARG);
+ CHK(senc2d_scene_create(NULL,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, NULL)
+ == RES_BAD_ARG);
+ CHK(senc2d_scene_create(dev, 0, NULL) == RES_BAD_ARG);
+ CHK(senc2d_scene_create(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
CHK(senc2d_scene_get_convention(NULL, &convention) == RES_BAD_ARG);
CHK(senc2d_scene_get_convention(scn, NULL) == RES_BAD_ARG);
CHK(senc2d_scene_get_convention(NULL, NULL) == RES_BAD_ARG);
CHK(senc2d_scene_get_convention(scn, &convention) == RES_OK);
- CHK(convention == SENC2D_CONVENTION_CW);
+ CHK(convention ==
+ (SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE));
CHK(senc2d_scene_get_segments_count(NULL, &count) == RES_BAD_ARG);
CHK(senc2d_scene_get_segments_count(scn, NULL) == RES_BAD_ARG);
@@ -78,8 +87,8 @@ main(int argc, char** argv)
CHK(count == 0);
/* A 2D square
- * With this geometry front is inside with CCW convention,
- * outside with CW convention */
+ * With this geometry front is inside with NORMAL_BACK convention,
+ * outside with NORMAL_FRONT convention */
ctx.positions = box_vertices;
ctx.indices = box_indices;
ctx.scale = 1;
@@ -127,9 +136,12 @@ main(int argc, char** argv)
CHK(senc2d_scene_ref_put(scn) == RES_OK);
CHK(senc2d_descriptor_ref_put(desc) == RES_OK);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CCW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_BACK | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
CHK(senc2d_scene_get_convention(scn, &convention) == RES_OK);
- CHK(convention == SENC2D_CONVENTION_CCW);
+ CHK(convention ==
+ (SENC2D_CONVENTION_NORMAL_BACK | SENC2D_CONVENTION_NORMAL_INSIDE));
CHK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
get_global_id, nvertices, get_position, &ctx) == RES_OK);
CHK(senc2d_scene_analyze(scn, &desc) == RES_OK);
@@ -145,12 +157,14 @@ main(int argc, char** argv)
/* gid has been set to gid_face. */
CHK(gid == gid_face[i]);
}
- CHK(senc2d_descriptor_get_global_segment_media(desc, 0, medccw) == RES_OK);
+ CHK(senc2d_descriptor_get_global_segment_media(desc, 0, medback) == RES_OK);
ctx.front_media = medium1_3;
CHK(senc2d_scene_ref_put(scn) == RES_OK);
CHK(senc2d_descriptor_ref_put(desc) == RES_OK);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
CHK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media,
get_global_id, nvertices, get_position, &ctx) == RES_OK);
/* Medium mismatch between neighbour segments, but OK */
@@ -171,7 +185,9 @@ main(int argc, char** argv)
ctx.front_media = medium0;
CHK(senc2d_scene_ref_put(scn) == RES_OK);
CHK(senc2d_descriptor_ref_put(desc) == RES_OK);
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
CHK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media, NULL,
nvertices, get_position, &ctx) == RES_OK);
CHK(senc2d_scene_analyze(scn, &desc) == RES_OK);
@@ -187,8 +203,8 @@ main(int argc, char** argv)
/* Default gid: segments rank. */
CHK(gid == i);
}
- CHK(senc2d_descriptor_get_global_segment_media(desc, 0, medcw) == RES_OK);
- FOR_EACH(i, 0, 2) CHK(medccw[i] == medcw[i]);
+ CHK(senc2d_descriptor_get_global_segment_media(desc, 0, medfront) == RES_OK);
+ FOR_EACH(i, 0, 2) CHK(medback[i] == medfront[i]);
/* Invalid vertex ID */
CHK(senc2d_scene_add_geometry(scn, nsegments, get_indices, get_media, NULL,
diff --git a/src/test_senc2d_square_behind_square.c b/src/test_senc2d_square_behind_square.c
@@ -34,7 +34,9 @@ main(int argc, char** argv)
(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev) == RES_OK);
/* Create the scene */
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
ctx.positions = box_vertices;
ctx.indices = box_indices;
diff --git a/src/test_senc2d_square_in_square.c b/src/test_senc2d_square_in_square.c
@@ -34,7 +34,9 @@ main(int argc, char** argv)
(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev) == RES_OK);
/* Create the scene */
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
ctx.positions = box_vertices;
ctx.indices = box_indices;
diff --git a/src/test_senc2d_square_on_square.c b/src/test_senc2d_square_on_square.c
@@ -57,7 +57,9 @@ main(int argc, char** argv)
(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev) == RES_OK);
/* Create the scene */
- CHK(senc2d_scene_create(dev, SENC2D_CONVENTION_CW, &scn) == RES_OK);
+ CHK(senc2d_scene_create(dev,
+ SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, &scn)
+ == RES_OK);
ctx.positions = square_vertices; /* Need true squares for squares #1 and #2 */
ctx.indices = box_indices;