Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPlaneGeometryDataMapper2DTest.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
15 #include "mitkTestingMacros.h"
16 
18 
19 #include <mitkPlaneGeometryData.h>
20 
21 // VTK
22 #include <vtkRegressionTestImage.h>
23 
27  mitk::ScalarType zPos)
28 {
29  auto geometry = mitk::PlaneGeometry::New();
30  geometry->InitializeStandardPlane(image->GetGeometry(), orientation, zPos);
31 
32  auto geometryData = mitk::PlaneGeometryData::New();
33  geometryData->SetPlaneGeometry(geometry);
34 
35  auto node = mitk::DataNode::New();
36  node->SetData(geometryData);
37 
38  renderingHelper.AddNodeToStorage(node);
39 
40  return node;
41 }
42 
43 int mitkPlaneGeometryDataMapper2DTest(int argc, char *argv[])
44 {
45  try
46  {
47  mitk::RenderingTestHelper openGlTest(640, 480);
48  }
49  catch (const mitk::TestNotRunException &e)
50  {
51  MITK_WARN << "Test not run: " << e.GetDescription();
52  return 77;
53  }
54  // load all arguments into a datastorage, take last argument as reference rendering
55  // setup a renderwindow of fixed size X*Y
56  // render the datastorage
57  // compare rendering to reference image
58  MITK_TEST_BEGIN("mitkPlaneGeometryDataMapper2DTest")
59 
60  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
61  auto image = static_cast<mitk::Image *>(
62  renderingHelper.GetDataStorage()->GetNode(mitk::TNodePredicateDataType<mitk::Image>::New())->GetData());
63 
64  auto zCoord = image->GetGeometry()->GetBoundingBox()->GetCenter()[0];
66  addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Frontal, zCoord);
67 
68  auto planeNode = addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Sagittal, zCoord);
69  auto planeGeometry = static_cast<mitk::PlaneGeometryData *>(planeNode->GetData())->GetPlaneGeometry();
70 
71  auto transform = mitk::AffineTransform3D::New();
72  mitk::Vector3D rotationAxis;
73  rotationAxis.Fill(0.0);
74  rotationAxis[2] = 1;
75  transform->Rotate3D(rotationAxis, vnl_math::pi_over_4);
76 
77  planeGeometry->Compose(transform);
78 
79  auto bounds = planeGeometry->GetBounds();
80  bounds[1] /= 3;
81  planeGeometry->SetBounds(bounds);
82 
83  planeGeometry->SetReferenceGeometry(nullptr);
84 
85  planeNode->SetIntProperty("Crosshair.Gap Size", 4);
86 
87  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
88  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 1) == true,
89  "CompareRenderWindowAgainstReference test result positive?");
90 
91  // use this to generate a reference screenshot or save the file:
92  if (false)
93  {
94  renderingHelper.SaveReferenceScreenShot("output.png");
95  }
96 
97  MITK_TEST_END();
98 }
double ScalarType
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void SaveReferenceScreenShot(std::string fileName)
SaveReferenceScreenShot Convenience method to save a reference screen shot.
Tests for type compatibility (dynamic_cast).
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
#define MITK_WARN
Definition: mitkLogMacros.h:19
static Pointer New()
#define MITK_TEST_CONDITION(COND, MSG)
Specialized mitk::Exception for skipped tests.
Image class for storing images.
Definition: mitkImage.h:72
Data class containing PlaneGeometry objects.
mitk::Image::Pointer image
static Pointer New()
mitk::DataNode::Pointer addPlaneToDataStorage(mitk::RenderingTestHelper &renderingHelper, mitk::Image *image, mitk::PlaneGeometry::PlaneOrientation orientation, mitk::ScalarType zPos)
mitk::DataStorage::Pointer GetDataStorage()
Returns the datastorage, in order to modify the data inside a rendering test.
static Pointer New()
void AddNodeToStorage(mitk::DataNode::Pointer node)
AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering...
and MITK_TEST_END()
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:138
int mitkPlaneGeometryDataMapper2DTest(int argc, char *argv[])