ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkDCMTKImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
39 class ITKIODCMTK_EXPORT DCMTKImageIO:public ImageIOBase
40 {
41 public:
42  ITK_DISALLOW_COPY_AND_ASSIGN(DCMTKImageIO);
43 
45  using Self = DCMTKImageIO;
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(DCMTKImageIO, ImageIOBase);
54 
59  enum LogLevel
60  {
61  TRACE_LOG_LEVEL = 0,
68  };
69 
71  void SetDicomImagePointer( DicomImage* UserProvided)
72  {
73  m_DImage = UserProvided;
74  m_DicomImageSetByUser = true;
75  }
76 
77  /*-------- This part of the interfaces deals with reading data. ----- */
78 
81  bool CanReadFile(const char *) override;
82 
84  void ReadImageInformation() override;
85 
87  void Read(void *buffer) override;
88 
89  /*-------- This part of the interfaces deals with writing data. ----- */
90 
93  bool CanWriteFile(const char *) override;
94 
96  void WriteImageInformation() override;
97 
100  void Write(const void *buffer) override;
101 
103  void SetLogLevel(LogLevel level);
104 
106  LogLevel GetLogLevel() const;
107 
108  DCMTKImageIO();
109  ~DCMTKImageIO() override;
110  void PrintSelf(std::ostream & os, Indent indent) const override;
111 
112 private:
113  void OpenDicomImage();
114 
116  void ReorderRGBValues(void *buffer, const void* data, unsigned long count, unsigned int voxel_size);
117 
123  template<typename T>
124  void
125  ReorderRGBValues(void *buffer, const void* data, unsigned long count, unsigned int voxel_size)
126  {
127  auto * output_buffer = static_cast<T*>(buffer);
128  const auto** input_buffer = static_cast<const T**>(const_cast<void *>(data));
129  for (unsigned long pos = 0; pos < count; ++pos)
130  {
131  for (unsigned int color = 0; color < voxel_size; ++color)
132  {
133  *(output_buffer++)=input_buffer[color][pos];
134  }
135  }
136  }
138 
139  /*----- internal helpers --------------------------------------------*/
143 
144  DicomImage* m_DImage;
145 
147 
150  std::string m_LastFileName;
151 };
152 } // end namespace itk
153 
154 #endif // itkDCMTKImageIO_h
DicomImage * m_DImage
Light weight base class for most itk classes.
std::string m_LastFileName
Abstract superclass defines image IO interface.
void SetDicomImagePointer(DicomImage *UserProvided)
void ReorderRGBValues(void *buffer, const void *data, unsigned long count, unsigned int voxel_size)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Read DICOM image file format.
Base class for most ITK classes.
Definition: itkObject.h:60