commit f6330fde88d1445e43e38ee65c4b2633af4f713e
parent b54696785e585f5efa90954dd0df09f560f8bd4e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 13 Dec 2019 10:38:45 +0100
Add some access operators to API
Diffstat:
3 files changed, 186 insertions(+), 13 deletions(-)
diff --git a/src/sg3_geometry.c b/src/sg3_geometry.c
@@ -17,6 +17,8 @@
#include "sg3_geometry.h"
#include "sg3_device.h"
+#include <rsys/double3.h>
+
#include <limits.h>
/*******************************************************************************
@@ -552,6 +554,28 @@ error:
}
res_T
+sg3_geometry_get_unique_vertex
+ (const struct sg3_geometry* geom,
+ const unsigned ivtx,
+ double coord[3])
+{
+ res_T res = RES_OK;
+ const struct vertex* vertices;
+ if(!geom || !coord
+ || ivtx >= darray_vertex_size_get(&geom->unique_vertices))
+ {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ vertices = darray_vertex_cdata_get(&geom->unique_vertices);
+ d3_set(coord, vertices[ivtx].coord);
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+res_T
sg3_geometry_get_unique_triangles_count
(const struct sg3_geometry* geom,
unsigned* count)
@@ -572,6 +596,75 @@ error:
}
res_T
+sg3_geometry_get_unique_triangle_vertices
+ (const struct sg3_geometry* geom,
+ const unsigned itri,
+ unsigned indices[3])
+{
+ res_T res = RES_OK;
+ const struct triangle* triangles;
+ size_t i;
+ if(!geom || !indices
+ || itri >= darray_triangle_size_get(&geom->unique_triangles))
+ {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ triangles = darray_triangle_cdata_get(&geom->unique_triangles);
+ FOR_EACH(i, 0, 3) indices[i] = triangles[itri].vertex_ids[i];
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+res_T
+sg3_geometry_get_unique_triangle_properties
+ (const struct sg3_geometry* geom,
+ const unsigned itri,
+ unsigned properties[SG3_PROP_TYPES_COUNT__])
+{
+ res_T res = RES_OK;
+ const struct triangle* triangles;
+ size_t i;
+ if(!geom || !properties
+ || itri >= darray_triangle_size_get(&geom->unique_triangles))
+ {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ triangles = darray_triangle_cdata_get(&geom->unique_triangles);
+ FOR_EACH(i, 0, SG3_PROP_TYPES_COUNT__)
+ properties[i] = triangles[itri].properties[i];
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+res_T
+sg3_geometry_get_unique_triangle_global_id
+ (const struct sg3_geometry* geom,
+ const unsigned itri,
+ unsigned* global_id)
+{
+ res_T res = RES_OK;
+ const struct triangle* triangles;
+ if(!geom || !global_id
+ || itri >= darray_triangle_size_get(&geom->unique_triangles))
+ {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ triangles = darray_triangle_cdata_get(&geom->unique_triangles);
+ *global_id = triangles[itri].global_id;
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+res_T
sg3_geometry_get_triangle_with_undefined_side_count
(const struct sg3_geometry* geom,
unsigned* count)
@@ -765,11 +858,9 @@ sg3_geometry_dump_as_vtk
fprintf(stream, "SCALARS Created_at_sg3_geometry_add int\n");
fprintf(stream, "LOOKUP_TABLE default\n");
FOR_EACH(i, 0, tsz) {
- size_t tdefs_count
- = darray_definition_size_get(&descriptions[i].defs[SG3_FRONT]);
const struct definition* tdefs;
const unsigned* ranks;
- ASSERT(tdefs_count);
+ ASSERT(darray_definition_size_get(&descriptions[i].defs[SG3_FRONT]) > 0);
/* Rank is the first set_id of the first definition of any property */
tdefs = darray_definition_cdata_get(&descriptions[i].defs[SG3_FRONT]);
ranks = darray_uint_cdata_get(&tdefs[0].set_ids);
diff --git a/src/star-geometry.h b/src/star-geometry.h
@@ -165,7 +165,9 @@ sg3_geometry_add
void(*indices)(const unsigned itri, unsigned ids[3], void* context),
/* User function that provides properties for added triangles */
void(*properties) /* Can be NULL <=> SG3_UNDEFINED_PROPERTY used */
- (const unsigned itri, unsigned med[3], void* context),
+ (const unsigned itri,
+ unsigned properties[SG3_PROP_TYPES_COUNT__],
+ void* context),
/* Number of added vertices */
const unsigned vertices_count,
/* User function that provides coordinates for added vertices */
@@ -188,26 +190,32 @@ sg3_geometry_add
* The triangle_properties and merged_properties args contain the involved
* properties. */
res_T(*merge_triangle) /* Can be NULL */
- (const unsigned global_id, const unsigned itri, const int reversed_triangle,
- unsigned triangle_properties[3], const unsigned merged_properties[3],
- void* context, int* merge_conflict_status),
+ (const unsigned global_id,
+ const unsigned itri,
+ const int reversed_triangle,
+ unsigned triangle_properties[SG3_PROP_TYPES_COUNT__],
+ const unsigned merged_properties[SG3_PROP_TYPES_COUNT__],
+ void* context,
+ int* merge_conflict_status),
void* context); /* Can be NULL */
/* Apply a validation callback on each triangle included in this geometry that
* is not already flagged with a merge error. If validate returns a non-RES_OK
* value, the validation stops and returns the same error value; on the other
* hand, validation goes to the end regardless of properties conflicts.
- * The properties_conflict argument can be set to any value. Any non-0 value
- * is accounted for a conflict and is kept as-is in dumps, allowing different
- * shades of conflict.
+ * The properties_conflict_status argument can be set to any value. Any non-0
+ * value is accounted for a conflict and is kept as-is in dumps, allowing
+ * different shades of conflict.
* If validation is processed again, the properties conflict count is reset,
- * as well as the properties_conflict status of the triangles. */
+ * as well as the properties_conflict_status status of the triangles. */
SG3_API res_T
sg3_geometry_validate_properties
(struct sg3_geometry* geometry,
res_T(*validate)
- (const unsigned itri, const unsigned properties[3], void* context,
- int* properties_conflict),
+ (const unsigned itri,
+ const unsigned properties[SG3_PROP_TYPES_COUNT__],
+ void* context,
+ int* properties_conflict_status),
void* context); /* Can be NULL */
/* Get the number of unique vertices. */
@@ -216,12 +224,41 @@ sg3_geometry_get_unique_vertices_count
(const struct sg3_geometry* geometry,
unsigned* count);
+/* Get the ivtx_th vertex. */
+SG3_API res_T
+sg3_geometry_get_unique_vertex
+ (const struct sg3_geometry* geometry,
+ const unsigned ivtx,
+ double coord[3]);
+
/* Get the number of unique triangles. */
SG3_API res_T
sg3_geometry_get_unique_triangles_count
(const struct sg3_geometry* geometry,
unsigned* count);
+/* Get the vertex indices of the itri_th triangle. */
+SG3_API res_T
+sg3_geometry_get_unique_triangle_vertices
+ (const struct sg3_geometry* geometry,
+ const unsigned itri,
+ unsigned indices[3]);
+
+/* Get the properties of the itri_th triangle. */
+SG3_API res_T
+sg3_geometry_get_unique_triangle_properties
+ (const struct sg3_geometry* geometry,
+ const unsigned itri,
+ unsigned properties[SG3_PROP_TYPES_COUNT__]);
+
+/* Get the global ID of the itri_th triangle, that is its original index in
+ * user world. */
+SG3_API res_T
+sg3_geometry_get_unique_triangle_global_id
+ (const struct sg3_geometry* geometry,
+ const unsigned itri,
+ unsigned* global_id);
+
/* Get the number of triangle with (at least) one undefined side. */
SG3_API res_T
sg3_geometry_get_triangle_with_undefined_side_count
diff --git a/src/test_sg3_geometry.c b/src/test_sg3_geometry.c
@@ -55,6 +55,10 @@ main(int argc, char** argv)
struct mem_allocator allocator;
struct sg3_device* dev;
struct sg3_geometry* geom;
+ double coord[3];
+ unsigned indices[3];
+ unsigned properties[SG3_PROP_TYPES_COUNT__];
+ unsigned global_id;
unsigned count, i;
struct context ctx;
(void)argc, (void)argv;
@@ -155,6 +159,47 @@ main(int argc, char** argv)
OK(sg3_geometry_dump_as_C_code(geom, stdout, NULL));
OK(sg3_geometry_dump_as_C_code(geom, stdout, "test"));
+ BA(sg3_geometry_get_unique_vertex(NULL, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_vertex(geom, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_vertex(NULL, 0, NULL));
+ BA(sg3_geometry_get_unique_vertex(NULL, ntriangles, coord));
+ BA(sg3_geometry_get_unique_vertex(geom, 0, NULL));
+ BA(sg3_geometry_get_unique_vertex(geom, ntriangles, coord));
+ BA(sg3_geometry_get_unique_vertex(NULL, 0, coord));
+ OK(sg3_geometry_get_unique_vertex(geom, 0, coord));
+
+ BA(sg3_geometry_get_unique_triangle_vertices(NULL, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_triangle_vertices(geom, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_triangle_vertices(NULL, 0, NULL));
+ BA(sg3_geometry_get_unique_triangle_vertices(NULL, ntriangles, indices));
+ BA(sg3_geometry_get_unique_triangle_vertices(geom, 0, NULL));
+ BA(sg3_geometry_get_unique_triangle_vertices(geom, ntriangles, indices));
+ BA(sg3_geometry_get_unique_triangle_vertices(NULL, 0, indices));
+ OK(sg3_geometry_get_unique_triangle_vertices(geom, 0, indices));
+ FOR_EACH(i, 0 , 3) CHK(indices[i] == cube_indices[i]);
+
+ BA(sg3_geometry_get_unique_triangle_properties(NULL, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_triangle_properties(geom, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_triangle_properties(NULL, 0, NULL));
+ BA(sg3_geometry_get_unique_triangle_properties(NULL, ntriangles, properties));
+ BA(sg3_geometry_get_unique_triangle_properties(geom, 0, NULL));
+ BA(sg3_geometry_get_unique_triangle_properties(geom, ntriangles, properties));
+ BA(sg3_geometry_get_unique_triangle_properties(NULL, 0, properties));
+ OK(sg3_geometry_get_unique_triangle_properties(geom, 0, properties));
+ CHK(medium0[0] == properties[SG3_FRONT]);
+ CHK(medium1[0] == properties[SG3_BACK]);
+ CHK(intface0[0] == properties[SG3_INTFACE]);
+
+ BA(sg3_geometry_get_unique_triangle_global_id(NULL, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_triangle_global_id(geom, ntriangles, NULL));
+ BA(sg3_geometry_get_unique_triangle_global_id(NULL, 0, NULL));
+ BA(sg3_geometry_get_unique_triangle_global_id(NULL, ntriangles, &global_id));
+ BA(sg3_geometry_get_unique_triangle_global_id(geom, 0, NULL));
+ BA(sg3_geometry_get_unique_triangle_global_id(geom, ntriangles, &global_id));
+ BA(sg3_geometry_get_unique_triangle_global_id(NULL, 0, &global_id));
+ OK(sg3_geometry_get_unique_triangle_global_id(geom, 0, &global_id));
+ CHK(global_id == 0);
+
/* Conflicts with merge_trg callback */
OK(sg3_geometry_add(geom, ntriangles, get_indices, get_properties,
nvertices, get_position, NULL, merge_trg, &ctx));