20 #include <vtkColorTransferFunction.h> 21 #include <vtkPiecewiseFunction.h> 25 CPPUNIT_TEST_SUITE(mitkLookupTableTestSuite);
29 MITK_TEST(TestCreateColorTransferFunction);
30 MITK_TEST(TestCreateOpacityTransferFunction);
31 MITK_TEST(TestCreateGradientTransferFunction);
32 CPPUNIT_TEST_SUITE_END();
38 void TestCreateLookupTable()
44 CPPUNIT_ASSERT_MESSAGE(
"Testing instantiation", myLookupTable.IsNotNull());
47 void TestSetVtkLookupTable()
52 vtkLookupTable *lut = vtkLookupTable::New();
53 lut->SetTableValue(0, 0.5, 0.5, 0.5, 1.0);
54 lut->SetTableValue(1, 0.5, 0.5, 0.5, 0.5);
57 myLookupTable->SetVtkLookupTable(lut);
60 vtkLookupTable *lut2 = myLookupTable->GetVtkLookupTable();
62 CPPUNIT_ASSERT_MESSAGE(
"Input and output table are not equal", lut == lut2);
72 vtkLookupTable *lut = vtkLookupTable::New();
73 lut->SetRange(0, 200);
74 lut->SetAlphaRange(0.0, 1.0);
77 myLookupTable->SetVtkLookupTable(lut);
79 myLookupTable->ChangeOpacityForAll(0.7f);
81 for (
int i = 0; i < lut->GetNumberOfTableValues(); ++i)
83 CPPUNIT_ASSERT_MESSAGE(
"Opacity not set for all",
mitk::Equal(0.7, lut->GetOpacity(i), 0.01,
true));
86 vtkIdType tableIndex = 10;
87 myLookupTable->ChangeOpacity(tableIndex, 1.0);
89 lut->GetTableValue(tableIndex, rgba);
90 CPPUNIT_ASSERT_MESSAGE(
"Opacity not set for value",
mitk::Equal(1.0, rgba[3], 0.01,
true));
94 void TestCreateColorTransferFunction()
99 vtkLookupTable *lut = vtkLookupTable::New();
100 lut->SetRange(0, 255);
103 myLookupTable->SetVtkLookupTable(lut);
104 vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = myLookupTable->CreateColorTransferFunction();
106 CPPUNIT_ASSERT(colorTransferFunction !=
nullptr);
108 vtkIdType numberOfTableEntries = lut->GetNumberOfTableValues();
110 double rgbaFunction[4];
111 for (
int i = 0; i < numberOfTableEntries; ++i)
113 lut->GetIndexedColor(i, rgbaTable);
114 colorTransferFunction->GetIndexedColor(i, rgbaFunction);
115 CPPUNIT_ASSERT_MESSAGE(
"Wrong color of transfer function",
116 mitk::Equal(rgbaTable[0], rgbaFunction[0], 0.000001,
true) &&
117 mitk::Equal(rgbaTable[1], rgbaFunction[1], 0.000001,
true) &&
118 mitk::Equal(rgbaTable[2], rgbaFunction[2], 0.000001,
true));
123 void TestCreateOpacityTransferFunction()
128 vtkLookupTable *lut = vtkLookupTable::New();
129 lut->SetAlphaRange(0, 1.0);
132 myLookupTable->SetVtkLookupTable(lut);
133 vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = myLookupTable->CreateOpacityTransferFunction();
134 CPPUNIT_ASSERT(opacityTransferFunction !=
nullptr);
136 int funcSize = opacityTransferFunction->GetSize();
137 auto table =
new double[funcSize];
139 opacityTransferFunction->GetTable(0, 1, funcSize, table);
140 for (
int i = 0; i < funcSize; ++i)
142 lut->GetIndexedColor(i, rgba);
143 CPPUNIT_ASSERT_MESSAGE(
"Wrong opacity of transfer function",
mitk::Equal(table[i], rgba[3], 0.000001,
true));
149 void TestCreateGradientTransferFunction()
154 vtkLookupTable *lut = vtkLookupTable::New();
155 lut->SetAlphaRange(0, 0.73);
158 myLookupTable->SetVtkLookupTable(lut);
159 vtkSmartPointer<vtkPiecewiseFunction> gradientTransferFunction = myLookupTable->CreateGradientTransferFunction();
160 CPPUNIT_ASSERT(gradientTransferFunction !=
nullptr);
162 int funcSize = gradientTransferFunction->GetSize();
163 auto table =
new double[funcSize];
165 gradientTransferFunction->GetTable(0, 1, funcSize, table);
166 for (
int i = 0; i < funcSize; ++i)
168 lut->GetIndexedColor(i, rgba);
169 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.