preCICE v3.1.2
Loading...
Searching...
No Matches
Triangle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <array>
6#include <iostream>
7#include <tuple>
8
10#include "mesh/Edge.hpp"
13#include "utils/assertion.hpp"
14
15namespace precice {
16namespace mesh {
17class Vertex;
18}
19} // namespace precice
20
21// ----------------------------------------------------------- CLASS DEFINITION
22
23namespace precice {
24namespace mesh {
25
27class Triangle {
28public:
30
36
39
42
44 static constexpr int vertexCount{3};
45
48 Edge &edgeOne,
49 Edge &edgeTwo,
50 Edge &edgeThree);
51
58 Vertex &VertexOne,
59 Vertex &VertexTwo,
60 Vertex &VertexThree);
61
63 int getDimensions() const;
64
72 Vertex &vertex(int i);
73
81 const Vertex &vertex(int i) const;
82
85
88
90 iterator end();
91
93 const_iterator begin() const;
94
96 const_iterator end() const;
97
99 const_iterator cbegin() const;
100
102 const_iterator cend() const;
103
105
107 Eigen::VectorXd computeNormal() const;
108
110 double getArea() const;
111
113 const Eigen::VectorXd getCenter() const;
114
116 double getEnclosingRadius() const;
117
124 bool operator==(const Triangle &other) const;
125
127 bool operator!=(const Triangle &other) const;
128
130 bool operator<(const Triangle &other) const
131 {
132 return std::make_tuple(_vertices[0]->getID(), _vertices[1]->getID(), _vertices[2]->getID()) <
133 std::make_tuple(other._vertices[0]->getID(), other._vertices[1]->getID(), other._vertices[2]->getID());
134 }
135
136private:
139};
140
141// --------------------------------------------------------- HEADER DEFINITIONS
142
144{
145 PRECICE_ASSERT((i >= 0) && (i < 3), i);
146 return *_vertices[i];
147}
148
149inline const Vertex &Triangle::vertex(int i) const
150{
151 PRECICE_ASSERT((i >= 0) && (i < 3), i);
152 return *_vertices[i];
153}
154
156{
157 return {this, 0};
158}
159
161{
162 return {this, 3};
163}
164
166{
167 return {this, 0};
168}
169
171{
172 return {this, 3};
173}
174
176{
177 return begin();
178}
179
181{
182 return end();
183}
184
186
187} // namespace mesh
188} // namespace precice
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:27
double getArea() const
Returns the surface area of the triangle.
Definition Triangle.cpp:70
int getDimensions() const
Returns dimensionalty of space the triangle is embedded in.
Definition Triangle.cpp:84
std::array< Vertex *, 3 > _vertices
Vertices defining the triangle, sorted by Vertex::getID()
Definition Triangle.hpp:138
iterator begin()
Returns a read-only random-access iterator to the begin (0) of the vertex range [0,...
Definition Triangle.hpp:155
const_iterator cbegin() const
Returns a read-only random-access iterator to the begin (0) of the vertex range [0,...
Definition Triangle.hpp:175
bool operator<(const Triangle &other) const
Weak ordering based on vertex ids.
Definition Triangle.hpp:130
iterator end()
Returns a read-only random-access iterator to the end (3) of the vertex range [0,1,...
Definition Triangle.hpp:160
double getEnclosingRadius() const
Returns the radius of the circle enclosing the triangle.
Definition Triangle.cpp:94
Eigen::VectorXd computeNormal() const
Computes the normal of the triangle.
Definition Triangle.cpp:75
Vertex & vertex(int i)
Returns triangle vertex with index 0, 1 or 2.
Definition Triangle.hpp:143
const_iterator iterator
Type of the read-only random access vertex iterator.
Definition Triangle.hpp:38
bool operator==(const Triangle &other) const
Compares two Triangles for equality.
Definition Triangle.cpp:102
const Eigen::VectorXd getCenter() const
Returns the barycenter of the triangle.
Definition Triangle.cpp:89
const_iterator cend() const
Returns a read-only random access iterator to the end (3) of the vertex range [0,1,...
Definition Triangle.hpp:180
bool operator!=(const Triangle &other) const
Not equal, implemented in terms of equal.
Definition Triangle.cpp:108
IndexRangeIterator< const Triangle, const Vertex::RawCoords > const_iterator
Type of the read-only const random-access iterator over Vertex coords.
Definition Triangle.hpp:35
static constexpr int vertexCount
Amount of vertices.
Definition Triangle.hpp:44
Triangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Constructor based on 3 edges.
Definition Triangle.cpp:23
Vertex of a mesh.
Definition Vertex.hpp:16
std::array< double, 3 > RawCoords
Definition Vertex.hpp:19
T make_tuple(T... args)
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
Main namespace of the precice library.