DelaunayTriangulation
A C++ Object Oriented data structure with algorithms that could be used to generate a Delaunay triangulation
Triangle.hpp
Go to the documentation of this file.
1//
2// Created by matt on 22/11/2019.
3//
4#include <vector>
5#include <Eigen/Dense>
6#include "IMesh.hpp"
7
8#pragma once
17class Triangle {
18public:
22 struct circumcircle {
26 double x;
30 double y;
34 double radius;
35 };
36private:
37 int index;
40 std::vector<double> attributes;
41 std::vector<IMesh::vertInd> vertices;
42 std::vector<IMesh::edge> edges;
43public:
44 // Constructors
48 Triangle() : index(-1), owner(), cc() {}
59 // Functionality
63 void calcCircumcircle();
69 bool circumcircleContainsPoint(const Eigen::Vector2d &p) const;
75 Eigen::Vector3d barycentric(const Eigen::Vector2d &p) const;
81 bool containsPoint(const Eigen::Vector2d &p) const;
86 double area() const;
87 // Getters & Setters
92 int getIndex() const;
97 void setIndex(int i);
102 const std::vector<int> &getVertices() const;
107 void setVertices(const std::vector<int> &vertices);
112 const std::vector<double> &getAttributes() const;
117 void setAttributes(const std::vector<double> &attributes);
122 const circumcircle &getCc() const;
127 void setCc(const circumcircle &cc);
132 const std::vector<IMesh::edge> &getEdges() const;
137 void setEdges(const std::vector<IMesh::edge> &edges);
142 IMesh *getOwner() const;
143 // Comparison Operators
149 bool operator==(const Triangle &rhs) const;
155 bool operator!=(const Triangle &rhs) const;
156
157 // Stream operators
164 friend std::istream &operator>>(std::istream &is, Triangle &triangle);
171 friend std::ostream &operator<<(std::ostream &os, Triangle &triangle);
178 friend std::ofstream &operator<<(std::ofstream &ofs, Triangle &triangle);
179};
IMesh class header.
Shallow class allowing Mesh to be imported in classes which Mesh owns.
Definition: IMesh.hpp:14
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
int getIndex() const
Accessor for private member index.
Definition: Triangle.cpp:17
std::vector< IMesh::edge > edges
Vector of edges making up the Triangle.
Definition: Triangle.hpp:42
Triangle(int index, IMesh *owner)
Constructor populating index and owner.
Definition: Triangle.hpp:54
const std::vector< IMesh::edge > & getEdges() const
Accessor for private member edges.
Definition: Triangle.cpp:183
const std::vector< double > & getAttributes() const
Accessor for private member attributes.
Definition: Triangle.cpp:43
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
void setIndex(int i)
Mutator for private member index.
Definition: Triangle.cpp:21
bool circumcircleContainsPoint(const Eigen::Vector2d &p) const
Check if the circumcircle of the Triangle contains a point.
Definition: Triangle.cpp:132
~Triangle()
Default destructor.
Definition: Triangle.hpp:58
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
bool containsPoint(const Eigen::Vector2d &p) const
Check if the Triangle contains a point.
Definition: Triangle.cpp:169
bool operator!=(const Triangle &rhs) const
Non-equality operator.
Definition: Triangle.cpp:199
void setVertices(const std::vector< int > &vertices)
Mutator for private member vertices.
Definition: Triangle.cpp:29
double radius
radius of the circumcircle
Definition: Triangle.hpp:34
circumcircle cc
Circumcircle of the current triangle.
Definition: Triangle.hpp:38
friend std::istream & operator>>(std::istream &is, Triangle &triangle)
Input stream operator.
Definition: Triangle.cpp:51
int index
Index of the triangle (loaded from file)
Definition: Triangle.hpp:37
void setAttributes(const std::vector< double > &attributes)
Mutator for private member attributes.
Definition: Triangle.cpp:47
IMesh * getOwner() const
Accessor for private member owner.
Definition: Triangle.cpp:224
Triangle()
Default constructor.
Definition: Triangle.hpp:48
double y
y coordinate of the circumcentre
Definition: Triangle.hpp:30
IMesh * owner
Pointer to interface class of the Mesh the Triangle is part of.
Definition: Triangle.hpp:39
void setCc(const circumcircle &cc)
Mutator for private member cc.
Definition: Triangle.cpp:179
friend std::ostream & operator<<(std::ostream &os, Triangle &triangle)
Output stream operator.
Definition: Triangle.cpp:203
std::vector< double > attributes
Vector of attributes of the Triangle (16 points of precision)
Definition: Triangle.hpp:40
std::vector< IMesh::vertInd > vertices
Vector of vertex indices making up the Triangle.
Definition: Triangle.hpp:41
void calcCircumcircle()
Calculate the circumcircle of the Triangle.
Definition: Triangle.cpp:104
void setEdges(const std::vector< IMesh::edge > &edges)
Mutator for private member edges.
Definition: Triangle.cpp:187
bool operator==(const Triangle &rhs) const
Equality operator.
Definition: Triangle.cpp:191
Circumcircle object.
Definition: Triangle.hpp:22