city_generator2

Generated conformal 3D meshes representing a city
git clone git://git.meso-star.fr/city_generator2.git
Log | Files | Refs | README | LICENSE

cg_city_parsing_schemas.h (5199B)


      1 /* Copyright (C) 2022 Université de Pau et des Pays de l'Adour UPPA
      2  * Copyright (C) 2022 CNRS
      3  * Copyright (C) 2022 Sorbonne Université
      4  * Copyright (C) 2022 Université Paul Sabatier
      5  * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com)
      6  *
      7  * This program is free software: you can redistribute it and/or modify
      8  * it under the terms of the GNU General Public License as published by
      9  * the Free Software Foundation, either version 3 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     19 
     20 #ifndef FG_CITY_PARSING_SCHEMAS__
     21 #define FG_CITY_PARSING_SCHEMAS__
     22 
     23 #include "cg_construction_modes_parsing_schemas.h"
     24 #include "cg_cyaml.h"
     25 
     26 #include <rsys/str.h>
     27 
     28 struct mem_allocator;
     29 struct logger;
     30 
     31 /********************************************************/
     32 /* Types used for parsing and to define parsing schemas */
     33 /********************************************************/
     34 
     35 struct parsed_city_building {
     36   char* name;
     37   enum parsed_cmode_type cmode_type;
     38   char* dataset_name;
     39   double* vertice; /* flat array of vertice: { x0 y0 x1 y1 x2 y2... } */
     40   double* levels_height;
     41   double height;
     42   unsigned levels_height_count;
     43 
     44   unsigned vertice_count;
     45 };
     46 
     47 struct parsed_ground {
     48   double extent[4];
     49   double depth;
     50 };
     51 
     52 struct parsed_city {
     53   struct mem_allocator* allocator;
     54   struct logger* logger;
     55   struct parsed_city_building* city_building_list;
     56   struct parsed_ground ground;
     57   struct str filename;
     58 
     59   unsigned city_building_list_count;
     60 };
     61 
     62 static const struct cyaml_schema_value coord_schema = {
     63   CYAML_VALUE_FLOAT(CYAML_FLAG_DEFAULT, double),
     64 };
     65 
     66 static const cyaml_schema_field_t ground_fields_schema[] = {
     67   CYAML_FIELD_FLOAT("depth", CYAML_FLAG_DEFAULT, struct parsed_ground,
     68       depth),
     69   CYAML_FIELD_SEQUENCE_FIXED("extent", CYAML_FLAG_FLOW, struct parsed_ground,
     70       extent, &coord_schema, 4),
     71   CYAML_FIELD_END
     72 };
     73 
     74 static const struct cyaml_schema_value p_ground_schema = {
     75   CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct parsed_ground,
     76       ground_fields_schema),
     77 };
     78 
     79 static const struct cyaml_schema_value entry_schema_double = {
     80   CYAML_VALUE_FLOAT(CYAML_FLAG_DEFAULT, double),
     81 };
     82 
     83 static const struct cyaml_schema_value double2_schema = {
     84   CYAML_VALUE_SEQUENCE_FIXED(CYAML_FLAG_DEFAULT, double,
     85       &entry_schema_double, 2),
     86 };
     87 
     88 static const cyaml_schema_field_t city_building_fields_schema[] = {
     89   CYAML_FIELD_STRING_PTR("name",
     90       CYAML_FLAG_POINTER, struct parsed_city_building, name, 0, CYAML_UNLIMITED),
     91   CYAML_FIELD_ENUM("construction_mode",
     92       CYAML_FLAG_CASE_INSENSITIVE, struct parsed_city_building, cmode_type,
     93       city_building_types_strings, CYAML_ARRAY_LEN(city_building_types_strings)),
     94   CYAML_FIELD_STRING_PTR("dataset",
     95       CYAML_FLAG_POINTER, struct parsed_city_building, dataset_name, 0, CYAML_UNLIMITED),
     96   {
     97     .key = "footprint",
     98     .value = {
     99       .type = CYAML_SEQUENCE,
    100       .flags = CYAML_FLAG_POINTER | CYAML_FLAG_FLOW,
    101       .data_size = sizeof(double[2]),
    102       .sequence = {
    103         .entry = &double2_schema,
    104         .min = 3,
    105         .max = CYAML_UNLIMITED,
    106       }
    107     },
    108     /* TODO: add list of polygons "internal_polygons" */
    109     .data_offset = offsetof(struct parsed_city_building, vertice),
    110     .count_size = sizeof(((struct parsed_city_building*)0)->vertice_count),
    111     .count_offset = offsetof(struct parsed_city_building, vertice_count),
    112   },
    113   CYAML_FIELD_FLOAT("height", CYAML_FLAG_OPTIONAL, struct parsed_city_building,
    114       height),
    115   CYAML_FIELD_SEQUENCE("levels_height",
    116       CYAML_FLAG_OPTIONAL | CYAML_FLAG_POINTER | CYAML_FLAG_FLOW,
    117       struct parsed_city_building, levels_height, &entry_schema_double,
    118       1, CYAML_UNLIMITED),
    119   CYAML_FIELD_END
    120 };
    121 
    122 static const struct cyaml_schema_value city_building_schema = {
    123   CYAML_VALUE_MAPPING(CYAML_FLAG_DEFAULT, struct parsed_city_building,
    124       city_building_fields_schema),
    125 };
    126 
    127 static const cyaml_schema_field_t city_fields_schema[] = {
    128   CYAML_FIELD_MAPPING("ground", CYAML_FLAG_DEFAULT,
    129       struct parsed_city, ground, ground_fields_schema),
    130   {
    131     .key = "buildings",
    132     .value = {
    133       .type = CYAML_SEQUENCE,
    134       .flags = CYAML_FLAG_POINTER,
    135       .data_size = sizeof(struct parsed_city_building),
    136       .sequence = {
    137         .entry = &city_building_schema,
    138         .min = 1,
    139         .max = CYAML_UNLIMITED,
    140       }
    141     },
    142     .data_offset = offsetof(struct parsed_city, city_building_list),
    143     .count_size = sizeof(((struct parsed_city*)0)->city_building_list_count),
    144     .count_offset = offsetof(struct parsed_city, city_building_list_count),
    145   },
    146   CYAML_FIELD_END
    147 };
    148 
    149 /* Top-level schema. The top level value for the city is a mapping.
    150  * Its fields are defined in plan_fields_schema.
    151  */
    152 static const cyaml_schema_value_t city_schema = {
    153   CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct parsed_city, city_fields_schema),
    154 };
    155 
    156 #endif