Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkVolumeCalculatorTest.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 "mitkIOUtil.h"
18 #include "mitkImage.h"
19 #include "mitkTestingMacros.h"
20 #include "mitkVolumeCalculator.h"
22 
23 int mitkVolumeCalculatorTest(int /*argc*/, char *argv[])
24 {
25  MITK_TEST_BEGIN("VolumeCalculator")
26  const char *filename = argv[1];
27  const char *filename3D = argv[2];
29  //*********************************************************************
30  // Part I: Testing calculated volume.
31  // The correct values have been manually calculated using external software.
32  //*********************************************************************
33 
35  MITK_TEST_CONDITION_REQUIRED(image.IsNotNull(), "01 Check if test image could be loaded");
36 
37  volumeCalculator->SetImage(image);
38  volumeCalculator->SetThreshold(0);
39  volumeCalculator->ComputeVolume();
40  float volume = volumeCalculator->GetVolume();
41 
42  MITK_TEST_CONDITION_REQUIRED(volume == 1600, "02 Test Volume Result. Expected 1600 actual value " << volume);
43 
44  volumeCalculator->SetThreshold(255);
45  volumeCalculator->ComputeVolume();
46  volume = volumeCalculator->GetVolume();
47 
48  MITK_TEST_CONDITION_REQUIRED(volume == 1272.50, "03 Test Volume Result. Expected 1272.50 actual value " << volume);
49 
50  image = mitk::IOUtil::LoadImage(filename3D);
51 
52  volumeCalculator->SetImage(image);
53  volumeCalculator->SetThreshold(-1023);
54  volumeCalculator->ComputeVolume();
55  std::vector<float> volumes = volumeCalculator->GetVolumes();
56 
57  for (std::vector<float>::iterator it = volumes.begin(); it != volumes.end(); ++it)
58  {
59  MITK_TEST_CONDITION_REQUIRED((*it) == 24.576f, "04 Test Volume Result.");
60  }
62 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkVolumeCalculatorTest(int, char *argv[])
static const std::string filename
and MITK_TEST_END()
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597
static Pointer New()