Medical Imaging Interaction Toolkit  2016.11.0
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,
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 // mitk includes
18 #include "mitkIOUtil.h"
19 #include "mitkImageReadAccessor.h"
21 #include "mitkTestingMacros.h"
22 
23 #include "itkNumericTraits.h"
24 
25 int mitkMultiComponentImageDataComparisonFilterTest(int /*argc*/, char *argv[])
26 {
27  MITK_TEST_BEGIN("MultiComponentImageDataComparisonFilter");
28 
29  // instantiation
32  MITK_TEST_CONDITION_REQUIRED(testObject.IsNotNull(), "Testing instantiation of test class!");
33 
34  MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() == NULL, "Testing initialization of result struct");
35  MITK_TEST_CONDITION_REQUIRED(testObject->GetTolerance() == 0.0f, "Testing initialization of tolerance member");
36  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing initialization of CompareResult member");
37 
38  // initialize compare result struct and pass it to the filter
39  mitk::CompareFilterResults compareResult;
40  compareResult.m_MaximumDifference = 0.0f;
41  compareResult.m_MinimumDifference = itk::NumericTraits<double>::max();
42  compareResult.m_MeanDifference = 0.0f;
43  compareResult.m_FilterCompleted = false;
44  compareResult.m_TotalDifference = 0.0f;
45  compareResult.m_PixelsWithDifference = 0;
46  testObject->SetCompareFilterResult(&compareResult);
47 
48  MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() != NULL,
49  "Testing set/get of compare result struct");
50  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "CompareResult still false");
51 
52  // now load an image with several components and present it to the filter
54  mitk::Image::Pointer testImg2 = testImg->Clone();
55 
56  testObject->SetValidImage(testImg);
57  testObject->SetTestImage(testImg2);
58 
59  MITK_TEST_CONDITION_REQUIRED(testObject->GetNumberOfIndexedInputs() == 2, "Testing correct handling of input images");
60 
61  testObject->Update();
62 
63  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult(), "Testing filter processing with equal image data");
64 
65  // now change some of the data and check if the response is correct
66  mitk::ImageReadAccessor imgAcc(testImg2);
67  unsigned char *imgData = (unsigned char *)imgAcc.GetData();
68  imgData[10] += 1;
69  imgData[20] += 2;
70  imgData[30] += 3;
71 
72  testObject->Update();
73 
74  MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing filter processing with unequal image data");
76  mitk::Equal((int)testObject->GetCompareFilterResult()->m_PixelsWithDifference, (int)3) &&
77  mitk::Equal((double)testObject->GetCompareFilterResult()->m_MaximumDifference, (double)3.0) &&
78  mitk::Equal((double)testObject->GetCompareFilterResult()->m_MeanDifference, (double)2.0),
79  "Assessing calculated image differences");
80  MITK_TEST_END();
81 }
#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:70
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[])
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597