DGtal  0.9.2
testDicomReader.cpp
1 
30 #include <iostream>
32 #include "DGtal/images/ImageContainerBySTLVector.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/io/readers/DicomReader.h"
35 
36 #include "ConfigTest.h"
37 
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 // Functions for testing class DicomReader.
46 
51 bool testDicomReader()
52 {
53  //Default image selector = STLVector
55 
56  std::string filename = testPath + "samples/dicomSample/1629.dcm";
57  Image3D image = DicomReader< Image3D >::importDicom( filename );
58 
59  trace.info() << image <<endl;
60 
61  unsigned int nbVal=0, nbPos = 0;
62  for ( Image3D::ConstIterator it=image.begin(), itend=image.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 
73 
74 bool testIOException()
75 {
76  //Default image selector = STLVector
78 
79  std::string filename = testPath + "samples/null.dcm";
80  try {
81  Image3D image = DicomReader< Image3D >::importDicom( filename );
82  }
83  catch(exception& e) {
84  trace.info() << "Exception catched. Message : " << e.what()<<endl;
85  return true;
86  }
87 
88  return false;
89 }
90 
92 // Standard services - public :
93 
94 int main( int argc, char** argv )
95 {
96  trace.beginBlock ( "Testing class DicomReader" );
97  trace.info() << "Args:";
98  for ( int i = 0; i < argc; ++i )
99  trace.info() << " " << argv[ i ];
100  trace.info() << endl;
101 
102  bool res = testDicomReader() && testIOException();
103  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
104  trace.endBlock();
105 
106  return !res;
107 }
108 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
Aim: Import a 3D DICOM image from file series.
Definition: DicomReader.h:90
STL namespace.
double endBlock()
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()