CBICA Toolkit  1.0.0
DicomIOManager.h
1 #ifndef DICOMIOMANAGER_H
2 #define DICOMIOMANAGER_H
3 
4 #include "itkGDCMImageIO.h"
5 #include "itkGDCMSeriesFileNames.h"
6 #include <string>
7 
8 namespace cbica
9 {
10  /**
11  \brief Check if the given file is a valid DICOM image or not
12 
13  \param fileNameToCheck The input file
14  */
15  inline bool IsDicom(const std::string fileNameToCheck)
16  {
17  gdcm::Reader reader;
18  reader.SetFileName(fileNameToCheck.c_str());
19  return reader.CanRead();
20  }
21 }
22 
23 template <class T>
25 {
26 public:
27 
28  typedef itk::GDCMSeriesFileNames NamesGeneratorType;
29  typedef itk::GDCMImageIO ImageIOType;
30  typedef std::vector<std::string> FileNamesContainer;
31 
33  ~DicomIOManager();
34 
35  //! set the input directory containing dicom series
36  void SetDirectoryPath(std::string path);
37 
38  //! get the read dicom data as 3D float ITK image
39  typename T::Pointer GetITKImage();
40 
41  //! load dicom data
42  bool LoadDicom();
43 
44  //! check if file is dicom
45  static bool IsDicom(std::string path);
46 
47  //! check if file can be read or not and return the base imageIO if readable
48  static bool CanReadFile(std::string path, itk::ImageIOBase::Pointer &imageIO);
49 
50  //! helper to write itk image
51  //template <class TInputImage>
52  //void WriteITKImage(typename T::Pointer image, std::string filename);
53 
54  //! convert itk image to float 3D itk image
55  template <class TInputImage>
56  typename T::Pointer ConvertImage3DToFloatImage3D(typename TInputImage::Pointer image);
57 
58 private:
59  std::string m_dir; //! input directory path
60  typename T::Pointer m_image3d;
61 };
62 
63 #include "DicomIOManager.hxx"
64 #endif // DICOMIOMANAGER_H
static bool IsDicom(std::string path)
check if file is dicom
Definition: DicomIOManager.hxx:284
void SetDirectoryPath(std::string path)
set the input directory containing dicom series
Definition: DicomIOManager.hxx:18
static bool CanReadFile(std::string path, itk::ImageIOBase::Pointer &imageIO)
check if file can be read or not and return the base imageIO if readable
Definition: DicomIOManager.hxx:290
Definition: DicomIOManager.h:24
T::Pointer GetITKImage()
get the read dicom data as 3D float ITK image
Definition: DicomIOManager.hxx:308
bool LoadDicom()
load dicom data
Definition: DicomIOManager.hxx:23
T::Pointer ConvertImage3DToFloatImage3D(typename TInputImage::Pointer image)
helper to write itk image
Definition: DicomIOManager.hxx:298