43 #include <geogram/mesh/mesh_repair.h> 56 template < index_t DIMENSION >
77 do_copy( rhs, copy_attributes );
81 virtual void load_mesh(
const std::string& filename ) = 0;
90 void clear(
bool keep_attributes,
bool keep_memory )
92 do_clear( keep_attributes, keep_memory );
102 void repair( GEO::MeshRepairMode mode,
double colocate_epsilon )
197 static std::unique_ptr< MeshBaseBuilder< DIMENSION > >
create_builder(
234 virtual void do_clear(
bool keep_attributes,
bool keep_memory ) = 0;
243 GEO::MeshRepairMode mode,
double colocate_epsilon ) = 0;
268 const std::vector< double >& point_coordinates ) = 0;
276 const std::vector< bool >& to_delete ) = 0;
286 bool keep_attributes,
bool keep_memory ) = 0;
288 const std::vector< index_t >& permutation ) = 0;
296 template < index_t DIMENSION >
300 static std::unique_ptr< PointSetMeshBuilder< DIMENSION > >
326 template < index_t DIMENSION >
333 template < index_t DIMENSION >
347 do_create_edge( v1_id, v2_id );
348 clear_edge_linked_objects();
357 index_t index = do_create_edges( nb_edges );
358 clear_edge_linked_objects();
373 do_set_edge_vertex( edge_local_vertex, vertex_id );
374 clear_edge_linked_objects();
385 bool remove_isolated_vertices )
387 do_delete_edges( to_delete );
388 if( remove_isolated_vertices )
390 this->remove_isolated_vertices();
392 clear_edge_linked_objects();
404 do_clear_edges( keep_attributes, keep_memory );
405 clear_edge_linked_objects();
409 do_permute_edges( permutation );
410 clear_edge_linked_objects();
418 std::vector< bool > to_delete( line_mesh_.nb_vertices(), true );
419 for(
auto e :
range( line_mesh_.nb_edges() ) )
421 for(
auto v :
range( 2 ) )
425 to_delete[vertex_id] =
false;
443 line_mesh_.edge_nn_search_.reset();
449 clear_edge_linked_objects();
454 delete_edge_nn_search();
462 virtual void do_create_edge( index_t v1_id, index_t v2_id ) = 0;
468 virtual index_t do_create_edges( index_t nb_edges ) = 0;
478 virtual void do_set_edge_vertex(
486 virtual void do_delete_edges(
487 const std::vector< bool >& to_delete ) = 0;
496 virtual void do_clear_edges(
497 bool keep_attributes,
bool keep_memory ) = 0;
498 virtual void do_permute_edges(
499 const std::vector< index_t >& permutation ) = 0;
507 template < index_t DIMENSION >
514 template < index_t DIMENSION >
518 static std::unique_ptr< SurfaceMeshBuilder< DIMENSION > >
532 const std::vector< index_t >& polygon_ptr )
534 do_create_polygons( polygons, polygon_ptr );
535 clear_polygon_linked_objects();
545 index_t index = do_create_polygon( vertices );
546 clear_polygon_linked_objects();
556 index_t index = do_create_triangles( nb_triangles );
557 clear_polygon_linked_objects();
567 index_t index = do_create_quads( nb_quads );
568 clear_polygon_linked_objects();
583 do_set_polygon_vertex( polygon_local_edge, vertex_id );
584 clear_polygon_linked_objects();
599 do_set_polygon_adjacent( polygon_local_edge, specifies );
611 do_clear_polygons( keep_attributes, keep_memory );
612 clear_polygon_linked_objects();
619 std::vector< index_t > polygons_to_connect(
620 surface_mesh_.nb_polygons() );
622 polygons_to_connect.begin(), polygons_to_connect.end(), 0 );
623 connect_polygons( polygons_to_connect );
626 const std::vector< index_t >& polygons_to_connect )
628 index_t nb_local_vertices = 0;
629 for(
auto polygon : polygons_to_connect )
632 this->surface_mesh_.nb_polygon_vertices( polygon );
635 std::vector< ElementLocalVertex > polygon_vertices;
636 polygon_vertices.reserve( nb_local_vertices );
637 for(
auto polygon : polygons_to_connect )
640 this->surface_mesh_.nb_polygon_vertices( polygon ) ) )
642 polygon_vertices.emplace_back( polygon, v );
646 std::vector< index_t > next_local_vertex_around_vertex(
647 nb_local_vertices, NO_ID );
648 std::vector< index_t > vertex2polygon_local_vertex(
649 this->surface_mesh_.nb_vertices(), NO_ID );
650 index_t local_vertex_count = 0;
651 for(
auto polygon : polygons_to_connect )
654 v < this->surface_mesh_.nb_polygon_vertices( polygon );
655 v++, local_vertex_count++ )
657 index_t vertex = this->surface_mesh_.polygon_vertex(
659 next_local_vertex_around_vertex[local_vertex_count] =
660 vertex2polygon_local_vertex[vertex];
661 vertex2polygon_local_vertex[vertex] = local_vertex_count;
665 local_vertex_count = 0;
666 for(
auto polygon : polygons_to_connect )
669 v < this->surface_mesh_.nb_polygon_vertices( polygon );
670 v++, local_vertex_count++ )
672 if( !this->surface_mesh_.is_edge_on_border(
677 index_t vertex = this->surface_mesh_.polygon_vertex(
679 index_t next_vertex = this->surface_mesh_.polygon_vertex(
680 this->surface_mesh_.next_polygon_vertex(
682 for(
auto local_vertex =
683 vertex2polygon_local_vertex[next_vertex];
684 local_vertex != NO_ID;
686 next_local_vertex_around_vertex[local_vertex] )
688 if( local_vertex == local_vertex_count )
692 index_t adj_polygon =
693 polygon_vertices[local_vertex].element_id_;
694 index_t adj_local_vertex =
695 polygon_vertices[local_vertex].local_vertex_id_;
696 index_t adj_next_vertex =
697 this->surface_mesh_.polygon_vertex(
698 this->surface_mesh_.next_polygon_vertex(
700 adj_polygon, adj_local_vertex ) ) );
701 if( adj_next_vertex == vertex )
703 this->set_polygon_adjacent(
705 this->set_polygon_adjacent(
707 adj_polygon, adj_local_vertex ),
718 do_permute_polygons( permutation );
719 clear_polygon_linked_objects();
731 bool remove_isolated_vertices )
733 do_delete_polygons( to_delete );
734 if( remove_isolated_vertices )
736 this->remove_isolated_vertices();
738 clear_polygon_linked_objects();
753 virtual void remove_small_connected_components(
754 double min_area, index_t min_polygons ) = 0;
755 virtual void triangulate(
762 void remove_isolated_vertices()
764 std::vector< bool > to_delete( surface_mesh_.nb_vertices(), true );
765 for(
auto p :
range( surface_mesh_.nb_polygons() ) )
767 for(
auto v :
range( surface_mesh_.nb_polygon_vertices( p ) ) )
769 index_t vertex_id = surface_mesh_.polygon_vertex(
771 to_delete[vertex_id] =
false;
787 void delete_polygon_nn_search()
789 surface_mesh_.nn_search_.reset();
795 void delete_polygon_aabb()
797 surface_mesh_.polygon_aabb_.reset();
803 clear_polygon_linked_objects();
806 void clear_polygon_linked_objects()
808 delete_polygon_aabb();
809 delete_polygon_nn_search();
817 virtual void do_create_polygons(
const std::vector< index_t >& polygons,
818 const std::vector< index_t >& polygon_ptr ) = 0;
825 virtual index_t do_create_polygon(
826 const std::vector< index_t >& vertices ) = 0;
832 virtual index_t do_create_triangles( index_t nb_triangles ) = 0;
838 virtual index_t do_create_quads( index_t nb_quads ) = 0;
848 virtual void do_set_polygon_vertex(
860 virtual void do_set_polygon_adjacent(
870 virtual void do_clear_polygons(
871 bool keep_attributes,
bool keep_memory ) = 0;
873 virtual void do_permute_polygons(
874 const std::vector< index_t >& permutation ) = 0;
881 virtual void do_delete_polygons(
882 const std::vector< bool >& to_delete ) = 0;
890 template < index_t DIMENSION >
897 template < index_t DIMENSION >
900 static_assert( DIMENSION == 3,
"DIMENSION template should be 3" );
903 static std::unique_ptr< VolumeMeshBuilder< DIMENSION > >
create_builder(
916 index_t index = do_create_cells( nb_cells, type );
917 clear_cell_linked_objects();
929 do_assign_cell_tet_mesh( tets );
930 clear_cell_linked_objects();
944 do_set_cell_vertex( cell_local_vertex, vertex_id );
945 clear_cell_linked_objects();
954 index_t corner_index, index_t vertex_index )
956 do_set_cell_corner_vertex_index( corner_index, vertex_index );
957 clear_cell_linked_objects();
968 do_set_cell_adjacent( cell_local_facet, cell_adjacent );
974 virtual void connect_cells() = 0;
986 do_clear_cells( keep_attributes, keep_memory );
987 clear_cell_linked_objects();
1002 do_permute_cells( permutation );
1003 clear_cell_linked_objects();
1015 bool remove_isolated_vertices )
1017 do_delete_cells( to_delete );
1018 if( remove_isolated_vertices )
1020 this->remove_isolated_vertices();
1022 clear_cell_linked_objects();
1027 std::vector< bool > to_delete( volume_mesh_.nb_vertices(), true );
1028 for(
auto c :
range( volume_mesh_.nb_cells() ) )
1030 for(
auto v :
range( volume_mesh_.nb_cell_vertices( c ) ) )
1034 to_delete[vertex_id] =
false;
1052 volume_mesh_.cell_nn_search_.reset();
1053 volume_mesh_.cell_facet_nn_search_.reset();
1061 volume_mesh_.cell_aabb_.reset();
1067 clear_cell_linked_objects();
1073 delete_cell_nn_search();
1084 virtual index_t do_create_cells( index_t nb_cells,
CellType type ) = 0;
1092 virtual void do_assign_cell_tet_mesh(
1093 const std::vector< index_t >& tets ) = 0;
1103 virtual void do_set_cell_vertex(
1105 index_t vertex_id ) = 0;
1112 virtual void do_set_cell_corner_vertex_index(
1113 index_t corner_index, index_t vertex_index ) = 0;
1120 virtual void do_set_cell_adjacent(
1121 const CellLocalFacet& cell_local_facet, index_t cell_adjacent ) = 0;
1130 virtual void do_clear_cells(
1131 bool keep_attributes,
bool keep_memory ) = 0;
1143 virtual void do_permute_cells(
1144 const std::vector< index_t >& permutation ) = 0;
1151 virtual void do_delete_cells(
1152 const std::vector< bool >& to_delete ) = 0;
1160 template < index_t DIMENSION >
void clear_cell_linked_objects()
void create_edge(index_t v1_id, index_t v2_id)
Create a new edge.
virtual ~MeshBaseBuilder()=default
GEO::vecng< DIMENSION, double > vecn
index_t create_vertex()
Creates a new vertex.
PointSetMesh< DIMENSION > & pointset_mesh_
void delete_vertex_nn_search()
void delete_edges(const std::vector< bool > &to_delete, bool remove_isolated_vertices)
Deletes a set of edges.
index_t create_polygon(const std::vector< index_t > &vertices)
Creates a polygon.
MeshBaseBuilder(MeshBase< DIMENSION > &mesh)
void delete_vertices(const std::vector< bool > &to_delete)
Deletes a set of vertices.
virtual void do_permute_vertices(const std::vector< index_t > &permutation)=0
index_t create_vertex(const vecn< DIMENSION > &vertex)
Creates a new vertex.
void set_cell_corner_vertex_index(index_t corner_index, index_t vertex_index)
Sets the vertex that a corner is incident to.
void permute_edges(const std::vector< index_t > &permutation)
virtual void do_clear_vertices(bool keep_attributes, bool keep_memory)=0
Removes all the vertices and attributes.
void clear_vertex_linked_objects() override
Deletes the NNSearch on vertices.
VolumeMesh< DIMENSION > & volume_mesh_
ringmesh_template_assert_2d_or_3d(DIMENSION)
virtual void do_clear(bool keep_attributes, bool keep_memory)=0
Removes all the entities and attributes of this mesh.
void copy(const MeshBase< DIMENSION > &rhs, bool copy_attributes)
Copy a mesh into this one.
void connect_polygons()
Retrieve the adjacencies of polygons.
virtual index_t do_create_vertex()=0
Creates a new vertex.
void permute_polygons(const std::vector< index_t > &permutation)
void repair(GEO::MeshRepairMode mode, double colocate_epsilon)
Fixes some defaults in a mesh.
VolumeMeshBuilder(VolumeMesh< DIMENSION > &mesh)
void set_cell_adjacent(const CellLocalFacet &cell_local_facet, index_t cell_adjacent)
Sets the cell adjacent.
void set_cell_vertex(const ElementLocalVertex &cell_local_vertex, index_t vertex_id)
Sets a vertex of a cell by local vertex index.
void remove_isolated_vertices()
void delete_cell_nn_search()
Deletes the NNSearch on cells.
void delete_edge_nn_search()
Deletes the NNSearch on edges.
void permute_vertices(const std::vector< index_t > &permutation)
void clear_cells(bool keep_attributes, bool keep_memory)
Removes all the cells and attributes.
virtual void load_mesh(const std::string &filename)=0
index_t create_triangles(index_t nb_triangles)
Creates a contiguous chunk of triangles.
PointSetMeshBuilder(PointSetMesh< DIMENSION > &mesh)
static std::unique_ptr< MeshBaseBuilder< DIMENSION > > create_builder(MeshBase< DIMENSION > &mesh)
void clear_edge_linked_objects()
index_t create_vertices(index_t nb)
Creates a contiguous chunk of vertices.
LineMeshBuilder(LineMesh< DIMENSION > &mesh)
virtual void do_set_vertex(index_t v_id, const vecn< DIMENSION > &vertex)=0
Sets a point.
LineMesh< DIMENSION > & line_mesh_
void set_polygon_vertex(const PolygonLocalEdge &polygon_local_edge, index_t vertex_id)
Sets a vertex of a polygon by local vertex index.
void delete_polygons(const std::vector< bool > &to_delete, bool remove_isolated_vertices)
Deletes a set of polygons.
void create_polygons(const std::vector< index_t > &polygons, const std::vector< index_t > &polygon_ptr)
void set_vertex(index_t v_id, const vecn< DIMENSION > &vertex)
Sets a point.
encapsulate adimensional mesh functionalities in order to provide an API on which we base the RINGMes...
index_t create_quads(index_t nb_quads)
Creates a contiguous chunk of quads.
void permute_cells(const std::vector< index_t > &permutation)
Applies a permutation to the entities and their attributes. On exit, permutation is modified (used fo...
virtual void do_copy(const MeshBase< DIMENSION > &rhs, bool copy_attributes)=0
Copy a mesh into this one.
index_t create_cells(index_t nb_cells, CellType type)
Creates a contiguous chunk of cells of the same type.
void set_polygon_adjacent(const PolygonLocalEdge &polygon_local_edge, index_t specifies)
Sets an adjacent polygon by both its polygon.
void remove_isolated_vertices()
Remove vertices not connected to any mesh element.
virtual void do_assign_vertices(const std::vector< double > &point_coordinates)=0
set vertex coordinates from a std::vector of coordinates
void clear_vertex_linked_objects() override
Deletes the NNSearch on vertices.
virtual void remove_isolated_vertices()
void clear_polygons(bool keep_attributes, bool keep_memory)
Removes all the polygons and attributes.
virtual void clear_vertex_linked_objects()=0
Deletes the NNSearch on vertices.
void clear_edges(bool keep_attributes, bool keep_memory)
Removes all the edges and attributes.
void clear_vertices(bool keep_attributes, bool keep_memory)
Removes all the vertices and attributes.
Classes to build GeoModel from various inputs.
virtual void do_repair(GEO::MeshRepairMode mode, double colocate_epsilon)=0
Fixes some defaults in a mesh.
index_t create_edges(index_t nb_edges)
Creates a contiguous chunk of edges.
virtual void do_delete_vertices(const std::vector< bool > &to_delete)=0
Deletes a set of vertices.
void set_edge_vertex(const EdgeLocalVertex &edge_local_vertex, index_t vertex_id)
Sets a vertex of a edge by local vertex index.
virtual index_t do_create_vertices(index_t nb)=0
Creates a contiguous chunk of vertices.
void assign_cell_tet_mesh(const std::vector< index_t > &tets)
void connect_polygons(const std::vector< index_t > &polygons_to_connect)
void delete_cell_aabb()
Deletes the AABB on cells.
void clear_vertex_linked_objects() final
Deletes the NNSearch on vertices.
ringmesh_disable_copy_and_move(MeshBaseBuilder)
void assign_vertices(const std::vector< double > &point_coordinates)
set vertex coordinates from a std::vector of coordinates
void delete_cells(const std::vector< bool > &to_delete, bool remove_isolated_vertices)
Deletes a set of cells.
MeshBase< DIMENSION > & mesh_base_
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
void clear(bool keep_attributes, bool keep_memory)
Removes all the entities and attributes of this mesh.