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

Few modif in parsing

Diffstat:
Msrc/cg_building.h | 6+++++-
Msrc/cg_building_model0.c | 5++---
Msrc/cg_city.c | 2+-
Msrc/cg_parsing.c | 48++++++++++++++++++++++++++++++++++--------------
Msrc/cg_parsing.h | 14--------------
5 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/src/cg_building.h b/src/cg_building.h @@ -26,10 +26,14 @@ #define BUILDING_H enum model { - MODEL0, + model0, MODEL_COUNT_ }; +static char const* model_str [] = { + "model0" +}; + struct building { /* generic building data */ size_t id; diff --git a/src/cg_building_model0.c b/src/cg_building_model0.c @@ -470,9 +470,8 @@ build_cad_model0(struct building* building) str_init(NULL, &prefix); is_init = 1; ERR(str_set(&prefix, "building_")); - ERR(str_append_printf(&prefix, "%lu", (unsigned long)id)); - ERR(str_append(&prefix, "_model_")); - ERR(str_append_printf(&prefix, "%lu", (unsigned long)model)); + ERR(str_append_printf(&prefix, "%lu_", (unsigned long)id)); + ERR(str_append(&prefix, model_str[model])); data_cad = malloc(sizeof(struct data_cad_model0)); building->data_cad = (struct data_cad_model0*)data_cad; diff --git a/src/cg_city.c b/src/cg_city.c @@ -41,7 +41,7 @@ city_init(struct logger* logger, struct city* city, struct args* args) for (i=0; i<city->n ; ++i) { switch(city->building[i].model) { - case MODEL0: + case model0: city->building[i].init = &init_model0; break; default: diff --git a/src/cg_parsing.c b/src/cg_parsing.c @@ -65,6 +65,14 @@ error: goto exit; } +static enum model get_enum_value(char * val) { + int i=0; + for (i=0; i<MODEL_COUNT_; ++i) + if (!strcmp(model_str[i], val)) + return i; + return MODEL_COUNT_; + } + static res_T parse_ground (struct logger* logger, @@ -100,14 +108,13 @@ parse_ground } if (value) free(value); - /*if new section goto check and exit*/ + /*if new section break*/ if (sscanf(line, "[%[^]]", value) == 1 ) { - goto check; + break; } ERR(txtrdr_read_line(reader)); } -check: /*check depth*/ if (ground->depth <= 0) { logger_print(logger, LOG_ERROR, @@ -179,16 +186,36 @@ parse_building building->pg[0].x[2] = polygon[4]; building->pg[0].y[2] = polygon[5]; building->pg[0].x[3] = polygon[6]; building->pg[0].y[3] = polygon[7]; } - if (value) free(value); - /*if new section goto check and exit*/ + if (sscanf(line, "model=%s", value) == 1 ) { + building->model = get_enum_value(value); + } + if (value) free(value); + + /*if new section break*/ if (sscanf(line, "[%[^]]", value) == 1 ) { - goto check; + break; } ERR(txtrdr_read_line(reader)); } -check: + /*check height*/ + if (building->height <= 0) { + logger_print(logger, LOG_ERROR, + "[building] height value not valid: must be > 0.\n"); + res = RES_BAD_ARG; + goto error; + } + + /*check model*/ + if (building->model == MODEL_COUNT_) { + logger_print(logger, LOG_ERROR, + "[model] not recognized.\n"); + res = RES_BAD_ARG; + goto error; + } + + /*TODO : check polygon and unique id*/ exit: return res; @@ -215,7 +242,6 @@ parse: ERR(strtolower(line, line)); if (strcmp(line, "[building]") == 0) { ERR(parse_building(logger, reader, &b)); - b.model = MODEL0; sa_push(city->building, b); goto parse; } @@ -223,17 +249,11 @@ parse: ERR(parse_ground(logger, reader, &city->ground)); goto parse; } - if (strcmp(line, "[model]") == 0) { - /* TODO FINISH */ - b.model = MODEL0; - goto parse; - } ERR(txtrdr_read_line(reader)); } city->n = sa_size(city->building); - exit: return res; error: diff --git a/src/cg_parsing.h b/src/cg_parsing.h @@ -30,20 +30,6 @@ #ifndef PARSING_H #define PARSING_H -/*res_T strtolower(const char * src, char* dst ); */ - -/*res_T*/ -/*parse_ground*/ - /*(struct logger* logger,*/ - /*struct txtrdr* reader,*/ - /*struct ground* ground);*/ - -/*res_T*/ -/*parse_building*/ - /*(struct logger* logger,*/ - /*struct txtrdr* reader,*/ - /*struct building* building);*/ - res_T parse_city (struct logger* logger,