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 b7726f0b2c4209707c77a1a66bee3e2b1dd6dd8f
parent 9be8ffef78c74a23eff315c20a78a0acbff7467b
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 15 Feb 2023 10:30:46 +0100

Adapt to star-cpr changes (device concept)

Diffstat:
Msrc/cg_building.h | 26+++++++++++++++++++-------
Msrc/cg_city.c | 27+++++++++++++++++++--------
Msrc/cg_city.h | 4+++-
Msrc/cg_construction_mode_0.c | 49++++++++++++++++++++++++++++++++-----------------
Msrc/cg_construction_mode_0.h | 18++++++++++++------
Msrc/cg_construction_mode_1.c | 152+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/cg_construction_mode_1.h | 18++++++++++++------
Msrc/cg_ground.c | 8++++----
8 files changed, 192 insertions(+), 110 deletions(-)

diff --git a/src/cg_building.h b/src/cg_building.h @@ -31,23 +31,35 @@ struct logger; struct catalog; struct building; struct parsed_city_building; +struct scpr_device; /* A type to store the functors of a construction mode */ struct construction_mode_functors { res_T (*init) - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct parsed_city_building* parsed_data, - struct catalog* catalog); + struct catalog* catalog, + const double lower[2], + const double upper[2]); res_T (*build_cad) - (struct building* building, struct mem_allocator* allocator, - struct logger* logger, void** cad); + (struct scpr_device* scpr, + struct mem_allocator* allocator, + struct logger* logger, + struct building* building, + void** cad); res_T (*build_footprint) - (struct building* building, struct mem_allocator* allocator, - struct logger* logger, struct scad_geometry** footprint); + (struct scpr_device* scpr, + struct mem_allocator* allocator, + struct logger* logger, + struct building* building, + struct scad_geometry** footprint); res_T (*export_stl) - (void* cad, struct mem_allocator* allocator, struct logger* logger, + (struct mem_allocator* allocator, + struct logger* logger, + void* cad, const int binary); res_T (*release_cad) (struct mem_allocator* allocator, struct logger* logger, void* cad); diff --git a/src/cg_city.c b/src/cg_city.c @@ -63,6 +63,7 @@ create_city struct city* city = NULL; struct htable_names names; int initialized = 0; + struct scpr_device_create_args scpr_args = SCPR_DEVICE_CREATE_ARGS_DEFAULT; (void)logger; ASSERT(logger && allocator && args && parsed_city && catalog && out_city); @@ -86,11 +87,18 @@ create_city city->allocator = allocator; city->logger = logger; + scpr_args.allocator = allocator; + scpr_args.logger = logger; + scpr_args.verbosity_level = args->verbosity_level; + ERR(scpr_device_create(&scpr_args, &city->scpr)); city->verbosisty_level = args->verbosity_level; city->binary_export = args->binary_export; city->ground_depth = parsed_city->ground.depth; - d4_set(city->ground_extent, parsed_city->ground.extent); + city->lower[0] = parsed_city->ground.extent[0]; + city->lower[1] = parsed_city->ground.extent[2]; + city->upper[0] = parsed_city->ground.extent[1]; + city->upper[1] = parsed_city->ground.extent[3]; /* create buildings depending on their construction modes */ for (i = 0; i < city->buildings_count ; i++) { @@ -99,10 +107,12 @@ create_city char one = 1; switch(parsed_data->cmode_type) { case PARSED_CMODE_0: - ERR(init_cmode_0(building, allocator, logger, parsed_data, catalog)); + ERR(init_cmode_0(city->scpr, allocator, logger, building, parsed_data, + catalog, city->lower, city->upper)); break; case PARSED_CMODE_1: - ERR(init_cmode_1(building, allocator, logger, parsed_data, catalog)); + ERR(init_cmode_1(city->scpr, allocator, logger, building, parsed_data, + catalog, city->lower, city->upper)); break; default: res = RES_BAD_ARG; @@ -137,6 +147,7 @@ release_city(struct city* city) if(!city) return; + if(city->scpr) SCPR(device_ref_put(city->scpr)); /* iterate on building */ for (i = 0; i < city->buildings_count; i++) { struct building* building = city->buildings + i; @@ -168,10 +179,10 @@ city_cad_build(struct city* city) struct building* building = city->buildings + i; struct data_cad_cmode_0* cad = NULL; /* create building */ - ERR(building->functors->build_cad(building, city->allocator, city->logger, - (void**)&cad)); + ERR(building->functors->build_cad(city->scpr, city->allocator, city->logger, + building, (void**)&cad)); ERR(scad_scene_mesh()); - ERR(building->functors->export_stl(cad, city->allocator, city->logger, + ERR(building->functors->export_stl(city->allocator, city->logger, cad, city->binary_export)); ERR(building->functors->release_cad(city->allocator, city->logger, cad)); ERR(scad_scene_clear()); @@ -207,8 +218,8 @@ city_ground_build(struct city* city) struct building* building = city->buildings + i; struct scad_geometry** footprint = ground.footprints + i; /* create building footprint */ - ERR(building->functors->build_footprint(building, city->allocator, - city->logger, footprint)); + ERR(building->functors->build_footprint(city->scpr, city->allocator, + city->logger, building, footprint)); } ERR(ground_build_cad(city->allocator, city, &ground)); diff --git a/src/cg_city.h b/src/cg_city.h @@ -28,9 +28,10 @@ struct building; struct args; struct parsed_city; struct catalog; +struct scpr_device; struct city { - double ground_extent[4]; /* [xmin, xmax, ymin, ymax */ + double lower[2], upper[2]; /* Bbox */ double ground_depth; struct building* buildings; /* list of buildings */ size_t buildings_count; @@ -38,6 +39,7 @@ struct city { struct mem_allocator* allocator; struct logger* logger; + struct scpr_device* scpr; int verbosisty_level; }; diff --git a/src/cg_construction_mode_0.c b/src/cg_construction_mode_0.c @@ -29,6 +29,7 @@ #include <rsys/str.h> #include <rsys/logger.h> #include <star/scad.h> +#include <star/scpr.h> static res_T build_floor_footprint @@ -289,7 +290,7 @@ build_connection cad->n_connection = 3; /* cavity/floor connection */ - str_init(NULL, &name); + str_init(allocator, &name); is_init = 1; if (prefix) { ERR(str_set(&name, prefix)); @@ -381,8 +382,10 @@ error: static res_T building_ground_connection - (const char* prefix, + (struct scpr_device* scpr, + struct mem_allocator* allocator, struct scpr_polygon* pg, + const char* prefix, const double e, struct scad_geometry** connection) { @@ -393,17 +396,17 @@ building_ground_connection struct str name; int is_init = 0; - ASSERT(pg && e > 0 && connection); + ASSERT(scpr && allocator && pg && e > 0 && connection); if (prefix) { - str_init(NULL, &name); + str_init(allocator, &name); is_init = 1; ERR(str_set(&name, prefix)); ERR(str_append(&name, "_C_ground")); cname = str_get(&name); } - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -e, SCPR_JOIN_MITER)); ERR(build_wall_footprint(pg, pg_int, &geom[0])); @@ -427,16 +430,19 @@ error: res_T init_cmode_0 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct parsed_city_building* parsed_data, - struct catalog* catalog) + struct catalog* catalog, + const double lower[2], + const double upper[2]) { res_T res = RES_OK; struct dataset_cmode_0* dataset; struct str dataset_name; - int name_initialized = 0; + int name_initialized = 0, inside; static struct construction_mode_functors functors_0 = { &init_cmode_0, @@ -462,9 +468,15 @@ init_cmode_0 ERR(str_set(&building->name, parsed_data->name)); ERR(str_set(&dataset_name, parsed_data->dataset_name)); - ERR(scpr_polygon_create(allocator, &building->pg)); + ERR(scpr_polygon_create(scpr, &building->pg)); ERR(scpr_polygon_setup_indexed_vertices(building->pg, 1, get_nverts, get_pos, parsed_data)); + ERR(scpr_polygon_in_bbox(building->pg, lower, upper, &inside)); + if(!inside) { + logger_print(logger, LOG_ERROR, + "Building '%s' is out of the ground extent.\n", + str_cget(&building->name)); + } dataset = htable_dataset_cmode_0_find(&catalog->catalog_0, &dataset_name); if (dataset == NULL) { ERR(logger_print(logger, LOG_ERROR, @@ -485,9 +497,10 @@ error: res_T build_cad_cmode_0 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, void** cad) { res_T res = RES_OK; @@ -520,7 +533,7 @@ build_cad_cmode_0 } e_wall = data->wall_thickness; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -e_wall, SCPR_JOIN_MITER)); /* build floor with pg_int */ @@ -542,7 +555,8 @@ build_cad_cmode_0 ERR(scad_scene_partition()); /* build ground/building connection */ - ERR(building_ground_connection(name, pg, e_wall, &data_cad->ground_connection)); + ERR(building_ground_connection(scpr, allocator, pg, name, e_wall, + &data_cad->ground_connection)); /* build boundary */ ERR(build_boundary(name, allocator, data_cad)); @@ -562,13 +576,13 @@ error: res_T build_footprint_cmode_0 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct scad_geometry** footprint) { res_T res = RES_OK; - struct scpr_polygon* pg = building->pg; struct dataset_cmode_0* data = (struct dataset_cmode_0 *)building->data; double e_wall; (void)allocator; (void)logger; @@ -580,7 +594,8 @@ build_footprint_cmode_0 e_wall = data->wall_thickness; - ERR(building_ground_connection(NULL, pg, e_wall, footprint)); + ERR(building_ground_connection(scpr, allocator, building->pg, NULL, e_wall, + footprint)); exit: return res; @@ -590,9 +605,9 @@ error: res_T export_stl_cmode_0 - (void* cad, - struct mem_allocator* allocator, + (struct mem_allocator* allocator, struct logger* logger, + void* cad, const int binary) { res_T res = RES_OK; diff --git a/src/cg_construction_mode_0.h b/src/cg_construction_mode_0.h @@ -30,6 +30,7 @@ struct mem_allocator; struct logger; struct parsed_city_building; struct catalog; +struct scpr_device; /* specific data for construction mode 0 */ struct dataset_cmode_0 { @@ -63,31 +64,36 @@ struct data_cad_cmode_0 { res_T init_cmode_0 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct parsed_city_building* parsed_data, - struct catalog* catalog); + struct catalog* catalog, + const double lower[2], + const double upper[2]); res_T build_cad_cmode_0 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, void** cad); res_T build_footprint_cmode_0 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct scad_geometry** footprint); res_T export_stl_cmode_0 - (void* cad, - struct mem_allocator* allocator, + (struct mem_allocator* allocator, struct logger* logger, + void* cad, const int binary); res_T diff --git a/src/cg_construction_mode_1.c b/src/cg_construction_mode_1.c @@ -31,8 +31,9 @@ static res_T build_floor - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const struct dataset_cmode_1* data, struct scad_geometry** floor) @@ -61,7 +62,7 @@ build_floor } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -82,9 +83,10 @@ error: static res_T build_wall - (const char* prefix, - const char* suffix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, + const char* suffix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -119,11 +121,11 @@ build_wall } offset = e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_ext)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_ext)); ERR(scpr_offset_polygon(pg_ext, -offset, SCPR_JOIN_MITER)); offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*wall footprint*/ @@ -155,8 +157,9 @@ error: static res_T build_int_insulation - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -194,11 +197,11 @@ build_int_insulation } offset = e_ext_insulation + e_wall; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_ext)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_ext)); ERR(scpr_offset_polygon(pg_ext, -offset, SCPR_JOIN_MITER)); offset = e_ext_insulation + e_wall + e_int_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /* insulation footprint */ @@ -235,8 +238,9 @@ error: static res_T build_roof - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -267,7 +271,7 @@ build_roof } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -289,8 +293,9 @@ error: static res_T build_roof_insulation - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -323,7 +328,7 @@ build_roof_insulation } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -346,8 +351,9 @@ error: static res_T build_floor_insulation - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const struct dataset_cmode_1* data, struct scad_geometry** insulation) @@ -378,7 +384,7 @@ build_floor_insulation } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -401,8 +407,9 @@ error: static res_T build_inter_floor - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -442,7 +449,7 @@ build_inter_floor } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); ERR(scpr_polygon_get_vertices_count(pg_int, 0, &nverts)); @@ -483,8 +490,9 @@ error: static res_T build_ext_insulation - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -515,8 +523,8 @@ build_ext_insulation } offset = e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); - ERR(scpr_polygon_create_copy(NULL, pg, &pg_ext)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_ext)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*insulation footprint*/ @@ -548,8 +556,9 @@ error: static res_T build_crawlspace - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const struct dataset_cmode_1* data, struct scad_geometry** crawlspace) @@ -581,7 +590,7 @@ build_crawlspace } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -604,8 +613,9 @@ error: static res_T build_habitable - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -640,7 +650,7 @@ build_habitable } offset = e_wall + e_ext_insulation + e_int_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -669,8 +679,9 @@ error: static res_T build_attic - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct scpr_polygon* pg, const double height, const struct dataset_cmode_1* data, @@ -702,7 +713,7 @@ build_attic } offset = e_wall + e_insulation; - ERR(scpr_polygon_create_copy(NULL, pg, &pg_int)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_int)); ERR(scpr_offset_polygon(pg_int, -offset, SCPR_JOIN_MITER)); /*footprint*/ @@ -725,8 +736,9 @@ error: static res_T build_windows - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, const struct dataset_cmode_1* data, struct data_cad_cmode_1* data_cad) { @@ -748,6 +760,7 @@ build_windows size_t list_n = 0, array_n; struct str gname; int is_init = 0; + (void)scpr; ASSERT(allocator && data && data_cad); @@ -871,8 +884,9 @@ error: static res_T build_boundary - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, struct data_cad_cmode_1* data_cad, struct darray_geometries* boundary) { @@ -885,6 +899,7 @@ build_boundary char* boundaryname = NULL; struct str name; int is_init = 0; + (void)scpr; ASSERT(allocator && prefix && data_cad && boundary); @@ -992,8 +1007,9 @@ error: static res_T build_connection - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, struct data_cad_cmode_1* data_cad, struct darray_geometries* connection) { @@ -1003,6 +1019,7 @@ build_connection char* cname = NULL; struct str name; int is_init = 0; + (void)scpr; ASSERT(allocator && prefix && data_cad && connection); @@ -1119,7 +1136,8 @@ error: static res_T build_fake_ground - (struct mem_allocator* allocator, + (struct scpr_device* scpr, + struct mem_allocator* allocator, struct data_cad_cmode_1* cad, struct scpr_polygon* pg, const double depth, @@ -1156,7 +1174,7 @@ build_fake_ground count = darray_geometries_size_get(&array); list = darray_geometries_data_get(&array); - ERR(scpr_polygon_create_copy(NULL, pg, &pg_offset)); + ERR(scpr_polygon_create_copy(scpr, pg, &pg_offset)); ERR(scpr_offset_polygon(pg_offset, 0.1, SCPR_JOIN_MITER)); ERR(build_footprint(pg_offset, &footprint)); @@ -1178,8 +1196,9 @@ error: static res_T building_ground_connection - (const char* prefix, + (struct scpr_device* scpr, struct mem_allocator* allocator, + const char* prefix, struct data_cad_cmode_1* cad, struct scad_geometry** connection) { @@ -1193,7 +1212,7 @@ building_ground_connection struct scad_geometry* list_boundary = NULL; struct scad_geometry* footprint = NULL; - ASSERT(prefix && allocator && cad && connection); + ASSERT(scpr && allocator && prefix && cad && connection); darray_geometries_init(allocator, &array); @@ -1246,16 +1265,19 @@ error: res_T init_cmode_1 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct parsed_city_building* parsed_data, - struct catalog* catalog) + struct catalog* catalog, + const double lower[2], + const double upper[2]) { res_T res = RES_OK; struct dataset_cmode_1* dataset; struct str dataset_name; - int name_initialized = 0; + int name_initialized = 0, inside; static struct construction_mode_functors functors_1 = { &init_cmode_1, @@ -1281,9 +1303,15 @@ init_cmode_1 ERR(str_set(&building->name, parsed_data->name)); ERR(str_set(&dataset_name, parsed_data->dataset_name)); - ERR(scpr_polygon_create(allocator, &building->pg)); + ERR(scpr_polygon_create(scpr, &building->pg)); ERR(scpr_polygon_setup_indexed_vertices(building->pg, 1, get_nverts, get_pos, parsed_data)); + ERR(scpr_polygon_in_bbox(building->pg, lower, upper, &inside)); + if(!inside) { + logger_print(logger, LOG_ERROR, + "Building '%s' is out of the ground extent.\n", + str_cget(&building->name)); + } dataset = htable_dataset_cmode_1_find(&catalog->catalog_1, &dataset_name); if (dataset == NULL) { ERR(logger_print(logger, LOG_ERROR, @@ -1304,9 +1332,10 @@ error: res_T build_cad_cmode_1 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, void** cad) { res_T res = RES_OK; @@ -1337,11 +1366,11 @@ build_cad_cmode_1 */ name = str_cget(&building->name); - ERR(build_floor(name, allocator, pg, data, &data_cad->floor)); + ERR(build_floor(scpr, allocator, name, pg, data, &data_cad->floor)); - ERR(build_wall(name, "S_walls", allocator, pg, height, data, &data_cad->wall)); + ERR(build_wall(scpr, allocator, name, "S_walls", pg, height, data, &data_cad->wall)); - ERR(build_roof(name, allocator, pg, height, data, &data_cad->roof)); + ERR(build_roof(scpr, allocator, name, pg, height, data, &data_cad->roof)); /* build optionnal elements : - foundation @@ -1354,32 +1383,32 @@ build_cad_cmode_1 if (data->foundation_depth > 0) { depth = -data->foundation_depth; - ERR(build_wall(name, "S_foundation", allocator, pg, depth, data, + ERR(build_wall(scpr, allocator, name, "S_foundation", pg, depth, data, &data_cad->foundation)); } if (data->inter_floor_count > 0) { - ERR(build_inter_floor(name, allocator, pg, height, data, + ERR(build_inter_floor(scpr, allocator, name, pg, height, data, &data_cad->intermediate_floor)); } if (data->external_insulation_thickness> 0) { - ERR(build_ext_insulation(name, allocator, pg, height, data, + ERR(build_ext_insulation(scpr, allocator, name, pg, height, data, &data_cad->external_insulation)); } if (data->internal_insulation_thickness> 0) { - ERR(build_int_insulation(name, allocator, pg, height, data, + ERR(build_int_insulation(scpr, allocator, name, pg, height, data, data_cad->intermediate_floor, &data_cad->internal_insulation)); } if (data->roof_insulation_thickness > 0) { - ERR(build_roof_insulation(name, allocator, pg, height, data, + ERR(build_roof_insulation(scpr, allocator, name, pg, height, data, &data_cad->roof_insulation)); } if (data->floor_insulation_thickness > 0) { - ERR(build_floor_insulation(name, allocator, pg, data, + ERR(build_floor_insulation(scpr, allocator, name, pg, data, &data_cad->floor_insulation)); } @@ -1390,38 +1419,39 @@ build_cad_cmode_1 */ if (data->attic_height > 0) { - ERR(build_attic(name, allocator, pg, height, data, &data_cad->attic_cavity)); + ERR(build_attic(scpr, allocator, name, pg, height, data, + &data_cad->attic_cavity)); } - ERR(build_habitable(name, allocator, pg, height, data, + ERR(build_habitable(scpr, allocator, name, pg, height, data, data_cad->intermediate_floor, &data_cad->habitable_cavity)); if (data->crawl_height > 0) { - ERR(build_crawlspace(name, allocator, pg, data, &data_cad->crawlspace_cavity)); + ERR(build_crawlspace(scpr, allocator, name, pg, data, &data_cad->crawlspace_cavity)); } /* windows */ if (data->glass_ratio > 0) { - ERR(build_windows(name, allocator, data, data_cad)); + ERR(build_windows(scpr, allocator, name, data, data_cad)); } /* fake ground */ depth = MMAX(data->foundation_depth, data->floor_thickness + data->floor_insulation_thickness + data->crawl_height); - ERR(build_fake_ground(allocator, data_cad, pg, depth, + ERR(build_fake_ground(scpr, allocator, data_cad, pg, depth, &data_cad->fake_ground)); ERR(scad_scene_partition()); /* build ground/buildind connection */ - ERR(building_ground_connection(name, allocator, data_cad, + ERR(building_ground_connection(scpr, allocator, name, data_cad, &data_cad->ground_connection)); /* build boundaries */ - ERR(build_boundary(name, allocator, data_cad, &data_cad->boundary)); + ERR(build_boundary(scpr, allocator, name, data_cad, &data_cad->boundary)); /* build connections */ - ERR(build_connection(name, allocator, data_cad, &data_cad->connection)); + ERR(build_connection(scpr, allocator, name, data_cad, &data_cad->connection)); exit: *(struct data_cad_cmode_1**)cad = data_cad; @@ -1434,21 +1464,21 @@ error: res_T build_footprint_cmode_1 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct scad_geometry** footprint) { res_T res = RES_OK; - struct scpr_polygon* pg = building->pg; - (void)allocator; (void)logger; + (void)scpr; (void)allocator; (void)logger; if (!building || !footprint) { res = RES_BAD_ARG; goto error; } - ERR(build_footprint(pg, footprint)); + ERR(build_footprint(building->pg, footprint)); exit: return res; @@ -1458,9 +1488,9 @@ error: res_T export_stl_cmode_1 - (void* cad, - struct mem_allocator* allocator, + (struct mem_allocator* allocator, struct logger* logger, + void* cad, const int binary) { res_T res = RES_OK; diff --git a/src/cg_construction_mode_1.h b/src/cg_construction_mode_1.h @@ -31,6 +31,7 @@ struct mem_allocator; struct logger; struct parsed_city_building; struct catalog; +struct scpr_device; #define DARRAY_NAME geometries #define DARRAY_DATA struct scad_geometry* @@ -88,31 +89,36 @@ struct data_cad_cmode_1 { res_T init_cmode_1 - (struct building* building, + (struct scpr_device* device, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct parsed_city_building* parsed_data, - struct catalog* catalog); + struct catalog* catalog, + const double lower[2], + const double upper[2]); res_T build_cad_cmode_1 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, void** cad); res_T build_footprint_cmode_1 - (struct building* building, + (struct scpr_device* scpr, struct mem_allocator* allocator, struct logger* logger, + struct building* building, struct scad_geometry** footprint); res_T export_stl_cmode_1 - (void* cad, - struct mem_allocator* allocator, + (struct mem_allocator* allocator, struct logger* logger, + void* cad, const int binary); res_T diff --git a/src/cg_ground.c b/src/cg_ground.c @@ -40,12 +40,12 @@ ground_build_cad ASSERT(city && ground); - origin[0] = city->ground_extent[0]; - origin[1] = city->ground_extent[2]; + origin[0] = city->lower[0]; + origin[1] = city->lower[1]; origin[2] = -city->ground_depth; - extent[0] = city->ground_extent[1] - city->ground_extent[0]; - extent[1] = city->ground_extent[3] - city->ground_extent[2]; + extent[0] = city->upper[0] - city->lower[0]; + extent[1] = city->upper[1] - city->lower[1]; extent[2] = city->ground_depth; if (origin[2] > 0 || extent[0] < 0 || extent[1] < 0 || extent[2] < 0 ) {