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 715ae8a5b68efacbb81df3bf6d866b1dfcebadae
parent 69757d03fa6ea40dd0fd419afb7506a57131406a
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Fri,  7 Oct 2022 12:12:00 +0200

Add ascii/binary argument for stl export in command line

Diffstat:
Msrc/cg_args.c | 10+++++++++-
Msrc/cg_args.h | 1+
Msrc/cg_building.h | 2+-
Msrc/cg_building_model0.c | 14+++++++-------
Msrc/cg_building_model0.h | 2+-
Msrc/cg_city.c | 28++++------------------------
Msrc/cg_city.h | 6++----
Msrc/cg_ground.c | 6+++---
Msrc/cg_ground.h | 2+-
9 files changed, 29 insertions(+), 42 deletions(-)

diff --git a/src/cg_args.c b/src/cg_args.c @@ -31,15 +31,23 @@ parse_args(struct logger* logger, int argc, char** argv, struct args* args) int opt = 0; int is_init1 = 0; int is_init2 = 0; - const char option_list[] = "b:c:"; + const char option_list[] = "ab:c:"; str_init(NULL, &args->building_model_file); is_init1 = 1; str_init(NULL, &args->city_model_file); is_init2 = 1; + /* by default the export is binary */ + args->binary_export = 1; + while((opt = getopt(argc, argv, option_list)) != -1) { switch (opt) { + case 'a': + { + args->binary_export = 0; + break; + } case 'b': { str_set(&args->building_model_file, optarg); diff --git a/src/cg_args.h b/src/cg_args.h @@ -28,6 +28,7 @@ struct args { struct str city_model_file; struct str building_model_file; + int binary_export; }; diff --git a/src/cg_building.h b/src/cg_building.h @@ -49,7 +49,7 @@ struct building { res_T (*build_footprint) (struct building* building, struct scad_geometry** footprint); - res_T (*export_stl)(const struct building* building); + res_T (*export_stl)(const struct building* building, const int binary); res_T (*release)(struct building* building); }; diff --git a/src/cg_building_model0.c b/src/cg_building_model0.c @@ -551,31 +551,31 @@ error: res_T export_stl_model0 -(const struct building* building) +(const struct building* building, const int binary) { res_T res = RES_OK; struct data_cad_model0* data_cad = (struct data_cad_model0 *)building->data_cad; size_t i; /* floor export */ - ERR(scad_stl_export(data_cad->floor, NULL, 0)); + ERR(scad_stl_export(data_cad->floor, NULL, binary)); /* roof export */ - ERR(scad_stl_export(data_cad->roof, NULL, 0)); + ERR(scad_stl_export(data_cad->roof, NULL, binary)); /* wall export */ - ERR(scad_stl_export(data_cad->wall, NULL, 0)); + ERR(scad_stl_export(data_cad->wall, NULL, binary)); /* cavity export */ - ERR(scad_stl_export(data_cad->cavity, NULL, 0)); + ERR(scad_stl_export(data_cad->cavity, NULL, binary)); /* connection export */ for (i=0; i<data_cad->n_connection; ++i) { - ERR(scad_stl_export(data_cad->connection[i], NULL, 0)); + ERR(scad_stl_export(data_cad->connection[i], NULL, binary)); } /* boundary export */ - ERR(scad_stl_export(data_cad->boundary, NULL, 0)); + ERR(scad_stl_export(data_cad->boundary, NULL, binary)); exit: return res; diff --git a/src/cg_building_model0.h b/src/cg_building_model0.h @@ -53,7 +53,7 @@ build_footprint_model0 res_T export_stl_model0 - (const struct building* building); + (const struct building* building, const int binary); res_T release_model0 diff --git a/src/cg_city.c b/src/cg_city.c @@ -33,6 +33,8 @@ city_init(struct logger* logger, struct city* city, struct args* args) size_t i=0; struct txtrdr* reader = NULL; + city->binary_export = args->binary_export; + ERR(txtrdr_file(NULL, str_cget(&args->city_model_file), '#', &reader)); ERR(parse_city(logger, reader, city)); @@ -91,7 +93,7 @@ city_cad_build(struct logger* logger, struct city* city) /* create building */ ERR(city->building[i].build_cad(&city->building[i])); ERR(scad_scene_mesh()); - ERR(city->building[i].export_stl(&city->building[i])); + ERR(city->building[i].export_stl(&city->building[i], city->binary_export)); ERR(scad_scene_clear()); } @@ -124,7 +126,7 @@ city_ground_build(struct logger* logger, struct city* city) ERR(ground_build_cad(&city->ground)); ERR(scad_scene_mesh()); - ERR(ground_export_stl(&city->ground)); + ERR(ground_export_stl(&city->ground, city->binary_export)); exit: scad_finalize(); @@ -132,25 +134,3 @@ exit: error: goto exit; } - - -res_T -city_export_stl(const struct city* city) -{ - res_T res = RES_OK; - size_t i,n; - - /* iterate on building */ - n = city->n; - for (i=0; i<n; ++i) { - ERR(city->building[i].export_stl(&city->building[i])); - } - - /* ground */ - ERR(ground_export_stl(&city->ground)); - -exit: - return res; -error: - goto exit; -} diff --git a/src/cg_city.h b/src/cg_city.h @@ -62,9 +62,10 @@ struct city { struct building* building; /* list of buildings */ size_t n; struct ground ground; + int binary_export; }; -#define CITY_NULL__ {NULL, 0, GROUND_NULL} +#define CITY_NULL__ {NULL, 0, GROUND_NULL, 0} static const struct city CITY_NULL = CITY_NULL__; res_T @@ -77,8 +78,5 @@ res_T city_ground_build(struct logger* logger, struct city* city); res_T -city_export_stl(const struct city* city); - -res_T city_release(struct city* city); #endif /*CITY_H*/ diff --git a/src/cg_ground.c b/src/cg_ground.c @@ -97,12 +97,12 @@ error: res_T -ground_export_stl(const struct ground* ground) +ground_export_stl(const struct ground* ground, const int binary) { res_T res = RES_OK; - ERR(scad_stl_export(ground->geometry, "S_ground", 0)); - ERR(scad_stl_export(ground->boundary, "B_ground", 0)); + ERR(scad_stl_export(ground->geometry, "S_ground", binary)); + ERR(scad_stl_export(ground->boundary, "B_ground", binary)); exit: return res; diff --git a/src/cg_ground.h b/src/cg_ground.h @@ -46,7 +46,7 @@ ground_build_cad (struct ground* ground); res_T -ground_export_stl(const struct ground* ground); +ground_export_stl(const struct ground* ground, const int binary); res_T ground_release(struct ground* ground);