42 vtkInformation *vtkNotUsed(request),
43 vtkInformationVector **inputVector,
44 vtkInformationVector *outputVector)
46 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
47 vtkInformation *outInfo = outputVector->GetInformationObject(0);
49 vtkPolyData *input = vtkPolyData::SafeDownCast(
50 inInfo->Get(vtkDataObject::DATA_OBJECT()));
51 vtkPolyData *output = vtkPolyData::SafeDownCast(
52 outInfo->Get(vtkDataObject::DATA_OBJECT()));
54 vtkIdList *boundary, *boundaryIds, *cellEdgeNeighbors, *newCell;
55 vtkIdType i, j, currentId, id, id0, id1;
57 bool foundAny, foundNeighbor, done;
59 vtkCellArray* newLines;
60 vtkIdTypeArray* newScalars;
71 vtkPolyData* working = vtkPolyData::New();
72 working->CopyStructure(input);
73 working->BuildCells();
74 working->BuildLinks();
77 boundary = vtkIdList::New();
78 boundaryIds = vtkIdList::New();
79 cellEdgeNeighbors = vtkIdList::New();
80 newCell = vtkIdList::New();
81 newPoints = vtkPoints::New();
82 newLines = vtkCellArray::New();
83 newScalars = vtkIdTypeArray::New();
86 for (i=0; i<working->GetNumberOfCells(); i++)
88 cell = working->GetCell(i);
91 cellEdgeNeighbors->Initialize();
92 auto edge = cell->GetEdge(j);
94 auto pointIds = edge->GetPointIds();
95 id0 = pointIds->GetId(0);
96 id1 = pointIds->GetId(1);
97 working->GetCellEdgeNeighbors(i,id0,id1,cellEdgeNeighbors);
98 if (cellEdgeNeighbors->GetNumberOfIds()==0)
100 boundaryIds->InsertUniqueId(id0);
101 boundaryIds->InsertUniqueId(id1);
106 if (boundaryIds->GetNumberOfIds() == 0)
108 output->SetPoints(newPoints);
109 output->SetLines(newLines);
110 output->GetPointData()->SetScalars(newScalars);
114 newScalars->Delete();
117 boundaryIds->Delete();
118 cellEdgeNeighbors->Delete();
123 working->Initialize();
130 foundNeighbor =
false;
139 foundNeighbor =
false;
141 for (i=0; i<boundaryIds->GetNumberOfIds(); i++)
143 id = boundaryIds->GetId(i);
147 isBoundaryEdge =
false;
148 if (currentId!=-1 && working->IsEdge(currentId,
id))
150 cellEdgeNeighbors->Initialize();
151 working->GetCellEdgeNeighbors(-1,currentId,
id,cellEdgeNeighbors);
152 if (cellEdgeNeighbors->GetNumberOfIds() == 1)
154 isBoundaryEdge =
true;
157 if ((currentId==-1) || isBoundaryEdge)
159 foundNeighbor =
true;
165 boundary->InsertNextId(currentId);
166 boundaryIds->SetId(i,-1);
172 if ( (((!foundNeighbor)&&(foundAny))||(!foundAny)) && (boundary->GetNumberOfIds() > 2))
180 newCell->Initialize();
181 newCell->SetNumberOfIds(boundary->GetNumberOfIds());
182 for (j=0; j<boundary->GetNumberOfIds(); j++)
184 id = boundary->GetId(j);
185 newCell->SetId(j,newPoints->InsertNextPoint(working->GetPoint(
id)));
186 newScalars->InsertNextValue(
id);
189 newLines->InsertNextCell(newCell);
192 boundary->Initialize();
201 if (loopCount > 2*boundaryIds->GetNumberOfIds())
204 for (
int n=0; n<boundaryIds->GetNumberOfIds(); n++)
206 if (boundaryIds->GetId(n) != -1)
211 vtkErrorMacro(<<
"Can't find adjacent point. Bailing out.");
216 output->SetPoints(newPoints);
217 output->SetLines(newLines);
218 output->GetPointData()->SetScalars(newScalars);
223 newScalars->Delete();
226 boundaryIds->Delete();
227 cellEdgeNeighbors->Delete();
232 working->Initialize();