forked from zippy84/vtkbool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPolyDataBooleanFilter.h
287 lines (225 loc) · 6.97 KB
/
vtkPolyDataBooleanFilter.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
/*
Copyright 2012-2020 Ronald Römer
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __vtkPolyDataBooleanFilter_h
#define __vtkPolyDataBooleanFilter_h
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <utility>
#include <iostream>
#include <vtkPolyDataAlgorithm.h>
#include <vtkKdTreePointLocator.h>
#include "Utilities.h"
#define LOC_NONE 0
#define LOC_INSIDE 1
#define LOC_OUTSIDE 2
#define OPER_UNION 0
#define OPER_INTERSECTION 1
#define OPER_DIFFERENCE 2
#define OPER_DIFFERENCE2 3
#define CAPT_NOT 0
#define CAPT_EDGE 1
#define CAPT_A 2
#define CAPT_B 3
#define SIDE_START 0
#define SIDE_END 1
class StripPt {
public:
StripPt () : t(0), capt(CAPT_NOT), catched(true) {
edge[0] = NO_USE;
edge[1] = NO_USE;
}
double t;
int ind;
double pt[3];
int edge[2];
int capt;
double captPt[3];
double cutPt[3];
friend std::ostream& operator<< (std::ostream &out, const StripPt &s) {
out << "ind=" << s.ind
<< ", edge=[" << s.edge[0] << ", " << s.edge[1] << "]"
<< ", t=" << s.t
<< ", capt=" << s.capt;
return out;
}
std::vector<Pair> history;
int polyId;
int src;
bool catched;
};
class StripPtR {
public:
StripPtR (int _ind) : ind(_ind)/*, desc{NO_USE, NO_USE}*/ {
strip = NO_USE;
side = NO_USE;
ref = NO_USE;
desc[0] = NO_USE;
desc[1] = NO_USE;
}
int ind;
int desc[2];
// nicht gesetzt bei CAPT_NOT
int strip;
int side;
int ref;
friend std::ostream& operator<< (std::ostream &out, const StripPtR &s) {
out << "ind=" << s.ind
<< ", desc=[" << s.desc[0] << ", " << s.desc[1] << "]"
<< ", strip=" << s.strip
<< ", side=" << s.side
<< ", ref=" << s.ref;
return out;
}
};
typedef std::map<int, StripPt> StripPtsType;
typedef std::deque<StripPtR> StripType;
typedef std::vector<StripType> StripsType;
class PStrips {
public:
PStrips () {}
double n[3];
IdsType poly;
StripPtsType pts;
StripsType strips;
};
typedef std::map<int, PStrips> PolyStripsType;
typedef std::vector<std::reference_wrapper<StripPtR>> RefsType;
class StripPtL {
public:
StripPtL (const StripPt &sp) : ind(sp.ind) {
Cpy(pt, sp.pt, 3);
Cpy(cutPt, sp.cutPt, 3);
}
int ind;
double pt[3];
double cutPt[3];
bool operator< (const StripPtL &other) const {
return ind < other.ind;
}
};
class StripPtL2 {
public:
StripPtL2 (const StripPt &sp) : ind(sp.ind), t(sp.t), history(sp.history) {
Cpy(pt, sp.pt, 3);
edge[0] = sp.edge[0];
edge[1] = sp.edge[1];
}
int ind;
int edge[2];
double pt[3];
double t;
bool operator< (const StripPtL2 &other) const {
return ind < other.ind;
}
std::vector<Pair> history;
};
class StripPtL3 {
public:
StripPtL3 (const double *_pt, double _t, int _ind = NO_USE) : t(_t), ind(_ind) {
Cpy(pt, _pt, 3);
}
double t;
int ind;
double pt[3];
bool operator< (const StripPtL3 &other) const {
return t < other.t;
}
friend std::ostream& operator<< (std::ostream &out, const StripPtL3 &s) {
out << "ind=" << s.ind
<< ", t=" << s.t
<< ", pt=[" << s.pt[0] << ", " << s.pt[1] << ", " << s.pt[2] << "]";
return out;
}
};
class MergePt {
public:
MergePt (int _polyInd, int _ind, double *_pt) : polyInd(_polyInd), ind(_ind) {
Cpy(pt, _pt, 3);
}
int polyInd;
int ind;
double pt[3];
};
typedef std::vector<IdsType> HolesType;
class _Wrapper {
vtkPolyData *pd;
IdsType descIds;
int origId;
Base base;
HolesType holes;
public:
_Wrapper (vtkPolyData* _pd, IdsType& _descIds, int _origId)
: pd(_pd), descIds(_descIds), origId(_origId) {}
void MergeAll ();
void Add (IdsType &hole) {
holes.push_back(hole);
}
};
typedef std::set<int> InvolvedType;
enum class Rel {
ORIG = 1,
DEC = 2
};
typedef std::map<int, Rel> RelationsType;
class VTK_EXPORT vtkPolyDataBooleanFilter : public vtkPolyDataAlgorithm {
vtkPolyData *resultA, *resultB, *contLines;
vtkPolyData *modPdA, *modPdB;
vtkCellData *cellDataA, *cellDataB;
vtkIntArray *cellIdsA, *cellIdsB;
unsigned long timePdA, timePdB;
PolyStripsType polyStripsA, polyStripsB;
InvolvedType involvedA, involvedB;
RelationsType relsA, relsB;
void GetStripPoints (vtkPolyData *pd, vtkIntArray *sources, PStrips &pStrips, IdsType &lines);
bool GetPolyStrips (vtkPolyData *pd, vtkIntArray *conts, vtkIntArray *sources, PolyStripsType &polyStrips);
void RemoveDuplicates (IdsType &lines);
void CompleteStrips (PStrips &pStrips);
bool HasArea (StripType &strip);
void CollapseCaptPoints (vtkPolyData *pd, PolyStripsType &polyStrips);
void CutCells (vtkPolyData *pd, PolyStripsType &polyStrips);
void RestoreOrigPoints (vtkPolyData *pd, PolyStripsType &polyStrips);
void DisjoinPolys (vtkPolyData *pd, PolyStripsType &polyStrips);
void ResolveOverlaps (vtkPolyData *pd, vtkIntArray *conts, PolyStripsType &polyStrips);
void AddAdjacentPoints (vtkPolyData *pd, vtkIntArray *conts, PolyStripsType &polyStrips);
void MergePoints (vtkPolyData *pd, PolyStripsType &polyStrips);
void DecPolys_ (vtkPolyData *pd, InvolvedType &involved, RelationsType &rels);
void CombineRegions ();
void MergeRegions ();
int OperMode;
bool MergeRegs, DecPolys;
public:
vtkTypeMacro(vtkPolyDataBooleanFilter, vtkPolyDataAlgorithm);
static vtkPolyDataBooleanFilter* New ();
vtkSetClampMacro(OperMode, int, OPER_UNION, OPER_DIFFERENCE2);
vtkGetMacro(OperMode, int);
void SetOperModeToUnion () { OperMode = OPER_UNION; }
void SetOperModeToIntersection () { OperMode = OPER_INTERSECTION; }
void SetOperModeToDifference () { OperMode = OPER_DIFFERENCE; }
void SetOperModeToDifference2 () { OperMode = OPER_DIFFERENCE2; }
vtkSetMacro(MergeRegs, bool);
vtkGetMacro(MergeRegs, bool);
vtkBooleanMacro(MergeRegs, bool);
vtkSetMacro(DecPolys, bool);
vtkGetMacro(DecPolys, bool);
vtkBooleanMacro(DecPolys, bool);
protected:
vtkPolyDataBooleanFilter ();
~vtkPolyDataBooleanFilter ();
int ProcessRequest (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector);
private:
vtkPolyDataBooleanFilter (const vtkPolyDataBooleanFilter&) = delete;
void operator= (const vtkPolyDataBooleanFilter&) = delete;
};
#endif