3#include <boost/iterator/function_output_iterator.hpp>
4#include <boost/range/irange.hpp>
18namespace bgi = boost::geometry::index;
58 auto tree = std::make_shared<VertexTraits::RTree>(
59 boost::irange<std::size_t>(0lu, mesh.
nVertices()), params, ind);
67 if (indices.edgeRTree) {
68 return indices.edgeRTree;
79 auto tree = std::make_shared<EdgeTraits::RTree>(
80 boost::irange<std::size_t>(0lu, mesh.
edges().
size()), params, ind);
82 indices.edgeRTree = std::move(tree);
83 return indices.edgeRTree;
88 if (indices.triangleRTree) {
89 return indices.triangleRTree;
99 for (
size_t i = 0; i < mesh.
triangles().size(); ++i) {
100 auto box = bg::return_envelope<RTreeBox>(mesh.
triangles()[i]);
109 auto tree = std::make_shared<TriangleTraits::RTree>(elements, params, ind);
110 indices.triangleRTree = std::move(tree);
111 return indices.triangleRTree;
116 if (indices.tetraRTree) {
117 return indices.tetraRTree;
127 for (
size_t i = 0; i < mesh.
tetrahedra().size(); ++i) {
139 auto tree = std::make_shared<TetrahedronTraits::RTree>(elements, params, ind);
140 indices.tetraRTree = std::move(tree);
141 return indices.tetraRTree;
146 indices.vertexRTree.reset();
147 indices.edgeRTree.reset();
148 indices.triangleRTree.reset();
149 indices.tetraRTree.reset();
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);
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();
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)
This class provides a lightweight logger.
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.
int getDimensions() const
VertexContainer & vertices()
Returns modifieable container holding all vertices.
const std::string & getName() const
Returns the name of the mesh, as set in the config file.
std::size_t nVertices() const
Returns the number of vertices.
TetraContainer & tetrahedra()
Returns modifiable container holding all tetrahedra.
Vertex & vertex(VertexID id)
Mutable access to a vertex by VertexID.
bool empty() const
Does the mesh contain any vertices?
TriangleContainer & triangles()
Returns modifiable container holding all triangles.
EdgeContainer & edges()
Returns modifiable container holding all edges.
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)
boost::geometry::index::rstar< 16 > RTreeParameters
The general rtree parameter type used in precice.
contains geometrical queries.
RTreeBox makeBox(const pm::Vertex::RawCoords &min, const pm::Vertex::RawCoords &max)
MatchType< struct VertexMatchTag > VertexMatch
constexpr auto get(span< E, S > s) -> decltype(s[N])
Struct to hold the index of a primitive match.
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< Primitive >::value, MeshContainerIndex, std::pair< RTreeBox, MeshContainerIndex > >::type IndexType
typename std::conditional< IsDirectIndexable< Primitive >::value, impl::VectorIndexable< MeshContainer >, boost::geometry::index::indexable< IndexType > >::type IndexGetter