Medical Imaging Interaction Toolkit  2018.4.99-b585543d
Medical Imaging Interaction Toolkit
mitkPixelType.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkPixelType.h"
14 #include <mitkLogMacros.h>
15 
17  : m_ComponentType(other.m_ComponentType),
18  m_PixelType(other.m_PixelType),
19  m_ComponentTypeName(other.m_ComponentTypeName),
20  m_PixelTypeName(other.m_PixelTypeName),
21  m_NumberOfComponents(other.m_NumberOfComponents),
22  m_BytesPerComponent(other.m_BytesPerComponent)
23 {
24 }
25 
27 {
28  m_ComponentType = other.m_ComponentType;
29  m_PixelType = other.m_PixelType;
30  m_ComponentTypeName = other.m_ComponentTypeName;
31  m_PixelTypeName = other.m_PixelTypeName;
32  m_NumberOfComponents = other.m_NumberOfComponents;
33  m_BytesPerComponent = other.m_BytesPerComponent;
34 
35  return *this;
36 }
37 
38 itk::ImageIOBase::IOPixelType mitk::PixelType::GetPixelType() const
39 {
40  return m_PixelType;
41 }
42 
44 {
45  return m_ComponentType;
46 }
47 
49 {
50  return m_PixelTypeName;
51 }
52 
54 {
55  return m_ComponentTypeName;
56 }
57 
59 {
60  return m_PixelTypeName + " (" + m_ComponentTypeName + ")";
61 }
62 
64 {
65  return (m_NumberOfComponents * m_BytesPerComponent);
66 }
67 
69 {
70  return this->GetSize() * 8;
71 }
72 
74 {
75  return m_NumberOfComponents;
76 }
77 
79 {
80  return m_BytesPerComponent * 8;
81 }
82 
84 {
85 }
86 
87 mitk::PixelType::PixelType(const int componentType,
88  const ItkIOPixelType pixelType,
89  std::size_t bytesPerComponent,
90  std::size_t numberOfComponents,
91  const std::string &componentTypeName,
92  const std::string &pixelTypeName)
93  : m_ComponentType(componentType),
94  m_PixelType(pixelType),
95  m_ComponentTypeName(componentTypeName),
96  m_PixelTypeName(pixelTypeName),
97  m_NumberOfComponents(numberOfComponents),
98  m_BytesPerComponent(bytesPerComponent)
99 {
100 }
101 
103 {
104  bool returnValue = ( this->m_PixelType == rhs.m_PixelType
105  && this->m_ComponentType == rhs.m_ComponentType
106  && this->m_NumberOfComponents == rhs.m_NumberOfComponents
107  && this->m_BytesPerComponent == rhs.m_BytesPerComponent );
108 
109  MITK_DEBUG << "|> mitk::PixelType::operator== rhs, lhs: \n"
110  << "| m_BytesPerComponent = " << m_BytesPerComponent << ", " << rhs.m_BytesPerComponent << '\n'
111  << "| m_NumberOfComponents = " << m_NumberOfComponents << ", " << rhs.m_NumberOfComponents << '\n'
112  << "| m_PixelTypeName = " << m_PixelTypeName << ", " << rhs.m_PixelTypeName << '\n'
113  << "| m_ComponentTypeName = " << m_ComponentTypeName << ", " << rhs.m_ComponentTypeName << '\n'
114  << "| m_PixelType = " << m_PixelType << ", " << rhs.m_PixelType << '\n'
115  << "| m_ComponentType = " << m_ComponentType << ", " << rhs.m_ComponentType
116  << ", returnValue = " << returnValue << (returnValue ? "[True]" : "[False]") << ". <|";
117 
118  return returnValue;
119 }
120 
122 {
123  return !(this->operator==(rhs));
124 }
125 
126 mitk::PixelType mitk::MakePixelType(vtkImageData *vtkimagedata)
127 {
128  int numOfComponents = vtkimagedata->GetNumberOfScalarComponents();
129 
130  switch (vtkimagedata->GetScalarType())
131  {
132  case VTK_BIT:
133  case VTK_CHAR:
134  return mitk::MakePixelType<char, char>(numOfComponents);
135  break;
136 
137  case VTK_UNSIGNED_CHAR:
138  return mitk::MakePixelType<unsigned char, unsigned char>(numOfComponents);
139  break;
140 
141  case VTK_SHORT:
142  return mitk::MakePixelType<short, short>(numOfComponents);
143  break;
144 
145  case VTK_UNSIGNED_SHORT:
146  return mitk::MakePixelType<unsigned short, unsigned short>(numOfComponents);
147  break;
148 
149  case VTK_INT:
150  return mitk::MakePixelType<int, int>(numOfComponents);
151  break;
152 
153  case VTK_UNSIGNED_INT:
154  return mitk::MakePixelType<unsigned int, unsigned int>(numOfComponents);
155  break;
156 
157  case VTK_LONG:
158  return mitk::MakePixelType<long, long>(numOfComponents);
159  break;
160 
161  case VTK_UNSIGNED_LONG:
162  return mitk::MakePixelType<unsigned long, unsigned long>(numOfComponents);
163  break;
164 
165  case VTK_FLOAT:
166  return mitk::MakePixelType<float, float>(numOfComponents);
167  break;
168 
169  case VTK_DOUBLE:
170  return mitk::MakePixelType<double, double>(numOfComponents);
171  break;
172 
173  default:
174  break;
175  }
176 
177  mitkThrow() << "tried to make pixeltype from vtkimage of unknown data type(short, char, int, ...)";
178 }
vcl_size_t GetBitsPerComponent() const
Get the number of bits per components.
std::string GetTypeAsString() const
Returns a string representing the pixel type and pixel components.
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
bool operator!=(const PixelType &rhs) const
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
PixelType(const mitk::PixelType &aPixelType)
itk::ImageIOBase::IOPixelType ItkIOPixelType
Definition: mitkPixelType.h:54
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
MITKCORE_EXPORT mitk::PixelType MakePixelType(vtkImageData *vtkimagedata)
deduct the PixelType for a given vtk image
#define mitkThrow()
itk::ImageIOBase::IOPixelType GetPixelType() const
vcl_size_t GetSize() const
Get size of the PixelType in bytes.
bool operator==(const PixelType &rhs) const
PixelType & operator=(const PixelType &other)
std::string GetComponentTypeAsString() const
Returns a string containing the name of the component.
std::string GetPixelTypeAsString() const
Returns a string containing the ITK pixel type name.
Class for defining the data type of pixels.
Definition: mitkPixelType.h:51