city_generator2

Generated conformal 3D meshes representing a city
git clone git://git.meso-star.fr/city_generator2.git
Log | Files | Refs | README | LICENSE

commit 9e3a1fcde981d35874dcf5433813646115a8ab70
parent 58fd8eafbca42b2e3eeaa8971a391967ef9a722e
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Thu, 15 Dec 2022 14:53:31 +0100

Adapt new ground strategy for model1

Diffstat:
Msrc/cg_building_model1.c | 179+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Msrc/cg_building_model1.h | 3++-
Msrc/cg_parsing.c | 2+-
3 files changed, 129 insertions(+), 55 deletions(-)

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, @@ -1096,6 +1080,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 +1273,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 +1372,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 +1402,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 +1492,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_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;