99{
100 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
101 vtkInformation* outInfo = outputVector->GetInformationObject(0);
102
103 vtkPolyData* input = vtkPolyData::SafeDownCast(
104 inInfo->Get(vtkDataObject::DATA_OBJECT()));
105 vtkPolyData* output = vtkPolyData::SafeDownCast(
106 outInfo->Get(vtkDataObject::DATA_OBJECT()));
107
108 bool anyRemoved, removeCell, considerPoint;
109 bool* isUnremovable;
110 vtkIdType i, j, id;
111 vtkIdType n;
112 vtkIdType npts, ncells;
113 const vtkIdType *pts;
114 vtkPolyData* poly = vtkPolyData::New();
115 poly->SetPoints(input->GetPoints());
116 npts = 0;
117 pts = NULL;
118 vtkIdType edge[2];
119 vtkCellArray* currentPolys;
120 vtkCellLinks* currentLinks;
121 vtkIdType newCellId;
122 vtkCellArray* inputPolys = input->GetPolys();
123
124 currentPolys = vtkCellArray::New();
125 currentLinks = vtkCellLinks::New();
126
127 n = 0;
129 {
130 n = input->GetNumberOfPoints();
131 }
133 {
134 n = inputPolys->GetNumberOfCells();
135 }
136
137 isUnremovable = new bool[n];
138
139 bool anyUnremovable = false;
140
141 for (i=0; i<n; i++)
142 {
143 isUnremovable[i] = false;
144 }
145
147 {
149 {
151 {
153 if ((id >= 0) && (id < n))
154 {
155 anyUnremovable = true;
156 isUnremovable[id] = true;
157 }
158 else
159 {
160 vtkErrorMacro(<< "Out of range id found among UnremovablePointIds!");
161 }
162 }
163 }
164 }
166 {
168 {
170 {
172 if ((id >= 0) && (id < n))
173 {
174 anyUnremovable = true;
175 isUnremovable[id] = true;
176 }
177 else if (id<0)
178 {
179 vtkErrorMacro(<< "Out of range id found among UnremovableCellIds!");
180 }
181 }
182 }
183 }
184
185 currentPolys->DeepCopy(inputPolys);
186
187 currentLinks->Allocate(input->GetNumberOfPoints());
188
189
190
191
192
193
194
195
196
197 poly->SetPolys(currentPolys);
198
199#if ((VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 0 && VTK_BUILD_VERSION >= 20221108) || (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 2 && VTK_BUILD_VERSION >= 0))
200 currentLinks->SetDataSet(poly);
201 currentLinks->BuildLinks();
202#else
203 currentLinks->BuildLinks(poly);
204#endif
205
206 anyRemoved = true;
207 while (anyRemoved)
208 {
209 anyRemoved = false;
210 vtkCellArray* newPolys = vtkCellArray::New();
211 vtkIdList* newCell = vtkIdList::New();
212 currentPolys->InitTraversal();
213 for (i=0; i<currentPolys->GetNumberOfCells(); i++)
214 {
215 currentPolys->GetNextCell(npts,pts);
216
217 if (npts==0)
218 {
219 continue;
220 }
221
222 newCell->Initialize();
224 {
225 for (j=0; j<npts; j++)
226 {
227 considerPoint = false;
228 ncells = currentLinks->GetNcells(pts[j]);
229
230 if (ncells==1)
231 {
232 considerPoint = true;
233 }
234
235 if (considerPoint)
236 {
237 if (isUnremovable[pts[j]])
238 {
239 newCell->InsertNextId(pts[j]);
240 }
241 else
242 {
243 anyRemoved = true;
244 }
245 }
246 else
247 {
248 newCell->InsertNextId(pts[j]);
249 }
250 }
251 }
253 {
254 removeCell = false;
255 if (!isUnremovable[i])
256 {
257 for (j=0; j<npts; j++)
258 {
259 edge[0] = pts[j];
260 edge[1] = pts[(j+1)%npts];
261
263 {
264 removeCell = true;
265 break;
266 }
267 }
268 }
269
270 if (removeCell)
271 {
272 anyRemoved = true;
273 }
274 else
275 {
276 for (j=0; j<npts; j++)
277 {
278 newCell->InsertNextId(pts[j]);
279 }
280 }
281 }
282
283 if (newCell->GetNumberOfIds() > 2)
284 {
285 newCellId = newPolys->InsertNextCell(newCell);
286 }
287 }
288
289 currentPolys->DeepCopy(newPolys);
290 currentLinks->Delete();
291 currentLinks = vtkCellLinks::New();
292 currentLinks->Allocate(input->GetNumberOfPoints());
293
294
295
296
297
298 poly->SetPolys(currentPolys);
299#if ((VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 0 && VTK_BUILD_VERSION >= 20221108) || (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 2 && VTK_BUILD_VERSION >= 0))
300 currentLinks->SetDataSet(poly);
301 currentLinks->BuildLinks();
302#else
303 currentLinks->BuildLinks(poly);
304#endif
305
306 newPolys->Delete();
307 newCell->Delete();
309 {
310 break;
311 }
312 }
313
315 {
316 vtkCellArray* newPolys = vtkCellArray::New();
317 vtkIdList* newCell = vtkIdList::New();
318 currentPolys->InitTraversal();
319 for (i=0; i<currentPolys->GetNumberOfCells(); i++)
320 {
321 currentPolys->GetNextCell(npts,pts);
322 newCell->Initialize();
323 if (npts==0)
324 {
325 newPolys->InsertNextCell(npts,pts);
326 continue;
327 }
328 if (!isUnremovable[i])
329 {
330 for (j=0; j<npts; j++)
331 {
332 newCell->InsertNextId(pts[j]);
333 }
334 }
335 if (newCell->GetNumberOfIds() > 2)
336 {
337 newPolys->InsertNextCell(newCell);
338 }
339 }
340 currentPolys->DeepCopy(newPolys);
341 newPolys->Delete();
342 newCell->Delete();
343 }
344
345
346
347 output->SetPoints(input->GetPoints());
348 output->GetPointData()->PassData(input->GetPointData());
349
350
351 output->SetPolys(currentPolys);
352
353 delete[] isUnremovable;
354
355 currentLinks->Delete();
356 currentPolys->Delete();
357 poly->Delete();
358
359 return 1;
360}
vtkIdType IsBoundaryEdge(vtkCellLinks *links, vtkIdType *edge)