commit 63bbfc7cf89284bfe7dfa867bcc61f0d9a13a725
parent 13e884ccb2b5ab56cda00a2d6f89f5e1a31955da
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 19 Dec 2022 10:12:28 +0100
Merge remote-tracking branch 'origin/feature_ground' into develop
Diffstat:
6 files changed, 191 insertions(+), 148 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,12 @@ build_boundary
ERR(scad_geometry_boundary(NULL, list, 4, &boundary));
- 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->ground_connection, 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 +342,46 @@ error:
goto exit;
}
+static res_T
+building_ground_connection
+ (const char* prefix,
+ struct scpr_polygon* pg,
+ const double e,
+ struct scad_geometry** connection)
+{
+ 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, connection));
+
+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 +470,24 @@ 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 */
+ ERR(building_ground_connection(str_cget(&prefix), pg, e_wall,
+ &data_cad->ground_connection));
+
/* 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 +501,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(building_ground_connection(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 +542,9 @@ export_stl_model0
/* boundary export */
ERR(scad_stl_export(data_cad->boundary, NULL, binary));
+ /* footprint export */
+ ERR(scad_stl_export(data_cad->ground_connection, NULL, binary));
+
exit:
return res;
error:
diff --git a/src/cg_building_model0.h b/src/cg_building_model0.h
@@ -39,9 +39,9 @@ struct data_cad_model0 {
struct scad_geometry* roof;
struct scad_geometry* floor;
struct scad_geometry* cavity;
- struct scad_geometry* ground;
struct scad_geometry* boundary;
struct scad_geometry** connection;
+ struct scad_geometry* ground_connection;
size_t n_connection;
};
diff --git a/src/cg_building_model1.c b/src/cg_building_model1.c
@@ -33,22 +33,6 @@ static void get_position_pg
CHK(scpr_polygon_get_position(pg, 0, ivert, pos) == RES_OK);
}
-/*static res_T*/
-/*build_floor_footprint*/
- /*(struct scpr_polygon* pg,*/
- /*struct scad_geometry** footprint)*/
-/*{*/
- /*res_T res = RES_OK;*/
- /*size_t nverts;*/
- /*ERR(scpr_polygon_get_vertices_count(pg, 0, &nverts));*/
- /*ERR(scad_add_polygon(NULL, get_position_pg, pg, 0, nverts, footprint));*/
-
-/*exit:*/
- /*return res;*/
-/*error:*/
- /*goto exit;*/
-/*}*/
-
static res_T
build_floor
(const char* prefix,
@@ -927,6 +911,7 @@ build_boundary
sa_push(list, data_cad->roof);
sa_push(list, data_cad->floor);
sa_push(list, data_cad->habitable_cavity);
+ sa_push(list, data_cad->fake_ground);
if (data_cad->foundation) sa_push(list, data_cad->foundation);
if (data_cad->intermediate_floor) sa_push(list, data_cad->intermediate_floor);
if (data_cad->external_insulation) sa_push(list, data_cad->external_insulation);
@@ -1096,6 +1081,120 @@ error:
goto exit;
}
+static res_T
+build_footprint
+ (struct scpr_polygon* pg, struct scad_geometry** footprint)
+{
+ res_T res = RES_OK;
+ size_t nverts = 0;
+
+ if (!pg || !footprint) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(scpr_polygon_get_vertices_count(pg, 0, &nverts));
+ ERR(scad_add_polygon(
+ NULL, get_position_pg, pg, 0, nverts, footprint));
+
+exit:
+ return res;
+error:
+ goto exit;
+
+}
+
+static res_T
+build_fake_ground
+ (struct data_cad_model1* cad,
+ struct scpr_polygon* pg,
+ const double depth,
+ struct scad_geometry** ground)
+{
+ res_T res = RES_OK;
+ double dir[3] = {0, 0, 0};
+ struct scpr_polygon* pg_offset = NULL;
+ struct scad_geometry** list = NULL;
+ struct scad_geometry* footprint = NULL;
+ struct scad_geometry* geom = NULL;
+
+ if (!cad || !pg || !ground ) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ if (cad->foundation) sa_push(list, cad->foundation);
+ if (cad->attic_cavity) sa_push(list, cad->attic_cavity);
+ if (cad->floor) sa_push(list, cad->floor);
+ if (cad->floor_insulation) sa_push(list, cad->floor_insulation);
+
+ ERR(scpr_polygon_create_copy(NULL, pg, &pg_offset));
+ ERR(scpr_offset_polygon(pg_offset, 0.1, SCPR_JOIN_MITER));
+
+ ERR(build_footprint(pg_offset, &footprint));
+
+ dir[2] = -depth*1.1;
+ ERR(scad_geometry_extrude(footprint, NULL, dir, &geom));
+
+ ERR(scad_cut_geometries(NULL, &geom, 1, list, sa_size(list), ground));
+
+exit:
+ if (pg_offset) scpr_polygon_ref_put(pg_offset);
+ if (list) sa_release(list);
+ if (footprint) scad_geometry_delete(footprint);
+ if (geom) scad_geometry_delete(geom);
+ return res;
+error:
+ goto exit;
+}
+
+
+static res_T
+building_ground_connection
+ (const char* prefix,
+ struct data_cad_model1* cad,
+ struct scad_geometry** connection)
+{
+ res_T res = RES_OK;
+ char* cname = NULL;
+ struct str name;
+ int is_init = 0;
+ struct scad_geometry** list = NULL;
+ struct scad_geometry* list_boundary = NULL;
+ struct scad_geometry* footprint = NULL;
+
+ if (!prefix || !cad || !connection) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ str_init(NULL, &name);
+ is_init = 1;
+ ERR(str_set(&name, prefix));
+ ERR(str_append(&name, "_C_building_ground"));
+ cname = str_get(&name);
+
+ if (cad->foundation) sa_push(list, cad->foundation);
+ if (cad->attic_cavity) sa_push(list, cad->attic_cavity);
+ if (cad->floor) sa_push(list, cad->floor);
+ if (cad->floor_insulation) sa_push(list, cad->floor_insulation);
+ if (cad->external_insulation) sa_push(list, cad->external_insulation);
+
+ ERR(scad_geometries_common_boundaries(
+ cname, list, sa_size(list),
+ &cad->fake_ground, 1,
+ connection));
+
+exit:
+ if (list) sa_release(list);
+ if (is_init) str_release(&name);
+ if (list_boundary) scad_geometry_delete(list_boundary);
+ if (footprint) scad_geometry_delete(footprint);
+ return res;
+error:
+ goto exit;
+}
+
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
@@ -1175,7 +1274,7 @@ build_cad_model1(struct building* building)
data_cad->roof_insulation = NULL;
data_cad->foundation = NULL;
data_cad->glass = NULL;
- data_cad->ground = NULL;
+ data_cad->ground_connection = NULL;
data_cad->boundary = NULL;
data_cad->connection = NULL;
building->data_cad = (struct data_cad_model1*)data_cad;
@@ -1274,8 +1373,15 @@ build_cad_model1(struct building* building)
ERR(build_windows(str_cget(&prefix), data, data_cad));
}
+ /* fake ground */
+ ERR(build_fake_ground(data_cad, pg, data->foundation, &data_cad->fake_ground));
+
ERR(scad_scene_partition());
+ /* build ground/buildind connection */
+ ERR(building_ground_connection(str_cget(&prefix), data_cad,
+ &data_cad->ground_connection));
+
/* build boundaries */
data_cad->boundary = NULL;
ERR(build_boundary(str_cget(&prefix), data_cad, &data_cad->boundary));
@@ -1297,51 +1403,16 @@ build_footprint_model1
struct scad_geometry** footprint)
{
res_T res = RES_OK;
- struct data_model1* data = (struct data_model1 *)building->data;
struct scpr_polygon* pg = building->pg;
- struct scad_geometry* floor = NULL;
- struct scad_geometry* foundation = NULL;
- struct scad_geometry* crawlspace = NULL;
- struct scad_geometry* floor_insulation = NULL;
- struct scad_geometry** list = NULL;
if (!building || !footprint) {
res = RES_BAD_ARG;
goto error;
}
- ERR(build_floor(NULL, pg, data, &floor));
- sa_push(list, floor);
-
- if (data->foundation > 0) {
- double depth = -data->foundation;
- ERR(build_wall(NULL, NULL, pg, depth, data, &foundation));
- sa_push(list, foundation);
- }
-
- if (data->crawl > 0) {
- ERR(build_crawlspace(NULL, pg, data, &crawlspace));
- sa_push(list, crawlspace);
- }
-
- if (data->floor_insulation > 0) {
- ERR(build_floor_insulation(NULL, pg, data, &floor_insulation));
- sa_push(list, floor_insulation);
- }
-
- if (sa_size(list) == 1) {
- ERR(scad_geometry_copy(list[0], NULL, footprint));
- } else {
- ERR(scad_fuse_geometries(NULL, list, 1, list+1, sa_size(list) - 1, footprint));
- }
-
+ ERR(build_footprint(pg, footprint));
exit:
- if (floor) scad_geometry_delete(floor);
- if (foundation) scad_geometry_delete(foundation);
- if (crawlspace) scad_geometry_delete(crawlspace);
- if (floor_insulation) scad_geometry_delete(floor_insulation);
- if (list) sa_release(list);
return res;
error:
goto exit;
@@ -1422,6 +1493,9 @@ export_stl_model1
ERR(scad_stl_export(data_cad->connection[i], NULL, binary));
}
+ /* ground/building connection export*/
+ ERR(scad_stl_export(data_cad->ground_connection, NULL, binary));
+
exit:
return res;
error:
diff --git a/src/cg_building_model1.h b/src/cg_building_model1.h
@@ -59,7 +59,8 @@ struct data_cad_model1 {
struct scad_geometry* floor_insulation; /* can be NULL */
struct scad_geometry* roof_insulation; /* can be NULL */
struct scad_geometry* glass;
- struct scad_geometry* ground;
+ struct scad_geometry* fake_ground;/*not exported, used for ground connection*/
+ struct scad_geometry* ground_connection;
struct scad_geometry** boundary;
struct scad_geometry** connection;
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:
diff --git a/src/cg_parsing.c b/src/cg_parsing.c
@@ -413,7 +413,7 @@ parse_building_params
data1->inter_floor_n = 0;
data1->roof = 0.3;
data1->int_insulation = 0.1;
- data1->ext_insulation = 0.;
+ data1->ext_insulation = 0.2;
data1->floor_insulation = 0;
data1->roof_insulation = 0;
data1->foundation = 2;