DGtal 1.4.0
Loading...
Searching...
No Matches
testDicomReader.cpp File Reference
#include <iostream>
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageContainerByITKImage.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/readers/DicomReader.h"
#include "ConfigTest.h"
Include dependency graph for testDicomReader.cpp:

Go to the source code of this file.

Functions

template<typename Image3D >
bool testDicomReader ()
 
static std::vector< std::string > getFirstDicomSerieFileNames (const std::string &path)
 
template<typename Image3D >
bool testDicomReaderFromDirectory ()
 
template<typename PixelType >
bool testSpatialInformation ()
 
bool testIOException ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Adrien Krähenbühl (adrie.nosp@m.n.kr.nosp@m.ahenb.nosp@m.uhl@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), Université de Lorraine, France
Date
2013/10/14

Functions for testing class DicomReader.

This file is part of the DGtal library.

Definition in file testDicomReader.cpp.

Function Documentation

◆ getFirstDicomSerieFileNames()

static std::vector< std::string > getFirstDicomSerieFileNames ( const std::string & path)
static

Definition at line 75 of file testDicomReader.cpp.

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}

Referenced by testDicomReaderFromDirectory(), and testSpatialInformation().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 164 of file testDicomReader.cpp.

165{
166 trace.beginBlock ( "Testing class DicomReader" );
167 trace.info() << "Args:";
168 for ( int i = 0; i < argc; ++i )
169 trace.info() << " " << argv[ i ];
170 trace.info() << endl;
171
180 && testIOException();
181 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
182 trace.endBlock();
183
184 return !res;
185}
Aim: implements a model of CImageContainer using a ITK Image.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool testSpatialInformation()
bool testDicomReaderFromDirectory()
bool testDicomReader()
bool testIOException()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testDicomReader(), testDicomReaderFromDirectory(), testIOException(), testSpatialInformation(), and DGtal::trace.

◆ testDicomReader()

template<typename Image3D >
bool testDicomReader ( )

Example of a test. To be completed.

Definition at line 53 of file testDicomReader.cpp.

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}
static ImageContainer importDicom(const std::string &aFilename, const Functor &aFunctor=Functor())

References DGtal::DicomReader< TImageContainer, TFunctor >::importDicom(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testDicomReaderFromDirectory()

template<typename Image3D >
bool testDicomReaderFromDirectory ( )

Definition at line 93 of file testDicomReader.cpp.

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}
static ImageContainer importDicomSeries(const std::vector< std::string > &filenames, const Functor &aFunctor=Functor())
static std::vector< std::string > getFirstDicomSerieFileNames(const std::string &path)

References getFirstDicomSerieFileNames(), DGtal::DicomReader< TImageContainer, TFunctor >::importDicomSeries(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testIOException()

bool testIOException ( )

Definition at line 142 of file testDicomReader.cpp.

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}

References DGtal::DicomReader< TImageContainer, TFunctor >::importDicom(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testSpatialInformation()

template<typename PixelType >
bool testSpatialInformation ( )

Definition at line 116 of file testDicomReader.cpp.

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}

References getFirstDicomSerieFileNames(), and DGtal::DicomReader< TImageContainer, TFunctor >::importDicomSeries().

Referenced by main(), and TEST_CASE().