Medical Imaging Interaction Toolkit  2018.4.99-6aa36ba9
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 (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 
17 // VTK
19 #include <mitkTransferFunction.h>
21 #include <vtkRegressionTestImage.h>
22 
24 {
25  try
26  {
27  mitk::RenderingTestHelper openGlTest(640, 480);
28  }
29  catch (const mitk::TestNotRunException &e)
30  {
31  MITK_WARN << "Test not run: " << e.GetDescription();
32  return 77;
33  }
34  // load all arguments into a datastorage, take last argument as reference rendering
35  // setup a renderwindow of fixed size X*Y
36  // render the datastorage
37  // compare rendering to reference image
38  MITK_TEST_BEGIN("mitkImageVtkMapper2DopacityTransferFunctionTest")
39 
40  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
41 
42  // define some controlpoints for a scalaropacity
43  mitk::TransferFunction::ControlPoints scalarOpacityPoints;
44  scalarOpacityPoints.push_back(std::make_pair(255, 0));
45  scalarOpacityPoints.push_back(std::make_pair(0, 0.1));
46  scalarOpacityPoints.push_back(std::make_pair(127, 0.3));
47 
48  // define an arbitrary colortransferfunction
49  vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
50  colorTransferFunction->SetColorSpaceToRGB();
51  colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); // black = red
52  colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); // grey = green
53  colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); // white = blue
54 
56  transferFunction->SetColorTransferFunction(colorTransferFunction);
57  transferFunction->SetScalarOpacityPoints(scalarOpacityPoints);
58 
59  // set the rendering mode to use the transfer function
60  renderingHelper.SetImageProperty(
62  // set the property for the image
63  renderingHelper.SetImageProperty("Image Rendering.Transfer Function",
64  mitk::TransferFunctionProperty::New(transferFunction));
65 
66  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
67  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true,
68  "CompareRenderWindowAgainstReference test result positive?");
69 
70  // renderingHelper.SetAutomaticallyCloseRenderWindow(false);
71 
72  // use this to generate a reference screenshot or save the file:
73  if (false)
74  {
75  renderingHelper.SaveReferenceScreenShot("/tmp/output3.png");
76  }
77 
78  MITK_TEST_END();
79 }
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_WARN
Definition: mitkLogMacros.h:19
#define MITK_TEST_CONDITION(COND, MSG)
Specialized mitk::Exception for skipped tests.
static Pointer New()
std::vector< std::pair< double, double > > ControlPoints
and MITK_TEST_END()