------------------------------------------------------------------------------
| 514 | |
| 515 | //------------------------------------------------------------------------------ |
| 516 | int vtkMNIObjectReader::ReadCells(vtkPolyData* data, vtkIdType numCells, int cellType) |
| 517 | { |
| 518 | vtkIntArray* endIndices = vtkIntArray::New(); |
| 519 | vtkIntArray* cellIndices = vtkIntArray::New(); |
| 520 | vtkCellArray* cellArray = vtkCellArray::New(); |
| 521 | |
| 522 | // Read the cell end indices |
| 523 | int status = this->ParseValues(endIndices, numCells); |
| 524 | |
| 525 | // Read the cell point indices |
| 526 | vtkIdType numIndices = 0; |
| 527 | if (status != 0) |
| 528 | { |
| 529 | if (numCells > 0) |
| 530 | { |
| 531 | numIndices = endIndices->GetValue(numCells - 1); |
| 532 | } |
| 533 | status = this->ParseValues(cellIndices, numIndices); |
| 534 | } |
| 535 | |
| 536 | // Create the cell array |
| 537 | if (status != 0) |
| 538 | { |
| 539 | cellArray->AllocateExact(numCells, endIndices->GetValue(numCells - 1)); |
| 540 | |
| 541 | vtkPoints* points = data->GetPoints(); |
| 542 | vtkIdType numPoints = points->GetNumberOfPoints(); |
| 543 | vtkIdType lastEndIndex = 0; |
| 544 | for (vtkIdType i = 0; i < numCells; i++) |
| 545 | { |
| 546 | vtkIdType endIndex = endIndices->GetValue(i); |
| 547 | numIndices = endIndex - lastEndIndex; |
| 548 | |
| 549 | cellArray->InsertNextCell(numIndices); |
| 550 | |
| 551 | // Check that the index values are okay and create the cell |
| 552 | for (vtkIdType j = 0; j < numIndices; j++) |
| 553 | { |
| 554 | vtkIdType idx = cellIndices->GetValue(lastEndIndex + j); |
| 555 | if (idx > numPoints) |
| 556 | { |
| 557 | vtkErrorMacro("Index " << idx << " is greater than the" |
| 558 | << " total number of points " << numPoints << " " |
| 559 | << this->FileName); |
| 560 | return 0; |
| 561 | } |
| 562 | cellArray->InsertCellPoint(idx); |
| 563 | } |
| 564 | |
| 565 | lastEndIndex = endIndex; |
| 566 | } |
| 567 | |
| 568 | if (cellType == VTK_POLYGON) |
| 569 | { |
| 570 | data->SetPolys(cellArray); |
| 571 | } |
| 572 | else if (cellType == VTK_POLY_LINE) |
| 573 | { |
no test coverage detected