commit 256bdd5b5360ac65c9c49b01ef28b60d11d87b4c
parent 13e884ccb2b5ab56cda00a2d6f89f5e1a31955da
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Tue, 13 Dec 2022 15:53:35 +0100
Implement new strategy for ground. Ground is not explicitly builded. The
mesh of ground will be composed by the concatenation of building/ground
mesh and ground/environnement mesh
Diffstat:
3 files changed, 61 insertions(+), 91 deletions(-)
diff --git a/src/cg_building_model0.c b/src/cg_building_model0.c
@@ -301,29 +301,6 @@ error:
}
static res_T
-build_ground
-(struct scpr_polygon* pg,
- struct scad_geometry** ground)
-{
- res_T res = RES_OK;
- struct scad_geometry* footprint = NULL;
- double dir[3] = {0, 0, -1};
- size_t nverts;
-
-
- ERR(scpr_polygon_get_vertices_count(pg, 0, &nverts));
- ERR(scad_add_polygon(NULL, get_position_pg, pg, 0, nverts, &footprint));
-
- ERR(scad_geometry_extrude(footprint, NULL, dir, ground));
-
-exit:
- if(footprint) scad_geometry_delete(footprint);
- return res;
-error:
- goto exit;
-}
-
-static res_T
build_boundary
(const char* prefix,
struct data_cad_model0* cad)
@@ -331,7 +308,7 @@ build_boundary
res_T res = RES_OK;
struct scad_geometry** list = NULL;
struct scad_geometry* boundary = NULL;
- struct scad_geometry* footprint = NULL;
+ /*struct scad_geometry* footprint = NULL;*/
char* cname = NULL;
struct str name;
int is_init = 0;
@@ -352,14 +329,14 @@ build_boundary
ERR(scad_geometry_boundary(NULL, list, 4, &boundary));
- ERR(scad_geometries_common_boundaries(NULL, list, 4, &cad->ground, 1,
- &footprint));
+ /*ERR(scad_geometries_common_boundaries(NULL, list, 4, &cad->ground, 1,*/
+ /*&footprint));*/
- ERR(scad_cut_geometries(cname, &boundary, 1, &footprint, 1, &cad->boundary));
+ ERR(scad_cut_geometries(cname, &boundary, 1, &cad->footprint, 1, &cad->boundary));
exit:
if(boundary) scad_geometry_delete(boundary);
- if(footprint) scad_geometry_delete(footprint);
+ /*if(footprint) scad_geometry_delete(footprint);*/
if (list) free(list);
if (is_init) str_release(&name);
return res;
@@ -367,6 +344,46 @@ error:
goto exit;
}
+static res_T
+build_footprint
+ (const char* prefix,
+ struct scpr_polygon* pg,
+ const double e,
+ struct scad_geometry** footprint)
+{
+ res_T res = RES_OK;
+ struct scpr_polygon* pg_int = NULL;
+ struct scad_geometry* geom[2];
+ char* cname = NULL;
+ struct str name;
+ int is_init = 0;
+
+ if (prefix) {
+ str_init(NULL, &name);
+ is_init = 1;
+ ERR(str_set(&name, prefix));
+ ERR(str_append(&name, "_C_building_ground"));
+ cname = str_get(&name);
+ }
+
+ ERR(scpr_polygon_create_copy(NULL, pg, &pg_int));
+ ERR(scpr_offset_polygon(pg_int, -e, SCPR_JOIN_MITER));
+
+ ERR(build_wall_footprint(pg, pg_int, &geom[0]));
+ ERR(build_floor_footprint(pg, &geom[1]));
+
+ ERR(scad_fragment_geometries(cname, &geom[0], 1, &geom[1], 1, footprint));
+
+exit:
+ if(is_init) str_release(&name);
+ if(geom[0]) scad_geometry_delete(geom[0]);
+ if(geom[1]) scad_geometry_delete(geom[1]);
+ if(pg_int) scpr_polygon_ref_put(pg_int);
+ return res;
+error:
+ goto exit;
+}
+
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
@@ -455,25 +472,23 @@ build_cad_model0(struct building* building)
/* build wall with pg and pg_int */
ERR(build_wall(str_cget(&prefix), pg, pg_int, building, &data_cad->wall));
- /* build ground */
- /*This is a 'local' ground. It is required to build boundary condition. */
- /*It is not exported.*/
- ERR(build_ground(pg, &data_cad->ground));
-
/* build cavity */
ERR(build_cavity(str_cget(&prefix), pg_int, building, &data_cad->cavity));
ERR(scad_scene_partition());
+ /* build ground/building connection aka the footprint*/
+ ERR(build_footprint(str_cget(&prefix), pg, e_wall, &data_cad->footprint));
+
/* build boundary */
ERR(build_boundary(str_cget(&prefix), building->data_cad));
- /* build connection cavity/floor */
+ /* build cavity/floor connectiona*/
ERR(build_connection(str_cget(&prefix), building->data_cad));
exit:
- if (is_init) str_release(&prefix);
+ if(is_init) str_release(&prefix);
if(pg_int) scpr_polygon_ref_put(pg_int);
return res;
error:
@@ -487,24 +502,14 @@ build_footprint_model0
{
res_T res = RES_OK;
struct scpr_polygon* pg = building->pg;
- struct scpr_polygon* pg_int = NULL;
struct data_model0* data = (struct data_model0 *)building->data;
double e_wall;
- struct scad_geometry* geom[2];
e_wall = data->wall;
- ERR(scpr_polygon_create_copy(NULL, pg, &pg_int));
- ERR(scpr_offset_polygon(pg_int, -e_wall, SCPR_JOIN_MITER));
- ERR(build_wall_footprint(pg, pg_int, &geom[0]));
- ERR(build_floor_footprint(pg, &geom[1]));
-
- ERR(scad_fragment_geometries(NULL, &geom[0], 1, &geom[1], 1, footprint));
+ ERR(build_footprint(NULL, pg, e_wall, footprint));
exit:
- scad_geometry_delete(geom[0]);
- scad_geometry_delete(geom[1]);
- if(pg_int) scpr_polygon_ref_put(pg_int);
return res;
error:
goto exit;
@@ -538,6 +543,9 @@ export_stl_model0
/* boundary export */
ERR(scad_stl_export(data_cad->boundary, NULL, binary));
+ /* footprint export */
+ ERR(scad_stl_export(data_cad->footprint, NULL, binary));
+
exit:
return res;
error:
diff --git a/src/cg_building_model0.h b/src/cg_building_model0.h
@@ -42,6 +42,7 @@ struct data_cad_model0 {
struct scad_geometry* ground;
struct scad_geometry* boundary;
struct scad_geometry** connection;
+ struct scad_geometry* footprint;
size_t n_connection;
};
diff --git a/src/cg_ground.c b/src/cg_ground.c
@@ -23,38 +23,6 @@
#include <rsys/str.h>
#include <star/scad.h>
-static res_T
-build_ground_boundary
- (struct scad_geometry* geom,
- struct scad_geometry** footprint,
- size_t n,
- struct scad_geometry** boundary)
-{
- res_T res = RES_OK;
- struct scad_geometry* interface = NULL;
- struct scad_geometry* bound = NULL;
-
- if (!geom || !footprint || !boundary) {
- res = RES_BAD_ARG;
- goto error;
- }
-
- ERR(scad_geometries_common_boundaries
- (NULL, &geom, 1, footprint, n,
- &interface));
-
- ERR(scad_geometry_boundary(NULL, &geom, 1, &bound));
-
- ERR(scad_cut_geometries(NULL, &bound, 1, &interface, 1, boundary));
-
-exit:
- if (interface) scad_geometry_delete(interface);
- if (bound) scad_geometry_delete(bound);
- return res;
-error:
- goto exit;
-}
-
res_T
ground_build_cad
(struct ground* ground)
@@ -63,6 +31,7 @@ ground_build_cad
double origin[3];
double extent[3];
struct scad_geometry* ground_box = NULL;
+ struct scad_geometry* bound = NULL;
struct str name;
int is_init = 0;
@@ -94,21 +63,14 @@ ground_build_cad
extent,
&ground_box));
- ERR(scad_cut_geometries
- ( str_cget(&name),
- &ground_box, 1,
- ground->footprint, ground->n,
- &ground->geometry));
-
- ERR(build_ground_boundary
- (ground->geometry,
- ground->footprint, ground->n,
- &ground->boundary));
-
+ ERR(scad_geometry_boundary(NULL, &ground_box, 1, &bound));
+
+ ERR(scad_cut_geometries(NULL, &bound, 1,
+ ground->footprint, ground->n, &ground->boundary));
exit:
if (is_init) str_release(&name);
- if (ground_box) scad_geometry_delete(ground_box);
+ if (bound) scad_geometry_delete(bound);
return res;
error:
goto exit;
@@ -119,7 +81,6 @@ ground_export_stl(const struct ground* ground, const int binary)
{
res_T res = RES_OK;
- ERR(scad_stl_export(ground->geometry, "S_ground", binary));
ERR(scad_stl_export(ground->boundary, "B_ground", binary));
exit: