3#include <boost/iterator/function_output_iterator.hpp>
4#include <boost/range/irange.hpp>
15precice::logging::Logger
Index::_log{
"query::Index"};
17namespace bg = boost::geometry;
18namespace bgi = boost::geometry::index;
59 boost::irange<std::size_t>(0lu,
mesh.nVertices()), params, ind);
61 indices.vertexRTree = std::move(tree);
80 boost::irange<std::size_t>(0lu,
mesh.edges().size()), params, ind);
82 indices.edgeRTree = std::move(tree);
99 for (
size_t i = 0; i <
mesh.triangles().size(); ++i) {
100 auto box = bg::return_envelope<RTreeBox>(
mesh.triangles()[i]);
110 indices.triangleRTree = std::move(tree);
127 for (
size_t i = 0; i <
mesh.tetrahedra().size(); ++i) {
140 indices.tetraRTree = std::move(tree);
177 const auto &rtree =
_pimpl->getVertexRTree(*
_mesh);
178 rtree->query(bgi::nearest(sourceCoord, 1), boost::make_function_output_iterator([&](
size_t matchID) {
189 const auto &rtree =
_pimpl->getVertexRTree(*
_mesh);
191 rtree->query(bgi::nearest(sourceCoord, n), boost::make_function_output_iterator([&](
size_t matchID) {
204 rtree->query(bgi::nearest(sourceCoord, n), boost::make_function_output_iterator([&](
size_t matchID) {
213 const auto &rtree =
_pimpl->getTriangleRTree(*
_mesh);
216 rtree->query(bgi::nearest(sourceCoord, n),
229 auto searchBox =
query::makeBox(coords.array() - radius, coords.array() + radius);
231 const auto &rtree =
_pimpl->getVertexRTree(*
_mesh);
233 rtree->query(bgi::intersects(searchBox) and bg::index::satisfies([&](
size_t const i) {
return bg::distance(centerVertex,
_mesh->vertex(i)) < radius; }),
244 auto searchBox =
query::makeBox(coords.array() - radius, coords.array() + radius);
246 const auto &rtree =
_pimpl->getVertexRTree(*
_mesh);
248 auto queryIter = rtree->qbegin(bgi::intersects(searchBox) and bg::index::satisfies([&](
size_t const i) {
return bg::distance(centerVertex,
_mesh->vertex(i)) < radius; }));
249 bool hasMatch = queryIter != rtree->qend();
257 const auto &rtree =
_pimpl->getVertexRTree(*
_mesh);
277 if (
_mesh->getDimensions() == 2) {
286 if (
_mesh->getDimensions() == 2) {
288 for (
const auto &match : matchedTriangles) {
290 if (polation.isInterpolation()) {
291 return {std::move(polation)};
301 for (
const auto &match : matchedTetra) {
304 if (polation.isInterpolation()) {
305 return {std::move(polation)};
324 if (polation.isInterpolation()) {
330 if (candidates.
empty()) {
331 return closestVertex;
337 return closestVertex;
348 if (polation.isInterpolation()) {
354 if (candidates.
empty()) {
375 auto rtreeBox =
_pimpl->getVertexRTree(*_mesh)->bounds();
376 int dim =
_mesh->getDimensions();
377 Eigen::VectorXd min(dim), max(dim);
379 min[0] = rtreeBox.min_corner().get<0>();
380 min[1] = rtreeBox.min_corner().get<1>();
381 max[0] = rtreeBox.max_corner().get<0>();
382 max[1] = rtreeBox.max_corner().get<1>();
385 min[2] = rtreeBox.min_corner().get<2>();
386 max[2] = rtreeBox.max_corner().get<2>();
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
T back_inserter(T... args)
Calculates the barycentric coordinates of a coordinate on the given vertex/edge/triangle and stores t...
double distance() const
Returns the projection distance.
An axis-aligned bounding box around a (partition of a) mesh.
Eigen::VectorXd maxCorner() const
the max corner of the bounding box
Eigen::VectorXd minCorner() const
the min corner of the bounding box
Container and creator for meshes.
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
VertexTraits::Ptr getVertexRTree(const mesh::Mesh &mesh)
TetrahedronTraits::Ptr getTetraRTree(const mesh::Mesh &mesh)
TriangleTraits::Ptr getTriangleRTree(const mesh::Mesh &mesh)
EdgeTraits::Ptr getEdgeRTree(const mesh::Mesh &mesh)
mesh::BoundingBox getRtreeBounds()
std::vector< TetrahedronID > getEnclosingTetrahedra(const Eigen::VectorXd &location)
Return all the tetrahedra whose axis-aligned bounding box contains a vertex.
mesh::Mesh * _mesh
The indexed Mesh.
ProjectionMatch findCellOrProjection(const Eigen::VectorXd &location, int n)
VertexMatch getClosestVertex(const Eigen::VectorXd &sourceCoord)
Get the closest vertex to the given vertex.
ProjectionMatch findNearestProjection(const Eigen::VectorXd &location, int n)
Find the closest interpolation element to the given location. If exists, triangle or edge projection ...
bool isAnyVertexInsideBox(const mesh::Vertex ¢erVertex, double radius)
Returns.
std::unique_ptr< IndexImpl > _pimpl
std::vector< TriangleMatch > getClosestTriangles(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest triangles to the given vertex.
std::vector< VertexID > getVerticesInsideBox(const mesh::Vertex ¢erVertex, double radius)
Return all the vertices inside the box formed by vertex and radius (boundary exclusive)
void clear()
Clear the index.
ProjectionMatch findEdgeProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex)
Find closest edge interpolation element. If cannot be found, it falls back to vertex projection.
ProjectionMatch findVertexProjection(const Eigen::VectorXd &location)
Closest vertex projection element is always the nearest neighbor.
Index(mesh::PtrMesh mesh)
std::vector< VertexID > getClosestVertices(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest vertices to the given vertex.
ProjectionMatch findTriangleProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex)
Find closest face interpolation element. If cannot be found, it falls back to first edge interpolatio...
std::vector< EdgeMatch > getClosestEdges(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest edges to the given vertex.
static precice::logging::Logger _log
T emplace_back(T... args)
provides Mesh, Data and primitives.
std::shared_ptr< Mesh > PtrMesh
boost::geometry::index::rstar< 16 > RTreeParameters
The general rtree parameter type used in precice.
contains geometrical queries.
impl::RTreeTraits< mesh::Edge > EdgeTraits
RTreeBox makeBox(const pm::Vertex::RawCoords &min, const pm::Vertex::RawCoords &max)
impl::RTreeTraits< mesh::Vertex > VertexTraits
impl::RTreeTraits< mesh::Triangle > TriangleTraits
impl::RTreeTraits< mesh::Tetrahedron > TetrahedronTraits
MatchType< struct VertexMatchTag > VertexMatch
constexpr auto get(span< E, S > s) -> decltype(s[N])
VertexTraits::Ptr vertexRTree
EdgeTraits::Ptr edgeRTree
TetrahedronTraits::Ptr tetraRTree
TriangleTraits::Ptr triangleRTree
Struct representing a projection match.
mapping::Polation polation
The type traits of a rtree based on a Primitive.
typename std::conditional< IsDirectIndexable< mesh::Triangle >::value, MeshContainerIndex, std::pair< RTreeBox, MeshContainerIndex > >::type IndexType
typename std::conditional< IsDirectIndexable< mesh::Vertex >::value, impl::VectorIndexable< MeshContainer >, boost::geometry::index::indexable< IndexType > >::type IndexGetter
std::shared_ptr< RTree > Ptr