DelaunayTriangulation
A C++ Object Oriented data structure with algorithms that could be used to generate a Delaunay triangulation
utils.hpp
Go to the documentation of this file.
1#include <string>
2#include <stdexcept>
3#include "Triangle.hpp"
12namespace Utils {
18 int lineLength(const std::string &line);
19
27 template<typename Stream>
28 void loadFile(Stream &gStream, const std::string &fileName) {
29 gStream.open(fileName.c_str(), std::ios::binary);
30 if (not gStream.is_open()) {
31 std::stringstream ss;
32 ss << "Could not open file \"" << fileName << "\".";
33 throw std::runtime_error(ss.str());
34 }
35 }
36
49 // View documentation at https://mattnotmitt.github.io/DelaunayTriangulation/namespaceUtils.html#aea35446b52e730679709eefcdf6fc8e2
50 template<typename T>
51 double constantValueApprox(T func, const Triangle &triangle) {
52 return triangle.area() * func(triangle.getCc().x, triangle.getCc().y);
53 }
54
69 // View documentation at https://mattnotmitt.github.io/DelaunayTriangulation/namespaceUtils.html#a5795be8719aeb33bdfe657d70ed61207
70 template<typename T>
71 double linearInterpolationApprox(T func, const Triangle &triangle) {
72 std::vector<Vec> vecs = triangle.getOwner()->resolvePoints(triangle.getVertices());
73 Eigen::Vector3d bar = triangle.barycentric(Eigen::Vector2d(triangle.getCc().x, triangle.getCc().y));
74 double area = triangle.area();
75 return area * ((bar(0) * func(vecs[0].getX(), vecs[0].getY())) +
76 (bar(1) * func(vecs[1].getX(), vecs[1].getY())) +
77 (bar(2) * func(vecs[2].getX(), vecs[2].getY())));
78 }
79}
Triangle class header.
virtual std::vector< Vec > resolvePoints(std::vector< vertInd > vertInds)=0
Resolves vector of vertex indices to vector of vertex pointers.
Class representing a polygon with 3 points and its member functions.
Definition: Triangle.hpp:17
double x
x coordinate of the circumcentre
Definition: Triangle.hpp:26
const circumcircle & getCc() const
Accessor for private member cc.
Definition: Triangle.cpp:175
Eigen::Vector3d barycentric(const Eigen::Vector2d &p) const
Get the barycentric coordinates of a point in relation to the triangle.
Definition: Triangle.cpp:153
double area() const
Calculate the area of the triangle in 2d (x & y coords)
Definition: Triangle.cpp:216
const std::vector< int > & getVertices() const
Accessor for private member vertices.
Definition: Triangle.cpp:25
IMesh * getOwner() const
Accessor for private member owner.
Definition: Triangle.cpp:224
double y
y coordinate of the circumcentre
Definition: Triangle.hpp:30
Namespace of utility functions.
Definition: utils.cpp:10
int lineLength(const std::string &line)
Find number of parameters in file import lines.
Definition: utils.cpp:11
double linearInterpolationApprox(T func, const Triangle &triangle)
Approximates integral of func over triangle using linear interpolation approximation.
Definition: utils.hpp:71
double constantValueApprox(T func, const Triangle &triangle)
Approximates integral of func over triangle using constant value approximation.
Definition: utils.hpp:51
void loadFile(Stream &gStream, const std::string &fileName)
Opens a stream with the specified file and verifies it has been opened correctly.
Definition: utils.hpp:28