24 #include <vtkColorTransferFunction.h>
25 #include <vtkPiecewiseFunction.h>
29 CPPUNIT_TEST_SUITE(mitkLookupTableTestSuite);
33 MITK_TEST(TestCreateColorTransferFunction);
34 MITK_TEST(TestCreateOpacityTransferFunction);
35 MITK_TEST(TestCreateGradientTransferFunction);
36 CPPUNIT_TEST_SUITE_END();
42 void TestCreateLookupTable()
48 CPPUNIT_ASSERT_MESSAGE(
"Testing instantiation", myLookupTable.IsNotNull());
51 void TestSetVtkLookupTable()
57 lut->SetTableValue(0, 0.5, 0.5, 0.5, 1.0);
58 lut->SetTableValue(1, 0.5, 0.5, 0.5, 0.5);
61 myLookupTable->SetVtkLookupTable(lut);
64 vtkLookupTable *lut2 = myLookupTable->GetVtkLookupTable();
66 CPPUNIT_ASSERT_MESSAGE(
"Input and output table are not equal", lut == lut2);
77 lut->SetRange(0, 200);
78 lut->SetAlphaRange(0.0, 1.0);
81 myLookupTable->SetVtkLookupTable(lut);
83 myLookupTable->ChangeOpacityForAll(0.7f);
85 for (
int i = 0; i < lut->GetNumberOfTableValues(); ++i)
87 CPPUNIT_ASSERT_MESSAGE(
"Opacity not set for all",
mitk::Equal(0.7, lut->GetOpacity(i), 0.01,
true));
90 vtkIdType tableIndex = 10;
91 myLookupTable->ChangeOpacity(tableIndex, 1.0);
93 lut->GetTableValue(tableIndex, rgba);
94 CPPUNIT_ASSERT_MESSAGE(
"Opacity not set for value",
mitk::Equal(1.0, rgba[3], 0.01,
true));
98 void TestCreateColorTransferFunction()
104 lut->SetRange(0, 255);
107 myLookupTable->SetVtkLookupTable(lut);
108 vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = myLookupTable->CreateColorTransferFunction();
110 CPPUNIT_ASSERT(colorTransferFunction !=
nullptr);
112 vtkIdType numberOfTableEntries = lut->GetNumberOfTableValues();
114 double rgbaFunction[4];
115 for (
int i = 0; i < numberOfTableEntries; ++i)
117 lut->GetIndexedColor(i, rgbaTable);
118 colorTransferFunction->GetIndexedColor(i, rgbaFunction);
119 CPPUNIT_ASSERT_MESSAGE(
"Wrong color of transfer function",
120 mitk::Equal(rgbaTable[0], rgbaFunction[0], 0.000001,
true) &&
121 mitk::Equal(rgbaTable[1], rgbaFunction[1], 0.000001,
true) &&
122 mitk::Equal(rgbaTable[2], rgbaFunction[2], 0.000001,
true));
127 void TestCreateOpacityTransferFunction()
133 lut->SetAlphaRange(0, 1.0);
136 myLookupTable->SetVtkLookupTable(lut);
137 vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = myLookupTable->CreateOpacityTransferFunction();
138 CPPUNIT_ASSERT(opacityTransferFunction !=
nullptr);
140 int funcSize = opacityTransferFunction->GetSize();
141 auto table =
new double[funcSize];
143 opacityTransferFunction->GetTable(0, 1, funcSize, table);
144 for (
int i = 0; i < funcSize; ++i)
146 lut->GetIndexedColor(i, rgba);
147 CPPUNIT_ASSERT_MESSAGE(
"Wrong opacity of transfer function",
mitk::Equal(table[i], rgba[3], 0.000001,
true));
153 void TestCreateGradientTransferFunction()
159 lut->SetAlphaRange(0, 0.73);
162 myLookupTable->SetVtkLookupTable(lut);
163 vtkSmartPointer<vtkPiecewiseFunction> gradientTransferFunction = myLookupTable->CreateGradientTransferFunction();
164 CPPUNIT_ASSERT(gradientTransferFunction !=
nullptr);
166 int funcSize = gradientTransferFunction->GetSize();
167 auto table =
new double[funcSize];
169 gradientTransferFunction->GetTable(0, 1, funcSize, table);
170 for (
int i = 0; i < funcSize; ++i)
172 lut->GetIndexedColor(i, rgba);
173 CPPUNIT_ASSERT_MESSAGE(
"Wrong opacity of transfer function",
mitk::Equal(table[i], rgba[3], 0.000001,
true));
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.