| 383 | } |
| 384 | |
| 385 | vtkPolyData* vtkSMPMergePolyDataHelper::MergePolyData(std::vector<InputData>& inputs) |
| 386 | { |
| 387 | // First merge points |
| 388 | |
| 389 | std::vector<InputData>::iterator itr = inputs.begin(); |
| 390 | std::vector<InputData>::iterator begin = itr; |
| 391 | std::vector<InputData>::iterator end = inputs.end(); |
| 392 | |
| 393 | std::vector<vtkMergePointsData> mpData; |
| 394 | while (itr != end) |
| 395 | { |
| 396 | mpData.emplace_back((*itr).Input, (*itr).Locator); |
| 397 | ++itr; |
| 398 | } |
| 399 | |
| 400 | std::vector<vtkIdList*> idMaps; |
| 401 | vtkPolyData* outPolyData = vtkPolyData::New(); |
| 402 | |
| 403 | MergePoints(mpData, idMaps, outPolyData); |
| 404 | |
| 405 | itr = begin; |
| 406 | vtkIdType vertSize = 0; |
| 407 | vtkIdType lineSize = 0; |
| 408 | vtkIdType polySize = 0; |
| 409 | vtkIdType numVerts = 0; |
| 410 | vtkIdType numLines = 0; |
| 411 | vtkIdType numPolys = 0; |
| 412 | std::vector<vtkMergeCellsData> mcData; |
| 413 | while (itr != end) |
| 414 | { |
| 415 | vertSize += (*itr).Input->GetVerts()->GetNumberOfConnectivityIds(); |
| 416 | lineSize += (*itr).Input->GetLines()->GetNumberOfConnectivityIds(); |
| 417 | polySize += (*itr).Input->GetPolys()->GetNumberOfConnectivityIds(); |
| 418 | numVerts += (*itr).Input->GetVerts()->GetNumberOfCells(); |
| 419 | numLines += (*itr).Input->GetLines()->GetNumberOfCells(); |
| 420 | numPolys += (*itr).Input->GetPolys()->GetNumberOfCells(); |
| 421 | ++itr; |
| 422 | } |
| 423 | |
| 424 | vtkIdType numOutCells = numVerts + numLines + numPolys; |
| 425 | |
| 426 | vtkCellData* outCellData = (*begin).Input->GetCellData(); |
| 427 | int numCellArrays = outCellData->GetNumberOfArrays(); |
| 428 | for (int i = 0; i < numCellArrays; i++) |
| 429 | { |
| 430 | // Resize preserves existing data on reallocation |
| 431 | outCellData->GetArray(i)->Resize(numOutCells); |
| 432 | outCellData->GetArray(i)->SetNumberOfTuples(numOutCells); |
| 433 | } |
| 434 | |
| 435 | // Now merge each cell type. Because vtkPolyData stores each |
| 436 | // cell type separately, we need to merge them separately. |
| 437 | |
| 438 | if (vertSize > 0) |
| 439 | { |
| 440 | vtkNew<vtkCellArray> outVerts; |
| 441 | outVerts->ResizeExact(numVerts, vertSize); |
| 442 |
nothing calls this directly
no test coverage detected