forked from JWHennessey/meshmixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatchT.cc
69 lines (59 loc) · 1.4 KB
/
PatchT.cc
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
#ifndef Patch_CC
#define Patch_CC
#include "PatchT.hh"
template <typename M>
PatchT<M>::PatchT(Vec c, Vec n, int handle)
{
centroid = c;
normal = n;
patchColour = QColor(rand() % 255, rand() % 255, rand() % 255);
addFaceHandle(handle);
}
template <typename M>
void
PatchT<M>::addVertex(Vec v)
{
verticies.push_back(v);
}
template <typename M>
void
PatchT<M>::updateNormal()
{
PointMatrix mat(verticies.size(), 3);
std::cout << "No. Faces on patch " << faceHandles.size() << "\n";
std::cout << "No. Vertices on patch " << verticies.size() << "\n";
for(int i = 0; i < verticies.size(); i++)
{
mat(i, 0) = verticies[i][0];
mat(i, 1) = verticies[i][1];
mat(i, 2) = verticies[i][2];
}
Eigen::MatrixXd centered = mat.rowwise() - mat.colwise().mean();
Eigen::MatrixXd cov = (centered.adjoint() * centered) / double(mat.rows());
Eigen::EigenSolver<Eigen::MatrixXd> es(cov);
Eigen::VectorXcd v = es.eigenvectors().row(1);
normal = Vec(std::real(v[0]), std::real(v[1]), std::real(v[2]));
}
template <typename M>
void
PatchT<M>::updateCentroid()
{
centroid = Vec(0,0,0);
for(int i=0; i < verticies.size(); i++)
centroid += verticies[i];
centroid = centroid / verticies.size();
}
template <typename M>
void
PatchT<M>::addFaceHandle(int handle)
{
faceHandles.push_back(handle);
}
template <typename M>
void
PatchT<M>::clear()
{
verticies.clear();
faceHandles.clear();
}
#endif