69int vtkvmtkPolyDataScissors::GetCellsOnSameSide(vtkPolyData* input, vtkIdType targetCellId0, vtkIdType targetCellId1, vtkIdType referenceCellId, vtkIdType linePointId0, vtkIdType linePointId1, vtkIdType linePointId2, vtkIdList *cellsOnSameSide)
73 vtkIdType previousCellId;
80 if (cellsOnSameSide->GetNumberOfIds()>0)
82 cellsOnSameSide->Initialize();
85 input->GetPointCells(linePointId1,ncells,cells);
87 edge[0] = linePointId1;
89 input->GetCellPoints(referenceCellId,npts,pts);
93 for (i=0; i<npts; i++)
95 if (pts[i]!=linePointId1 && pts[i]!=linePointId0)
104 vtkErrorMacro(<<
"Bad request for CellsOnSameSide of CutLine. Not an edge.");
108 previousCellId = referenceCellId;
115 for (i=0; i<ncells; i++)
117 if (cells[i]==previousCellId)
122 if ((cells[i]==targetCellId0)||(cells[i]==targetCellId1))
124 cellsOnSameSide->InsertNextId(cells[i]);
130 cellsOnSameSide->InsertNextId(cells[i]);
131 previousCellId = cells[i];
133 input->GetCellPoints(cells[i],npts,pts);
134 for (j=0; j<npts; j++)
136 if (pts[j]!=edge[0] && pts[j]!=edge[1])
152 vtkInformation *vtkNotUsed(request),
153 vtkInformationVector **inputVector,
154 vtkInformationVector *outputVector)
156 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
157 vtkInformation *outInfo = outputVector->GetInformationObject(0);
159 vtkPolyData *input = vtkPolyData::SafeDownCast(
160 inInfo->Get(vtkDataObject::DATA_OBJECT()));
161 vtkPolyData *output = vtkPolyData::SafeDownCast(
162 outInfo->Get(vtkDataObject::DATA_OBJECT()));
165 vtkIdType surfacePointId, newPointId;
166 vtkIdType id0, id1, previousId;
167 vtkIdType duplicatePointLocation;
168 vtkIdType numberOfLines, numberOfLinePoints, numberOfInputPoints;
169 vtkIdType cellId, previousCellToEdit;
171 const vtkIdType *pts;
172 vtkDataArray *cutLinePointIdsArray;
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();
185 previousCellToEdit = -1;
189 vtkErrorMacro(<<
"CutLine not specified!");
195 vtkErrorMacro(<<
"CutLinePointIdsArrayName not specified!");
201 if (cutLinePointIdsArray==NULL)
203 vtkErrorMacro(<<
"CutLinePointIdsArray with name specified does not exist!");
207 newPoints = vtkPoints::New();
208 newPolys = vtkCellArray::New();
210 editedCells = vtkCellArray::New();
212 duplicatePointIds = vtkIdList::New();
213 duplicatedPointIds = vtkIdList::New();
214 cellsToEdit = vtkIdList::New();
215 editedCellIds = vtkIdList::New();
216 cellEdgeNeighbors = vtkIdList::New();
217 cellsOnSameSide = vtkIdList::New();
219 numberOfInputPoints = input->GetNumberOfPoints();
220 newPoints->DeepCopy(input->GetPoints());
222 numberOfLinePoints = this->
CutLine->GetNumberOfPoints();
224 numberOfLines = this->
CutLine->GetNumberOfCells();
230 for (k=0; k<numberOfLines; k++)
232 polyLine = this->
CutLine->GetCell(k);
233 if (polyLine->GetCellType() != VTK_LINE && polyLine->GetCellType() != VTK_POLY_LINE)
238 numberOfLinePoints = polyLine->GetNumberOfPoints();
240 duplicatedPointIds->Initialize();
241 duplicatePointIds->Initialize();
242 cellsToEdit->Initialize();
244 for (i=0; i<numberOfLinePoints; i++)
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);
252 for (i=0; i<numberOfLinePoints-1; i++)
254 id0 =
static_cast<vtkIdType
>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i),0));
255 id1 =
static_cast<vtkIdType
>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i+1),0));
259 vtkErrorMacro(<<
"Coincident points found on CutLine! ");
263 if (!input->IsEdge(id0,id1))
265 vtkErrorMacro(<<
"CutLine is not entirely defined on mesh edges! ");
269 cellEdgeNeighbors->Initialize();
270 input->GetCellEdgeNeighbors(-1,id0,id1,cellEdgeNeighbors);
272 if (cellEdgeNeighbors->GetNumberOfIds()<2)
274 vtkWarningMacro(<<
"Surface boundary or hole found.");
278 if (cellEdgeNeighbors->GetNumberOfIds()>2)
280 vtkErrorMacro(<<
"Surface is non-manifold! ");
291 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(0));
292 previousCellToEdit = cellEdgeNeighbors->GetId(0);
296 if (cellsToEdit->IsId(cellEdgeNeighbors->GetId(0))!=-1)
298 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(0));
299 previousCellToEdit = cellEdgeNeighbors->GetId(0);
303 cellsToEdit->InsertUniqueId(cellEdgeNeighbors->GetId(1));
304 previousCellToEdit = cellEdgeNeighbors->GetId(1);
310 previousId =
static_cast<vtkIdType
>(cutLinePointIdsArray->GetComponent(polyLine->GetPointId(i-1),0));
314 cellsOnSameSide->Initialize();
315 if (this->
GetCellsOnSameSide(input,cellEdgeNeighbors->GetId(0),cellEdgeNeighbors->GetId(1),previousCellToEdit,previousId,id0,id1,cellsOnSameSide))
317 for (j=0; j<cellsOnSameSide->GetNumberOfIds(); j++)
319 cellsToEdit->InsertUniqueId(cellsOnSameSide->GetId(j));
321 previousCellToEdit = cellsOnSameSide->GetId(cellsOnSameSide->GetNumberOfIds()-1);
326 vtkErrorMacro(<<
"Hole in the surface found. Can't determine line orientation.");
331 for (i=0; i<cellsToEdit->GetNumberOfIds(); i++)
333 cellId = cellsToEdit->GetId(i);
334 input->GetCellPoints(cellId,npts,pts);
336 editedCellIds->InsertUniqueId(cellId);
337 editedCells->InsertNextCell(npts);
338 for (j=0; j<npts; j++)
340 duplicatePointLocation = duplicatedPointIds->IsId(pts[j]);
341 if (duplicatePointLocation!=-1)
343 editedCells->InsertCellPoint(duplicatePointIds->GetId(duplicatePointLocation));
347 editedCells->InsertCellPoint(pts[j]);
353 input->GetPolys()->InitTraversal();
354 for (i=0; i<input->GetPolys()->GetNumberOfCells(); i++)
356 input->GetPolys()->GetNextCell(npts,pts);
357 if (editedCellIds->IsId(i)==-1)
359 newPolys->InsertNextCell(npts,pts);
363 editedCells->InitTraversal();
364 for (i=0; i<editedCells->GetNumberOfCells(); i++)
366 editedCells->GetNextCell(npts,pts);
367 newPolys->InsertNextCell(npts,pts);
370 output->SetPoints(newPoints);
371 output->SetPolys(newPolys);
373 outputPD->CopyAllocate(inputPD,numberOfInputPoints+numberOfLinePoints);
375 for (i=0; i<numberOfInputPoints; i++)
377 outputPD->CopyData(inputPD,i,i);
380 for (i=0; i<duplicatedPointIds->GetNumberOfIds(); i++)
382 outputPD->CopyData(inputPD,duplicatedPointIds->GetId(i),duplicatePointIds->GetId(i));
385 duplicatePointIds->Delete();
386 duplicatedPointIds->Delete();
387 cellsToEdit->Delete();
388 cellEdgeNeighbors->Delete();
389 cellsOnSameSide->Delete();
390 editedCells->Delete();
391 editedCellIds->Delete();