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
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,
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
19 #include "mitkTestingMacros.h"
20 
22 
23 #include <mitkPlaneGeometryData.h>
24 
25 // VTK
26 #include <vtkRegressionTestImage.h>
27 
29  mitk::Image *image,
31  mitk::ScalarType zPos)
32 {
33  auto geometry = mitk::PlaneGeometry::New();
34  geometry->InitializeStandardPlane(image->GetGeometry(), orientation, zPos);
35 
36  auto geometryData = mitk::PlaneGeometryData::New();
37  geometryData->SetPlaneGeometry(geometry);
38 
39  auto node = mitk::DataNode::New();
40  node->SetData(geometryData);
41 
42  renderingHelper.AddNodeToStorage(node);
43 
44  return node;
45 }
46 
47 int mitkPlaneGeometryDataMapper2DTest(int argc, char *argv[])
48 {
49  // load all arguments into a datastorage, take last argument as reference rendering
50  // setup a renderwindow of fixed size X*Y
51  // render the datastorage
52  // compare rendering to reference image
53  MITK_TEST_BEGIN("mitkPlaneGeometryDataMapper2DTest")
54 
55  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
56  auto image = static_cast<mitk::Image *>(
57  renderingHelper.GetDataStorage()->GetNode(mitk::TNodePredicateDataType<mitk::Image>::New())->GetData());
58 
59  auto zCoord = image->GetGeometry()->GetBoundingBox()->GetCenter()[0];
60  addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Sagittal, zCoord);
61  addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Frontal, zCoord);
62 
63  auto planeNode = addPlaneToDataStorage(renderingHelper, image, mitk::PlaneGeometry::Sagittal, zCoord);
64  auto planeGeometry = static_cast<mitk::PlaneGeometryData *>(planeNode->GetData())->GetPlaneGeometry();
65 
66  auto transform = mitk::AffineTransform3D::New();
67  mitk::Vector3D rotationAxis;
68  rotationAxis.Fill(0.0);
69  rotationAxis[2] = 1;
70  transform->Rotate3D(rotationAxis, vnl_math::pi_over_4);
71 
72  planeGeometry->Compose(transform);
73 
74  auto bounds = planeGeometry->GetBounds();
75  bounds[1] /= 3;
76  planeGeometry->SetBounds(bounds);
77 
78  planeGeometry->SetReferenceGeometry(nullptr);
79 
80  planeNode->SetIntProperty("Crosshair.Gap Size", 4);
81 
82  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
83  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 1) == true,
84  "CompareRenderWindowAgainstReference test result positive?");
85 
86  // use this to generate a reference screenshot or save the file:
87  if (false)
88  {
89  renderingHelper.SaveReferenceScreenShot("output.png");
90  }
91 
92  MITK_TEST_END();
93 }
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 ...
static Pointer New()
#define MITK_TEST_CONDITION(COND, MSG)
Image class for storing images.
Definition: mitkImage.h:76
Data class containing PlaneGeometry objects.
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:129
int mitkPlaneGeometryDataMapper2DTest(int argc, char *argv[])
virtual const BoundingBoxType * GetBoundingBox()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.