24 double const radius_squared)
28 if (radius_squared == 0.)
30 return {start_element.
getID()};
34 std::vector<MathLib::Point3d> start_element_nodes;
37 start_element_nodes.reserve(start_element_n_nodes);
38 for (
unsigned n = 0; n < start_element_n_nodes; ++n)
40 start_element_nodes.push_back(*start_element.
getNode(n));
46 auto node_inside_radius =
47 [&start_element_nodes, radius_squared](
Node const* test_node)
50 start_element_nodes.begin(), start_element_nodes.end(),
51 [test_node, &radius_squared](
auto const node)
52 { return MathLib::sqrDist(*test_node, node) <= radius_squared; });
57 auto element_in_radius = [&node_inside_radius](
Element const& element)
59 auto const n_nodes = element.getNumberOfNodes();
60 for (
unsigned i = 0; i < n_nodes; ++i)
62 if (node_inside_radius(element.getNode(i)))
70 std::set<std::size_t> found_elements;
71 std::vector<Element const*> neighbors_to_visit;
72 std::unordered_set<std::size_t> visited_elements;
74 auto mark_visited_and_add_neighbors =
75 [&found_elements, &neighbors_to_visit, &visited_elements](
78 found_elements.insert(element.getID());
79 visited_elements.insert(element.getID());
80 auto const n_neighbors = element.getNumberOfNeighbors();
81 for (
unsigned n = 0; n < n_neighbors; ++n)
83 auto neighbor = element.getNeighbor(n);
84 if (neighbor ==
nullptr)
88 auto x = visited_elements.find(neighbor->getID());
89 if (x != visited_elements.end())
94 neighbors_to_visit.push_back(neighbor);
96 visited_elements.insert(neighbor->getID());
101 mark_visited_and_add_neighbors(start_element);
103 while (!neighbors_to_visit.empty())
105 auto const& current_element = *neighbors_to_visit.back();
106 neighbors_to_visit.pop_back();
109 if (element_in_radius(current_element))
111 mark_visited_and_add_neighbors(current_element);
115 return {std::begin(found_elements), std::end(found_elements)};