Discard unused points; renumber output polylines and polygons. Performs this operation in place.
| 242 | // Discard unused points; renumber output polylines and polygons. |
| 243 | // Performs this operation in place. |
| 244 | void CleanOutputPoints(vtkPolyData* output) |
| 245 | { |
| 246 | // Mark points used by lines or polygons, and create a point map |
| 247 | // of old point ids to new point ids. |
| 248 | vtkIdType numPts = output->GetNumberOfPoints(); |
| 249 | std::vector<vtkIdType> ptMap(numPts, 0); |
| 250 | vtkPoints* pts = output->GetPoints(); |
| 251 | |
| 252 | // Get the connectivity of the lines and polygons. Run through them |
| 253 | // and mark points that are used. |
| 254 | vtkCellArray* lines = output->GetLines(); |
| 255 | vtkIdType numLinesIds = lines->GetNumberOfConnectivityIds(); |
| 256 | if (numLinesIds > 0) |
| 257 | { |
| 258 | MarkPointUses(lines, numLinesIds, ptMap); |
| 259 | } |
| 260 | |
| 261 | vtkCellArray* polys = output->GetPolys(); |
| 262 | vtkIdType numPolysIds = polys->GetNumberOfConnectivityIds(); |
| 263 | if (numPolysIds > 0) |
| 264 | { |
| 265 | MarkPointUses(polys, numPolysIds, ptMap); |
| 266 | } |
| 267 | |
| 268 | // Renumber points / build the point map |
| 269 | vtkNew<vtkPoints> newPts; |
| 270 | vtkIdType newId; |
| 271 | for (auto pId = 0; pId < numPts; ++pId) |
| 272 | { |
| 273 | if (ptMap[pId] != 0) |
| 274 | { |
| 275 | newId = newPts->InsertNextPoint(pts->GetPoint(pId)); |
| 276 | ptMap[pId] = newId; |
| 277 | } |
| 278 | } |
| 279 | output->SetPoints(newPts); |
| 280 | |
| 281 | // Update the point ids (in place). |
| 282 | if (numLinesIds > 0) |
| 283 | { |
| 284 | UpdatePointUses(lines, numLinesIds, ptMap); |
| 285 | } |
| 286 | if (numPolysIds > 0) |
| 287 | { |
| 288 | UpdatePointUses(polys, numPolysIds, ptMap); |
| 289 | } |
| 290 | } // CleanOutputPoints |
| 291 | |
| 292 | } // anonymous namespace |
| 293 |
no test coverage detected