ITK  5.2.0
Insight Toolkit
itkDCMTKImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkDCMTKImageIO_h
19 #define itkDCMTKImageIO_h
20 #include "ITKIODCMTKExport.h"
21 
22 
23 #include <fstream>
24 #include <cstdio>
25 #include "itkImageIOBase.h"
26 
27 class DicomImage;
28 
29 namespace itk
30 {
37 {
38 public:
47  enum class LogLevel : uint8_t
48  {
49  TRACE_LOG_LEVEL = 0,
56  };
57 };
58 // Define how to print enumeration
59 extern ITKIODCMTK_EXPORT std::ostream &
60  operator<<(std::ostream & out, const DCMTKImageIOEnums::LogLevel value);
61 
71 class ITKIODCMTK_EXPORT DCMTKImageIO : public ImageIOBase
72 {
73 public:
74  ITK_DISALLOW_COPY_AND_ASSIGN(DCMTKImageIO);
75 
77  using Self = DCMTKImageIO;
80 
82  itkNewMacro(Self);
83 
85  itkTypeMacro(DCMTKImageIO, ImageIOBase);
86 
88 #if !defined(ITK_LEGACY_REMOVE)
89 
90  static constexpr LogLevelEnum TRACE_LOG_LEVEL = LogLevelEnum::TRACE_LOG_LEVEL;
91  static constexpr LogLevelEnum DEBUG_LOG_LEVEL = LogLevelEnum::DEBUG_LOG_LEVEL;
92  static constexpr LogLevelEnum INFO_LOG_LEVEL = LogLevelEnum::INFO_LOG_LEVEL;
93  static constexpr LogLevelEnum WARN_LOG_LEVEL = LogLevelEnum::WARN_LOG_LEVEL;
94  static constexpr LogLevelEnum ERROR_LOG_LEVEL = LogLevelEnum::ERROR_LOG_LEVEL;
95  static constexpr LogLevelEnum FATAL_LOG_LEVEL = LogLevelEnum::FATAL_LOG_LEVEL;
96  static constexpr LogLevelEnum OFF_LOG_LEVEL = LogLevelEnum::OFF_LOG_LEVEL;
97 #endif
98 
100  void
101  SetDicomImagePointer(DicomImage * UserProvided)
102  {
103  m_DImage = UserProvided;
104  m_DicomImageSetByUser = true;
105  }
106 
107  /*-------- This part of the interfaces deals with reading data. ----- */
108 
111  bool
112  CanReadFile(const char *) override;
113 
115  void
116  ReadImageInformation() override;
117 
119  void
120  Read(void * buffer) override;
121 
122  /*-------- This part of the interfaces deals with writing data. ----- */
123 
126  bool
127  CanWriteFile(const char *) override;
128 
130  void
131  WriteImageInformation() override;
132 
135  void
136  Write(const void * buffer) override;
137 
139  void
140  SetLogLevel(LogLevelEnum level);
141 
143  LogLevelEnum
144  GetLogLevel() const;
145 
146  DCMTKImageIO();
147  ~DCMTKImageIO() override;
148  void
149  PrintSelf(std::ostream & os, Indent indent) const override;
150 
151 private:
152  void
153  OpenDicomImage();
154 
156  void
157  ReorderRGBValues(void * buffer, const void * data, size_t count, unsigned int voxel_size);
158 
164  template <typename T>
165  void
166  ReorderRGBValues(void * buffer, const void * data, size_t count, unsigned int voxel_size)
167  {
168  auto * output_buffer = static_cast<T *>(buffer);
169  const auto ** input_buffer = static_cast<const T **>(const_cast<void *>(data));
170  for (size_t pos = 0; pos < count; ++pos)
171  {
172  for (unsigned int color = 0; color < voxel_size; ++color)
173  {
174  *(output_buffer++) = input_buffer[color][pos];
175  }
176  }
177  }
179 
180  /*----- internal helpers --------------------------------------------*/
184 
185  DicomImage * m_DImage;
186 
188 
191  std::string m_LastFileName;
192 };
193 
194 // Define how to print enumeration
195 extern ITKCommon_EXPORT std::ostream &
196  operator<<(std::ostream & out, DCMTKImageIO::LogLevelEnum value);
197 
198 } // end namespace itk
199 
200 #endif // itkDCMTKImageIO_h
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:75
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
LogLevel
itk::DCMTKImageIO::m_LastFileName
std::string m_LastFileName
Definition: itkDCMTKImageIO.h:191
itk::DCMTKImageIO::SetDicomImagePointer
void SetDicomImagePointer(DicomImage *UserProvided)
Definition: itkDCMTKImageIO.h:101
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:213
itk::DCMTKImageIOEnums::LogLevel::OFF_LOG_LEVEL
itk::DCMTKImageIO
Read DICOM image file format.
Definition: itkDCMTKImageIO.h:71
itk::DCMTKImageIOEnums::LogLevel::ERROR_LOG_LEVEL
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::DCMTKImageIOEnums::LogLevel
LogLevel
Definition: itkDCMTKImageIO.h:47
itk::DCMTKImageIO::m_RescaleSlope
double m_RescaleSlope
Definition: itkDCMTKImageIO.h:189
itk::DCMTKImageIOEnums::LogLevel::FATAL_LOG_LEVEL
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::DCMTKImageIOEnums::LogLevel::TRACE_LOG_LEVEL
itk::DCMTKImageIO::m_DicomImageSetByUser
bool m_DicomImageSetByUser
Definition: itkDCMTKImageIO.h:187
itk::DCMTKImageIOEnums::LogLevel::DEBUG_LOG_LEVEL
itk::DCMTKImageIO::ReorderRGBValues
void ReorderRGBValues(void *buffer, const void *data, vcl_size_t count, unsigned int voxel_size)
Definition: itkDCMTKImageIO.h:166
itkImageIOBase.h
itk::DCMTKImageIO::m_UseJPEGCodec
bool m_UseJPEGCodec
Definition: itkDCMTKImageIO.h:181
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::DCMTKImageIO::m_RescaleIntercept
double m_RescaleIntercept
Definition: itkDCMTKImageIO.h:190
itk::DCMTKImageIOEnums::LogLevel::INFO_LOG_LEVEL
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::DCMTKImageIOEnums::LogLevel::WARN_LOG_LEVEL
itk::DCMTKImageIO::m_DImage
DicomImage * m_DImage
Definition: itkDCMTKImageIO.h:185
itk::DCMTKImageIO::m_UseJPLSCodec
bool m_UseJPLSCodec
Definition: itkDCMTKImageIO.h:182
itk::DCMTKImageIO::m_UseRLECodec
bool m_UseRLECodec
Definition: itkDCMTKImageIO.h:183
itk::DCMTKImageIOEnums
Enums used by the DCMTKImageIO class.
Definition: itkDCMTKImageIO.h:36