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 89f5dce17d309a2ff83676cd5c826c076692f97f
parent b7726f0b2c4209707c77a1a66bee3e2b1dd6dd8f
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Tue, 21 Feb 2023 14:59:43 +0100

Beginning adjoining_feature. Seems ok for mode_0.

Diffstat:
Mcmake/CMakeLists.txt | 1+
Asrc/cg_building.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/cg_building.h | 8++++++++
Msrc/cg_city.c | 11+++++++++++
Msrc/cg_construction_mode_0.c | 4++++
5 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -103,6 +103,7 @@ endif() ################################################################################ set(CG2_FILES_SRC cg_args.c + cg_building.c cg_catalog.c cg_catalog_parsing.c cg_city.c diff --git a/src/cg_building.c b/src/cg_building.c @@ -0,0 +1,80 @@ +/* Copyright (C) 2022 Université de Pau et des Pays de l'Adour UPPA + * Copyright (C) 2022 CNRS + * Copyright (C) 2022 Sorbonne Université + * Copyright (C) 2022 Université Paul Sabatier + * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "cg.h" +#include "cg_building.h" +#include "cg_construction_mode.h" + +#include <rsys/stretchy_array.h> +#include <star/scad.h> +#include <star/scpr.h> + +res_T +build_adjoining + (const struct building* adjoining, + const size_t adjoining_n, + struct scad_geometry** geom) +{ + res_T res = RES_OK; + size_t i = 0; + struct scad_geometry** envelop_list = NULL; + + if (!adjoining || adjoining_n < 1 || !geom) { + res = RES_BAD_ARG; + goto error; + } + + /* iterate over adjoining building */ + for (i=0; i<adjoining_n; i++) { + size_t nverts = 0; + double height = adjoining[i].height; + double d[3] = {0, 0, 0}; + struct scpr_polygon* pg = adjoining[i].pg; + struct scad_geometry* envelop = NULL; + struct scad_geometry* footprint = NULL; + + ERR(scpr_polygon_get_vertices_count(pg, 0, &nverts)); + ERR(scad_add_polygon(NULL, get_position_pg, pg, 0, nverts, &footprint)); + + d[2] = height; + ERR(scad_geometry_extrude(footprint, NULL, d, &envelop)); + sa_push(envelop_list, envelop); + ERR(scad_geometry_delete(footprint)); + footprint = NULL; + } + + /* fuse envelops in the same geometries */ + if (adjoining_n > 1) { + ERR(scad_fuse_geometries(NULL, envelop_list, 1, + envelop_list+1, sa_size(envelop_list) - 1, geom)); + } else { + *geom = envelop_list[0]; + } + +exit: + if (envelop_list) sa_release(envelop_list); + return res; +error: + goto exit; +} + + + + + diff --git a/src/cg_building.h b/src/cg_building.h @@ -87,9 +87,17 @@ struct building { struct str name; double height; struct scpr_polygon* pg; + struct building* adjoining; + size_t adjoining_n; /* specific data depending to the construction mode */ void* data; }; +res_T +build_adjoining + (const struct building* adjoining, + const size_t adjoining_n, + struct scad_geometry** geom); + #endif /* BUILDING_H */ diff --git a/src/cg_city.c b/src/cg_city.c @@ -178,6 +178,17 @@ city_cad_build(struct city* city) for(i = 0; i < city->buildings_count; i++) { struct building* building = city->buildings + i; struct data_cad_cmode_0* cad = NULL; + + if (i==0) { + city->buildings[i].adjoining = &city->buildings[1]; + city->buildings[i].adjoining_n = 1; + } + + if (i==1) { + city->buildings[i].adjoining = &city->buildings[0]; + city->buildings[i].adjoining_n = 1; + } + /* create building */ ERR(building->functors->build_cad(city->scpr, city->allocator, city->logger, building, (void**)&cad)); diff --git a/src/cg_construction_mode_0.c b/src/cg_construction_mode_0.c @@ -511,6 +511,7 @@ build_cad_cmode_0 struct data_cad_cmode_0* data_cad = NULL; double e_wall; const char* name; + struct scad_geometry* adjoining_cad = NULL; if (!building || !allocator || !cad) { res = RES_BAD_ARG; @@ -552,6 +553,9 @@ build_cad_cmode_0 /* build fake ground */ ERR(build_fake_ground(pg, &data_cad->fake_ground)); + /* build adjoining envelop */ + ERR(build_adjoining(building->adjoining, building->adjoining_n, &adjoining_cad)); + ERR(scad_scene_partition()); /* build ground/building connection */