commit 2efc0ac6009832e83f5399f085c6b2798122d998
parent 118c3de3d010ca6424c0c0587d4cf9d43e7dcfd2
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 10 Jan 2020 14:52:00 +0100
Change dump of geometries as C code.
Undefined properties are now printed as 'SG3_UNDEFINED_PROPERTY'.
Diffstat:
3 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/src/sg3.h b/src/sg3.h
@@ -351,10 +351,10 @@ sg3_geometry_dump_as_vtk
/* Dump the geometry as C code.
* The geometry cannot be empty and must be conflict-free.
* The C code defines the 3 variables:
- * - [static] [const] double <name_prefix>_vertices[<N1>] = { .... };
* - [static] [const] unsigned <name_prefix>_vertices_count = N1;
- * - [static] [const] unsigned <name_prefix>_triangles[<N2>] = { .... };
+ * - [static] [const] double <name_prefix>_vertices[<N1>] = { .... };
* - [static] [const] unsigned <name_prefix>_triangles_count = N2;
+ * - [static] [const] unsigned <name_prefix>_triangles[<N2>] = { .... };
* - [static] [const] unsigned <name_prefix>_properties[<N2>] = { .... };
* Where <N1> is 3 * vertices_count and <N2> is 3 * triangles_count.
* The two qualifiers static and const are output or not according to flags;
diff --git a/src/sg3_geometry.c b/src/sg3_geometry.c
@@ -987,7 +987,6 @@ sg3_geometry_dump_as_C_code
goto error;
}
- /* Dump vertices */
if(flags & SG3_CDUMP_CONST && flags & SG3_CDUMP_STATIC)
qualifiers = "static const ";
else if(flags & SG3_CDUMP_CONST)
@@ -995,10 +994,15 @@ sg3_geometry_dump_as_C_code
else if(flags & SG3_CDUMP_STATIC)
qualifiers = "static ";
else qualifiers = "";
+
+ /* Dump vertices */
+ fprintf(stream, "%sunsigned %s_vertices_count = %u;\n",
+ qualifiers, name_prefix, (unsigned)vsz);
+
vertices = darray_vertex_cdata_get(&geom->unique_vertices);
fprintf(stream,
"%sdouble %s_vertices[%u] =\n"
- " {\n",
+ "{\n",
qualifiers, name_prefix, (unsigned)(3 * vsz));
FOR_EACH(i, 0, vsz - 1)
fprintf(stream,
@@ -1007,14 +1011,15 @@ sg3_geometry_dump_as_C_code
" %g, %g, %g\n", SPLIT3(vertices[vsz - 1].coord));
fprintf(stream,
"};\n");
- fprintf(stream, "%sunsigned %s_vertices_count = %u;\n",
- qualifiers, name_prefix, (unsigned)vsz);
/* Dump triangles */
+ fprintf(stream, "%sunsigned %s_triangles_count = %u;\n",
+ qualifiers, name_prefix, (unsigned)tsz);
+
triangles = darray_triangle_cdata_get(&geom->unique_triangles);
fprintf(stream,
"%sunsigned %s_triangles[%u] =\n"
- " {\n",
+ "{\n",
qualifiers, name_prefix, (unsigned)(3 * tsz));
FOR_EACH(i, 0, tsz - 1)
fprintf(stream,
@@ -1023,20 +1028,24 @@ sg3_geometry_dump_as_C_code
" %u, %u, %u\n", SPLIT3(triangles[tsz - 1].vertex_ids));
fprintf(stream,
"};\n");
- fprintf(stream, "%sunsigned %s_triangles_count = %u;\n",
- qualifiers, name_prefix, (unsigned)tsz);
/* Dump properties */
triangles = darray_triangle_cdata_get(&geom->unique_triangles);
fprintf(stream,
"%sunsigned %s_properties[%u] =\n"
- " {\n",
+ "{\n",
qualifiers, name_prefix, (unsigned)(3 * tsz));
- FOR_EACH(i, 0, tsz - 1)
- fprintf(stream,
- " %u, %u, %u,\n", SPLIT3(triangles[i].properties));
- fprintf(stream,
- " %u, %u, %u\n", SPLIT3(triangles[tsz - 1].properties));
+ FOR_EACH(i, 0, tsz) {
+ int p;
+ fprintf(stream, " ");
+ FOR_EACH(p, 0, 3) {
+ if(triangles[i].properties[p] == SG3_UNDEFINED_PROPERTY)
+ fprintf(stream, " SG3_UNDEFINED_PROPERTY");
+ else fprintf(stream," %u", triangles[i].properties[p]);
+ if(i < tsz-1 || p < 2) fprintf(stream, ",");
+ if(p == 2) fprintf(stream, "\n");
+ }
+ }
fprintf(stream,
"};\n");
diff --git a/src/test_sg3_geometry_2.c b/src/test_sg3_geometry_2.c
@@ -169,6 +169,9 @@ main(int argc, char** argv)
OK(sg3_geometry_get_properties_conflict_count(geom, &count));
CHK(count == 0);
+ OK(sg3_geometry_dump_as_C_code(geom, stdout, "test_undefined",
+ SG3_CDUMP_STATIC | SG3_CDUMP_CONST));
+
/* Clear geometry */
SG3(geometry_ref_put(geom));
OK(sg3_geometry_create(dev, &geom));