DGtal 1.4.2
Loading...
Searching...
No Matches
testDicomReader.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/images/ImageContainerBySTLVector.h"
33#include "DGtal/images/ImageContainerByITKImage.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/io/readers/DicomReader.h"
36
37#include "ConfigTest.h"
38
40
41using namespace std;
42using namespace DGtal;
43
45// Functions for testing class DicomReader.
47
52template <typename Image3D>
54{
55 const std::string filename = testPath + "samples/dicomSample/1629.dcm";
56 Image3D image = DicomReader< Image3D >::importDicom( filename );
57
58 trace.info() << image <<endl;
59
60 unsigned int nbVal=0, nbPos = 0;
61 typename Image3D::ConstRange r = image.constRange();
62 for ( typename Image3D::ConstRange::ConstIterator it=r.begin(), itend=r.end() ; it != itend ; ++it )
63 {
64 nbVal++;
65 if ( (*it) > 0 ) nbPos++;
66 }
67
68 trace.info() << "Number of points with (val>0) = " << nbVal << endl;
69
70 return nbVal==2130048 && nbPos==296030;
71}
72
73static
74std::vector<std::string>
75getFirstDicomSerieFileNames(const std::string &path)
76{
77 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
78 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
79 nameGenerator->SetUseSeriesDetails( true );
80 nameGenerator->SetDirectory( path );
81
82 typedef itk::GDCMSeriesFileNames::SeriesUIDContainerType SeriesIdContainer;
83 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
84
85 if (! seriesUID.empty() )
86 {
87 return nameGenerator->GetFileNames( *(seriesUID.begin()) );
88 }
89 return std::vector<std::string>();
90}
91
92template <typename Image3D>
94{
95 const std::string path = testPath + "samples/dicomSample";
96 const std::vector<std::string> fileNames = getFirstDicomSerieFileNames( path );
97 Image3D image = DicomReader< Image3D >::importDicomSeries( fileNames );
98
99 trace.info() << image <<endl;
100
101 unsigned int nbVal=0, nbPos = 0;
102 typename Image3D::ConstRange r = image.constRange();
103 for ( typename Image3D::ConstRange::ConstIterator it=r.begin(), itend=r.end() ; it != itend ; ++it )
104 {
105 nbVal++;
106 if ( (*it) > 0 ) nbPos++;
107 }
108
109 trace.info() << "Number of points with (val>0) = " << nbVal << endl;
110
111 return nbVal==2130048 && nbPos==296030;
112}
113
114
115template <typename PixelType>
117{
118 const std::string path = testPath + "samples/dicomSample";
119
120 const std::vector<std::string> fileNames = getFirstDicomSerieFileNames( path );
121
123 Image3D image = DicomReader< Image3D >::importDicomSeries( fileNames );
124 typename Image3D::ITKImagePointer dgtal_itk = image.getITKImagePointer();
125
126 typedef itk::Image<PixelType, 3> ItkImage;
127 typedef itk::ImageSeriesReader<ItkImage> ItkReader;
128 typename ItkReader::Pointer reader = ItkReader::New();
129 reader->SetFileNames( fileNames );
130
131 reader->Update();
132
133 typename ItkImage::Pointer itk = reader->GetOutput();
134
135 const bool ok1 = ( dgtal_itk->GetSpacing() == itk->GetSpacing() );
136 const bool ok2 = ( dgtal_itk->GetOrigin() == itk->GetOrigin() );
137 const bool ok3 = ( dgtal_itk->GetDirection() == itk->GetDirection() );
138 return ok1 && ok2 && ok3;
139}
140
141
143{
144 //Default image selector = STLVector
146
147 std::string filename = testPath + "samples/null.dcm";
148 try {
149 Image3D image = DicomReader< Image3D >::importDicom( filename );
150 }
151 catch(exception& e) {
152 trace.info() << "Exception catched. Message : " << e.what()<<endl;
153 return true;
154 }
155
156 return false;
157}
158
159
160
162// Standard services - public :
163
186// //
Aim: implements a model of CImageContainer using a ITK Image.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
static ImageContainer importDicomSeries(const std::vector< std::string > &filenames, const Functor &aFunctor=Functor())
static ImageContainer importDicom(const std::string &aFilename, const Functor &aFunctor=Functor())
int main()
Definition testBits.cpp:56
bool testSpatialInformation()
bool testDicomReaderFromDirectory()
bool testDicomReader()
static std::vector< std::string > getFirstDicomSerieFileNames(const std::string &path)
bool testIOException()