-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.h
118 lines (93 loc) · 2.82 KB
/
test_utils.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
template <typename LoopType, typename Kernel>
void extrude(LoopType bottom, const CGAL::Vector_3<Kernel>& V, CGAL::Polyhedron_3<Kernel>& P) {
std::list<LoopType> face_list = { bottom };
for (auto current_vertex = bottom.begin(); current_vertex != bottom.end(); ++current_vertex) {
auto next_vertex = current_vertex;
++next_vertex;
if (next_vertex == bottom.end()) {
next_vertex = bottom.begin();
}
LoopType side = { {
*next_vertex,
*current_vertex,
*current_vertex + V,
*next_vertex + V ,
} };
face_list.push_back(side);
}
auto top = bottom;
for (auto& v : top) {
v += V;
}
std::reverse(top.begin(), top.end());
face_list.push_back(top);
std::vector<Point> unique_points;
std::vector<std::vector<std::size_t>> facet_vertices;
std::map<Point, size_t> points;
for (auto &face : face_list) {
facet_vertices.emplace_back();
for (auto &point : face) {
auto p = points.insert({ point, points.size() });
if (p.second) {
unique_points.push_back(point);
}
facet_vertices.back().push_back(p.first->second);
}
}
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(unique_points, facet_vertices, P);
}
template <typename Kernel>
void createCube(CGAL::Polyhedron_3<Kernel>& P, double d) {
quad bottom = { {
Point(-d, -d, -d),
Point(+d, -d, -d),
Point(+d, +d, -d),
Point(-d, +d, -d)
} };
Kernel::Vector_3 V(0, 0, d * 2);
extrude(bottom, V, P);
}
void rotatePolyhedron(Polyhedron& P, double angle, Kernel::Vector_3 axis) {
axis = axis / std::sqrt(CGAL::to_double(axis.squared_length()));
double c = std::cos(angle);
double s = std::sin(angle);
// Compute the 4x4 rotation matrix
CGAL::Aff_transformation_3<Kernel> rotation_matrix(
c + (1 - c) * axis.x() * axis.x(),
(1 - c) * axis.x() * axis.y() - s * axis.z(),
(1 - c) * axis.x() * axis.z() + s * axis.y(),
0.0,
(1 - c) * axis.y() * axis.x() + s * axis.z(),
c + (1 - c) * axis.y() * axis.y(),
(1 - c) * axis.y() * axis.z() - s * axis.x(),
0.0,
(1 - c) * axis.z() * axis.x() - s * axis.y(),
(1 - c) * axis.z() * axis.y() + s * axis.x(),
c + (1 - c) * axis.z() * axis.z(),
0.0
);
for (auto it = P.vertices_begin(); it != P.vertices_end(); ++it) {
it->point() = rotation_matrix.transform(it->point());
}
}
template <typename T>
void scalePolyhedron(Polyhedron& P, T sx, T sy, T sz) {
CGAL::Aff_transformation_3<Kernel> scale(
sx, 0, 0, 0,
0, sy, 0, 0,
0, 0, sz, 0);
for (auto it = P.vertices_begin(); it != P.vertices_end(); ++it) {
it->point() = scale.transform(it->point());
}
}
void translatePolyhedron(Polyhedron& P, Kernel::Vector_3 v) {
CGAL::Aff_transformation_3<Kernel> rotation_matrix(
CGAL::TRANSLATION, v
);
for (auto it = P.vertices_begin(); it != P.vertices_end(); ++it) {
it->point() = rotation_matrix.transform(it->point());
}
}
#endif