Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
vtkMitkThickSlicesFilterTest.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 "mitkTestingMacros.h"
18 
20 
21 #include "mitkImage.h"
22 #include "mitkImageWriteAccessor.h"
23 
24 #include <vtkDataArray.h>
25 #include <vtkImageData.h>
26 #include <vtkPointData.h>
27 
28 class vtkMitkThickSlicesFilterTestHelper
29 {
30 public:
31  static mitk::Image::Pointer CreateTestImage(int min, int max)
32  {
33  mitk::PixelType pixelType(mitk::MakeScalarPixelType<unsigned char>());
35  auto dim = new unsigned int[3];
36  dim[0] = 10;
37  dim[1] = 10;
38  dim[2] = max + 1 - min;
39  testImage->Initialize(pixelType, 3, dim);
40  size_t buffer_size = dim[0] * dim[1] * sizeof(unsigned char);
41 
42  for (int i = min; i <= max; ++i)
43  {
44  mitk::ImageWriteAccessor writeAccess(testImage, testImage->GetSliceData(i - min));
45  memset(writeAccess.GetData(), i, buffer_size);
46  }
47 
48  return testImage;
49  }
50 
51  static void EvaluateResult(unsigned char expectedValue, vtkImageData *image, const char *projection)
52  {
54  image->GetDimensions()[0] == 10 && image->GetDimensions()[1] == 10 && image->GetDimensions()[2] == 1,
55  "Resulting image has correct size");
56 
57  unsigned char *value = static_cast<unsigned char *>(image->GetScalarPointer(0, 0, 0));
58  MITK_INFO << "Evaluating projection mode: " << projection;
59  MITK_INFO << "expected value: " << static_cast<double>(expectedValue);
60  MITK_INFO << "actual value: " << static_cast<double>(value[0]);
61  MITK_TEST_CONDITION_REQUIRED(value[0] == expectedValue, "Resulting image has correct pixel-value");
62  }
63 };
64 
69 int vtkMitkThickSlicesFilterTest(int, char *[])
70 {
71  // always start with this!
72  MITK_TEST_BEGIN("vtkMitkThickSlicesFilterTest")
73 
75 
77  // Image looks like:
78  // 000000000
79  // 111111111
80  // 222222222
81  mitk::Image::Pointer testImage1 = vtkMitkThickSlicesFilterTestHelper::CreateTestImage(0, 2);
82  thickSliceFilter->SetInputData(testImage1->GetVtkImageData());
83 
84  // MaxIP
85  thickSliceFilter->SetThickSliceMode(0);
86  thickSliceFilter->Modified();
87  thickSliceFilter->Update();
88  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(2, thickSliceFilter->GetOutput(), "MaxIP");
89 
90  // Sum
91  thickSliceFilter->SetThickSliceMode(1);
92  thickSliceFilter->Modified();
93  thickSliceFilter->Update();
94  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(1, thickSliceFilter->GetOutput(), "Sum");
95 
96  // Weighted
97  thickSliceFilter->SetThickSliceMode(2);
98  thickSliceFilter->Modified();
99  thickSliceFilter->Update();
100  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(1, thickSliceFilter->GetOutput(), "Weighted");
101 
102  // MinIP
103  thickSliceFilter->SetThickSliceMode(3);
104  thickSliceFilter->Modified();
105  thickSliceFilter->Update();
106  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(0, thickSliceFilter->GetOutput(), "MinIP");
107 
108  // Mean
109  thickSliceFilter->SetThickSliceMode(4);
110  thickSliceFilter->Modified();
111  thickSliceFilter->Update();
112  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(1, thickSliceFilter->GetOutput(), "Mean");
113 
115  // Image looks like:
116  // 333333333
117  // 444444444
118  // 555555555
119  // 666666666
120  // 777777777
121  // 888888888
122 
123  mitk::Image::Pointer testImage2 = vtkMitkThickSlicesFilterTestHelper::CreateTestImage(3, 8);
124  thickSliceFilter->SetInputData(testImage2->GetVtkImageData());
125 
126  // MaxIP
127  thickSliceFilter->SetThickSliceMode(0);
128  thickSliceFilter->Modified();
129  thickSliceFilter->Update();
130  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(8, thickSliceFilter->GetOutput(), "MaxIP");
131 
132  // Sum
133  thickSliceFilter->SetThickSliceMode(1);
134  thickSliceFilter->Modified();
135  thickSliceFilter->Update();
136  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(5, thickSliceFilter->GetOutput(), "Sum");
137 
138  // Weighted
139  thickSliceFilter->SetThickSliceMode(2);
140  thickSliceFilter->Modified();
141  thickSliceFilter->Update();
142  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(4, thickSliceFilter->GetOutput(), "Weighted");
143 
144  // MinIP
145  thickSliceFilter->SetThickSliceMode(3);
146  thickSliceFilter->Modified();
147  thickSliceFilter->Update();
148  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(3, thickSliceFilter->GetOutput(), "MinIP");
149 
150  // Mean
151  thickSliceFilter->SetThickSliceMode(4);
152  thickSliceFilter->Modified();
153  thickSliceFilter->Update();
154  vtkMitkThickSlicesFilterTestHelper::EvaluateResult(6, thickSliceFilter->GetOutput(), "Mean");
155 
156  thickSliceFilter->Delete();
157 
158  MITK_TEST_END()
159 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static vtkMitkThickSlicesFilter * New()
static T max(T x, T y)
Definition: svm.cpp:70
int vtkMitkThickSlicesFilterTest(int, char *[])
static Pointer New()
static T min(T x, T y)
Definition: svm.cpp:67
ImageWriteAccessor class to get locked write-access for a particular image part.
and MITK_TEST_END()
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55