preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Index.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "logging/Logger.hpp"
9#include "mesh/Edge.hpp"
11#include "mesh/Tetrahedron.hpp"
12#include "mesh/Triangle.hpp"
13#include "mesh/Vertex.hpp"
15
16namespace precice::query {
17
19using MatchID = int;
20
21constexpr MatchID NO_MATCH{-1};
22
24using Distance = double;
25constexpr double INVALID_DISTANCE{-1};
26
28template <class Tag>
29struct MatchType {
31 MatchType() = default;
32 explicit MatchType(MatchID i)
33 : index(i) {};
34};
35
42
49
50 ProjectionMatch(const ProjectionMatch &other) = default;
51 ProjectionMatch(ProjectionMatch &&other) = default;
52 ProjectionMatch &operator=(const ProjectionMatch &other) = default;
54
56
57 bool operator<(ProjectionMatch const &other) const
58 {
59 return polation.distance() < other.polation.distance();
60 };
61};
62
64class Index {
65
66public:
67 Index(mesh::PtrMesh mesh);
68 Index(mesh::Mesh &mesh);
70
72 VertexMatch getClosestVertex(const Eigen::VectorXd &sourceCoord);
73
75 std::vector<VertexID> getClosestVertices(const Eigen::VectorXd &sourceCoord, int n);
76
78 std::vector<EdgeMatch> getClosestEdges(const Eigen::VectorXd &sourceCoord, int n);
79
81 std::vector<TriangleMatch> getClosestTriangles(const Eigen::VectorXd &sourceCoord, int n);
82
84 std::vector<VertexID> getVerticesInsideBox(const mesh::Vertex &centerVertex, double radius);
85
88
90 bool isAnyVertexInsideBox(const mesh::Vertex &centerVertex, double radius);
91
93 std::vector<TetrahedronID> getEnclosingTetrahedra(const Eigen::VectorXd &location);
94
105 ProjectionMatch findNearestProjection(const Eigen::VectorXd &location, int n);
106
107 ProjectionMatch findCellOrProjection(const Eigen::VectorXd &location, int n);
108
109 // Index tree, bounds
111
113 void clear();
114
115private:
116 class IndexImpl;
118
121
123
125 ProjectionMatch findVertexProjection(const Eigen::VectorXd &location);
126
128 ProjectionMatch findEdgeProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex);
129
131 ProjectionMatch findTriangleProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex);
132};
133
134} // namespace precice::query
This class provides a lightweight logger.
Definition Logger.hpp:17
Calculates the barycentric coordinates of a coordinate on the given vertex/edge/triangle and stores t...
Definition Polation.hpp:23
double distance() const
Returns the projection distance.
Definition Polation.cpp:96
An axis-aligned bounding box around a (partition of a) mesh.
Container and creator for meshes.
Definition Mesh.hpp:38
Vertex of a mesh.
Definition Vertex.hpp:16
Class to query the index trees of the mesh.
Definition Index.hpp:64
mesh::BoundingBox getRtreeBounds()
Definition Index.cpp:367
std::vector< TetrahedronID > getEnclosingTetrahedra(const Eigen::VectorXd &location)
Return all the tetrahedra whose axis-aligned bounding box contains a vertex.
Definition Index.cpp:263
mesh::Mesh * _mesh
The indexed Mesh.
Definition Index.hpp:120
ProjectionMatch findCellOrProjection(const Eigen::VectorXd &location, int n)
Definition Index.cpp:284
VertexMatch getClosestVertex(const Eigen::VectorXd &sourceCoord)
Get the closest vertex to the given vertex.
Definition Index.cpp:171
ProjectionMatch findNearestProjection(const Eigen::VectorXd &location, int n)
Find the closest interpolation element to the given location. If exists, triangle or edge projection ...
Definition Index.cpp:275
bool isAnyVertexInsideBox(const mesh::Vertex &centerVertex, double radius)
Returns.
Definition Index.cpp:238
std::unique_ptr< IndexImpl > _pimpl
Definition Index.hpp:117
std::vector< TriangleMatch > getClosestTriangles(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest triangles to the given vertex.
Definition Index.cpp:210
std::vector< VertexID > getVerticesInsideBox(const mesh::Vertex &centerVertex, double radius)
Return all the vertices inside the box formed by vertex and radius (boundary exclusive)
Definition Index.cpp:223
void clear()
Clear the index.
Definition Index.cpp:391
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.
Definition Index.cpp:318
ProjectionMatch findVertexProjection(const Eigen::VectorXd &location)
Closest vertex projection element is always the nearest neighbor.
Definition Index.cpp:312
Index(mesh::PtrMesh mesh)
Definition Index.cpp:156
std::vector< VertexID > getClosestVertices(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest vertices to the given vertex.
Definition Index.cpp:184
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...
Definition Index.cpp:342
std::vector< EdgeMatch > getClosestEdges(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest edges to the given vertex.
Definition Index.cpp:197
static precice::logging::Logger _log
Definition Index.hpp:122
contains geometrical queries.
double Distance
Type used for the distance of a match to the queried point.
Definition Index.hpp:24
int MatchID
Type used for the IDs of matching entities.
Definition Index.hpp:19
constexpr double INVALID_DISTANCE
Definition Index.hpp:25
constexpr MatchID NO_MATCH
Definition Index.hpp:21
STL namespace.
Struct to hold the index of a primitive match.
Definition Index.hpp:29
Struct representing a projection match.
Definition Index.hpp:44
mapping::Polation polation
Definition Index.hpp:55
ProjectionMatch(mapping::Polation &&p)
Definition Index.hpp:47
ProjectionMatch(const ProjectionMatch &other)=default
bool operator<(ProjectionMatch const &other) const
Definition Index.hpp:57
ProjectionMatch & operator=(ProjectionMatch &&other)=default
ProjectionMatch(ProjectionMatch &&other)=default
ProjectionMatch(const mapping::Polation &p)
Definition Index.hpp:45
ProjectionMatch & operator=(const ProjectionMatch &other)=default