Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkBaseDataTest.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 "itkImage.h"
19 #include "mitkStringProperty.h"
20 #include "mitkTestingMacros.h"
22 #include <mitkTimeGeometry.h>
23 
24 int mitkBaseDataTest(int /*argc*/, char * /*argv*/ [])
25 {
26  MITK_TEST_BEGIN("BaseData")
27 
28  // Create a BaseData implementation
29  MITK_INFO << "Creating a base data instance...";
31 
32  MITK_TEST_CONDITION_REQUIRED(baseDataImpl.IsNotNull(), "Testing instantiation");
33  MITK_TEST_CONDITION(baseDataImpl->IsInitialized(), "BaseDataTestImplementation is initialized");
34  MITK_TEST_CONDITION(baseDataImpl->IsEmpty(), "BaseDataTestImplementation is initialized and empty");
35 
36  mitk::BaseDataTestImplementation::Pointer cloneBaseData = baseDataImpl->Clone();
37  MITK_TEST_CONDITION_REQUIRED(cloneBaseData.IsNotNull(), "Testing instantiation of base data clone");
38  MITK_TEST_CONDITION(cloneBaseData->IsInitialized(), "Clone of BaseDataTestImplementation is initialized");
39  MITK_TEST_CONDITION(cloneBaseData->IsEmpty(), "Clone of BaseDataTestImplementation is initialized and empty");
40 
41  MITK_INFO << "Testing setter and getter for geometries...";
42 
43  // test method GetTimeGeometry()
44  MITK_TEST_CONDITION(baseDataImpl->GetTimeGeometry(), "Testing creation of TimeGeometry");
45 
46  mitk::TimeGeometry *geo = nullptr;
47  baseDataImpl->SetTimeGeometry(geo);
48 
49  MITK_TEST_CONDITION(baseDataImpl->GetTimeGeometry() == nullptr, "Reset Geometry");
50 
52  baseDataImpl->SetTimeGeometry(geo2);
53  geo2->Initialize(2);
54  MITK_TEST_CONDITION(baseDataImpl->GetTimeGeometry() == geo2.GetPointer(), "Correct Reinit of TimeGeometry");
55 
56  // test method GetGeometry(int timeStep)
57  MITK_TEST_CONDITION(baseDataImpl->GetGeometry(1) != nullptr, "... and single Geometries");
58 
59  // test method Expand(unsigned int timeSteps)
60  baseDataImpl->Expand(5);
61  MITK_TEST_CONDITION(baseDataImpl->GetTimeSteps() == 5, "Expand the geometry to further time slices!");
62 
63  // test method GetUpdatedGeometry(int timeStep);
65  mitk::BaseGeometry::Pointer geo3 = dynamic_cast<mitk::BaseGeometry *>(geometry3D.GetPointer());
67  dynamic_cast<mitk::ProportionalTimeGeometry *>(baseDataImpl->GetTimeGeometry());
68  if (timeGeometry.IsNotNull())
69  {
70  timeGeometry->SetTimeStepGeometry(geo3, 1);
71  }
72 
73  MITK_TEST_CONDITION(baseDataImpl->GetUpdatedGeometry(1) == geo3, "Set Geometry for time step 1");
74  MITK_TEST_CONDITION(baseDataImpl->GetMTime() != 0, "Check if modified time is set");
75  baseDataImpl->SetClonedGeometry(geo3, 1);
76 
77  mitk::ScalarType x[3];
78  x[0] = 2;
79  x[1] = 4;
80  x[2] = 6;
81  mitk::Point3D p3d(x);
82  baseDataImpl->SetOrigin(p3d);
83  geo3->SetOrigin(p3d);
84 
85  MITK_TEST_CONDITION(baseDataImpl->GetGeometry(1)->GetOrigin() == geo3->GetOrigin(), "Testing Origin set");
86 
87  cloneBaseData = baseDataImpl->Clone();
88  MITK_TEST_CONDITION(cloneBaseData->GetGeometry(1)->GetOrigin() == geo3->GetOrigin(), "Testing origin set in clone!");
89 
90  MITK_TEST_CONDITION(!baseDataImpl->IsEmptyTimeStep(1), "Is not empty before clear()!");
91  baseDataImpl->Clear();
92  MITK_TEST_CONDITION(baseDataImpl->IsEmptyTimeStep(1), "...but afterwards!");
93  // test method Set-/GetProperty()
94  baseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty"));
95  // baseDataImpl->SetProperty("visibility", mitk::BoolProperty::New());
96  MITK_TEST_CONDITION(baseDataImpl->GetProperty("property38")->GetValueAsString() == "testproperty",
97  "Check if base property is set correctly!");
98 
99  cloneBaseData = baseDataImpl->Clone();
100  MITK_TEST_CONDITION(cloneBaseData->GetProperty("property38")->GetValueAsString() == "testproperty",
101  "Testing origin set in clone!");
102 
103  // test method Set-/GetPropertyList
105  propertyList->SetFloatProperty("floatProperty1", 123.45);
106  propertyList->SetBoolProperty("visibility", true);
107  propertyList->SetStringProperty("nameXY", "propertyName");
108  baseDataImpl->SetPropertyList(propertyList);
109  bool value = false;
110  MITK_TEST_CONDITION(baseDataImpl->GetPropertyList() == propertyList, "Check if base property list is set correctly!");
111  MITK_TEST_CONDITION(baseDataImpl->GetPropertyList()->GetBoolProperty("visibility", value) == true,
112  "Check if base property is set correctly in the property list!");
113 
114  // test method UpdateOutputInformation()
115  baseDataImpl->UpdateOutputInformation();
116  MITK_TEST_CONDITION(baseDataImpl->GetUpdatedTimeGeometry() == geo2, "TimeGeometry update!");
117  // Test method CopyInformation()
119  newBaseData->CopyInformation(baseDataImpl);
120  MITK_TEST_CONDITION_REQUIRED(newBaseData->GetTimeGeometry()->CountTimeSteps() == 5,
121  "Check copying of of Basedata Data Object!");
122 
123  MITK_TEST_END()
124 }
static Pointer New()
#define MITK_INFO
Definition: mitkLogMacros.h:22
double ScalarType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
int mitkBaseDataTest(int, char *[])
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static Pointer New()
#define MITK_TEST_CONDITION(COND, MSG)
and MITK_TEST_END()
static Pointer New()
BaseGeometry Describes the geometry of a data object.