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_building.h (5604B)


      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 BUILDING_H
     21 #define BUILDING_H
     22 
     23 #include <rsys/rsys.h>
     24 #include <rsys/str.h>
     25 #include <rsys/dynamic_array.h>
     26 #include <rsys/dynamic_array_double.h>
     27 #include <rsys/hash_table.h>
     28 
     29 struct scpr_polygon;
     30 struct scad_geometry;
     31 struct catalog;
     32 struct building;
     33 struct parsed_city_building;
     34 struct city;
     35 struct darray_adjoining_data;
     36 struct darray_geometries;
     37 
     38 /* An htable to uniquely associate flags to buildings */
     39 #define HTABLE_NAME building
     40 #define HTABLE_KEY struct building*
     41 #define HTABLE_DATA unsigned char
     42 #include <rsys/hash_table.h>
     43 
     44 /* An enum to encode building events types. */
     45 enum building_event {
     46   /* 0x0000# */
     47   BUILDING_REMOVED_EARLY = BIT(0), /* Removed before CAO stage started */
     48   BUILDING_REMOVED = BIT(1), /* Removed after CAO stage started */
     49 
     50   /* 0x000#0 */
     51   BUILDING_INSIDE_BUILDING = BIT(4) | BUILDING_REMOVED_EARLY,
     52   BUILDING_WITH_OVERLAPPING = BIT(5) | BUILDING_REMOVED_EARLY,
     53   BUILDING_OUT_OF_GROUND_EXTENT = BIT(6) | BUILDING_REMOVED_EARLY,
     54   BUILDING_TOO_CLOSE_TO_BORDER = BIT(7) | BUILDING_REMOVED_EARLY,
     55 
     56   /* 0x0#000 */
     57   BUILDING_CREATED = BIT(12),
     58   BUILDING_WITH_CLOSE_NEIGHBOR = BIT(13),
     59   BUILDING_CAD_EXPORTED_TO_STL = BIT(14),
     60   BUILDING_GROUND_PATCH_CREATED = BIT(15),
     61   /* 0x#0000 */
     62   BUILDING_DUMPED_TO_OBJ = BIT(16)
     63 };
     64 
     65 /* A type to store the functors of a construction mode */
     66 struct construction_mode_functors {
     67   res_T (*init)
     68     (struct building* building,
     69      struct city* city,
     70      struct parsed_city_building* parsed_data,
     71      struct catalog* catalog,
     72      const double lower[2],
     73      const double upper[2]);
     74   res_T (*release)
     75     (struct building* building);
     76   res_T (*build_cad)
     77     (struct building* building,
     78      int dump_footprints_on_error,
     79      int keep_running_on_errors,
     80      struct darray_adjoining_data* adjoining_data,
     81      struct darray_geometries* current_cad,
     82      void** cad);
     83   res_T (*build_footprint)
     84     (struct building* building,
     85      struct scad_geometry** footprint);
     86   res_T (*save_ground_connection_triangles)
     87     (void* cad,
     88      struct darray_double* triangles);
     89   res_T (*export_stl)
     90     (void* cad,
     91      const int binary);
     92   res_T (*release_cad)
     93     (void* cad);
     94 };
     95 
     96 /* A type to give an ID to construction modes.
     97  * Add a new entry for each new construction mode. */
     98 enum construction_mode_type {
     99   mode_0,
    100   mode_1,
    101   mode_2,
    102   Construction_MODES_COUNT__
    103 };
    104 
    105 /* The name of the construction modes, as expected in the city description. */
    106 extern char const* construction_mode_name[Construction_MODES_COUNT__];
    107 
    108 /* The type of buildings as described in the city description */
    109 struct building {
    110   /* construction mode */
    111   struct construction_mode_functors* functors;
    112   enum construction_mode_type construction_mode;
    113 
    114   /* generic construction mode data */
    115   struct str name;
    116   struct str dataset_name;
    117   struct str external_layer_name;
    118   struct city* city;
    119   double total_height;
    120   struct darray_double levels_height;
    121   struct scpr_polygon* pg;
    122   struct htable_building close_buildings; /* links to other buildings */
    123   int structs_initialized;
    124   unsigned int event_flags;
    125 
    126   /* specific data depending to the construction mode */
    127   void* data;
    128   void* data_cad;
    129 };
    130 
    131 #define DARRAY_NAME pbuilding
    132 #define DARRAY_DATA struct building*
    133 #include <rsys/dynamic_array.h>
    134 
    135 struct adjoining_data {
    136   struct building* adjoining_building;
    137   struct building* main_building;
    138   /* Only valid for building save */
    139   struct scad_geometry* envelop;
    140   struct scad_geometry* common_geometry;
    141   int save, really_adjoining;
    142 };
    143 static FINLINE void
    144 adjoining_data_init(struct mem_allocator* alloc, struct adjoining_data* data)
    145 {
    146   ASSERT(data); (void)alloc;
    147   data->adjoining_building = NULL;
    148   data->main_building = NULL;
    149   data->envelop = NULL;
    150   data->common_geometry = NULL;
    151   data->save = 0;
    152 }
    153 void adjoining_data_release(struct adjoining_data* data);
    154 res_T adjoining_data_copy
    155   (struct adjoining_data* dst, const struct adjoining_data* src);
    156 res_T adjoining_data_copy_and_release
    157   (struct adjoining_data* dst, const struct adjoining_data* src);
    158 #define DARRAY_NAME adjoining_data
    159 #define DARRAY_DATA struct adjoining_data
    160 #define DARRAY_FUNCTOR_INIT adjoining_data_init
    161 #define DARRAY_FUNCTOR_COPY adjoining_data_copy
    162 #define DARRAY_FUNCTOR_RELEASE adjoining_data_release
    163 #define DARRAY_FUNCTOR_COPY_AND_RELEASE adjoining_data_copy_and_release
    164 #include <rsys/dynamic_array.h>
    165 
    166 void get_position_pg
    167   (const size_t ivert, double pos[2], void* ctx);
    168 
    169 res_T
    170 build_envelop
    171   (struct building* building,
    172    struct scad_geometry** envelop);
    173 
    174 res_T
    175 build_adjoining
    176   (struct building* building,
    177    const int silent,
    178    struct darray_geometries* current_cad,
    179    struct darray_adjoining_data* adjoining);
    180 
    181 #endif /* BUILDING_H */