Skip to content

Commit

Permalink
ENH: Add test to improve vtkDICOMImageReader coverage.
Browse files Browse the repository at this point in the history
This patch set adds a new test to exercise the vtkDICOMImageReader's
ability to parse a folder containing DICOM files.

The DICOM files were generated using David Gobbi's niftitodicom tool from
the vtk-dicom project, and using the filtered_func_data.nii.gz NIfTI file
already present in VTK's testing data. Only 10 slices around the central
axial region of the volume are included to limit the testing data size.
  • Loading branch information
Jon Haitz Legarreta committed Dec 15, 2016
1 parent f359477 commit 0ed16ca
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 2 deletions.
11 changes: 10 additions & 1 deletion IO/Image/Testing/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Tell ExternalData to fetch test input at build time.
ExternalData_Expand_Arguments(VTKData _
"DATA{${VTK_TEST_INPUT_DIR}/dicom/collection/,REGEX:.*}"
)

vtk_add_test_cxx(${vtk-module}CxxTests data_tests
# TestImageReader2Factory.cxx # fixme (deps not satisfied)
TestNrrdReader.cxx
Expand All @@ -13,11 +18,15 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestImportExport.cxx
)

# Each of these most be added in a separate vtk_add_test_cxx
# Each of these must be added in a separate vtk_add_test_cxx
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestDICOMImageReader.cxx,NO_OUTPUT
"DATA{${VTK_TEST_INPUT_DIR}/dicom/prostate.IMG}")

vtk_add_test_cxx(${vtk-module}CxxTests tests
TestDICOMImageReaderFileCollection.cxx,NO_OUTPUT
"collection")

vtk_add_test_cxx(${vtk-module}CxxTests tests
TestTIFFReaderMultipleMulti,TestTIFFReaderMultiple.cxx,NO_VALID,NO_OUTPUT
"DATA{${VTK_TEST_INPUT_DIR}/libtiff/multipage_tiff_example.tif}")
Expand Down
128 changes: 128 additions & 0 deletions IO/Image/Testing/Cxx/TestDICOMImageReaderFileCollection.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*=========================================================================
Program: Visualization Toolkit
Module: TestDICOMImageReaderFileCollection.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkDICOMImageReader
// .SECTION Description
//


#include "vtkSmartPointer.h"

#include "vtkDICOMImageReader.h"

#include "vtkImageData.h"
#include "vtkImageViewer2.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTestUtilities.h"


int TestDICOMImageReaderFileCollection(int argc, char *argv[])
{

if ( argc <= 1 )
{
cout << "Usage: " << argv[0] << " <dicom folder>" << endl;
return 1;
}

char* dirName = vtkTestUtilities::ExpandDataFileName( argc, argv, "Data/dicom/collection" );
std::string directoryName = dirName;
delete [] dirName;

vtkSmartPointer<vtkDICOMImageReader> DICOMReader =
vtkSmartPointer<vtkDICOMImageReader>::New();

// Read the input files
DICOMReader->SetDirectoryName(directoryName.c_str());
cout << "Directory name: " << DICOMReader->GetDirectoryName() << endl;

DICOMReader->Update();

// Read and display the image properties
const char* fileExtensions = DICOMReader->GetFileExtensions();
cout << "File extensions: " << fileExtensions << endl;

const char* descriptiveName = DICOMReader->GetDescriptiveName();
cout << "Descriptive name: " << descriptiveName << endl;

double* pixelSpacing = DICOMReader->GetPixelSpacing();
cout << "Pixel spacing: " << *pixelSpacing << endl;

int width = DICOMReader->GetWidth();
cout << "Image width: " << width << endl;

int height = DICOMReader->GetHeight();
cout << "Image height: " << height << endl;

float* imagePositionPatient = DICOMReader->GetImagePositionPatient();
cout << "Image position patient: " << *imagePositionPatient << endl;

float* imageOrientationPatient = DICOMReader->GetImageOrientationPatient();
cout << "Image orientation patient: " << *imageOrientationPatient << endl;

int bitsAllocated = DICOMReader->GetBitsAllocated();
cout << "Bits allocated: " << bitsAllocated << endl;

int pixelRepresentation = DICOMReader->GetPixelRepresentation();
cout << "Pixel representation: " << pixelRepresentation << endl;

int numberOfComponents = DICOMReader->GetNumberOfComponents();
cout << "Number of components: " << numberOfComponents << endl;

const char* transferSyntaxUID = DICOMReader->GetTransferSyntaxUID();
cout << "Transfer syntax UID: " << transferSyntaxUID << endl;

float rescaleSlope = DICOMReader->GetRescaleSlope();
cout << "Rescale slope: " << rescaleSlope << endl;

float rescaleOffset = DICOMReader->GetRescaleOffset();
cout << "Rescale offset: " << rescaleOffset << endl;

const char* patientName = DICOMReader->GetPatientName();
cout << "Patient name: " << patientName << endl;

const char* studyUID = DICOMReader->GetStudyUID();
cout << "Study UID: " << studyUID << endl;

const char* studyID = DICOMReader->GetStudyID();
cout << "Study ID: " << studyID << endl;

float gantryAngle = DICOMReader->GetGantryAngle();
cout << "Gantry angle: " << gantryAngle << endl;


// Display the center slice
int sliceNumber =
(DICOMReader->GetOutput()->GetExtent()[5] +
DICOMReader->GetOutput()->GetExtent()[4]) / 2;

// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(DICOMReader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->SetSlice(sliceNumber);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
renderWindowInteractor->Initialize();
imageViewer->Render();

renderWindowInteractor->Start();


return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6c042ee4549194e7ad928446e82896b9
2 changes: 1 addition & 1 deletion IO/Image/vtkDICOMImageReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int vtkDICOMImageReader::CanReadFile(const char* fname)
}
else
{
vtkErrorMacro("DICOMParser couldn't parse : " << fname);
vtkWarningMacro("DICOMParser couldn't parse : " << fname);
return 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1983.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3258ea5d2a205a17c47d9360c9748f5b
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1984.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
07ebebd3fd24d2391a6c70655b6796f6
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1985.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8eb81359e5d950cf1afb0afe7b2371f6
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1986.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7bc8b3eeaf480aecba5d58ee83eee000
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1987.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6d68ed1fbc44a83e5edc57def951a416
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1988.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ac8befa7248e9a6a98df3a8bb02e4e3a
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1989.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca1cfecd2cd54e34f4d6715f030b7ca7
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1990.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8bc833af0701dbf9e9e2101930ad95f8
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1991.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bfc7b2189f7f4ada15ecdbfb2416c223
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1992.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c5ca32209c7ecd151635581d97a43b81
1 change: 1 addition & 0 deletions Testing/Data/dicom/collection/IM-0001-1993.dcm.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dc1ac27b3f31512d5863ea16e86ca634

0 comments on commit 0ed16ca

Please sign in to comment.