------------------------------------------------------------------------------
| 579 | |
| 580 | //------------------------------------------------------------------------------ |
| 581 | int vtkNIFTIImageWriter::RequestData(vtkInformation* vtkNotUsed(request), |
| 582 | vtkInformationVector** inputVector, vtkInformationVector* vtkNotUsed(outputVector)) |
| 583 | { |
| 584 | this->SetErrorCode(vtkErrorCode::NoError); |
| 585 | |
| 586 | vtkInformation* info = inputVector[0]->GetInformationObject(0); |
| 587 | vtkImageData* data = vtkImageData::SafeDownCast(info->Get(vtkDataObject::DATA_OBJECT())); |
| 588 | |
| 589 | if (data == nullptr) |
| 590 | { |
| 591 | vtkErrorMacro("No input provided!"); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | const char* filename = this->GetFileName(); |
| 596 | if (filename == nullptr) |
| 597 | { |
| 598 | vtkErrorMacro("A FileName must be provided"); |
| 599 | this->SetErrorCode(vtkErrorCode::NoFileNameError); |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | int extent[6]; |
| 604 | info->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent); |
| 605 | |
| 606 | // use compression if name ends in .gz |
| 607 | bool isCompressed = false; |
| 608 | size_t n = strlen(filename); |
| 609 | size_t m = n; |
| 610 | if (n > 2 && filename[n - 3] == '.' && tolower(filename[n - 2]) == 'g' && |
| 611 | tolower(filename[n - 1]) == 'z') |
| 612 | { |
| 613 | m = n - 3; |
| 614 | isCompressed = true; |
| 615 | } |
| 616 | |
| 617 | // after the optional ".gz" is removed, is it a ".img/.hdr" file? |
| 618 | bool singleFile = true; |
| 619 | if (m > 4 && filename[m - 4] == '.' && |
| 620 | ((tolower(filename[m - 3]) == 'h' && tolower(filename[m - 2]) == 'd' && |
| 621 | tolower(filename[m - 1]) == 'r') || |
| 622 | (tolower(filename[m - 3]) == 'i' && tolower(filename[m - 2]) == 'm' && |
| 623 | tolower(filename[m - 1]) == 'g'))) |
| 624 | { |
| 625 | singleFile = false; |
| 626 | } |
| 627 | |
| 628 | // generate the header information |
| 629 | if (this->GenerateHeader(info, singleFile) == 0) |
| 630 | { |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | // if file is not .nii, then get .hdr and .img filenames |
| 635 | char* hdrname = vtkNIFTIImageWriter::ReplaceExtension(filename, ".img", ".hdr"); |
| 636 | char* imgname = vtkNIFTIImageWriter::ReplaceExtension(filename, ".hdr", ".img"); |
| 637 | |
| 638 | vtkDebugMacro(<< "Writing NIFTI file " << hdrname); |
nothing calls this directly
no test coverage detected