------------------------------------------------------------------------------
| 499 | |
| 500 | //------------------------------------------------------------------------------ |
| 501 | int vtkCommunicator::MarshalDataObject(vtkDataObject* object, vtkCharArray* buffer) |
| 502 | { |
| 503 | buffer->Initialize(); |
| 504 | buffer->SetNumberOfComponents(1); |
| 505 | |
| 506 | if (object == nullptr) |
| 507 | { |
| 508 | buffer->SetNumberOfTuples(0); |
| 509 | return 1; |
| 510 | } |
| 511 | |
| 512 | VTK_CREATE(vtkGenericDataObjectWriter, writer); |
| 513 | |
| 514 | vtkSmartPointer<vtkDataObject> copy; |
| 515 | copy.TakeReference(object->NewInstance()); |
| 516 | copy->ShallowCopy(object); |
| 517 | |
| 518 | writer->SetFileTypeToBinary(); |
| 519 | // There is a problem with binary files with no data. |
| 520 | if (vtkDataSet::SafeDownCast(copy) != nullptr) |
| 521 | { |
| 522 | vtkDataSet* ds = vtkDataSet::SafeDownCast(copy); |
| 523 | if (ds->GetNumberOfCells() + ds->GetNumberOfPoints() == 0) |
| 524 | { |
| 525 | writer->SetFileTypeToASCII(); |
| 526 | } |
| 527 | } |
| 528 | writer->WriteToOutputStringOn(); |
| 529 | writer->SetInputData(copy); |
| 530 | |
| 531 | if (!writer->Write()) |
| 532 | { |
| 533 | vtkGenericWarningMacro("Error detected while marshaling data object."); |
| 534 | return 0; |
| 535 | } |
| 536 | const vtkIdType size = writer->GetOutputStringLength(); |
| 537 | if (object->GetExtentType() == VTK_3D_EXTENT) |
| 538 | { |
| 539 | // You would think that the extent information would be properly saved, but |
| 540 | // no, it is not. |
| 541 | int extent[6] = { 0, 0, 0, 0, 0, 0 }; |
| 542 | vtkRectilinearGrid* rg = vtkRectilinearGrid::SafeDownCast(object); |
| 543 | vtkStructuredGrid* sg = vtkStructuredGrid::SafeDownCast(object); |
| 544 | vtkImageData* id = vtkImageData::SafeDownCast(object); |
| 545 | if (rg) |
| 546 | { |
| 547 | rg->GetExtent(extent); |
| 548 | } |
| 549 | else if (sg) |
| 550 | { |
| 551 | sg->GetExtent(extent); |
| 552 | } |
| 553 | else if (id) |
| 554 | { |
| 555 | id->GetExtent(extent); |
| 556 | } |
| 557 | char extentHeader[EXTENT_HEADER_SIZE]; |
| 558 | auto result = |
no test coverage detected