@@ -656,18 +656,29 @@ PlusStatus vtkPlusStealthLinkTracker::GetImage(const std::string& requestedImage
656656 examImageDirectoryToDelete = examImageDirectory;
657657
658658 vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New ();
659- reader->SetDirectoryName (examImageDirectory.c_str ());
660-
661- // to go from the vtk orientation to lps orientation, the vtk image has to be flipped around y and z axis
662- vtkSmartPointer<vtkImageFlip> flipYFilter = vtkSmartPointer<vtkImageFlip>::New ();
663- flipYFilter->SetFilteredAxis (1 ); // flip y axis
664- flipYFilter->SetInputConnection (reader->GetOutputPort ());
665-
666- vtkSmartPointer<vtkImageFlip> flipZFilter = vtkSmartPointer<vtkImageFlip>::New ();
667- flipZFilter->SetFilteredAxis (2 ); // flip z axis
668- flipZFilter->SetInputConnection (flipYFilter->GetOutputPort ());
669- flipZFilter->Update ();
670- imageData->DeepCopy (flipZFilter->GetOutput ());
659+ try
660+ {
661+ reader->SetDirectoryName (examImageDirectory.c_str ());
662+ reader->ReleaseDataFlagOn ();
663+
664+ // to go from the vtk orientation to lps orientation, the vtk image has to be flipped around y and z axis
665+ vtkSmartPointer<vtkImageFlip> flipYFilter = vtkSmartPointer<vtkImageFlip>::New ();
666+ flipYFilter->SetFilteredAxis (1 ); // flip y axis
667+ flipYFilter->ReleaseDataFlagOn ();
668+ flipYFilter->SetInputConnection (reader->GetOutputPort ());
669+
670+ vtkSmartPointer<vtkImageFlip> flipZFilter = vtkSmartPointer<vtkImageFlip>::New ();
671+ flipZFilter->SetFilteredAxis (2 ); // flip z axis
672+ flipZFilter->ReleaseDataFlagOn ();
673+ flipZFilter->SetInputConnection (flipYFilter->GetOutputPort ());
674+ flipZFilter->Update ();
675+ imageData->DeepCopy (flipZFilter->GetOutput ());
676+ }
677+ catch (const std::bad_alloc& e)
678+ {
679+ LOG_ERROR (" Error when downloading image from StealthLink: " << e.what () << " . Image may be too large" );
680+ return PLUS_FAIL;
681+ }
671682
672683 float * ijkOrigin_LPS = reader->GetImagePositionPatient (); // (0020,0032) ImagePositionPatient
673684 double * ijkVectorMagnitude_LPS = reader->GetPixelSpacing (); // (0020,0037) ImageOrientationPatient
0 commit comments