commit 00fa10c2029d5150b2a6be775518770f4e9602f2
parent 02f61adb2314c48643991b5961f598d42cf7f44c
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Tue, 22 Nov 2022 15:27:48 +0100
Add get name and get normal operator
Diffstat:
2 files changed, 154 insertions(+), 1 deletion(-)
diff --git a/src/scad.h b/src/scad.h
@@ -128,6 +128,11 @@ scad_geometry_get_count
(const struct scad_geometry* geom,
size_t* count);
+SCAD_API res_T
+scad_geometry_get_name
+ (const struct scad_geometry* geom,
+ char** name);
+
/* Add a rectangle to the scene, defined by a point `xyz' and
* `dxdy' the extents along the x-, y-axes. */
SCAD_API res_T
@@ -363,6 +368,23 @@ SCAD_API res_T /* FIXME TEMPORARY */
scad_scene_partition
(void);
+SCAD_API res_T
+scad_geometry_normal
+ (struct scad_geometry* geom,
+ double p[3],
+ double N[3],
+ const char* name, /* Can be NULL */
+ struct scad_geometry** out_geometry);
+
+/* Scale the geometry by * factors `scale' along the three coordinate axes;
+ * use `center', as the center of the homothetic transformation. */
+SCAD_API res_T
+scad_geometry_dilate
+ (struct scad_geometry* geom,
+ double center[3],
+ double scale[3]);
+
+
END_DECLS
#endif /* SCAD_H */
diff --git a/src/scad_geometry.c b/src/scad_geometry.c
@@ -22,9 +22,11 @@
#include <rsys/mem_allocator.h>
#include <rsys/str.h>
#include <rsys/math.h>
+#include <rsys/double3.h>
#include <stdlib.h>
-#include <gmshc.h>
+#include <string.h>
+#include <gmsh/gmshc.h>
/*******************************************************************************
* Utility functions
@@ -321,6 +323,26 @@ error:
goto exit;
}
+res_T
+scad_geometry_get_name
+ (const struct scad_geometry* geom,
+ char** name)
+{
+ res_T res = RES_OK;
+
+ if(!geom || !name) goto error;
+
+ ERR(check_device(FUNC_NAME));
+
+ *name = malloc((strlen(str_cget(&geom->name)) + 1)*sizeof(char));
+ strcpy(*name, str_cget(&geom->name));
+
+exit:
+ return res;
+error:
+ res = RES_BAD_ARG;
+ goto exit;
+}
res_T
scad_add_rectangle
@@ -1401,3 +1423,112 @@ error:
goto exit;
}
+
+res_T
+scad_geometry_normal
+ (struct scad_geometry* geom,
+ double p[3],
+ double N[3],
+ const char* name, /* Can be NULL */
+ struct scad_geometry** out_geometry)
+{
+ res_T res = RES_OK;
+ int ierr = 0;
+ size_t i;
+ int* data;
+ size_t sz;
+ struct scad_geometry* surface = NULL;
+ struct scad_geometry* out = NULL;
+
+ if(!geom || !p || !N || !out_geometry) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(check_device(FUNC_NAME));
+
+ if (geom->gmsh_dimTags[0] == 2) {
+ ERR(scad_geometry_copy(geom, NULL, &surface));
+ } else if (geom->gmsh_dimTags[0] == 3) {
+ ERR(scad_geometry_boundary(NULL, &geom, 1, &surface));
+ } else {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(gather_tags(&surface, 1, SIZE_MAX, &data, &sz));
+
+ for (i=0; sz/2; ++i) {
+ double* coord;
+ double* pcoord;
+ size_t pcoord_n;
+ size_t coord_n;
+ double* normals;
+ size_t normals_n;
+
+ gmshModelGetParametrization(2, data[2*i + 1], p, 3, &pcoord, &pcoord_n, &ierr);
+ ERR(gmsh_err_to_res_T(ierr));
+
+ gmshModelGetValue(2,
+ data[2*i + 1],
+ pcoord, pcoord_n,
+ &coord, &coord_n,
+ &ierr);
+ ERR(gmsh_err_to_res_T(ierr));
+
+ if (d3_eq_eps(p, coord, 1e-6)) {
+ gmshModelGetNormal(data[2*i + 1], pcoord, pcoord_n,
+ &normals, &normals_n, &ierr);
+ ERR(gmsh_err_to_res_T(ierr));
+
+ ERR(scad_geometry_create(name, &out));
+ out->gmsh_dimTags = (int*)malloc(2*sizeof(int));
+ out->gmsh_dimTags_n = 2;
+ out->gmsh_dimTags[0] = data[2*i];
+ out->gmsh_dimTags[1] = data[2*i+1];
+ ERR(device_register_tags(out));
+
+ d3_set(N, normals);
+ if (coord) free(coord);
+ if (pcoord) free(pcoord);
+ if (normals) free(normals);
+ break;
+ }
+ }
+
+exit:
+ *out_geometry = out;
+ if (data) free(data);
+ if (surface) scad_geometry_delete(surface);
+ return res;
+error:
+ goto exit;
+}
+
+res_T
+scad_geometry_dilate
+ (struct scad_geometry* geom,
+ double center[3],
+ double scale[3])
+{
+ res_T res = RES_OK;
+ int ierr = 0;
+ int* data;
+ size_t sz;
+
+ if(!geom || !scale|| !center) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(gather_tags(&geom, 1, SIZE_MAX, &data, &sz));
+
+ gmshModelOccDilate(data, sz, SPLIT3(center), SPLIT3(scale), &ierr);
+ ERR(gmsh_err_to_res_T(ierr));
+
+exit:
+ if (data) free(data);
+ return res;
+error:
+ goto exit;
+}