MCPcopy Create free account
hub / github.com/Kitware/VTK / RequestData

Method RequestData

IO/Image/vtkNIFTIImageWriter.cxx:581–948  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

579
580//------------------------------------------------------------------------------
581int 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);

Callers

nothing calls this directly

Calls 15

GenerateHeaderMethod · 0.95
tolowerFunction · 0.85
gzwriteFunction · 0.85
gzcloseFunction · 0.85
GetInformationObjectMethod · 0.80
GetHeaderMethod · 0.80
InvokeEventMethod · 0.80
GetScalarPointerMethod · 0.80
GetScalarSizeMethod · 0.80
GZFopenFunction · 0.70
GetMethod · 0.45
GetFileNameMethod · 0.45

Tested by

no test coverage detected