Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkImageVtkMapper2DTransferFunctionTest.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 
23 int mitkImageVtkMapper2DTransferFunctionTest(int argc, char *argv[])
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("mitkImageVtkMapper2DTransferFunctionTest")
39 
40  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
41 
42  // define an arbitrary colortransferfunction
43  vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
44  colorTransferFunction->SetColorSpaceToRGB();
45  colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0); // black = red
46  colorTransferFunction->AddRGBPoint(127.5, 0, 1, 0); // grey = green
47  colorTransferFunction->AddRGBPoint(255.0, 0, 0, 1); // white = blue
49  transferFucntion->SetColorTransferFunction(colorTransferFunction);
50 
51  // set the rendering mode to use the transfer function
52  renderingHelper.SetImageProperty(
54  // set the property for the image
55  renderingHelper.SetImageProperty("Image Rendering.Transfer Function",
56  mitk::TransferFunctionProperty::New(transferFucntion));
57 
58  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
59  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true,
60  "CompareRenderWindowAgainstReference test result positive?");
61 
62  // use this to generate a reference screenshot or save the file:
63  if (false)
64  {
65  renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/tmp/output2.png");
66  }
67 
68  MITK_TEST_END();
69 }
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.
int mitkImageVtkMapper2DTransferFunctionTest(int argc, char *argv[])
#define MITK_WARN
Definition: mitkLogMacros.h:19
#define MITK_TEST_CONDITION(COND, MSG)
Specialized mitk::Exception for skipped tests.
static Pointer New()
and MITK_TEST_END()