155{
156 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
157 vtkInformation *outInfo = outputVector->GetInformationObject(0);
158
159 vtkPolyData *input = vtkPolyData::SafeDownCast(
160 inInfo->Get(vtkDataObject::DATA_OBJECT()));
161 vtkPolyData *output = vtkPolyData::SafeDownCast(
162 outInfo->Get(vtkDataObject::DATA_OBJECT()));
163
164 vtkIdType k, i , j;
165 vtkIdType surfacePointId, newPointId;
166 vtkIdType id0, id1, previousId;
167 vtkIdType duplicatePointLocation;
168 vtkIdType numberOfLines, numberOfLinePoints, numberOfInputPoints;
169 vtkIdType cellId, previousCellToEdit;
170 vtkIdType npts;
171 const vtkIdType *pts;
172 vtkDataArray *cutLinePointIdsArray;
173 vtkCell *polyLine;
174 vtkPoints *newPoints;
175 vtkCellArray *newPolys;
176 vtkCellArray *editedCells;
177 vtkIdList *duplicatePointIds;
178 vtkIdList *duplicatedPointIds;
179 vtkIdList *cellsToEdit, *editedCellIds;
180 vtkIdList *cellEdgeNeighbors;
181 vtkIdList *cellsOnSameSide;
182 vtkPointData *inputPD = input->GetPointData();
183 vtkPointData *outputPD = output->GetPointData();
184
185 previousCellToEdit = -1;
186
188 {
189 vtkErrorMacro(<<"CutLine not specified!");
190 return 1;
191 }
192
194 {
195 vtkErrorMacro(<<"CutLinePointIdsArrayName not specified!");
196 return 1;
197 }
198
200
201 if (cutLinePointIdsArray==NULL)
202 {
203 vtkErrorMacro(<<"CutLinePointIdsArray with name specified does not exist!");
204 return 1;
205 }
206
207 newPoints = vtkPoints::New();
208 newPolys = vtkCellArray::New();
209
210 editedCells = vtkCellArray::New();
211
212 duplicatePointIds = vtkIdList::New();
213 duplicatedPointIds = vtkIdList::New();
214 cellsToEdit = vtkIdList::New();
215 editedCellIds = vtkIdList::New();
216 cellEdgeNeighbors = vtkIdList::New();
217 cellsOnSameSide = vtkIdList::New();
218
219 numberOfInputPoints = input->GetNumberOfPoints();
220 newPoints->DeepCopy(input->GetPoints());
221
222 numberOfLinePoints = this->
CutLine->GetNumberOfPoints();
223
224 numberOfLines = this->
CutLine->GetNumberOfCells();
225
226 input->BuildCells();
227 input->BuildLinks();
229
230 for (k=0; k<numberOfLines; k++)
231 {
232 polyLine = this->
CutLine->GetCell(k);
233 if (polyLine->GetCellType() != VTK_LINE && polyLine->GetCellType() != VTK_POLY_LINE)
234 {
235 continue;
236 }
237
238 numberOfLinePoints = polyLine->GetNumberOfPoints();
239
240 duplicatedPointIds->Initialize();
241 duplicatePointIds->Initialize();
242 cellsToEdit->Initialize();
243
244 for (i=0; i<numberOfLinePoints; i++)
245 {
246 surfacePointId = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i),0));
247 newPointId = newPoints->InsertNextPoint(input->GetPoint(surfacePointId));
248 duplicatedPointIds->InsertNextId(surfacePointId);
249 duplicatePointIds->InsertNextId(newPointId);
250 }
251
252 for (i=0; i<numberOfLinePoints-1; i++)
253 {
254 id0 = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i),0));
255 id1 = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i+1),0));
256
257 if (id0==id1)
258 {
259 vtkErrorMacro(<<"Coincident points found on CutLine! ");
260 return 1;
261 }
262
263 if (!input->IsEdge(id0,id1))
264 {
265 vtkErrorMacro(<<"CutLine is not entirely defined on mesh edges! ");
266 return 1;
267 }
268
269 cellEdgeNeighbors->Initialize();
270 input->GetCellEdgeNeighbors(-1,id0,id1,cellEdgeNeighbors);
271
272 if (cellEdgeNeighbors->GetNumberOfIds()<2)
273 {
274 vtkWarningMacro(<<"Surface boundary or hole found.");
275 continue;
276 }
277
278 if (cellEdgeNeighbors->GetNumberOfIds()>2)
279 {
280 vtkErrorMacro(<<"Surface is non-manifold! ");
281 return 1;
282 }
283
284
285
286
287 if (i==0)
288 {
289 if (k==0)
290 {
291 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(0));
292 previousCellToEdit = cellEdgeNeighbors->GetId(0);
293 }
294 else
295 {
296 if (cellsToEdit->IsId(cellEdgeNeighbors->GetId(0))!=-1)
297 {
298 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(0));
299 previousCellToEdit = cellEdgeNeighbors->GetId(0);
300 }
301 else
302 {
303 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(1));
304 previousCellToEdit = cellEdgeNeighbors->GetId(1);
305 }
306 }
307 continue;
308 }
309
310 previousId = static_cast<vtkIdType>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i-1),0));
311
312
313
314 cellsOnSameSide->Initialize();
315 if (this->
GetCellsOnSameSide(input,cellEdgeNeighbors->GetId(0),cellEdgeNeighbors->GetId(1),previousCellToEdit,previousId,id0,id1,cellsOnSameSide))
316 {
317 for (j=0; j<cellsOnSameSide->GetNumberOfIds(); j++)
318 {
319 cellsToEdit->InsertUniqueId(cellsOnSameSide->GetId(j));
320 }
321 previousCellToEdit = cellsOnSameSide->GetId(cellsOnSameSide->GetNumberOfIds()-1);
322 }
323 else
324 {
325
326 vtkErrorMacro(<<"Hole in the surface found. Can't determine line orientation.");
327 return 1;
328 }
329 }
330
331 for (i=0; i<cellsToEdit->GetNumberOfIds(); i++)
332 {
333 cellId = cellsToEdit->GetId(i);
334 input->GetCellPoints(cellId,npts,pts);
335
336 editedCellIds->InsertUniqueId(cellId);
337 editedCells->InsertNextCell(npts);
338 for (j=0; j<npts; j++)
339 {
340 duplicatePointLocation = duplicatedPointIds->IsId(pts[j]);
341 if (duplicatePointLocation!=-1)
342 {
343 editedCells->InsertCellPoint(duplicatePointIds->GetId(duplicatePointLocation));
344 }
345 else
346 {
347 editedCells->InsertCellPoint(pts[j]);
348 }
349 }
350 }
351 }
352
353 input->GetPolys()->InitTraversal();
354 for (i=0; i<input->GetPolys()->GetNumberOfCells(); i++)
355 {
356 input->GetPolys()->GetNextCell(npts,pts);
357 if (editedCellIds->IsId(i)==-1)
358 {
359 newPolys->InsertNextCell(npts,pts);
360 }
361 }
362
363 editedCells->InitTraversal();
364 for (i=0; i<editedCells->GetNumberOfCells(); i++)
365 {
366 editedCells->GetNextCell(npts,pts);
367 newPolys->InsertNextCell(npts,pts);
368 }
369
370 output->SetPoints(newPoints);
371 output->SetPolys(newPolys);
372
373 outputPD->CopyAllocate(inputPD,numberOfInputPoints+numberOfLinePoints);
374
375 for (i=0; i<numberOfInputPoints; i++)
376 {
377 outputPD->CopyData(inputPD,i,i);
378 }
379
380 for (i=0; i<duplicatedPointIds->GetNumberOfIds(); i++)
381 {
382 outputPD->CopyData(inputPD,duplicatedPointIds->GetId(i),duplicatePointIds->GetId(i));
383 }
384
385 duplicatePointIds->Delete();
386 duplicatedPointIds->Delete();
387 cellsToEdit->Delete();
388 cellEdgeNeighbors->Delete();
389 cellsOnSameSide->Delete();
390 editedCells->Delete();
391 editedCellIds->Delete();
392 newPoints->Delete();
393 newPolys->Delete();
394
395 return 1;
396}
int GetCellsOnSameSide(vtkPolyData *input, vtkIdType targetCellId0, vtkIdType targetCellId1, vtkIdType referenceCellId, vtkIdType linePointId0, vtkIdType linePointId1, vtkIdType linePointId2, vtkIdList *cellsOnSameSide)