DelaunayTriangulation
A C++ Object Oriented data structure with algorithms that could be used to generate a Delaunay triangulation
Mesh.hpp
Go to the documentation of this file.
1//
2// Created by matt on 17/11/2019.
3//
4
5#include <map>
6#include <memory>
7#include <ostream>
8#include "Vertex.hpp"
9#include "Triangle.hpp"
10#include "IMesh.hpp"
11
12#pragma once
17// Whole program could (?) be sped up using DCEL https://en.wikipedia.org/wiki/Doubly_connected_edge_list
21class Mesh : public IMesh {
22private:
26 std::map<triInd, Triangle> triangles;
27 std::map<vertInd, Vertex> vertices;
33 std::map<edge, std::vector<triInd> > edges;
38 std::map<vertInd, std::vector<triInd> > vertTri;
39public:
40 // Constructors
48 ~Mesh() {};
49 // Functionality
57 std::vector<Vec> resolvePoints(std::vector<vertInd> vertInds);
63 bool isDelaunay();
71 std::vector<edge> newEdges(triInd triInd, const std::vector<vertInd> &vert);
78 void removeEdges(triInd triInd, const std::vector<edge> &rEdge);
85 int containingTriangle(double x, double y);
91 std::vector<int> adjacentTriangles(triInd triInd);
106 void updateVertTri(triInd triInd, std::vector<vertInd> vertInds);
113 void removeVertTri(triInd triInd, std::vector<vertInd> rVertInds);
122 template <typename T>
123 double integrate(T func, double (*interp)(T, const Triangle&)) {
124 double res = 0;
125 for (int i = 0; i < triangles.size(); i++) {
126 res += std::abs(interp(func, triangles[i]));
127 }
128 return res;
129 };
130 // Getters & Setters
135 const std::map<int, Vertex> &getVertices() const;
140 void setVertices(const std::map<int, Vertex> &vertices);
145 const std::map<int, Triangle> &getTriangles() const;
150 void setTriangles(const std::map<int, Triangle> &triangles);
155 int getVertexAttributes() const;
160 void setVertexAttributes(int verAttr);
165 int getTriangleAttributes() const;
170 void setTriangleAttributes(int triAttr);
175 int getDimensions() const;
180 const std::map<std::pair<int, int>, std::vector<int> > &getEdges() const;
181 // Equality Operators
183
188 bool operator==(const Mesh &rhs) const;
194 bool operator!=(const Mesh &rhs) const;
195 // Stream Operators
202 friend std::ifstream &operator>>(std::ifstream &ifs, Mesh &mesh);
209 friend std::ofstream &operator<<(std::ofstream &ofs, Mesh &mesh);
210};
IMesh class header.
Triangle class header.
Vertex class header.
Shallow class allowing Mesh to be imported in classes which Mesh owns.
Definition: IMesh.hpp:14
int vertInd
Type representing an index of a vertex.
Definition: IMesh.hpp:23
int triInd
Type representing an index of a triangle.
Definition: IMesh.hpp:27
Parent class of all objects, contains full triangulation and its constituent parts.
Definition: Mesh.hpp:21
void updateVertTri(triInd triInd, std::vector< vertInd > vertInds)
Implementation of IMesh::updateVertTri Add Triangle represented by triInd to vertTri.
Definition: Mesh.cpp:274
bool isDelaunay()
Checks whether mesh is Delauney.
Definition: Mesh.cpp:193
const std::map< int, Vertex > & getVertices() const
Accessor to private member vertices.
Definition: Mesh.cpp:16
double integrate(T func, double(*interp)(T, const Triangle &))
Estimate the integral of the function func over the mesh.
Definition: Mesh.hpp:123
std::map< vertInd, std::vector< triInd > > vertTri
Map of a vertex index to a vector of triangles using them.
Definition: Mesh.hpp:38
bool operator!=(const Mesh &rhs) const
Not-equality operator.
Definition: Mesh.cpp:300
std::map< vertInd, Vertex > vertices
Map of vertex indices to vertices they refer to.
Definition: Mesh.hpp:27
void setVertexAttributes(int verAttr)
Mutator for private member vertexAttributes.
Definition: Mesh.cpp:36
Mesh()
Default contructor.
Definition: Mesh.hpp:44
void removeVertTri(triInd triInd, std::vector< vertInd > rVertInds)
Implementation of IMesh::removeVertTri Remove triangle index from vertTri.
Definition: Mesh.cpp:282
int containingTriangle(double x, double y)
Find the triangle which contains the point .
Definition: Mesh.cpp:183
friend std::ofstream & operator<<(std::ofstream &ofs, Mesh &mesh)
Output filestream operator.
Definition: Mesh.cpp:149
std::vector< int > adjacentTriangles(triInd triInd)
Find all triangles that share an edge with triangle represented by triInd.
Definition: Mesh.cpp:241
int getTriangleAttributes() const
Accessor for private member triangleAttributes.
Definition: Mesh.cpp:40
std::vector< Vec > resolvePoints(std::vector< vertInd > vertInds)
Implementation of IMesh::resolvePoints Resolves vector of vertex indices to vector of vertex pointers...
Definition: Mesh.cpp:167
std::vector< edge > newEdges(triInd triInd, const std::vector< vertInd > &vert)
Implementation of IMesh::newEdges Adds triangle's new edges to map.
Definition: Mesh.cpp:215
int getDimensions() const
Accessor for private member dimensions.
Definition: Mesh.cpp:48
std::map< triInd, Triangle > triangles
Map of triangle indices to triangles they refer to.
Definition: Mesh.hpp:26
~Mesh()
Default destructor.
Definition: Mesh.hpp:48
bool operator==(const Mesh &rhs) const
Equality operator.
Definition: Mesh.cpp:290
void setTriangleAttributes(int triAttr)
Mutator for private member triangleAttributes.
Definition: Mesh.cpp:44
std::map< edge, std::vector< triInd > > edges
Map of pairs of vertex indices (representing an edge) to a vector of triangles using them.
Definition: Mesh.hpp:33
int getVertexAttributes() const
Accessor for private member vertexAttributes.
Definition: Mesh.cpp:32
void setTriangles(const std::map< int, Triangle > &triangles)
Mutator for private member triangles.
Definition: Mesh.cpp:28
const std::map< int, Triangle > & getTriangles() const
Accessor to private member vertices.
Definition: Mesh.cpp:24
const std::map< std::pair< int, int >, std::vector< int > > & getEdges() const
Accessor for private member edges.
Definition: Mesh.cpp:237
int vertexAttributes
Number of attributes in a vertex object.
Definition: Mesh.hpp:23
int triangleAttributes
Number of attributes in a triangle object.
Definition: Mesh.hpp:24
void removeEdges(triInd triInd, const std::vector< edge > &rEdge)
Implementation of IMesh::removeEdges Remove triangle's old edges from map.
Definition: Mesh.cpp:258
void setVertices(const std::map< int, Vertex > &vertices)
Mutator for private member vertices.
Definition: Mesh.cpp:20
void recalcCircum(vertInd vertInd)
Implementation of IMesh::recalcCircum Recalculate the Triangle::circumcircle of all Triangles using v...
Definition: Mesh.cpp:266
friend std::ifstream & operator>>(std::ifstream &ifs, Mesh &mesh)
Input filestream operator.
Definition: Mesh.cpp:52
int dimensions
Number of dimensions of the mesh.
Definition: Mesh.hpp:25
Class representing a polygon with 3 points and its member functions.
Definition: Triangle.hpp:17