-
Notifications
You must be signed in to change notification settings - Fork 2
/
io.cpp
142 lines (115 loc) · 5.14 KB
/
io.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "geom.h"
Vector3d PointVector3d(Point_3 p) {
return Vector3d(p[0], p[1], p[2]);
}
Point_3 VectorPoint3d(Vector3d p) {
return Point_3(p[0], p[1], p[2]);
}
Vector2d PointVector2d(Point_2 p) {
return Vector2d(p[0], p[1]);
}
Point_2 VectorPoint2d(Vector2d p) {
return Point_2(p[0], p[1]);
}
extern "C" CARPENTRY_GEOM_EXPORT void CGAL_Vector_Base(Vector3d n, Vector3d &result) {
Plane_3 plane(Point_3(0.0, 0.0, 0.0), Vector_3(n[0], n[1], n[2]));
Vector_3 v = plane.base1();
result = Vector3d(v[0], v[1], v[2]);
}
//3d plane relaed
Vector3d CGAL_3D_Plane_Base_1(Vector3d plane_p, Vector3d plane_n) {
Plane_3 plane(VectorPoint3d(plane_p), Vector_3(plane_n[0], plane_n[1], plane_n[2]));
Vector_3 v = plane.base1();
return Vector3d(v[0], v[1], v[2]);
}
extern "C" CARPENTRY_GEOM_EXPORT void CGAL_Export_Path_Segment(std::ofstream &export_file_output, int &export_index,
std::string s_name, double r, double g, double b,
Vector3d &start, Vector3d &end, double radius) {
Vector3d normal = end - start;
Vector3d base_1;
CGAL_Vector_Base(normal, base_1);
double length_base_1 = glm::length(base_1);
base_1[0] = base_1[0] / length_base_1 * radius;
base_1[1] = base_1[1] / length_base_1 * radius;
base_1[2] = base_1[2] / length_base_1 * radius;
std::vector<Vector3d> vecs;
for (int i = 0; i < 4; i++) {
double angle = i * 2 * Math::Math_PI / 4;
Vector3d v = Math::RotationAxis(normal + base_1, angle, normal);
vecs.push_back(v + start);
}
for (int i = 0; i < 4; i++) {
vecs.push_back(vecs[i] - normal);
}
std::vector<std::vector<int>> faces;
int face_index_0[4] = {0, 1, 2, 3};
int face_index_1[4] = {5, 1, 0, 4};
int face_index_2[4] = {4, 0, 3, 7};
int face_index_3[4] = {5, 4, 7, 6};
int face_index_4[4] = {7, 3, 2, 6};
int face_index_5[4] = {6, 2, 1, 5};
faces.push_back(std::vector<int>(face_index_0, face_index_0 + 4));
faces.push_back(std::vector<int>(face_index_1, face_index_1 + 4));
faces.push_back(std::vector<int>(face_index_2, face_index_2 + 4));
faces.push_back(std::vector<int>(face_index_3, face_index_3 + 4));
faces.push_back(std::vector<int>(face_index_4, face_index_4 + 4));
faces.push_back(std::vector<int>(face_index_5, face_index_5 + 4));
export_file_output << "g " + s_name << std::endl;
for (int i = 0; i < vecs.size(); i++) {
export_file_output << "v " << vecs[i][0] << " " << vecs[i][1] << " " << vecs[i][2] << " " << r << " " << g
<< " " << b << std::endl;
}
for (int i = 0; i < faces.size(); i++) {
export_file_output << "f ";
for (int j = 0; j < faces[i].size(); j++) {
export_file_output << faces[i][j] + export_index << " ";
}
export_file_output << "" << std::endl;
}
export_index += 8;
}
extern "C" CARPENTRY_GEOM_EXPORT void CGAL_Export_Path_Point(std::ofstream &export_file_output, int &export_index,
std::string s_name, double r, double g, double b,
Vector3d point, double radius) {
std::vector<Vector3d> vecs;
vecs.push_back(Vector3d(0.5, 0.5, 0.5));
vecs.push_back(Vector3d(-0.5, 0.5, 0.5));
vecs.push_back(Vector3d(-0.5, 0.5, -0.5));
vecs.push_back(Vector3d(0.5, 0.5, -0.5));
vecs.push_back(Vector3d(0.5, -0.5, 0.5));
vecs.push_back(Vector3d(-0.5, -0.5, 0.5));
vecs.push_back(Vector3d(-0.5, -0.5, -0.5));
vecs.push_back(Vector3d(0.5, -0.5, -0.5));
std::vector<std::vector<int>> faces;
int face_index_0[4] = {0, 1, 2, 3};
int face_index_1[4] = {5, 1, 0, 4};
int face_index_2[4] = {4, 0, 3, 7};
int face_index_3[4] = {5, 4, 7, 6};
int face_index_4[4] = {7, 3, 2, 6};
int face_index_5[4] = {6, 2, 1, 5};
faces.push_back(std::vector<int>(face_index_0, face_index_0 + 4));
faces.push_back(std::vector<int>(face_index_1, face_index_1 + 4));
faces.push_back(std::vector<int>(face_index_2, face_index_2 + 4));
faces.push_back(std::vector<int>(face_index_3, face_index_3 + 4));
faces.push_back(std::vector<int>(face_index_4, face_index_4 + 4));
faces.push_back(std::vector<int>(face_index_5, face_index_5 + 4));
export_file_output << "g " + s_name << std::endl;
for (int i = 0; i < vecs.size(); i++) {
vecs[i][0] = vecs[i][0] * radius;
vecs[i][1] = vecs[i][1] * radius;
vecs[i][2] = vecs[i][2] * radius;
vecs[i][0] += point[0];
vecs[i][1] += point[1];
vecs[i][2] += point[2];
export_file_output << "v " << vecs[i][0] << " " << vecs[i][1] << " " << vecs[i][2] << " " << r << " " << g
<< " " << b << std::endl;
}
for (int i = 0; i < faces.size(); i++) {
export_file_output << "f ";
for (int j = faces[i].size() - 1; j >= 0; j--) {
export_file_output << faces[i][j] + export_index << " ";
}
export_file_output << "" << std::endl;
}
export_index += 8;
}