-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMesh3Triangulation.cpp
77 lines (61 loc) · 2.1 KB
/
Mesh3Triangulation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#define CGAL_USE_BASIC_VIEWER
#define QT_NO_KEYWORDS
#define GL_SILENCE_DEPRECATION
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "Mesh3Triangulation.h"
#include <CGAL/draw_triangulation_3.h>
#include <cmath>
#include <QPushButton>
// To avoid verbose function and named parameters call
using namespace CGAL::parameters;
Mesh3Triangulation::Mesh3Triangulation(const char* filename) :
success(false)
{
CGAL::Image_3 image;
std::cerr << "reading..." << std::endl;
if(!image.read(filename)){
std::cerr << "Error: Cannot read file " << filename << std::endl;
return;
}
Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image);
// Mesh criteria
Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=4,
cell_radius_edge_ratio=3, cell_size=8);
std::cerr << "making mesh..." << std::endl;
c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
std::cerr << "done!" << std::endl;
success = true;
}
Mesh3Triangulation::operator bool() const
{
return success;
}
void Mesh3Triangulation::draw()
{
glLineWidth(1.0f);
glColor4f(0.5f, 0.0f, 0.0f, 0.5f);
// Completely slow implementation!!!
Tr& tr = c3t3.triangulation();
for (Tr::Finite_edges_iterator it = tr.finite_edges_begin(); it != tr.finite_edges_end() ; it++ ) {
Point_3 p1 = Point_3(it->first->vertex((it->second + 1) % 3)->point());
Point_3 p2 = Point_3(it->first->vertex((it->second + 2) % 3)->point());
// All hacky just to make it work
if (abs(p2.x()) + abs(p2.y()) + abs(p2.z()) <= 0.05f
|| abs(p1.x()) + abs(p1.y()) + abs(p1.z()) <= 0.05f) {
continue;
}
glBegin(GL_LINES);
glVertex3f(p1.x() / 100.0f, p1.y() / 100.0f, p1.z() / 100.0f);
glVertex3f(p2.x() / 100.0f, p2.y() / 100.0f, p2.z() / 100.0f);
glEnd();
}
}
QWidget* Mesh3Triangulation::createVisualisationWindow(QWidget* parent)
{
using namespace CGAL;
return new SimpleTriangulation3ViewerQt<Tr, DefaultColorFunctorT3>(parent, c3t3.triangulation());
}