Last active
August 31, 2017 20:36
-
-
Save agirault/971c81bb8e033be9957bd68f3223e239 to your computer and use it in GitHub Desktop.
Reslice vtkImageData from vtkDICOMReader using patient matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Directory | |
const char *folderASCII = [folder cStringUsingEncoding:NSASCIIStringEncoding]; | |
auto dicomDir = vtkSmartPointer<vtkDICOMDirectory>::New(); | |
dicomDir->SetDirectoryName(folderASCII); | |
dicomDir->Update(); | |
// Reader | |
auto reader = vtkSmartPointer<vtkDICOMReader>::New(); | |
reader->SetFileNames(dicomDir->GetFileNamesForSeries(0)); | |
//reader->SetMemoryRowOrderToFileNative(); | |
reader->Update(); | |
vtkImageData *data = reader->GetOutput(); | |
// Patient Matrix | |
auto matrixInv = vtkSmartPointer<vtkMatrix4x4>::New(); | |
vtkMatrix4x4::Invert(reader->GetPatientMatrix(), matrixInv); | |
// Transform | |
auto transformFilter = vtkSmartPointer<vtkImageReslice>::New(); | |
transformFilter->SetInputData(data); | |
transformFilter->SetResliceAxes(matrixInv); | |
transformFilter->SetInterpolationModeToLinear(); | |
transformFilter->Update(); | |
// Final image | |
data = transformFilter->GetOutput(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Applying the PatientMatrix on the mapper (UserMatrix)
@agirault: But then don't you also need to apply PatientMatrix to the camera if you slice based on its focal point? I currently have issues when sliding the focalpoint along the slices where the view just dissapears.
Applying the inverse of the PatientMatrix on the pointsets
@agirault: Makes sense, however, I would like the datasets to be correctly oriented in space using the same orientation widget for my different views in LPS. If I move the surfaces instead I kind of lose that.
@agirault: Are there any other major issues apart from the performance? I'm aware than resampling the image is much slower than transforming a point set, but since I only do this once at load time I assume that the performance wouldn't affect my use case.
Applying the PatientMatrix on the data (ImageReslice)
@agirault: Merci David, that worked well! See code attached.