36 #include <ringmesh/ringmesh_tests_config.h> 51 void point_set_mesh_connected_component_test()
53 auto point_set = PointSetMesh3D::create_mesh();
54 auto point_set_builder =
55 PointSetMeshBuilder3D::create_builder( *point_set );
57 index_t nb_connected_components{ NO_ID };
58 std::vector< index_t > connected_components;
59 std::tie( nb_connected_components, connected_components ) =
60 point_set->connected_components();
61 if( nb_connected_components != 0 || connected_components.size() != 0 )
64 "Point set should have 0 connected component." );
66 const index_t max_itr{ 5 };
67 for(
auto i :
range( 1, max_itr + 1 ) )
69 point_set_builder->create_vertex( {
static_cast< double >( i ),
70 static_cast< double >( i ),
static_cast< double >( i ) } );
71 nb_connected_components = NO_ID;
72 connected_components.clear();
73 std::tie( nb_connected_components, connected_components ) =
74 point_set->connected_components();
75 if( nb_connected_components != i
76 || connected_components.size() != i )
79 "Point set should have ", i,
" connected components." );
82 std::vector< index_t > solution( i );
83 std::iota( solution.begin(), solution.end(), 0 );
84 if( connected_components != solution )
87 "Point set connected components are not correct." );
92 void line_mesh_connected_component_test()
94 auto line_mesh = LineMesh3D::create_mesh();
95 auto line_mesh_builder =
96 LineMeshBuilder3D::create_builder( *line_mesh );
98 index_t nb_connected_components{ NO_ID };
99 std::vector< index_t > connected_components;
100 std::tie( nb_connected_components, connected_components ) =
101 line_mesh->connected_components();
102 if( nb_connected_components != 0 || connected_components.size() != 0 )
105 "Line mesh should have 0 connected component." );
108 nb_connected_components = NO_ID;
109 auto v0 = line_mesh_builder->create_vertex( { 0., 0., 0. } );
110 auto v1 = line_mesh_builder->create_vertex( { 0., 0., 1. } );
111 line_mesh_builder->create_edge( v0, v1 );
112 std::tie( nb_connected_components, connected_components ) =
113 line_mesh->connected_components();
114 std::vector< index_t > solution( 1, 0 );
115 if( nb_connected_components != 1 || connected_components != solution )
118 "Line mesh should have 1 connected component with index 0." );
121 nb_connected_components = NO_ID;
122 auto v2 = line_mesh_builder->create_vertex( { 0., 0., 2. } );
123 line_mesh_builder->create_edge( v1, v2 );
124 std::tie( nb_connected_components, connected_components ) =
125 line_mesh->connected_components();
126 solution.push_back( 0 );
127 if( nb_connected_components != 1 || connected_components != solution )
130 "Line mesh should have 1 connected component with index 0." );
133 nb_connected_components = NO_ID;
134 auto v3 = line_mesh_builder->create_vertex( { 0., 0., 3. } );
135 auto v4 = line_mesh_builder->create_vertex( { 0., 0., 4. } );
136 line_mesh_builder->create_edge( v3, v4 );
137 std::tie( nb_connected_components, connected_components ) =
138 line_mesh->connected_components();
139 solution.push_back( 1 );
140 if( nb_connected_components != 2 || connected_components != solution )
143 "Line mesh should have 2 connected components: 0 0 1." );
146 nb_connected_components = NO_ID;
147 auto v5 = line_mesh_builder->create_vertex( { 1., 0., 0. } );
148 line_mesh_builder->create_edge( v5, v0 );
149 std::tie( nb_connected_components, connected_components ) =
150 line_mesh->connected_components();
151 solution.push_back( 0 );
152 if( nb_connected_components != 2 || connected_components != solution )
155 "Line mesh should have 2 connected components: 0 0 1 0." );
158 nb_connected_components = NO_ID;
159 auto v6 = line_mesh_builder->create_vertex( { 0., 0., 5. } );
160 auto v7 = line_mesh_builder->create_vertex( { 0., 0., 6. } );
161 line_mesh_builder->create_edge( v6, v7 );
162 line_mesh_builder->create_edge( v4, v6 );
163 std::tie( nb_connected_components, connected_components ) =
164 line_mesh->connected_components();
165 solution.push_back( 1 );
166 solution.push_back( 1 );
167 if( nb_connected_components != 2 || connected_components != solution )
170 "Line mesh should have 2 connected components: 0 0 1 0 1 1." );
173 nb_connected_components = NO_ID;
174 line_mesh_builder->create_edge( v2, v3 );
175 std::tie( nb_connected_components, connected_components ) =
176 line_mesh->connected_components();
180 solution.push_back( 0 );
181 if( nb_connected_components != 1 || connected_components != solution )
184 "Line mesh should have 1 connected component: 0 0 0 0 0 0 0." );
187 nb_connected_components = NO_ID;
188 auto v8 = line_mesh_builder->create_vertex( { 0., 0., 7. } );
189 auto v9 = line_mesh_builder->create_vertex( { 0., 0., 8. } );
190 line_mesh_builder->create_edge( v8, v9 );
191 auto v10 = line_mesh_builder->create_vertex( { 0., 0., 9. } );
192 auto v11 = line_mesh_builder->create_vertex( { 0., 0., 10. } );
193 line_mesh_builder->create_edge( v10, v11 );
194 line_mesh_builder->create_edge( v7, v8 );
195 std::tie( nb_connected_components, connected_components ) =
196 line_mesh->connected_components();
197 solution.push_back( 0 );
198 solution.push_back( 1 );
199 solution.push_back( 0 );
200 if( nb_connected_components != 2 || connected_components != solution )
203 "connected components: 0 " 204 "0 0 0 0 0 0 0 1 0." );
208 void update_polygon_adjacencies_after_adding_a_new_polygon(
209 SurfaceMeshBuilder3D& surface_mesh_builder, index_t new_polygon_id )
211 surface_mesh_builder.set_polygon_adjacent(
212 { new_polygon_id, 0 }, NO_ID );
213 surface_mesh_builder.set_polygon_adjacent(
214 { new_polygon_id, 1 }, NO_ID );
215 surface_mesh_builder.set_polygon_adjacent(
216 { new_polygon_id, 2 }, NO_ID );
217 surface_mesh_builder.connect_polygons();
218 surface_mesh_builder.repair(
219 GEO::MESH_REPAIR_TOPOLOGY, global_epsilon );
222 void surface_mesh_connected_component_test()
224 auto surface_mesh = SurfaceMesh3D::create_mesh();
225 auto surface_mesh_builder =
226 SurfaceMeshBuilder3D::create_builder( *surface_mesh );
228 index_t nb_connected_components{ NO_ID };
229 std::vector< index_t > connected_components;
230 std::tie( nb_connected_components, connected_components ) =
231 surface_mesh->connected_components();
232 if( nb_connected_components != 0 || connected_components.size() != 0 )
235 "Surface mesh should have 0 connected component." );
238 nb_connected_components = NO_ID;
239 std::vector< index_t > polygon_vertices = {
240 surface_mesh_builder->create_vertex( { 0., 0., 0. } ),
241 surface_mesh_builder->create_vertex( { 1., 0., 0. } ),
242 surface_mesh_builder->create_vertex( { 0., 1., 0. } )
245 surface_mesh_builder->create_polygon( polygon_vertices );
246 update_polygon_adjacencies_after_adding_a_new_polygon(
247 *surface_mesh_builder, polygon_id );
248 std::tie( nb_connected_components, connected_components ) =
249 surface_mesh->connected_components();
250 std::vector< index_t > solution( 1, 0 );
251 if( nb_connected_components != 1 || connected_components != solution )
254 "RINGMesh Test",
"Surface mesh should have 1 connected " 255 "component with an index at 0." );
258 nb_connected_components = NO_ID;
259 polygon_vertices[0] =
260 surface_mesh_builder->create_vertex( { 1., 1., 1. } );
261 polygon_id = surface_mesh_builder->create_polygon( polygon_vertices );
262 update_polygon_adjacencies_after_adding_a_new_polygon(
263 *surface_mesh_builder, polygon_id );
264 polygon_vertices[0] =
265 surface_mesh_builder->create_vertex( { 5., 5., 0. } );
266 polygon_vertices[1] =
267 surface_mesh_builder->create_vertex( { 5., 6., 0. } );
268 polygon_vertices[2] =
269 surface_mesh_builder->create_vertex( { 6., 5., 0. } );
270 polygon_id = surface_mesh_builder->create_polygon( polygon_vertices );
271 update_polygon_adjacencies_after_adding_a_new_polygon(
272 *surface_mesh_builder, polygon_id );
273 std::tie( nb_connected_components, connected_components ) =
274 surface_mesh->connected_components();
275 solution.push_back( 0 );
276 solution.push_back( 1 );
277 if( nb_connected_components != 2 || connected_components != solution )
280 "RINGMesh Test",
"Surface mesh should have 2 connected " 281 "component with an index at 0 0 1." );
285 void volume_mesh_connected_component_test()
288 auto volume_mesh_builder =
291 index_t nb_connected_components{ NO_ID };
292 std::vector< index_t > connected_components;
293 std::tie( nb_connected_components, connected_components ) =
294 volume_mesh->connected_components();
295 if( nb_connected_components != 0 || connected_components.size() != 0 )
298 "Volume mesh should have 0 connected component." );
304 point_set_mesh_connected_component_test();
305 line_mesh_connected_component_test();
306 surface_mesh_connected_component_test();
307 volume_mesh_connected_component_test();
319 Logger::out(
"TEST",
"Test connected components" );
327 catch(
const std::exception& e )
void run_tests(GeoModel3D &geomodel)
static std::unique_ptr< VolumeMeshBuilder< DIMENSION > > create_builder(VolumeMesh< DIMENSION > &mesh)
static void err(const std::string &feature, const Args &... args)
static void out(const std::string &feature, const Args &... args)
const std::string & category() const
Classes to build GeoModel from various inputs.
static std::unique_ptr< VolumeMesh< DIMENSION > > create_mesh(const MeshType type="")
void RINGMESH_API default_configure()