Commit 782b4799 authored by Mathieu Malaterre's avatar Mathieu Malaterre
Browse files

ENH: Update API of DICOM reader to provide access to the much needed Image...

ENH: Update API of DICOM reader to provide access to the much needed Image Orientation (Patient). Also it nows set the origin to Image Position (Patient). Backport other patch from VTK CVS so that part of API is not public as it should. STYLE: Add doc for header
parent f2f887ee
......@@ -12,22 +12,23 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "DICOMParser.h"
#include "DICOMAppHelper.h"
#include "vtkDICOMImageReader.h"
#include "vtkDirectory.h"
#include "vtkDataArray.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkDirectory.h"
#include <vtkstd/vector>
#include <vtkstd/string>
#include <sys/stat.h>
vtkCxxRevisionMacro(vtkDICOMImageReader, "1.32");
#include "DICOMAppHelper.h"
#include "DICOMParser.h"
vtkCxxRevisionMacro(vtkDICOMImageReader, "1.32.6.1");
vtkStandardNewMacro(vtkDICOMImageReader);
class vtkDICOMImageReaderVector : public vtkstd::vector<vtkstd::string>
......@@ -354,7 +355,7 @@ void vtkDICOMImageReader::ExecuteData(vtkDataObject *output)
char* filename = new char[len+1];
strcpy(filename, (char*) (*fiter).c_str());
this->SetProgressText(filename);
delete[] filename;
}
}
}
......@@ -400,6 +401,10 @@ void vtkDICOMImageReader::SetupOutputInformation(int num_slices)
this->SetNumberOfScalarComponents(num_comp);
this->GetPixelSpacing();
float *pos = this->GetImagePositionPatient();
this->DataOrigin[0] = pos[0];
this->DataOrigin[1] = pos[1];
this->DataOrigin[2] = pos[2];
this->vtkImageReader2::ExecuteInformation();
}
......@@ -481,6 +486,12 @@ float* vtkDICOMImageReader::GetImagePositionPatient()
return this->AppHelper->GetImagePositionPatient();
}
//----------------------------------------------------------------------------
float* vtkDICOMImageReader::GetImageOrientationPatient()
{
return this->AppHelper->GetImageOrientationPatient();
}
//----------------------------------------------------------------------------
int vtkDICOMImageReader::GetBitsAllocated()
{
......
......@@ -12,8 +12,16 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkDICOMImageReader - Reads DICOM images
// .NAME vtkDICOMImageReader - Reads some DICOM images
// .SECTION Description
// DICOM (stands for Digital Imaging in COmmunications and Medicine)
// is a medical image file format widely used to exchange data, provided
// by various modalities.
// .SECTION Warnings
// This reader might eventually handle ACR-NEMA file (predecessor of the DICOM
// format for medical images).
// This reader does not handle encapsulated format, only plain raw file are
// handled. This reader also does not handle multi-frames DICOM datasets.
// .SECTION See Also
// vtkBMPReader vtkPNMReader vtkTIFFReader
......@@ -90,6 +98,12 @@ class VTK_IO_EXPORT vtkDICOMImageReader : public vtkImageReader2
// DICOMParser
float* GetImagePositionPatient();
// Description:
// Get the (DICOM) directions cosines. It consist of the components
// of the first two vectors. The third vector needs to be computed
// to form an orthonormal basis.
float* GetImageOrientationPatient();
// Description:
// Get the number of bits allocated for each pixel in the file.
int GetBitsAllocated();
......@@ -138,12 +152,6 @@ class VTK_IO_EXPORT vtkDICOMImageReader : public vtkImageReader2
//
virtual int CanReadFile(const char* fname);
protected:
//
// Setup the volume size
//
void SetupOutputInformation(int num_slices);
//
// What file extensions are supported?
//
......@@ -159,6 +167,12 @@ protected:
return "DICOM";
}
protected:
//
// Setup the volume size
//
void SetupOutputInformation(int num_slices);
virtual void ExecuteInformation();
virtual void ExecuteData(vtkDataObject *out);
......
......@@ -543,7 +543,8 @@ void DICOMAppHelper::SliceLocationCallback(DICOMParser *parser,
ord.SliceLocation = (float)atof( (char *) val);
// insert into the map
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string, DICOMOrderingElements>(parser->GetFileName(), ord));
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string,
DICOMOrderingElements>(parser->GetFileName(), ord));
}
else
{
......@@ -583,7 +584,8 @@ void DICOMAppHelper::ImagePositionPatientCallback(DICOMParser *parser,
}
// insert into the map
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string, DICOMOrderingElements>(parser->GetFileName(), ord));
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string,
DICOMOrderingElements>(parser->GetFileName(), ord));
// cache the value
memcpy( this->ImagePositionPatient, ord.ImagePositionPatient,
......@@ -650,7 +652,12 @@ void DICOMAppHelper::ImageOrientationPatientCallback(DICOMParser *parser,
}
// insert into the map
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string, DICOMOrderingElements>(parser->GetFileName(), ord));
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string,
DICOMOrderingElements>(parser->GetFileName(), ord));
// cache the value
memcpy( this->ImageOrientationPatient, ord.ImageOrientationPatient,
6*sizeof(float) );
}
else
{
......@@ -675,6 +682,10 @@ void DICOMAppHelper::ImageOrientationPatientCallback(DICOMParser *parser,
(*it).second.ImageOrientationPatient[4] = 1.0;
(*it).second.ImageOrientationPatient[5] = 0.0;
}
// cache the value
memcpy( this->ImageOrientationPatient, (*it).second.ImageOrientationPatient,
6*sizeof(float) );
}
}
......@@ -1224,7 +1235,8 @@ void DICOMAppHelper::GetImagePositionPatientFilenamePairs(const dicom_stl::strin
float image_position;
float normal[3];
dicom_stl::map<dicom_stl::string, DICOMOrderingElements, ltstdstr>::iterator sn_iter = Implementation->SliceOrderingMap.find(*fileIter);
dicom_stl::map<dicom_stl::string, DICOMOrderingElements, ltstdstr>::iterator sn_iter =
Implementation->SliceOrderingMap.find(*fileIter);
if (sn_iter != Implementation->SliceOrderingMap.end())
{
......@@ -1267,7 +1279,8 @@ void DICOMAppHelper::GetImagePositionPatientFilenamePairs(dicom_stl::vector<dico
// Default to using the first series
if (this->Implementation->SeriesUIDMap.size() > 0)
{
this->GetImagePositionPatientFilenamePairs( (*this->Implementation->SeriesUIDMap.begin()).first, v, ascending);
this->GetImagePositionPatientFilenamePairs(
(*this->Implementation->SeriesUIDMap.begin()).first, v, ascending);
}
else
{
......
......@@ -288,7 +288,14 @@ public:
{
return this->ImagePositionPatient;
}
/** Get the (DICOM) directions cosines. It consist of the components
* of the first two vectors. The third vector needs to be computed
* to form an orthonormal basis. */
float *GetImageOrientationPatient()
{
return this->ImageOrientationPatient;
}
/** Get the number of bits allocated per pixel of the last image
* processed by the DICOMParser */
......@@ -470,6 +477,7 @@ public:
int SliceNumber;
int Dimensions[2];
float ImagePositionPatient[3];
float ImageOrientationPatient[6];
// map from series UID to vector of files in the series
// dicom_stl::map<dicom_stl::string, dicom_stl::vector<dicom_stl::string>, ltstdstr> SeriesUIDMap;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment