-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkgeometry.cpp
More file actions
237 lines (178 loc) · 5.9 KB
/
kgeometry.cpp
File metadata and controls
237 lines (178 loc) · 5.9 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//
// kgeometry.cpp
// ktools
//
// Created by Joowhi Lee on 8/31/15.
//
//
#include "kgeometry.h"
#include <vtkNew.h>
#include <vtkMath.h>
#include <vtkPolyDataNormals.h>
#include <set>
using namespace std;
size_t Geometry::extractEdges(vtkDataSet *ds, std::vector<EdgeMap> &edges) {
size_t nEdges = 0;
if (ds == NULL) {
return nEdges;
}
vector<set<vtkIdType> > edgeList;
edgeList.resize(ds->GetNumberOfPoints());
edges.resize(ds->GetNumberOfPoints());
const size_t nCells = ds->GetNumberOfCells();
for (size_t j = 0; j < nCells; j++) {
vtkCell* cell = ds->GetCell(j);
const size_t ne = cell->GetNumberOfEdges();
for (size_t k = 0; k < ne; k++) {
vtkCell* edge = cell->GetEdge(k);
vtkIdType s = edge->GetPointId(0);
vtkIdType e = edge->GetPointId(1);
double sPt[3], ePt[3];
ds->GetPoint(s, sPt);
ds->GetPoint(e, ePt);
size_t nEq = 0;
for (size_t j = 0; j < 3; j++) {
if (sPt[j] == ePt[j]) {
nEq++;
}
}
if (edgeList[e].find(s) != edgeList[e].end()) {
edgeList[e].erase(s);
edges[s][e] = Edge(s, e);
edges[e][s].boundary = false;
} else {
edgeList[s].insert(e);
edges[s][e] = Edge(s, e, true);
}
edges[s][e].axisAligned = nEq;
}
}
return nEdges;
}
size_t Geometry::extractNeighbors(vtkDataSet *ds, NeighborList &nbrs) {
const size_t nPoints = ds->GetNumberOfPoints();
nbrs.resize(nPoints);
vtkNew<vtkIdList> cellIds;
for (size_t j = 0; j < nPoints; j++) {
Neighbors& nbrPts = nbrs[j];
cellIds->Reset();
ds->GetPointCells(j, cellIds.GetPointer());
for (size_t k = 0; k < cellIds->GetNumberOfIds(); k++) {
vtkIdType cellId = cellIds->GetId(k);
vtkCell* cell = ds->GetCell(cellId);
for (size_t l = 0; l < cell->GetNumberOfEdges(); l++) {
vtkCell* edge = cell->GetEdge(l);
vtkIdType s = edge->GetPointId(0);
vtkIdType e = edge->GetPointId(1);
if (s == j) {
if (find(nbrPts.begin(), nbrPts.end(), e) == nbrPts.end()) {
nbrPts.push_back(e);
}
} else if (e == j) {
if (find(nbrPts.begin(), nbrPts.end(), s) == nbrPts.end()) {
nbrPts.push_back(s);
}
}
}
}
}
return nPoints;
}
double Geometry::tangentVector(const double *u, const double *v, const double *n, double *tv, vtkTransform* txf) {
double uv[3];
vtkMath::Subtract(v, u, uv);
double dotProd = vtkMath::Dot(uv, n);
double cross[3];
vtkMath::Cross(uv, n, cross);
double crossProd = vtkMath::Normalize(cross);
double angRad = atan2(crossProd, dotProd);
double angDeg = vtkMath::DegreesFromRadians(angRad) - 90;
if (txf == NULL) {
vtkNew<vtkTransform> tx;
tx->RotateWXYZ(angDeg, cross);
tx->TransformPoint(uv, tv);
vtkMath::Add(tv, u, tv);
} else {
txf->RotateWXYZ(angDeg, cross);
txf->TransformPoint(uv, tv);
vtkMath::Add(tv, u, tv);
}
return angRad;
}
double Geometry::rotateVector(const double p[3], const double q[3], vtkTransform* txf, double* crossOut) {
double u[3], v[3];
memcpy(u, p, sizeof(u));
memcpy(v, q, sizeof(v));
// double pNorm = vtkMath::Normalize(u);
// double qNorm = vtkMath::Normalize(v);
double dotProd = vtkMath::Dot(u, v);
double cross[3];
vtkMath::Cross(u, v, cross);
double crossProd = vtkMath::Normalize(cross);
if (crossProd == 0) {
memcpy(cross, u, sizeof(u));
}
if (crossOut != NULL) {
for (size_t j = 0; j < 3; j++) crossOut[j] = cross[j];
}
double angRad = atan2(crossProd, dotProd);
double angDeg = vtkMath::DegreesFromRadians(angRad);
txf->RotateWXYZ(angDeg, cross);
return angDeg;
}
double Geometry::rotatePlane(const double u1[3], const double v1[3], const double u2[3], const double v2[3], vtkTransform* txf) {
double cross1[3], cross2[3];
vtkMath::Cross(u1, v1, cross1);
vtkMath::Cross(u2, v2, cross2);
return rotateVector(cross1, cross2, txf);
}
double Geometry::normalizeToNorthPole(const double *u, const double *n, double* cross, vtkTransform* txf) {
static const double northPole[3] = { 0, 0, 1 };
static const double xAxis[3] = { 1, 0, 0 };
vtkMath::Cross(n, northPole, cross);
double crossProd = vtkMath::Norm(cross);
double dotProd = vtkMath::Dot(n, northPole);
if (crossProd == 0) {
memcpy(cross, xAxis, sizeof(xAxis));
}
double angDeg = vtkMath::DegreesFromRadians(atan2(crossProd, dotProd));
txf->PostMultiply();
txf->Translate(-u[0], -u[1], -u[2]);
txf->RotateWXYZ(angDeg, cross);
return angDeg;
}
double Geometry::denormalizeFromNorthPole(const double u[3], const double n[3], double* cross, vtkTransform* txf) {
static const double northPole[3] = { 0, 0, 1 };
static const double xAxis[3] = { 1, 0, 0 };
vtkMath::Cross(northPole, n, cross);
double crossProd = vtkMath::Norm(cross);
double dotProd = vtkMath::Dot(northPole, n);
if (crossProd == 0) {
memcpy(cross, xAxis, sizeof(xAxis));
}
double angDeg = vtkMath::DegreesFromRadians(atan2(crossProd, dotProd));
txf->PostMultiply();
txf->RotateWXYZ(angDeg, cross);
txf->Translate(u[0], u[1], u[2]);
return angDeg;
}
bool Geometry::computeContourNormals(vtkDataSet* ds, vtkDoubleArray* normals) {
Geometry geom;
EdgeList edges;
geom.extractEdges(ds, edges);
for (size_t j = 0; j < edges.size(); j++) {
EdgeMap::const_iterator iter = edges[j].cbegin();
for (; iter != edges[j].cend(); iter++) {
}
}
return false;
}
vtkPolyData* Geometry::computeSurfaceNormals(vtkPolyData *pd) {
vtkNew<vtkPolyDataNormals> normalsFilter;
normalsFilter->SetInput(pd);
normalsFilter->ComputePointNormalsOn();
normalsFilter->Update();
return normalsFilter->GetOutput();
}
void Geometry::print() {
}