Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImageVtkMapper2DOpacityTransferFunctionTest.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 
21 // VTK
23 #include <mitkTransferFunction.h>
25 #include <vtkRegressionTestImage.h>
26 
28 {
29  // load all arguments into a datastorage, take last argument as reference rendering
30  // setup a renderwindow of fixed size X*Y
31  // render the datastorage
32  // compare rendering to reference image
33  MITK_TEST_BEGIN("mitkImageVtkMapper2DopacityTransferFunctionTest")
34 
35  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
36 
37  // define some controlpoints for a scalaropacity
38  mitk::TransferFunction::ControlPoints scalarOpacityPoints;
39  scalarOpacityPoints.push_back(std::make_pair(255, 0));
40  scalarOpacityPoints.push_back(std::make_pair(0, 0.1));
41  scalarOpacityPoints.push_back(std::make_pair(127, 0.3));
42 
43  // define an arbitrary colortransferfunction
44  vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
45  colorTransferFunction->SetColorSpaceToRGB();
46  colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); // black = red
47  colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); // grey = green
48  colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); // white = blue
49 
51  transferFunction->SetColorTransferFunction(colorTransferFunction);
52  transferFunction->SetScalarOpacityPoints(scalarOpacityPoints);
53 
54  // set the rendering mode to use the transfer function
55  renderingHelper.SetImageProperty(
57  // set the property for the image
58  renderingHelper.SetImageProperty("Image Rendering.Transfer Function",
59  mitk::TransferFunctionProperty::New(transferFunction));
60 
61  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
62  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true,
63  "CompareRenderWindowAgainstReference test result positive?");
64 
65  // renderingHelper.SetAutomaticallyCloseRenderWindow(false);
66 
67  // use this to generate a reference screenshot or save the file:
68  if (false)
69  {
70  renderingHelper.SaveReferenceScreenShot("/tmp/output3.png");
71  }
72 
73  MITK_TEST_END();
74 }
int mitkImageVtkMapper2DOpacityTransferFunctionTest(int argc, char *argv[])
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void SaveReferenceScreenShot(std::string fileName)
SaveReferenceScreenShot Convenience method to save a reference screen shot.
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
void SetImageProperty(const char *propertyKey, mitk::BaseProperty *property)
This method set the property of the member datastorage.
#define MITK_TEST_CONDITION(COND, MSG)
static Pointer New()
std::vector< std::pair< double, double > > ControlPoints
and MITK_TEST_END()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.