43 #include <geogram/basic/line_stream.h> 51 class GeoModelBuilderTSolid;
52 class GeoModelBuilderTSolidImpl;
53 class GeoModelBuilderML;
55 struct TSolidLoadingStorage;
67 file_line_( filename_ )
69 if( !file_line_.OK() )
72 "I/O",
"Failed to open file ", filename_ );
86 virtual void read_line() = 0;
89 GEO::LineInput file_line_{ filename_ };
102 : builder_( gm_builder ), geomodel_( geomodel )
122 index_t nb_polygon_corners =
static_cast< index_t
>(
123 cur_surf_polygon_corners_gocad_id_.size() );
124 cur_surf_polygon_ptr_.push_back( nb_polygon_corners );
135 index_t nb_attribute_fields_{ 0 };
138 index_t cur_interface_{ NO_ID };
141 index_t cur_surface_{ NO_ID };
154 virtual void execute(
178 return vertices_gocad_id_[id];
184 return vertices_region_id_[id];
189 region_ids_.push_back( region_id );
190 region_names_.push_back( region_name );
194 index_t gocad_vertex_id, index_t region_id )
196 vertices_gocad_id_.push_back( gocad_vertex_id );
197 vertices_region_id_.push_back( region_id );
203 return static_cast< index_t
>( region_ids_.size() );
207 const std::string& region_name )
209 index_t region_id{ NO_ID };
210 for(
auto i :
range( region_names_.size() ) )
212 if( region_name.compare( region_names_[i] ) == 0 )
214 region_id = region_ids_[i];
216 return std::make_tuple(
true, region_id );
219 return std::make_tuple(
false, region_id );
228 std::vector< index_t >& region_tetra_corners_local )
const 230 index_t counter{ 0 };
231 for(
auto tetra_region_id : vertices_region_id_ )
233 if( tetra_region_id == region_id )
235 region_tetra_corners_local.push_back(
236 local_id( vertices_gocad_id_[counter] ) );
243 const std::vector< std::vector< double > >& stored_attributes,
245 const std::map< index_t, index_t >& lighttsolid_atom_map,
246 std::vector< std::vector< double > >& region_tetra_attributes )
250 stored_attributes.size() == gocad_ids2region_ids_.size() );
251 for(
auto gocad_id :
range( stored_attributes.size() ) )
253 if( gocad_ids2region_ids_[gocad_id] == region_id )
255 if( lighttsolid_atom_map.find( gocad_id )
256 == lighttsolid_atom_map.end() )
258 region_tetra_attributes.push_back(
259 stored_attributes[gocad_id] );
263 index_t corresponding_gocad_id{
264 lighttsolid_atom_map.find( gocad_id )->second
266 if( region( corresponding_gocad_id )
267 != region( gocad_id ) )
269 region_tetra_attributes.push_back(
270 stored_attributes[corresponding_gocad_id] );
281 : tetra_vertex( std::move( vertex ) ), local_id( local_id )
285 index_t local_id{ NO_ID };
288 std::vector< RegionLocalVertex >
290 const std::vector< vec3 >& stored_vertices,
291 const index_t region_id,
292 const std::map< index_t, index_t >& lighttsolid_atom_map
297 stored_vertices.size() == gocad_ids2region_ids_.size() );
298 std::vector< RegionLocalVertex > region_tetra_vertices;
299 for(
auto gocad_id :
range( stored_vertices.size() ) )
301 if( gocad_ids2region_ids_[gocad_id] == region_id )
303 if( lighttsolid_atom_map.find( gocad_id )
304 == lighttsolid_atom_map.end() )
306 region_tetra_vertices.emplace_back(
307 stored_vertices[gocad_id], gocad_id );
311 index_t corresponding_gocad_id{
312 lighttsolid_atom_map.find( gocad_id )->second
314 if( region( corresponding_gocad_id )
315 != region( gocad_id ) )
317 region_tetra_vertices.emplace_back(
318 stored_vertices[corresponding_gocad_id],
325 return region_tetra_vertices;
331 return gocad_ids2local_ids_[gocad_vertex_id];
334 index_t
region( index_t gocad_vertex_id )
const 337 return gocad_ids2region_ids_[gocad_vertex_id];
340 void add_vertex( index_t local_vertex_id, index_t region_id )
342 gocad_ids2local_ids_.push_back( local_vertex_id );
343 gocad_ids2region_ids_.push_back( region_id );
348 gocad_ids2local_ids_.reserve( capacity );
349 gocad_ids2region_ids_.reserve( capacity );
354 vertices_gocad_id_.reserve( capacity );
355 vertices_region_id_.reserve( capacity );
361 vertices_gocad_id_.size() == vertices_region_id_.size() );
362 size_t lighttsolid_vertices_nb = vertices_gocad_id_.size();
363 size_t lighttsolid_region_nb = nb_regions();
366 for(
auto region_index :
range( lighttsolid_region_nb ) )
370 for(
auto lighttsolid_vertices_id :
371 range( lighttsolid_vertices_nb ) )
374 if( region_id( lighttsolid_vertices_id ) == region_index )
376 index_t gocad_vertex_i{ gocad_vertex_id(
377 lighttsolid_vertices_id ) };
379 gocad_ids2region_ids_[gocad_vertex_i] =
380 region_id( lighttsolid_vertices_id );
389 vertices_gocad_id_.size() == vertices_region_id_.size() );
390 size_t lighttsolid_vertices_nb = vertices_gocad_id_.size();
391 size_t lighttsolid_region_nb = nb_regions();
394 for(
auto rgion_id :
range( lighttsolid_region_nb ) )
398 const auto& local_ids = local_ids_[rgion_id];
399 for(
auto lighttsolid_vertices_id :
400 range( lighttsolid_vertices_nb ) )
403 if( region_id( lighttsolid_vertices_id ) == rgion_id )
405 index_t gocad_vertex_i{ gocad_vertex_id(
406 lighttsolid_vertices_id ) };
407 for(
auto local_id :
range( local_ids.size() ) )
409 index_t gocad_id{ local_ids[local_id] };
410 if( gocad_id == gocad_vertex_i )
412 gocad_ids2local_ids_[gocad_vertex_i] = local_id;
421 const std::map< index_t, index_t >& lighttsolid_atom_map )
423 for(
const std::pair< index_t, index_t >& pair :
424 lighttsolid_atom_map )
426 if( region( pair.first ) == region( pair.second ) )
428 gocad_ids2local_ids_[pair.first] =
429 gocad_ids2local_ids_[pair.second];
498 index_t cur_region_{ NO_ID };
504 std::vector< index_t > tetra_corners_{};
507 std::vector< std::string > vertex_attribute_names_{};
510 std::vector< index_t > vertex_attribute_dims_{};
513 index_t cur_gocad_vrtx_id1_{ NO_ID };
514 index_t cur_gocad_vrtx_id2_{ NO_ID };
515 index_t cur_gocad_vrtx_id3_{ NO_ID };
516 index_t cur_gocad_vrtx_id4_{ NO_ID };
519 std::map< index_t, index_t > lighttsolid_atom_map_{};
522 index_t nb_vertices_{ 0 };
528 virtual void execute(
530 virtual void execute_light(
545 class RINGMESH_API GeoModelBuilderTSolid final :
public GeoModelBuilderGocad
548 static const index_t NB_TYPE = 2;
554 GeoModelBuilderTSolid( GeoModel3D& geomodel, std::string filename );
557 void read_number_of_vertices();
559 void load_file()
final;
567 void read_line()
final;
578 void compute_surface_internal_borders( index_t surface_id,
579 const std::vector< std::unique_ptr< NNSearch3D > >& surface_nns,
580 const std::vector< Box3D >& surface_boxes );
589 void compute_polygon_edge_centers_nn_and_surface_boxes(
590 std::vector< std::unique_ptr< NNSearch3D > >& surface_nns,
591 std::vector< Box3D >& surface_boxes )
const;
601 void compute_surfaces_internal_borders();
608 std::array< std::unique_ptr< GeoModelBuilderTSolidImpl >, NB_TYPE >
620 GeoModel3D& geomodel,
621 GEO::LineInput& file_line,
623 : builder_( builder ),
624 geomodel_( geomodel ),
625 file_line_( file_line ),
626 tsolid_load_storage_( tsolid_load_storage )
631 virtual void read_line() = 0;
645 GeoModel3D& geomodel,
646 GEO::LineInput& file_line,
649 builder, geomodel, file_line, tsolid_load_storage )
655 std::string keyword = file_line_.field( 0 );
656 std::unique_ptr< TSolidLineParser > tsolid_parser =
660 tsolid_parser->execute( file_line_, tsolid_load_storage_ );
664 std::unique_ptr< GocadLineParser > gocad_parser =
666 keyword, this->builder_, geomodel_ );
669 gocad_parser->execute( file_line_, tsolid_load_storage_ );
680 GeoModel3D& geomodel,
681 GEO::LineInput& file_line,
684 builder, geomodel, file_line, tsolid_load_storage )
690 std::string keyword = file_line_.field( 0 );
691 std::unique_ptr< TSolidLineParser > tsolid_parser =
695 tsolid_parser->execute_light(
696 file_line_, tsolid_load_storage_ );
700 std::unique_ptr< GocadLineParser > gocad_parser =
702 keyword, this->builder_, geomodel_ );
705 gocad_parser->execute( file_line_, tsolid_load_storage_ );
715 bool is_header_read_{
false };
718 index_t tface_vertex_ptr_{ 0 };
723 virtual void execute(
739 : GeoModelBuilderGocad( geomodel, std::move( filename ) )
761 void load_file()
final;
768 void read_line()
final;
#define ringmesh_disable_copy_and_move(Class)
index_t nb_regions() const
void end_polygon()
Ends a polygon (by adding the size of list of polygon corners at the end of the vector) ...
GeoModelBuilderML(GeoModel3D &geomodel, std::string filename)
GEO::LineInput & file_line_
static std::unique_ptr< BaseClass > create(const Key &key, const Args &... args)
std::vector< index_t > region_ids_
std::vector< std::vector< double > > attributes_
GeoModelBuilderTSolidImpl_TSolid(GeoModelBuilderTSolid &builder, GeoModel3D &geomodel, GEO::LineInput &file_line, TSolidLoadingStorage &tsolid_load_storage)
Structure used to load a GeoModel by GeoModelBuilderTSolid.
void reserve(index_t capacity)
index_t local_id(index_t gocad_vertex_id) const
TSolidLoadingStorage tsolid_load_storage_
void get_vertices_attributes_list_from_gocad_ids(const std::vector< std::vector< double > > &stored_attributes, index_t region_id, const std::map< index_t, index_t > &lighttsolid_atom_map, std::vector< std::vector< double > > ®ion_tetra_attributes) const
void get_tetra_corners_with_this_region_id(index_t region_id, std::vector< index_t > ®ion_tetra_corners_local) const
void fill_with_lighttsolid_region_ids()
std::vector< index_t > gocad_ids2local_ids_
void fill_with_lighttsolid_local_ids()
void RINGMESH_API initialize_gocad_import_factories()
Abstract interface class to load and build GeoModels from files.
const std::vector< index_t > & get_regions() const
RegionLocalVertex(vec3 vertex, index_t local_id)
std::vector< std::string > region_names_
std::vector< index_t > vertices_gocad_id_
GocadLineParser(GeoModelBuilderGocad &gm_builder, GeoModel3D &geomodel)
TSolidLoadingStorage & tsolid_load_storage_
std::tuple< bool, index_t > find_region_id_from_name(const std::string ®ion_name)
MLLoadingStorage ml_load_storage_
GeoModelBuilderGocad & builder_
void read_line() override
GeoModelBuilderTSolidImpl(GeoModelBuilderTSolid &builder, GeoModel3D &geomodel, GEO::LineInput &file_line, TSolidLoadingStorage &tsolid_load_storage)
Build a GeoModel from a Gocad Model3D (file_model.ml)
void record_vertex_with_its_region(index_t gocad_vertex_id, index_t region_id)
index_t region(index_t gocad_vertex_id) const
std::vector< vec3 > vertices_
std::array< std::unique_ptr< GeoModelBuilderTSolidImpl >, NB_TYPE > type_impl_
GeoModelBuilderTSolid & builder_
Builds a meshed GeoModel from a Gocad TSolid (file.so)
#define ringmesh_assert(x)
std::vector< index_t > vertices_region_id_
void add_vertex(index_t local_vertex_id, index_t region_id)
void add_new_region(index_t region_id, const std::string ®ion_name)
void reserve_nb_vertices(index_t capacity)
std::vector< index_t > gocad_ids2region_ids_
Classes to build GeoModel from various inputs.
void deal_with_same_region_atoms(const std::map< index_t, index_t > &lighttsolid_atom_map)
index_t gocad_vertex_id(index_t id) const
GeoModelBuilderGocad(GeoModel3D &geomodel, std::string filename)
void read_line() override
GeoModelBuilderTSolidImpl_LightTSolid(GeoModelBuilderTSolid &builder, GeoModel3D &geomodel, GEO::LineInput &file_line, TSolidLoadingStorage &tsolid_load_storage)
Structure which maps the vertex indices in Gocad::TSolid to the pair (region, index in region) in the...
std::vector< RegionLocalVertex > get_vertices_list_and_local_ids_from_gocad_ids(const std::vector< vec3 > &stored_vertices, const index_t region_id, const std::map< index_t, index_t > &lighttsolid_atom_map) const
std::vector< std::vector< index_t > > local_ids_
std::vector< index_t > cur_surf_polygon_ptr_
std::vector< index_t > cur_surf_polygon_corners_gocad_id_
index_t region_id(index_t id) const
GocadBaseParser(GeoModelBuilderGocad &gm_builder, GeoModel3D &geomodel)