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 1c3062ed61b83dd52a38ce569f47b4d4dd124ae2
parent 5d926a3709644da603a4ecc5a98d33a1ba8a3d7c
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Fri,  2 Dec 2022 10:40:18 +0100

Change ground building for model1. It implies to separate foundation
from wall. B_ground is missing and ground is broken for model0.

Diffstat:
Msrc/cg_building_model1.c | 288+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Msrc/cg_building_model1.h | 1+
Msrc/cg_ground.c | 33++++++++-------------------------
Msrc/cg_parsing.c | 4++--
4 files changed, 197 insertions(+), 129 deletions(-)

diff --git a/src/cg_building_model1.c b/src/cg_building_model1.c @@ -33,21 +33,21 @@ 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)); +/*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; -} +/*exit:*/ + /*return res;*/ +/*error:*/ + /*goto exit;*/ +/*}*/ static res_T build_floor @@ -69,16 +69,18 @@ build_floor struct str name; int is_init = 0; - if (!prefix || !pg || !data || !floor) { + if (!pg || !data || !floor) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_floor")); - floorname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_floor")); + floorname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -103,6 +105,7 @@ error: static res_T build_wall (const char* prefix, + const char* suffix, const struct scpr_polygon* pg, const double height, const struct data_model1* data, @@ -111,7 +114,6 @@ build_wall res_T res = RES_OK; double e_wall = data->wall; double e_insulation = data->ext_insulation; - double depth = data->foundation; double offset = 0; struct scpr_polygon* pg_int = NULL; struct scpr_polygon* pg_ext = NULL; @@ -124,16 +126,21 @@ build_wall struct str name; int is_init = 0; - if (!prefix || !pg || !data || !wall) { + if (!pg || !data || !wall) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_wall")); - wallname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + if (suffix) { + ERR(str_append(&name, "_")); + ERR(str_append(&name, suffix)); + } + wallname = str_get(&name); + } offset = e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_ext)); @@ -146,16 +153,16 @@ build_wall /*wall footprint*/ ERR(scpr_polygon_get_vertices_count(pg_ext, 0, &nverts)); ERR(scad_add_polygon( - NULL, get_position_pg, pg_ext, -depth, nverts, &footprint_ext)); + NULL, get_position_pg, pg_ext, 0, nverts, &footprint_ext)); ERR(scpr_polygon_get_vertices_count(pg_int, 0, &nverts)); ERR(scad_add_polygon( - NULL, get_position_pg, pg_int, -depth, nverts, &footprint_int)); + NULL, get_position_pg, pg_int, 0, nverts, &footprint_int)); ERR(scad_cut_geometries( NULL, &footprint_ext, 1, &footprint_int, 1, &footprint)); - d[2] = depth + height; + d[2] = height; ERR(scad_geometry_extrude(footprint, wallname, d, wall)); exit: @@ -199,16 +206,18 @@ build_int_insulation struct str name; int is_init = 0; - if (!prefix || !pg || !data || !insulation) { + if (!pg || !data || !insulation) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_int_insulation")); - insulationname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_int_insulation")); + insulationname = str_get(&name); + } offset = e_ext_insulation + e_wall; ERR(scpr_polygon_create_copy(NULL, pg, &pg_ext)); @@ -276,16 +285,18 @@ build_roof struct str name; int is_init = 0; - if (!prefix || !pg || !data || !roof) { + if (!pg || !data || !roof) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_roof")); - roofname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_roof")); + roofname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -332,16 +343,18 @@ build_roof_insulation struct str name; int is_init = 0; - if (!prefix || !pg || !data || !insulation) { + if (!pg || !data || !insulation) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_roof_insulation")); - insulationname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_roof_insulation")); + insulationname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -387,16 +400,18 @@ build_floor_insulation struct str name; int is_init = 0; - if (!prefix || !pg || !data || !insulation) { + if (!pg || !data || !insulation) { res = RES_BAD_ARG; goto error; } - - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_floor_insulation")); - insulationname = str_get(&name); + + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_floor_insulation")); + insulationname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -447,16 +462,18 @@ build_inter_floor struct str name; int is_init = 0; - if (!prefix || !pg || !data || !inter_floor) { + if (!pg || !data || !inter_floor) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_inter_floor")); - floorname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_inter_floor")); + floorname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -519,16 +536,18 @@ build_ext_insulation struct str name; int is_init = 0; - if (!prefix || !pg || !data || !insulation) { + if (!pg || !data || !insulation) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_ext_insulation")); - insulationname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_ext_insulation")); + insulationname = str_get(&name); + } offset = e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -585,16 +604,18 @@ build_crawlspace struct str name; int is_init = 0; - if (!prefix || !pg || !data || !crawlspace) { + if (!pg || !data || !crawlspace) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_crawlspace")); - crawlname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_crawlspace")); + crawlname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -644,16 +665,18 @@ build_habitable struct str name; int is_init = 0; - if (!prefix || !pg || !data || !cavity) { + if (!pg || !data || !cavity) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_cavity")); - cavityname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_cavity")); + cavityname = str_get(&name); + } offset = e_wall + e_ext_insulation + e_int_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -706,16 +729,18 @@ build_attic struct str name; int is_init = 0; - if (!prefix || !pg || !data || !attic) { + if (!pg || !data || !attic) { res = RES_BAD_ARG; goto error; } - str_init(NULL, &name); - is_init = 1; - ERR(str_set(&name, prefix)); - ERR(str_append(&name, "_attic")); - atticname = str_get(&name); + if (prefix) { + str_init(NULL, &name); + is_init = 1; + ERR(str_set(&name, prefix)); + ERR(str_append(&name, "_attic")); + atticname = str_get(&name); + } offset = e_wall + e_insulation; ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); @@ -763,6 +788,11 @@ build_windows struct str gname; int is_init = 0; + if (!data || !data_cad) { + res = RES_BAD_ARG; + goto error; + } + scale[0] = sqrt(data->glass_ratio); scale[1] = scale[0]; scale[2] = scale[0]; @@ -838,10 +868,13 @@ build_windows } /* build glass */ - str_init(NULL, &gname); - is_init = 1; - ERR(str_set(&gname, prefix)); - ERR(str_append(&gname, "_glass")); + if (prefix) { + str_init(NULL, &gname); + is_init = 1; + ERR(str_set(&gname, prefix)); + ERR(str_append(&gname, "_glass")); + } + ERR(scad_fuse_geometries(str_cget(&gname), glass_list, 1, glass_list+1, sa_size(glass_list) - 1, &data_cad->glass)); @@ -894,6 +927,7 @@ build_boundary sa_push(list, data_cad->roof); sa_push(list, data_cad->floor); sa_push(list, data_cad->habitable_cavity); + 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); if (data_cad->internal_insulation) sa_push(list, data_cad->internal_insulation); @@ -1035,7 +1069,7 @@ build_connection } /* with wall */ - CREATE_CONNECT(crawlspace_cavity, wall,"_C_crawlspace_wall"); + CREATE_CONNECT(crawlspace_cavity, foundation,"_C_crawlspace_foundation"); } /* -------------------------------------------------------------------------*/ @@ -1139,6 +1173,7 @@ build_cad_model1(struct building* building) data_cad->external_insulation = NULL; data_cad->floor_insulation = NULL; data_cad->roof_insulation = NULL; + data_cad->foundation = NULL; data_cad->glass = NULL; data_cad->ground = NULL; data_cad->boundary = NULL; @@ -1153,11 +1188,12 @@ build_cad_model1(struct building* building) ERR(build_floor(str_cget(&prefix), pg, data, &data_cad->floor)); - ERR(build_wall(str_cget(&prefix), pg, height, data, &data_cad->wall)); + ERR(build_wall(str_cget(&prefix), "wall", pg, height, data, &data_cad->wall)); ERR(build_roof(str_cget(&prefix), pg, height, data, &data_cad->roof)); /* build optionnal elements : + - foundation - intermediate floor - external insulation - internal insulation @@ -1165,6 +1201,14 @@ build_cad_model1(struct building* building) - floor insulation */ + if (data->foundation > 0) { + double depth = -data->foundation; + ERR(build_wall( + str_cget(&prefix), "foundation", pg, depth, data, &data_cad->foundation)); + } else { + data_cad->foundation = NULL; + } + if (data->inter_floor_n > 0) { ERR(build_inter_floor( str_cget(&prefix), pg, height, data, &data_cad->intermediate_floor)); @@ -1253,20 +1297,55 @@ build_footprint_model1 struct scad_geometry** footprint) { res_T res = RES_OK; -/* struct scpr_polygon* pg = building->pg;*/ - /*struct scpr_polygon* pg_int = NULL;*/ - /*struct data_model1* data = (struct data_model1 *)building->data;*/ - /*double e_wall;*/ - /*struct scad_geometry* geom[2];*/ + 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; + } -/*exit:*/ - /*scad_geometry_delete(geom[0]);*/ - /*scad_geometry_delete(geom[1]);*/ -/* if(pg_int) scpr_polygon_ref_put(pg_int);*/ + 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)); + } + + +exit: + if (pg) scpr_polygon_ref_put(pg); + 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;*/ +error: + goto exit; } res_T @@ -1286,6 +1365,11 @@ export_stl_model1 /* roof export */ ERR(scad_stl_export(data_cad->roof, NULL, binary)); + /* foundation export */ + if (data_cad->foundation) { + ERR(scad_stl_export(data_cad->foundation, NULL, binary)); + } + /* glass export */ if (data_cad->glass) { ERR(scad_stl_export(data_cad->glass, NULL, binary)); diff --git a/src/cg_building_model1.h b/src/cg_building_model1.h @@ -49,6 +49,7 @@ struct data_cad_model1 { struct scad_geometry* wall; struct scad_geometry* roof; struct scad_geometry* floor; + struct scad_geometry* foundation; /* can be NULL */ struct scad_geometry* intermediate_floor; /* can be NULL */ struct scad_geometry* habitable_cavity; struct scad_geometry* crawlspace_cavity; /* can be NULL */ diff --git a/src/cg_ground.c b/src/cg_ground.c @@ -58,37 +58,20 @@ ground_build_cad ERR(str_set(&name, "ground")); ERR(scad_add_box - (str_cget(&name), + (NULL /*str_cget(&name)*/, origin, extent, &ground_box)); - ERR(scad_fragment_geometries - (NULL, - &ground_box, 1, - ground->footprint, ground->n, - &ground->geometry)); - - ERR(scad_geometry_boundary - (NULL, - &ground->geometry, 1, - &boundary)); - ERR(scad_cut_geometries - ("B_ground", - &boundary, 1, - ground->footprint, ground->n, - &ground->boundary)); - - /* TODO: do something for building with foundation. - * without foundation, the mesh is conformal because ground->footprint include - * geometry in contact with ground. */ - /*ERR(scad_scene_conformal_mesh(ground->scene));*/ - ERR(scad_geometry_delete(ground_box)); - ERR(scad_geometry_delete(boundary)); - + ( str_cget(&name), + &ground_box, 1, + ground->footprint, ground->n, + &ground->geometry)); + exit: if (is_init) str_release(&name); + if (ground_box) scad_geometry_delete(ground_box); return res; error: goto exit; @@ -100,7 +83,7 @@ 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)); + /*ERR(scad_stl_export(ground->boundary, "B_ground", binary));*/ exit: return res; diff --git a/src/cg_parsing.c b/src/cg_parsing.c @@ -390,13 +390,13 @@ parse_building_params data1->wall = 0.25; data1->floor = 0.35; data1->inter_floor = 0.2; - data1->inter_floor_n = 1; + data1->inter_floor_n = 0; data1->roof = 0.3; data1->int_insulation = 0.1; data1->ext_insulation = 0.; data1->floor_insulation = 0; data1->roof_insulation = 0; - data1->foundation = 0; + data1->foundation = 2; data1->crawl = 0; data1->attic = 0; data1->glass_ratio = 0.5;