-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureExtraction.h
325 lines (293 loc) · 8.04 KB
/
FeatureExtraction.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#pragma once
#include <TopoDS_Shape.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <vector>
#include <tuple>
#include <set>
#include <map>
#include <stack>
#include <Eigen/Eigen>
#include <Eigen/Core>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <GeomLProp_SLProps.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <queue>
#include <unordered_map>
#include "Utilities.h"
//#include "FeatureCategorisation.h"
using namespace std;
using namespace Eigen;
using namespace Utilities;
namespace FeatureExtractionAlgo
{
//public:
enum EdgeVertexType
{
NONE = -1,
PLANAR = 0,
CREASE = 1,
CORNER = 2
};
struct Shape_Compare {
bool operator() (const TopoDS_Shape& lhs, const TopoDS_Shape& rhs) const {
return lhs.HashCode(1<<30)<rhs.HashCode(1<<30);
}
};
struct Shape_Hash {
size_t operator() (const TopoDS_Shape& shape) const {
return shape.HashCode(1 << 30);
}
};
class VerticesSet : public set<TopoDS_Vertex, Shape_Compare>
{
};
class VerticesTypeMap : public map<TopoDS_Vertex, EdgeVertexType, Shape_Compare>
{
};
template<typename ValType>
class VerticesMap : public map<TopoDS_Vertex, ValType, Shape_Compare>
{
};
template <typename ValType>
class FacesMap : public std::map<TopoDS_Face, ValType, Shape_Compare>
{
};
class FacesSet : public std::set<TopoDS_Face, Shape_Compare> {};
class EdgesSet :public set<TopoDS_Edge, Shape_Compare>
{
};
enum EdgeType
{
CONTINUOUS,
FINITE
};
enum EdgeVertexStatus
{
UNPROCESSED = 1,
QUEUED = 2,
PROCESSED = 4
};
class ExtractedFeatureEdge : public vector<TopoDS_Vertex>
{
public:
FeatureExtractionAlgo::EdgeType Type() const { return type; }
void AddVertex(TopoDS_Vertex vertex) { push_back(vertex); }
void Type(FeatureExtractionAlgo::EdgeType val) { type = val; }
const vector<TopoDS_Vertex> EdgeVertices() const { return edgeVertices; }
size_t Hash()
{
size_t result;
if (Type() == FINITE)
{
TopoDS_Vertex front;
TopoDS_Vertex front2;
TopoDS_Vertex back2;
TopoDS_Vertex back;
if (Shape_Compare().operator()(this->front(), this->back()))
{
front = this->front();
back = this->back();
}
else
{
front = this->back();
back = this->front();
}
if (Shape_Compare().operator()((*(this->begin()++)), (*(this->rbegin()++))))
{
front2 = (*(this->begin()++));
back2 = (*(this->rbegin()++));
}
else
{
front2 = (*(this->rbegin()++));
back2 = (*(this->begin()++));
}
size_t first = front.HashCode(0xFFFF);
size_t second = front2.HashCode(0xFFFF);
size_t secondLast = back2.HashCode(0xFFFF);
size_t last = back.HashCode(0x7FFF);
result = first | second << 16 | secondLast << 32 | last << 48;
}
else
{
size_t maxHash = 0;
size_t minHash = 0xFFFFFFFFFFFFFFFF;
for (auto v : *this)
{
auto currentHash = v.HashCode(0x7FFFFFFF);
if (currentHash > maxHash)
{
maxHash = currentHash;
}
if (currentHash < minHash)
{
minHash = currentHash;
}
}
result = maxHash | minHash << 32;
}
return result;
}
protected:
private:
EdgeType type;
vector<TopoDS_Vertex> edgeVertices;
};
struct EdgeHash
{
size_t operator() (const ExtractedFeatureEdge &edge) const {
size_t result;
if (edge.Type()==FINITE)
{
TopoDS_Vertex front;
TopoDS_Vertex front2;
TopoDS_Vertex back2;
TopoDS_Vertex back;
if (Shape_Compare().operator()(edge.front(),edge.back()))
{
front = edge.front();
back = edge.back();
}
else
{
front = edge.back();
back = edge.front();
}
if (Shape_Compare().operator()((*(edge.begin()++)), (*(edge.rbegin()++))))
{
front2 = (*(edge.begin()++));
back2 = (*(edge.rbegin()++));
}
else
{
front2 = (*(edge.rbegin()++));
back2 = (*(edge.begin()++));
}
size_t first = front.HashCode(0xFFFF);
size_t second = front2.HashCode(0xFFFF);
size_t secondLast = back2.HashCode(0xFFFF);
size_t last = back.HashCode(0x7FFF);
result = first | second << 16 | secondLast<< 32 | last << 48;
}
else
{
size_t maxHash = 0;
size_t minHash = 0xFFFFFFFFFFFFFFFF;
for (auto v:edge)
{
auto currentHash = v.HashCode(0x7FFFFFFF);
if (currentHash>maxHash)
{
maxHash = currentHash;
}
if (currentHash<minHash)
{
minHash = currentHash;
}
}
result = maxHash | minHash << 32;
}
return result;
}
};
class EdgeGroup : public vector<ExtractedFeatureEdge>
{
public:
protected:
private:
};
class EdgeGroups : public vector<EdgeGroup>
{
public:
vector<ExtractedFeatureEdge>& FindEdgeGroup(TopoDS_Vertex v, int &index);
};
class ExtractedFeature
{
public:
void AddFace(TopoDS_Face face)
{
if (!ContainsFace(face))
faces.push_back(face);
}
void AddVertex(TopoDS_Vertex vertex, EdgeVertexType type = PLANAR) { vertices.insert({ vertex, type }); }
void AddEdgeVertex(TopoDS_Vertex vertex, EdgeVertexType type) { vertices[vertex] = type; edgeVertices.insert({ vertex,type }); }
int NumFaces() { return faces.size(); }
bool ContainsFace(TopoDS_Face face);
bool ContainsVertex(TopoDS_Vertex vertex);
TopoDS_Face GetFace(int n) { return faces[n]; };
TopoDS_Vertex GetNearbyEdgeVertex(TopoDS_Shape shape, TopoDS_Vertex vertex);
void ProcessEdges();
void CreateEdge(TopoDS_Vertex vertex, TopoDS_Edge edge, EdgeType type, map<TopoDS_Vertex, pair<EdgeVertexType, int>, Shape_Compare> &edgeVertexMap, map<int, ExtractedFeatureEdge> &edgeMap, queue<int> &edgeQueue, int &numProcessed, vector<TopoDS_Vertex> &verticesToProcess);
void ProcessEdgeGroups();
void GetOuterEdgeGroup(int &index);
const vector<TopoDS_Face> GetFaces() { return faces; }
const vector<TopoDS_Vertex> GetVertices();
int NumEdges() { return extractedEdges.size(); }
int NumEdgeGroups() { return edgeGroups.size(); }
EdgeGroups& GetEdgeGroups() { return edgeGroups; }
const vector<ExtractedFeatureEdge> GetEdges() const { return extractedEdges; }
int NumEdgeVertices() { return edgeVertices.size(); }
//FeatureCategorisation::CategorisationType Type() const { return type; }
protected:
private:
vector<TopoDS_Face> faces;
VerticesTypeMap vertices;
map<TopoDS_Vertex,EdgeVertexType, Shape_Compare> edgeVertices;
vector<EdgeVertexType> edgeVerticesTypes;
vector<ExtractedFeatureEdge> extractedEdges;
EdgeGroups edgeGroups;
};
class ExtractedFeatures : public vector<ExtractedFeature>
{
public:
bool IsFaceProcessed(TopoDS_Face face);
bool IsVertexProcessed(TopoDS_Vertex vertex);
int NumFaces();
void ProcessEdges();
template<typename Iter>
void ExpandFeature(TopoDS_Face face, Iter begin, Iter end)
{
this->back().AddFace(face);
while (begin!=end)
{
this->back().AddVertex(*begin);
begin++;
}
}
template<typename Iter>
void AddEdgeVertices(Iter begin, Iter end, EdgeVertexType type)
{
while (begin!=end)
{
this->back().AddEdgeVertex(*begin, type);
begin++;
}
}
void AddEdgeVertex(TopoDS_Vertex vertex, EdgeVertexType type)
{
this->back().AddEdgeVertex(vertex, type);
}
int NumVerts();
int NumEdgeVerts();
protected:
private:
};
//static double NormalWeight(TopoDS_Face face, TopoDS_Vertex vertex);
ExtractedFeatures NormalTensorFrameworkMethod(TopoDS_Shape model, float creaseAngle = 5.0f);
ExtractedFeatures HybridEdgewiseNormalTensorFrameworkMethod(TopoDS_Shape model, float creaseAngle = 5.0f);
ExtractedFeatures EdgewiseMethod(TopoDS_Shape model, float creaseAngle = 5.0f);
double FaceNormalWeightMWSLER(TopoDS_Face currentFace, TopoDS_Vertex currentVertex);
Vector3d FaceNormal(TopoDS_Face face);
template<typename List>
void CalcNormalTensor(List ¤tFaces, TopoDS_Vertex v, Matrix3d &normalTensorSum, Vector3d &normalSum);
bool IsVertexInQueue(vector<TopoDS_Vertex> list, TopoDS_Vertex vertex);
int FindVertex(vector<TopoDS_Vertex> list, TopoDS_Vertex vertex);
};