Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkMultiComponentImageDataComparisonFilterTest.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 // mitk includes
14 #include "mitkIOUtil.h"
15 #include "mitkImageReadAccessor.h"
17 #include "mitkTestingMacros.h"
18 
19 #include "itkNumericTraits.h"
20 
21 int mitkMultiComponentImageDataComparisonFilterTest(int /*argc*/, char *argv[])
22 {
23  MITK_TEST_BEGIN("MultiComponentImageDataComparisonFilter");
24 
25  // instantiation
28  MITK_TEST_CONDITION_REQUIRED(testObject.IsNotNull(), "Testing instantiation of test class!");
29 
30  MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() == nullptr, "Testing initialization of result struct");
31  MITK_TEST_CONDITION_REQUIRED(testObject->GetTolerance() == 0.0f, "Testing initialization of tolerance member");
32  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing initialization of CompareResult member");
33 
34  // initialize compare result struct and pass it to the filter
35  mitk::CompareFilterResults compareResult;
36  compareResult.m_MaximumDifference = 0.0f;
37  compareResult.m_MinimumDifference = itk::NumericTraits<double>::max();
38  compareResult.m_MeanDifference = 0.0f;
39  compareResult.m_FilterCompleted = false;
40  compareResult.m_TotalDifference = 0.0f;
41  compareResult.m_PixelsWithDifference = 0;
42  testObject->SetCompareFilterResult(&compareResult);
43 
44  MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() != nullptr,
45  "Testing set/get of compare result struct");
46  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "CompareResult still false");
47 
48  // now load an image with several components and present it to the filter
49  mitk::Image::Pointer testImg = mitk::IOUtil::Load<mitk::Image>(argv[1]);
50  mitk::Image::Pointer testImg2 = testImg->Clone();
51 
52  testObject->SetValidImage(testImg);
53  testObject->SetTestImage(testImg2);
54 
55  MITK_TEST_CONDITION_REQUIRED(testObject->GetNumberOfIndexedInputs() == 2, "Testing correct handling of input images");
56 
57  testObject->Update();
58 
59  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult(), "Testing filter processing with equal image data");
60 
61  // now change some of the data and check if the response is correct
62  mitk::ImageReadAccessor imgAcc(testImg2);
63  auto *imgData = (unsigned char *)imgAcc.GetData();
64  imgData[10] += 1;
65  imgData[20] += 2;
66  imgData[30] += 3;
67 
68  testObject->Update();
69 
70  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing filter processing with unequal image data");
72  mitk::Equal((int)testObject->GetCompareFilterResult()->m_PixelsWithDifference, (int)3) &&
73  mitk::Equal((double)testObject->GetCompareFilterResult()->m_MaximumDifference, (double)3.0) &&
74  mitk::Equal((double)testObject->GetCompareFilterResult()->m_MeanDifference, (double)2.0),
75  "Assessing calculated image differences");
76  MITK_TEST_END();
77 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static Pointer New()
A simple struct to hold the result of the comparison filter.
static T max(T x, T y)
Definition: svm.cpp:56
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
and MITK_TEST_END()
ImageReadAccessor class to get locked read access for a particular image part.
int mitkMultiComponentImageDataComparisonFilterTest(int, char *argv[])