TopoMesh
Topological mesh, triangulations and operations
m_mesh.h
1 #ifndef M_GEOMETRY_H
2 #define M_GEOMETRY_H
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <cmath>
8 
9 #include <QtCore/qmath.h>
10 #include <QVector3D>
11 #include <QVector>
12 #include <QFile>
13 #include <QTextStream>
14 #include <QMap>
15 #include <QQueue>
16 #include <QList>
17 
18 #include <GL/gl.h>
19 //#include <GL/glut.h>
20 
21 #include "predicate.h"
22 #include "it_faceiterator.h"
23 #include "it_vertexcirculator.h"
24 #include "it_convexhullcirculator.h"
25 
26 /*
27  * TODO
28  * - les plusieurs passes de crust pour sauvegarder plusieurs éventuels contours
29  * - repérer les circulateurs, manque un passage, cf begin() et end()?
30  * - remplacer tout ce qui est getFacesContainingPoint par un circulateur de sommets
31  *
32  */
33 
34 class g_Point : public QVector3D {
35 
36 public:
37  g_Point() : QVector3D() {}
38  g_Point(const float &_x, const float &_y, const float &_z) : QVector3D(_x, _y, _z) {}
39  friend std::ostream& operator<< (std::ostream& os, const g_Point &p) {
40  os << "[" << p.x() << ", " << p.y() << ", " << p.z() << "]";
41  return os;
42  }
43 };
44 
45 // Forward declaration of iterator
46 class FaceIterator;
47 // Forward declaration of circulator
49 // Forward declaration of circulator
50 class VertexCirculator;
51 
52 class Mesh {
53 
54 public:
55  typedef Mesh Self;
57  typedef QVector<int> g_Face;
59  typedef QVector<int> t_Face;
61  typedef QVector<int> g_Edge;
62 
64  friend class FaceIterator;
66  FaceIterator fbegin();
68  FaceIterator fend();
69 
71  friend class VertexCirculator;
73  VertexCirculator vcbegin(int v);
75  VertexCirculator vcend(int v);
76 
78  friend class ConvexHullCirculator;
80  ConvexHullCirculator chbegin();
82  ConvexHullCirculator chend();
83 
84  Mesh();
85  void clear();
86 
87  void load_off(const QString &filename);
88  bool load_tri(const QString &filename);
89  bool load_ctri(const QString &filename);
90  void save_off(const QString &name);
91 
92 
93  void draw();
94 
95  void show();
97  void swapDisplayCrust() { b_crusted = !b_crusted; }
99  void swapDisplayCircles() { b_circles = !b_circles; }
101  void swapAddVertexMode() { b_add_vertex_mode = !b_add_vertex_mode; }
103  bool getAddVertexMode() { return b_add_vertex_mode; }
104 
105 
106  // GEOMETRY -> m_geometry.cpp
107  bool contains(int triangle, const QVector3D &point);
108  bool contains(int triangle, int point);
109  QVector<FaceIterator> getFacesContainingPoint(int ind);
110  int add_voronoi_centers();
111  g_Point center_of_gravity(const g_Point &a, const g_Point &b, const g_Point &c);
112  g_Point center_of_gravity(const g_Face &f);
113  g_Point center_of_circumscribed_circle(const g_Face & f, float &r);
114  g_Point center_of_circumscribed_circle(const g_Face & f);
115  g_Point center_of_circumscribed_circle(const g_Point & a, const g_Point & b, const g_Point & c, float &r);
116  g_Point center_of_circumscribed_circle(const g_Point & a, const g_Point & b, const g_Point & c);
117  float radius_of_circumscribed_circle(const g_Face & f);
118 
119 
120  // TOPOLOGY -> m_topology.cpp
121  void make_topology();
122  g_Edge getCommonEdge(const FaceIterator &f1, const FaceIterator &f2);
123  bool need_flip(const FaceIterator &f1, const FaceIterator &f2);
124  void flip(const FaceIterator &f1, const FaceIterator &f2);
125  int the_walking_face(const QVector3D &v);
126  bool isInfiniteFace(const int &i);
127  bool isInfiniteFace(const g_Face &f);
128  QVector<int>getNeighborVertices(const FaceIterator &f);
129  void Crust();
130  void Lawson();
131 
132 
133  // NAIVE TRIANGULATION -> m_topology_naive.cpp
134  void triangulation_naive();
135  void add_vertex_naive(const g_Point &v);
136  void add_vertex_naive(const int &ind_vertex);
137  void add_point_in_face_naive(const int &v, const int &f);
138 
139 
140  // INCREMENTAL TRIANGULATION -> m_topology_inc.cpp
141  void triangulation_delaunay();
142  void add_vertex_inc(const g_Point &v);
143  void add_vertex_inc(const int &ind_vertex);
144  void add_point_in_face_inc(const int &v, const int &f);
145  void full_flip(const QVector<QVector<FaceIterator>> & to_flip);
146 
147 
148  // CONSTRAINED TRIANGULATION -> m_topology_con.cpp
149  void setConstrainedTriangulation();
150  void refine();
151  void Ruppert();
152  void splitSeg(const g_Edge &edge);
153  bool isConstrainedEdge(const g_Edge &e);
154  bool isConstrainedEdge(const FaceIterator &f1, const FaceIterator &f2);
155  void removeConstrainedEdge(const g_Edge &e);
156  bool isWellFormed(const g_Face &f, const float &angle = 20);
157 
159  QVector<g_Point> getVertices() { return vertices; }
161  QVector<g_Face> getFaces() { return faces; }
162 
163 protected:
165  QVector<g_Point> vertices;
167  QVector<g_Face> faces;
169  QVector<t_Face> topology;
170 
172  QVector<g_Point> voronoi_center;
174  QVector<QVector<int>> crust_lines;
176  QVector<QVector<int>> crust_border;
178  QVector<QVector<int>> constrained_edges;
179 
181  bool b_crusted;
183  bool b_circles;
188 };
189 
190 #endif
void swapDisplayCircles()
Swap circumscribed circles display, draw circles or not.
Definition: m_mesh.h:99
Definition: it_vertexcirculator.h:14
Definition: it_faceiterator.h:11
QVector< g_Point > vertices
List of vertices.
Definition: m_mesh.h:165
Definition: m_mesh.h:52
QVector< QVector< int > > crust_lines
List of Crust edges, used for display.
Definition: m_mesh.h:174
void swapDisplayCrust()
Swap Crust display, draw border or triangulation with Voronoï centers.
Definition: m_mesh.h:97
bool b_circles
Display of circumscribed circles.
Definition: m_mesh.h:183
QVector< int > g_Edge
Edge, index pair of vertex.
Definition: m_mesh.h:61
bool b_add_vertex_mode
Interactive vertex adding.
Definition: m_mesh.h:187
QVector< g_Face > getFaces()
Get list of faces.
Definition: m_mesh.h:161
bool b_crusted
Display of Crust border.
Definition: m_mesh.h:181
QVector< t_Face > topology
Topology of each face, topology[ii][jj] define the neighbor of face ii which is in front of vertex jj...
Definition: m_mesh.h:169
QVector< int > g_Face
Geometry face.
Definition: m_mesh.h:57
bool b_constrained
Display of constrained egdes.
Definition: m_mesh.h:185
QVector< g_Face > faces
List of faces, vertex index triplet.
Definition: m_mesh.h:167
bool getAddVertexMode()
Get interactive vertex adding mode state.
Definition: m_mesh.h:103
QVector< QVector< int > > crust_border
List of Crust edges sorted without doublons, used for display.
Definition: m_mesh.h:176
QVector< int > t_Face
Topology face.
Definition: m_mesh.h:59
QVector< g_Point > getVertices()
Get list of vertices.
Definition: m_mesh.h:159
QVector< g_Point > voronoi_center
List of Voronoï centers added, used for display.
Definition: m_mesh.h:172
void swapAddVertexMode()
Swap interactive vertex adding mode.
Definition: m_mesh.h:101
Definition: m_mesh.h:34
Definition: it_convexhullcirculator.h:16
QVector< QVector< int > > constrained_edges
List of constrained edges, used for display.
Definition: m_mesh.h:178