Medical Imaging Interaction Toolkit  2016.11.0
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,
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 "mitkTestingMacros.h"
19 #include <itkImage.h>
20 #include <mitkLogMacros.h>
21 
22 #include <itkVectorImage.h>
23 
24 struct MyObscurePixelType
25 {
26  typedef float ValueType;
27  static const size_t Length = 2;
28 };
29 
30 //## Documentation
31 //## main testing method
32 int mitkPixelTypeTest(int /*argc*/, char * /*argv*/ [])
33 {
34  MITK_TEST_BEGIN("PixelTypeTest");
35 
36  MITK_INFO << "ptype = mitk::MakePixelType<int, int, 5>();";
37  MITK_INFO
38  << "itkPtype = mitk::MakePixelType<ItkImageType>();\n with itk::Image<itk::FixedArray< int, 5>, 3> ItkImageType";
39 
40  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
41  typedef itk::Image<itk::FixedArray<int, 5>, 3> ItkImageType;
42  mitk::PixelType itkPtype = mitk::MakePixelType<ItkImageType>();
43 
44  MITK_TEST_CONDITION_REQUIRED(ptype.GetComponentType() == itk::ImageIOBase::INT, "GetComponentType()");
45  // MITK_TEST_CONDITION( ptype.GetPixelTypeId() == typeid(ItkImageType), "GetPixelTypeId()");
46 
48  MITK_INFO << typeid(ItkImageType).name();
49 
50  MITK_TEST_CONDITION_REQUIRED(ptype.GetBpe() == 8 * sizeof(int) * 5, "[ptype] GetBpe()");
51  MITK_TEST_CONDITION_REQUIRED(ptype.GetNumberOfComponents() == 5, "[ptype]GetNumberOfComponents()");
52  MITK_TEST_CONDITION_REQUIRED(ptype.GetBitsPerComponent() == 8 * sizeof(int), "[ptype]GetBitsPerComponent()");
53 
54  MITK_TEST_CONDITION_REQUIRED(itkPtype.GetBpe() == 8 * sizeof(int) * 5, "[itkPType] GetBpe()");
55  MITK_TEST_CONDITION_REQUIRED(itkPtype.GetNumberOfComponents() == 5, "[itkPType] GetNumberOfComponents()");
56  MITK_TEST_CONDITION_REQUIRED(itkPtype.GetBitsPerComponent() == 8 * sizeof(int), "[itkPType] GetBitsPerComponent()");
57 
58  // MITK_TEST_CONDITION_REQUIRED( itkPtype == ptype, "[itkPtype = ptype]");
59 
60  // MITK_TEST_CONDITION( ptype.GetPixelTypeAsString().compare("unknown") == 0, "GetPixelTypeAsString()");
61  {
62  {
63  mitk::PixelType ptype2(ptype);
64  MITK_TEST_CONDITION_REQUIRED(ptype2.GetComponentType() == itk::ImageIOBase::INT,
65  "ptype2( ptype)- GetComponentType()");
66  MITK_TEST_CONDITION(ptype2.GetPixelType() == ptype.GetPixelType(), "ptype2( ptype)-GetPixelType(");
67  MITK_TEST_CONDITION(ptype2.GetComponentType() == ptype.GetComponentType(), "ptype2( ptype)-GetComponentType(");
68  MITK_TEST_CONDITION_REQUIRED(ptype2.GetBpe() == 8 * sizeof(int) * 5, "ptype2( ptype)-GetBpe()");
69  MITK_TEST_CONDITION_REQUIRED(ptype2.GetNumberOfComponents() == 5, "ptype2( ptype)-GetNumberOfComponents()");
70  MITK_TEST_CONDITION_REQUIRED(ptype2.GetBitsPerComponent() == 8 * sizeof(int),
71  "ptype2( ptype)-GetBitsPerComponent()");
72  // MITK_TEST_CONDITION_REQUIRED( ptype.GetPixelTypeAsString().compare("unknown") == 0, "ptype2(
73  // ptype)-GetPixelTypeAsString()");
74  }
75 
76  {
77  mitk::PixelType ptype2 = ptype;
78  MITK_TEST_CONDITION_REQUIRED(ptype2.GetComponentType() == itk::ImageIOBase::INT,
79  "ptype2 = ptype- GetComponentType()");
80  MITK_TEST_CONDITION(ptype2.GetPixelType() == ptype.GetPixelType(), "ptype2 = ptype- GetPixelType(");
81  MITK_TEST_CONDITION(ptype2.GetComponentType() == ptype.GetComponentType(), "ptype2( ptype)-GetComponentType(");
82  MITK_TEST_CONDITION_REQUIRED(ptype2.GetBpe() == 8 * sizeof(int) * 5, "ptype2 = ptype- GetBpe()");
83  MITK_TEST_CONDITION_REQUIRED(ptype2.GetNumberOfComponents() == 5, "ptype2 = ptype- GetNumberOfComponents()");
84  MITK_TEST_CONDITION_REQUIRED(ptype2.GetBitsPerComponent() == 8 * sizeof(int),
85  "ptype2 = ptype- GetBitsPerComponent()");
86  // MITK_TEST_CONDITION_REQUIRED( ptype.GetPixelTypeAsString().compare("unknown") == 0, "ptype2 = ptype-
87  // GetPixelTypeAsString()");
88  }
89 
90  {
91  mitk::PixelType ptype2 = ptype;
92  MITK_TEST_CONDITION_REQUIRED(ptype == ptype2, "operator ==");
93  // MITK_TEST_CONDITION_REQUIRED( ptype == typeid(int), "operator ==");
94  // mitk::PixelType ptype3 = mitk::MakePixelType<char, char ,5>;
95  // MITK_TEST_CONDITION_REQUIRED( ptype != ptype3, "operator !=");
96  // MITK_TEST_CONDITION_REQUIRED( *ptype3 != typeid(int), "operator !=");
97  }
98  }
99 
100  // test instantiation
101  typedef itk::Image<MyObscurePixelType> MyObscureImageType;
102  mitk::PixelType obscurePixelType = mitk::MakePixelType<MyObscureImageType>();
103 
104  MITK_TEST_CONDITION(obscurePixelType.GetPixelType() == itk::ImageIOBase::UNKNOWNPIXELTYPE,
105  "PixelTypeId is 'UNKNOWN' ");
106  MITK_TEST_CONDITION(obscurePixelType.GetNumberOfComponents() == MyObscurePixelType::Length,
107  "Lenght was set correctly");
110  "ValueType corresponds.");
111 
112  typedef itk::VectorImage<short, 3> VectorImageType;
113  mitk::PixelType vectorPixelType = mitk::MakePixelType<VectorImageType>(78);
114  // vectorPixelType.SetVectorLength( 78 );
115 
116  typedef itk::Image<itk::Vector<short, 7>> FixedVectorImageType;
117  mitk::PixelType fixedVectorPixelType = mitk::MakePixelType<FixedVectorImageType>();
118 
119  mitk::PixelType scalarPixelType = mitk::MakeScalarPixelType<float>();
120 
121  // test ImageTypeTrait traits class
122  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<int, 3>::ImageType) == typeid(itk::Image<int, 3>), "ImageTypeTrait");
124 
125  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::FixedArray<short, 2>, 3>::ImageType) ==
126  typeid(itk::Image<itk::FixedArray<short, 2>, 3>),
127  "ImageTypeTrait");
128  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::FixedArray<short, 2>, 3>::IsVectorImage == false), "ImageTypeTrait");
129 
131  typeid(mitk::ImageTypeTrait<itk::VariableLengthVector<short>, 3>::ImageType) == typeid(itk::VectorImage<short, 3>),
132  "ImageTypeTrait");
134  "ImageTypeTrait");
135 
136  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::Image<int, 3>>::ImageType) == typeid(itk::Image<int, 3>),
137  "ImageTypeTrait");
138  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::Image<int, 3>>::IsVectorImage == false), "ImageTypeTrait");
139 
140  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::Image<itk::FixedArray<short, 2>, 3>>::ImageType) ==
141  typeid(itk::Image<itk::FixedArray<short, 2>, 3>),
142  "ImageTypeTrait");
143  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::Image<itk::FixedArray<short, 2>, 3>>::IsVectorImage == false),
144  "ImageTypeTrait");
145 
147  typeid(mitk::ImageTypeTrait<itk::VectorImage<short, 3>>::ImageType) == typeid(itk::VectorImage<short, 3>),
148  "ImageTypeTrait");
149  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::VectorImage<short, 3>>::IsVectorImage == true), "ImageTypeTrait");
150 
151  // test CastableTo
152 
153  MITK_TEST_END();
154 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
itk::Image< unsigned char, 3 > ImageType
std::string GetPixelTypeAsString() const
Returns a string containing the ITK pixel type name.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
itk::ImageIOBase::IOPixelType GetPixelType() const
vcl_size_t GetBitsPerComponent() const
Get the number of bits per components.
itk::Image< TPixelType, VDimension > ImageType
itk::VectorImage< float, 3 > VectorImageType
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
class ITK_EXPORT Image
int mitkPixelTypeTest(int, char *[])
#define MITK_TEST_CONDITION(COND, MSG)
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
and MITK_TEST_END()
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55