cg_city.h (6188B)
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 CITY_H 21 #define CITY_H 22 23 #include "cg_building.h" 24 #include "cg_ground.h" 25 26 #include <star/scpr.h> 27 #include <star/scad.h> 28 29 #include <rsys/rsys.h> 30 #include <rsys/str.h> 31 #include <rsys/hash_table.h> 32 #include <rsys/dynamic_array.h> 33 #include <rsys/dynamic_array_double.h> 34 35 struct logger; 36 struct mem_allocator; 37 struct args; 38 struct parsed_city; 39 struct catalog; 40 struct scpr_device; 41 struct scpr_callback_segment; 42 struct vertex_denoiser; 43 44 static FINLINE void 45 ppoly_init 46 (struct mem_allocator* alloc, struct scpr_polygon** data) 47 { 48 ASSERT(data); (void)alloc; 49 *data = NULL; 50 } 51 static INLINE void 52 ppoly_release(struct scpr_polygon** data) { 53 ASSERT(data); 54 if(*data) SCPR(polygon_ref_put(*data)); 55 } 56 static INLINE res_T 57 ppoly_copy(struct scpr_polygon** dst, struct scpr_polygon* const* src) { 58 ASSERT(dst && src); 59 *dst = *src; 60 if(*src) SCPR(polygon_ref_get(*src)); 61 return RES_OK; 62 } 63 static FINLINE res_T 64 ppoly_copy_and_release 65 (struct scpr_polygon** dst, struct scpr_polygon* const* src) 66 { 67 ASSERT(dst && src); 68 *dst = *src; 69 return RES_OK; 70 } 71 #define DARRAY_NAME polygons 72 #define DARRAY_DATA struct scpr_polygon* 73 #define DARRAY_FUNCTOR_RELEASE ppoly_release 74 #define DARRAY_FUNCTOR_COPY ppoly_copy 75 #define DARRAY_FUNCTOR_COPY_AND_RELEASE ppoly_copy_and_release 76 #include <rsys/dynamic_array.h> 77 78 #define HTABLE_NAME polygons 79 #define HTABLE_KEY double 80 #define HTABLE_DATA struct scpr_polygon* 81 #define HTABLE_DATA_FUNCTOR_INIT ppoly_init 82 #define HTABLE_DATA_FUNCTOR_RELEASE ppoly_release 83 #define HTABLE_DATA_FUNCTOR_COPY ppoly_copy 84 #define HTABLE_DATA_FUNCTOR_COPY_AND_RELEASE ppoly_copy_and_release 85 #include <rsys/hash_table.h> 86 87 #define HTABLE_NAME names 88 #define HTABLE_DATA char 89 #define HTABLE_KEY struct str 90 #define HTABLE_KEY_FUNCTOR_INIT str_init 91 #define HTABLE_KEY_FUNCTOR_RELEASE str_release 92 #define HTABLE_KEY_FUNCTOR_COPY str_copy 93 #define HTABLE_KEY_FUNCTOR_COPY_AND_RELEASE str_copy_and_release 94 #define HTABLE_KEY_FUNCTOR_COPY_AND_CLEAR str_copy_and_clear 95 #define HTABLE_KEY_FUNCTOR_EQ str_eq 96 #define HTABLE_KEY_FUNCTOR_HASH str_hash 97 #include <rsys/hash_table.h> 98 99 /* A table to link a bunch of triangles and their normals to a pair of buildings. 100 * Used to store the common triangles and normals to ensure conformity despite 101 * the fact that buildings are meshed during differents star-cad sessions. */ 102 struct b_pair { 103 struct building* b1; 104 struct building* b2; 105 }; 106 static INLINE char 107 b_pair_eq(const struct b_pair* p0, const struct b_pair* p1) 108 { 109 return p0->b1 == p1->b1 && p0->b2 == p1->b2; 110 } 111 void 112 make_b_pair 113 (struct b_pair* pair, 114 struct building* b1, 115 struct building* b2); 116 #define HTABLE_NAME common 117 #define HTABLE_DATA struct darray_double 118 #define HTABLE_DATA_FUNCTOR_INIT darray_double_init 119 #define HTABLE_DATA_FUNCTOR_RELEASE darray_double_release 120 #define HTABLE_DATA_FUNCTOR_COPY darray_double_copy 121 #define HTABLE_DATA_FUNCTOR_COPY_AND_RELEASE darray_double_copy_and_release 122 #define HTABLE_KEY struct b_pair 123 #define HTABLE_KEY_FUNCTOR_EQ b_pair_eq 124 #include <rsys/hash_table.h> 125 126 struct city { 127 double lower[2], upper[2]; /* Bbox */ 128 double ground_depth; 129 struct building* buildings; /* list of buildings */ 130 struct ground ground; 131 struct vertex_denoiser* denoiser; 132 size_t cad_generated_buildings_count, allocated_buildings_count, 133 initialized_buildings_count; 134 struct htable_names dump_footprint_names; 135 struct htable_common common; 136 struct mem_allocator* allocator; 137 struct logger* logger; 138 struct scpr_device* scpr; 139 int single_thread; 140 int binary_export; 141 int verbosisty_level; 142 int keep_running_on_errors; 143 int dump_footprints_level; 144 int array_and_tables_initialized; 145 FILE* stardis_model; 146 FILE* set_vars; 147 }; 148 149 res_T 150 darray_double_merge 151 (struct darray_double* dest, 152 const struct darray_double* src); 153 154 res_T 155 create_city 156 (struct mem_allocator* allocator, 157 struct logger* logger, 158 const struct args* args, 159 struct parsed_city* parsed_city, 160 struct catalog* catalog, 161 struct city** out_city); 162 163 res_T 164 city_cad_build 165 (struct city* city); 166 167 res_T 168 city_ground_build 169 (struct city* city); 170 171 res_T 172 release_city(struct city* city); 173 174 res_T 175 dump_footprint_to_obj 176 (struct mem_allocator* allocator, 177 struct building* building, 178 struct scpr_polygon* alternate_polygon); /* Can be NULL */ 179 180 /* An enum to encode type of proximity of buildings. */ 181 enum building_proximity { 182 NO_PROXIMITY, 183 CLOSE_PROXIMITY = BIT(0), 184 OVERLAPPING_PROXIMITY = BIT(1), 185 TESTING_1_BUILDING_INTERNALS = BIT(2) 186 }; 187 188 /* the type of context expected by simple_intersection */ 189 struct callback_ctx { 190 struct city* city; 191 struct building* buildings; 192 struct scpr_polygon** alternate_polygons; 193 size_t buildings_count; 194 int* intersection_found; /* Can be NULL if not to be registered */ 195 enum building_proximity search_type; 196 int dump_footprints_level; 197 int keep_running_on_errors; 198 }; 199 #define CB_CTX_NULL__ { NULL, NULL, NULL, 0, NULL, NO_PROXIMITY, 0, 0 } 200 201 int overlapping_segments 202 (struct scpr_callback_segment* segment1, 203 struct scpr_callback_segment* segment2, 204 void* ctx__); 205 206 int simple_intersection 207 (struct scpr_callback_segment* segment1, 208 struct scpr_callback_segment* segment2, 209 void* ctx__); 210 211 res_T 212 save_ground_hole_patch_triangles 213 (struct building* building, 214 struct darray_double* ground_trg); 215 216 #endif /*CITY_H*/