Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkPixelType.h"
18 #include <mitkLogMacros.h>
19 
21  : m_ComponentType(other.m_ComponentType),
22  m_PixelType(other.m_PixelType),
23  m_ComponentTypeName(other.m_ComponentTypeName),
24  m_PixelTypeName(other.m_PixelTypeName),
25  m_NumberOfComponents(other.m_NumberOfComponents),
26  m_BytesPerComponent(other.m_BytesPerComponent)
27 {
28 }
29 
31 {
32  m_ComponentType = other.m_ComponentType;
33  m_PixelType = other.m_PixelType;
34  m_ComponentTypeName = other.m_ComponentTypeName;
35  m_PixelTypeName = other.m_PixelTypeName;
36  m_NumberOfComponents = other.m_NumberOfComponents;
37  m_BytesPerComponent = other.m_BytesPerComponent;
38 
39  return *this;
40 }
41 
42 itk::ImageIOBase::IOPixelType mitk::PixelType::GetPixelType() const
43 {
44  return m_PixelType;
45 }
46 
48 {
49  return m_ComponentType;
50 }
51 
53 {
54  return m_PixelTypeName;
55 }
56 
58 {
59  return m_ComponentTypeName;
60 }
61 
63 {
64  return m_PixelTypeName + " (" + m_ComponentTypeName + ")";
65 }
66 
68 {
69  return (m_NumberOfComponents * m_BytesPerComponent);
70 }
71 
73 {
74  return this->GetSize() * 8;
75 }
76 
78 {
79  return m_NumberOfComponents;
80 }
81 
83 {
84  return m_BytesPerComponent * 8;
85 }
86 
88 {
89 }
90 
91 mitk::PixelType::PixelType(const int componentType,
92  const ItkIOPixelType pixelType,
93  std::size_t bytesPerComponent,
94  std::size_t numberOfComponents,
95  const std::string &componentTypeName,
96  const std::string &pixelTypeName)
97  : m_ComponentType(componentType),
98  m_PixelType(pixelType),
99  m_ComponentTypeName(componentTypeName),
100  m_PixelTypeName(pixelTypeName),
101  m_NumberOfComponents(numberOfComponents),
102  m_BytesPerComponent(bytesPerComponent)
103 {
104 }
105 
107 {
108  MITK_DEBUG << "operator==" << std::endl;
109 
110  MITK_DEBUG << "m_NumberOfComponents = " << m_NumberOfComponents << " " << rhs.m_NumberOfComponents << std::endl;
111  MITK_DEBUG << "m_BytesPerComponent = " << m_BytesPerComponent << " " << rhs.m_BytesPerComponent << std::endl;
112  MITK_DEBUG << "m_PixelTypeName = " << m_PixelTypeName << " " << rhs.m_PixelTypeName << std::endl;
113  MITK_DEBUG << "m_PixelType = " << m_PixelType << " " << rhs.m_PixelType << std::endl;
114 
115  bool returnValue =
116  (this->m_PixelType == rhs.m_PixelType && this->m_ComponentType == rhs.m_ComponentType &&
117  this->m_NumberOfComponents == rhs.m_NumberOfComponents && this->m_BytesPerComponent == rhs.m_BytesPerComponent);
118 
119  if (returnValue)
120  MITK_DEBUG << " [TRUE] ";
121  else
122  MITK_DEBUG << " [FALSE] ";
123 
124  return returnValue;
125 }
126 
128 {
129  return !(this->operator==(rhs));
130 }
131 
132 mitk::PixelType mitk::MakePixelType(vtkImageData *vtkimagedata)
133 {
134  int numOfComponents = vtkimagedata->GetNumberOfScalarComponents();
135 
136  switch (vtkimagedata->GetScalarType())
137  {
138  case VTK_BIT:
139  case VTK_CHAR:
140  return mitk::MakePixelType<char, char>(numOfComponents);
141  break;
142 
143  case VTK_UNSIGNED_CHAR:
144  return mitk::MakePixelType<unsigned char, unsigned char>(numOfComponents);
145  break;
146 
147  case VTK_SHORT:
148  return mitk::MakePixelType<short, short>(numOfComponents);
149  break;
150 
151  case VTK_UNSIGNED_SHORT:
152  return mitk::MakePixelType<unsigned short, unsigned short>(numOfComponents);
153  break;
154 
155  case VTK_INT:
156  return mitk::MakePixelType<int, int>(numOfComponents);
157  break;
158 
159  case VTK_UNSIGNED_INT:
160  return mitk::MakePixelType<unsigned int, unsigned int>(numOfComponents);
161  break;
162 
163  case VTK_LONG:
164  return mitk::MakePixelType<long, long>(numOfComponents);
165  break;
166 
167  case VTK_UNSIGNED_LONG:
168  return mitk::MakePixelType<unsigned long, unsigned long>(numOfComponents);
169  break;
170 
171  case VTK_FLOAT:
172  return mitk::MakePixelType<float, float>(numOfComponents);
173  break;
174 
175  case VTK_DOUBLE:
176  return mitk::MakePixelType<double, double>(numOfComponents);
177  break;
178 
179  default:
180  break;
181  }
182 
183  mitkThrow() << "tried to make pixeltype from vtkimage of unknown data type(short, char, int, ...)";
184 }
std::string GetTypeAsString() const
Returns a string representing the pixel type and pixel components.
std::string GetPixelTypeAsString() const
Returns a string containing the ITK pixel type name.
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
PixelType(const mitk::PixelType &aPixelType)
itk::ImageIOBase::IOPixelType GetPixelType() const
vcl_size_t GetBitsPerComponent() const
Get the number of bits per components.
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
vcl_size_t GetSize() const
Get size of the PixelType in bytes.
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
MITKCORE_EXPORT mitk::PixelType MakePixelType(vtkImageData *vtkimagedata)
deduct the PixelType for a given vtk image
std::string GetComponentTypeAsString() const
Returns a string containing the name of the component.
#define mitkThrow()
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
bool operator!=(const PixelType &rhs) const
bool operator==(const PixelType &rhs) const
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
PixelType & operator=(const PixelType &other)
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55