-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathvtkPolyDataBooleanFilter.h
More file actions
238 lines (179 loc) · 6.33 KB
/
vtkPolyDataBooleanFilter.h
File metadata and controls
238 lines (179 loc) · 6.33 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
238
/*
Copyright 2012-2025 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 <type_traits>
#include <vtkPolyDataAlgorithm.h>
#include <vtkKdTree.h>
#include <vtkModifiedBSPTree.h>
#include <vtkMatrixToLinearTransform.h>
#include <vtkMatrix4x4.h>
#include "Contact.h"
#include "Utilities.h"
enum OperMode {
OPER_NONE = 0,
OPER_UNION,
OPER_INTERSECTION,
OPER_DIFFERENCE,
OPER_DIFFERENCE2
};
enum class Capt {
Not = 1 << 0,
Edge = 1 << 1,
A = 1 << 2,
B = 1 << 3,
Branched = 1 << 4,
Boundary = 0xe
};
// inline std::underlying_type_t<Capt> operator| (Capt lhs, Capt rhs) {
// return static_cast<std::underlying_type_t<Capt>>(lhs) |
// static_cast<std::underlying_type_t<Capt>>(rhs);
// }
inline std::underlying_type_t<Capt> operator& (Capt lhs, Capt rhs) {
return static_cast<std::underlying_type_t<Capt>>(lhs) &
static_cast<std::underlying_type_t<Capt>>(rhs);
}
enum class Side {
None,
Start,
End
};
enum class Loc {
None,
Inside,
Outside
};
class StripPt {
public:
StripPt () : t(0), capt(Capt::Not), catched(true) {
edge[0] = NOTSET;
edge[1] = NOTSET;
}
double t;
Capt capt;
double captPt[3];
vtkIdType ind, edge[2];
double pt[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
<< ", polyId " << s.polyId;
return out;
}
vtkIdType polyId;
bool catched;
};
class StripPtR {
public:
StripPtR () = delete;
StripPtR (vtkIdType ind, std::size_t strip) : ind(ind), strip(strip), ref(NOTSET), side(Side::None) {
desc[0] = NOTSET;
desc[1] = NOTSET;
}
vtkIdType ind;
std::size_t strip;
vtkIdType ref, desc[2];
Side side;
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<vtkIdType, StripPt> StripPtsType;
typedef std::deque<StripPtR> StripType;
typedef std::vector<StripType> StripsType;
typedef std::vector<std::reference_wrapper<StripType>> _StripsType;
class PStrips {
public:
PStrips (vtkPolyData *pd, vtkIdType cellId) {
const vtkIdType *cell;
vtkIdType numPts;
pd->GetCellPoints(cellId, numPts, cell);
for (vtkIdType i = 0; i < numPts; i++) {
poly.push_back(cell[i]);
}
ComputeNormal(pd->GetPoints(), n, numPts, cell);
base = Base(pd->GetPoints(), numPts, cell);
}
StripPtsType pts;
StripsType strips;
double n[3];
IdsType poly;
Base base;
};
typedef std::map<vtkIdType, PStrips> PolyStripsType;
typedef std::vector<std::reference_wrapper<StripPtR>> RefsType;
typedef std::vector<std::reference_wrapper<const StripPtR>> ConstRefsType;
class VTK_EXPORT vtkPolyDataBooleanFilter : public vtkPolyDataAlgorithm {
vtkPolyData *resultA, *resultB, *resultC;
vtkSmartPointer<vtkPolyData> modPdA, modPdB, contLines;
vtkSmartPointer<vtkCellData> cellDataA, cellDataB;
vtkSmartPointer<vtkIdTypeArray> cellIdsA, cellIdsB;
vtkIdTypeArray *contsA, *contsB;
vtkMTimeType timePdA, timePdB;
PolyStripsType polyStripsA, polyStripsB;
void GetStripPoints (vtkPolyData *pd, vtkIdTypeArray *sources, PStrips &pStrips, IdsType &lines);
bool GetPolyStrips (vtkPolyData *pd, vtkIdTypeArray *conts, vtkIdTypeArray *sources, PolyStripsType &polyStrips);
bool CleanStrips ();
void RemoveDuplicates (IdsType &lines);
void CompleteStrips (PStrips &pStrips);
bool HasArea (const StripType &strip) const;
bool CutCells (vtkPolyData *pd, PolyStripsType &polyStrips);
void RestoreOrigPoints (vtkPolyData *pd, PolyStripsType &polyStrips);
void DisjoinPolys (vtkPolyData *pd, PolyStripsType &polyStrips);
void ResolveOverlaps (vtkPolyData *pd, PolyStripsType &polyStrips);
void AddAdjacentPoints (vtkPolyData *pd, vtkIdTypeArray *conts, PolyStripsType &polyStrips);
void MergePoints (vtkPolyData *pd, PolyStripsType &polyStrips);
bool CombineRegions ();
int OperMode;
vtkMatrix4x4 *matrices[2];
vtkLinearTransform *transforms[2];
vtkSmartPointer<vtkPolyData> cleanA, cleanB;
std::shared_ptr<Contact> contact;
vtkMTimeType timeMatrixA, timeMatrixB;
public:
vtkTypeMacro(vtkPolyDataBooleanFilter, vtkPolyDataAlgorithm);
static vtkPolyDataBooleanFilter* New ();
vtkSetClampMacro(OperMode, int, OPER_NONE, OPER_DIFFERENCE2);
vtkGetMacro(OperMode, int);
void SetOperModeToNone () { OperMode = OPER_NONE; Modified(); }
void SetOperModeToUnion () { OperMode = OPER_UNION; Modified(); }
void SetOperModeToIntersection () { OperMode = OPER_INTERSECTION; Modified(); }
void SetOperModeToDifference () { OperMode = OPER_DIFFERENCE; Modified(); }
void SetOperModeToDifference2 () { OperMode = OPER_DIFFERENCE2; Modified(); }
void SetMatrix (int i, vtkMatrix4x4 *matrix);
vtkMatrix4x4* GetMatrix (int i);
vtkMTimeType GetMTime () override;
protected:
vtkPolyDataBooleanFilter ();
~vtkPolyDataBooleanFilter ();
int RequestData (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override;
void PrintSelf (ostream&, vtkIndent) override {};
private:
vtkPolyDataBooleanFilter (const vtkPolyDataBooleanFilter&) = delete;
void operator= (const vtkPolyDataBooleanFilter&) = delete;
};
#endif