17#include <lagrange/Connectivity.h>
18#include <lagrange/MeshGeometry.h>
19#include <lagrange/common.h>
20#include <lagrange/legacy/inline.h>
21#include <lagrange/utils/safe_cast.h>
27template <
typename GeometryType>
31 using Index =
typename GeometryType::Index;
32 using IndexList =
typename Connectivity<GeometryType>::IndexList;
36 std::unique_ptr<Connectivity<GeometryType>> temporary_conn_ptr =
nullptr;
39 temporary_conn_ptr = compute_connectivity<GeometryType>(geometry);
40 conn = temporary_conn_ptr.get();
44 const auto num_facets = geometry.get_num_facets();
45 std::vector<bool> visited(num_facets,
false);
46 for (Index i = 0; i < num_facets; i++) {
47 if (visited[i])
continue;
48 m_components.emplace_back();
49 auto& comp = m_components.back();
59 const auto& adj_facets = conn->get_facets_adjacent_to_facet(f);
60 for (
const Index& adj_f : adj_facets) {
61 if (!visited[adj_f]) {
63 visited[adj_f] =
true;
69 m_per_facet_component_ids.resize(num_facets);
71 for (
const auto& comp : m_components) {
72 for (
const auto fid : comp) {
73 m_per_facet_component_ids[fid] = comp_id;
79 const std::vector<IndexList>& get_components()
const {
return m_components; }
81 const IndexList& get_per_facet_component_ids()
const {
return m_per_facet_component_ids; }
83 Index get_num_components()
const {
return safe_cast<Index>(m_components.size()); }
86 std::vector<IndexList> m_components;
87 IndexList m_per_facet_component_ids;
90template <
typename GeometryType>
92 const GeometryType& geometry,
95 auto ptr = std::make_unique<Components<GeometryType>>();
97 ptr->initialize(geometry, conn);
Definition: Connectivity.h:23
Definition: Components.h:29
size_t compute_components(SurfaceMesh< Scalar, Index > &mesh, ComponentOptions options={})
Compute connected components of an input mesh.
Definition: compute_components.cpp:99
Main namespace for Lagrange.
Definition: AABBIGL.h:30