Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPixelTypeTest.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 // Testing
14 #include "mitkTestFixture.h"
15 #include "mitkTestingMacros.h"
16 // std includes
17 #include <string>
18 // MITK includes
19 #include "mitkPixelType.h"
20 #include <mitkLogMacros.h>
21 // ITK includes
22 #include "itkImage.h"
23 #include <itkVectorImage.h>
24 // VTK includes
25 #include <vtkDebugLeaks.h>
26 
27 struct MyObscurePixelType
28 {
29  typedef float ValueType;
30  static const size_t Length = 2;
31 };
32 
33 //## Documentation
34 //## main testing method
35 class mitkPixelTypeTestSuite : public mitk::TestFixture
36 {
37  CPPUNIT_TEST_SUITE(mitkPixelTypeTestSuite);
38 
39  MITK_TEST(GetComponentType_Success);
40  MITK_TEST(GetPixelTypeAsString_Success);
41  MITK_TEST(GetBpePtype_Success);
42  MITK_TEST(GetNumberOfComponentsPtype_Success);
43  MITK_TEST(GetBitsPerComponentPtype_Success);
44  MITK_TEST(GetBpeItkPtype_Success);
45  MITK_TEST(GetNumberOfComponentsItkPtype_Success);
46  MITK_TEST(GetBitsPerComponentItkPtype_Success);
47  MITK_TEST(ConstructorWithBrackets_Success);
48  MITK_TEST(InitializeWithEqualSign_Success);
49  MITK_TEST(EqualityOperator_Success);
50  MITK_TEST(NotEqualityOperator_Success);
51  MITK_TEST(GetPixelTypeUnknown_Success);
52  MITK_TEST(SetLengthCorrectly_Success);
53  MITK_TEST(ValueTypeCorresponds_Success);
54  MITK_TEST(ImageTypeTraitInt3D_Success);
55  MITK_TEST(ImageTypeTraitShort2D_Success);
56  MITK_TEST(ImageTypeTraitVectorShort3D_Success);
57  MITK_TEST(ImageTypeTraitItkInt3D_Success);
58  MITK_TEST(ImageTypeTraitItkShort2D_Success);
59  MITK_TEST(ImageTypeTraitItkVectorShort3D_Success);
60 
61  CPPUNIT_TEST_SUITE_END();
62 
63 private:
64  typedef itk::Image<itk::FixedArray<int, 5>, 3> ItkImageType;
65  typedef itk::Image<MyObscurePixelType> MyObscureImageType;
66  typedef itk::VectorImage<short, 3> VectorImageType;
67  typedef itk::Image<itk::Vector<short, 7>> FixedVectorImageType;
68 
69 
70 public:
71  void setUp() override
72  {
73  }
74 
75  void tearDown() override
76  {
77  }
78 
79  void GetComponentType_Success()
80  {
81  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
82  MITK_INFO << "m_Ptype = mitk::MakePixelType<int, int, 5>();";
83  MITK_INFO
84  << "m_ItkPtype = mitk::MakePixelType<ItkImageType>();\n with itk::Image<itk::FixedArray< int, 5>, 3> ItkImageType";
85  CPPUNIT_ASSERT_MESSAGE("GetComponentType()", ptype.GetComponentType() == itk::ImageIOBase::INT);
86  }
87 
88  void GetPixelTypeAsString_Success()
89  {
90  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
91  MITK_INFO << ptype.GetPixelTypeAsString();
92  MITK_INFO << typeid(ItkImageType).name();
93  }
94 
95  void GetBpePtype_Success()
96  {
97  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
98  CPPUNIT_ASSERT_MESSAGE("[m_Ptype] GetBpe()", ptype.GetBpe() == 8 * sizeof(int) * 5);
99  }
100 
101  void GetNumberOfComponentsPtype_Success()
102  {
103  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
104  CPPUNIT_ASSERT_MESSAGE("[ptype]GetNumberOfComponents()", ptype.GetNumberOfComponents() == 5);
105  }
106 
107  void GetBitsPerComponentPtype_Success()
108  {
109  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
110  CPPUNIT_ASSERT_MESSAGE("[ptype]GetBitsPerComponent()", ptype.GetBitsPerComponent() == 8 * sizeof(int));
111  }
112 
113  void GetBpeItkPtype_Success()
114  {
115  mitk::PixelType itkPtype = mitk::MakePixelType<ItkImageType>();
116  CPPUNIT_ASSERT_MESSAGE("[itkPType] GetBpe()", itkPtype.GetBpe() == 8 * sizeof(int) * 5);
117  }
118 
119  void GetNumberOfComponentsItkPtype_Success()
120  {
121  mitk::PixelType itkPtype = mitk::MakePixelType<ItkImageType>();
122  CPPUNIT_ASSERT_MESSAGE("[itkPType] GetNumberOfComponents()", itkPtype.GetNumberOfComponents() == 5);
123  }
124 
125  void GetBitsPerComponentItkPtype_Success()
126  {
127  mitk::PixelType itkPtype = mitk::MakePixelType<ItkImageType>();
128  CPPUNIT_ASSERT_MESSAGE("[itkPType] GetBitsPerComponent()", itkPtype.GetBitsPerComponent() == 8 * sizeof(int));
129  }
130 
131  void ConstructorWithBrackets_Success()
132  {
133  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
134  mitk::PixelType ptype2(ptype);
135  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)- GetComponentType()", ptype2.GetComponentType() == itk::ImageIOBase::INT);
136  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetPixelType(", ptype2.GetPixelType() == ptype.GetPixelType());
137  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetComponentType(", ptype2.GetComponentType() == ptype.GetComponentType());
138  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetBpe()", ptype2.GetBpe() == 8 * sizeof(int) * 5);
139  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetNumberOfComponents()", ptype2.GetNumberOfComponents() == 5);
140  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetBitsPerComponent()", ptype2.GetBitsPerComponent() == 8 * sizeof(int));
141  }
142 
143  void InitializeWithEqualSign_Success()
144  {
145  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
146  mitk::PixelType ptype2 = ptype;
147  CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetComponentType()", ptype2.GetComponentType() == itk::ImageIOBase::INT);
148  CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetPixelType(", ptype2.GetPixelType() == ptype.GetPixelType());
149  CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetComponentType(", ptype2.GetComponentType() == ptype.GetComponentType());
150  CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetBpe()", ptype2.GetBpe() == 8 * sizeof(int) * 5);
151  CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetNumberOfComponents()", ptype2.GetNumberOfComponents() == 5);
152  CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetBitsPerComponent()", ptype2.GetBitsPerComponent() == 8 * sizeof(int));
153  }
154 
155  void EqualityOperator_Success()
156  {
157  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
158  mitk::PixelType ptype2 = ptype;
159  CPPUNIT_ASSERT_MESSAGE("operator ==", ptype == ptype2);
160  }
161 
162  void NotEqualityOperator_Success()
163  {
164  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
165  mitk::PixelType ptype3 = mitk::MakePixelType<char, char ,5>();
166  CPPUNIT_ASSERT_MESSAGE("operator !=", ptype != ptype3);
167  }
168 
169  void GetPixelTypeUnknown_Success()
170  {
171  // test instantiation
172  mitk::PixelType obscurePixelType = mitk::MakePixelType<MyObscureImageType>();
173  CPPUNIT_ASSERT_MESSAGE("PixelTypeId is 'UNKNOWN' ", obscurePixelType.GetPixelType() == itk::ImageIOBase::UNKNOWNPIXELTYPE);
174  }
175 
176  void SetLengthCorrectly_Success()
177  {
178  mitk::PixelType obscurePixelType = mitk::MakePixelType<MyObscureImageType>();
179  CPPUNIT_ASSERT_MESSAGE("Lenght was set correctly", obscurePixelType.GetNumberOfComponents() == MyObscurePixelType::Length);
180  }
181 
182  void ValueTypeCorresponds_Success()
183  {
184  mitk::PixelType obscurePixelType = mitk::MakePixelType<MyObscureImageType>();
185  CPPUNIT_ASSERT_MESSAGE("ValueType corresponds.",
186 
188  }
189 
190  void ImageTypeTraitInt3D_Success()
191  {
192  // test ImageTypeTrait traits class
193  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid int 3D equals ITK typeid",
194 
195  typeid(mitk::ImageTypeTrait<int, 3>::ImageType) == typeid(itk::Image<int, 3>));
196  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", (mitk::ImageTypeTrait<int, 3>::IsVectorImage == false));
197  }
198 
199  void ImageTypeTraitShort2D_Success()
200  {
201  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid short 2D equals ITK typeid",
202  typeid(mitk::ImageTypeTrait<itk::FixedArray<short, 2>, 3>::ImageType) ==
203  typeid(itk::Image<itk::FixedArray<short, 2>, 3>));
204  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", (mitk::ImageTypeTrait<itk::FixedArray<short, 2>, 3>::IsVectorImage == false));
205  }
206 
207  void ImageTypeTraitVectorShort3D_Success()
208  {
209  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid short 3D equals ITK typeid",
210  typeid(mitk::ImageTypeTrait<itk::VariableLengthVector<short>, 3>::ImageType) == typeid(itk::VectorImage<short, 3>));
211  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is a vector image", (mitk::ImageTypeTrait<itk::VariableLengthVector<short>, 3>::IsVectorImage == true));
212  }
213 
214  void ImageTypeTraitItkInt3D_Success()
215  {
216  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid ITK int 3D equals ITK typeid",
217  typeid(mitk::ImageTypeTrait<itk::Image<int, 3>>::ImageType) == typeid(itk::Image<int, 3>));
218  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", (mitk::ImageTypeTrait<itk::Image<int, 3>>::IsVectorImage == false));
219  }
220 
221  void ImageTypeTraitItkShort2D_Success()
222  {
223  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid ITK short 2D equals ITK typeid",
224  typeid(mitk::ImageTypeTrait<itk::Image<itk::FixedArray<short, 2>, 3>>::ImageType) ==
225  typeid(itk::Image<itk::FixedArray<short, 2>, 3>));
226  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image",
227 
228  (mitk::ImageTypeTrait<itk::Image<itk::FixedArray<short, 2>, 3>>::IsVectorImage == false));
229  }
230 
231  void ImageTypeTraitItkVectorShort3D_Success()
232  {
233  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid ITK short 3D equals ITK typeid",
234  typeid(mitk::ImageTypeTrait<itk::VectorImage<short, 3>>::ImageType) == typeid(itk::VectorImage<short, 3>));
235  CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is a vector image",
236  (mitk::ImageTypeTrait<itk::VectorImage<short, 3>>::IsVectorImage == true));
237  }
238 };
239 MITK_TEST_SUITE_REGISTRATION(mitkPixelType)
240 
241 
vcl_size_t GetBitsPerComponent() const
Get the number of bits per components.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:18
itk::Image< unsigned char, 3 > ImageType
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
itk::Image< TPixelType, VDimension > ImageType
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...
class ITK_EXPORT Image
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
Test fixture for parameterized tests.
itk::ImageIOBase::IOPixelType GetPixelType() const
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