00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkTransferFunction.h"
00019 #include "mitkTransferFunctionInitializer.h"
00020
00021 #include "mitkTestingMacros.h"
00022
00023 #include <iostream>
00024
00033 int mitkTransferFunctionTest(int , char* [])
00034 {
00035
00036 MITK_TEST_BEGIN("TransferFunction");
00037
00038
00039 mitk::TransferFunction::Pointer myTransferFunction = mitk::TransferFunction::New();
00040
00041
00042
00043
00044 MITK_TEST_CONDITION_REQUIRED( myTransferFunction.IsNotNull(), "Testing instantiation" );
00045
00046
00047
00048 mitk::TransferFunction::ControlPoints scalarOpacityPoints;
00049 scalarOpacityPoints.push_back( std::make_pair( 0.0, 0.0 ) );
00050 scalarOpacityPoints.push_back( std::make_pair( 5.0, 0.3 ) );
00051 scalarOpacityPoints.push_back( std::make_pair( 10.0, 1.0 ) );
00052 myTransferFunction->SetScalarOpacityPoints( scalarOpacityPoints );
00053 MITK_TEST_CONDITION_REQUIRED(
00054 myTransferFunction->GetScalarOpacityFunction()->GetSize() == 3,
00055 "Adding three point/value pairs to scalar opacity transfer function via VTK interface" );
00056
00057
00058 mitk::TransferFunction::ControlPoints gradientOpacityPoints;
00059 gradientOpacityPoints.push_back( std::make_pair( 0.0, 0.2 ) );
00060 gradientOpacityPoints.push_back( std::make_pair( 3.0, 0.7 ) );
00061 gradientOpacityPoints.push_back( std::make_pair( 7.0, 0.8 ) );
00062 gradientOpacityPoints.push_back( std::make_pair( 15.0, 0.9 ) );
00063 myTransferFunction->SetGradientOpacityPoints( gradientOpacityPoints );
00064 MITK_TEST_CONDITION_REQUIRED(
00065 myTransferFunction->GetGradientOpacityFunction()->GetSize() == 4,
00066 "Adding four point/value pairs to gradient opacity transfer function via VTK interface" );
00067
00068
00069 mitk::TransferFunction::RGBControlPoints colorPoints;
00070 itk::RGBPixel< double > rgb0, rgb1, rgb2, rgb3;
00071 rgb0[0] = 0.1f; rgb0[1] = 0.3f; rgb0[2] = 0.5f;
00072 colorPoints.push_back( std::make_pair( 2.0, rgb0 ) );
00073 rgb1[0] = 0.3; rgb1[1] = 0.8; rgb1[2] = 0.9;
00074 colorPoints.push_back( std::make_pair( 3.0, rgb1 ) );
00075 rgb2[0] = 0.6; rgb2[1] = 0.5; rgb2[2] = 0.4;
00076 colorPoints.push_back( std::make_pair( 4.0, rgb2 ) );
00077 rgb3[0] = 0.7; rgb3[1] = 0.1; rgb3[2] = 0.2;
00078 colorPoints.push_back( std::make_pair( 5.0, rgb3 ) );
00079
00080 myTransferFunction->SetRGBPoints( colorPoints );
00081 MITK_TEST_CONDITION_REQUIRED(
00082 myTransferFunction->GetColorTransferFunction()->GetSize() == 4,
00083 "Adding four point/value pairs to color transfer function via VTK interface" );
00084
00085
00086
00087
00088 myTransferFunction->AddScalarOpacityPoint( 3.0, 0.2 );
00089 MITK_TEST_CONDITION_REQUIRED(
00090 myTransferFunction->GetScalarOpacityFunction()->GetSize() == 4,
00091 "Adding new point/value to scalar opacity transfer function via MITK interface" );
00092
00093
00094 myTransferFunction->AddGradientOpacityPoint( 19.0, 1.0 );
00095 MITK_TEST_CONDITION_REQUIRED(
00096 myTransferFunction->GetGradientOpacityFunction()->GetSize() == 5,
00097 "Adding new point/value to gradient opacity transfer function via MITK interface" );
00098
00099
00100 myTransferFunction->AddRGBPoint( 1.0, 0.0, 0.1, 0.2 );
00101 MITK_TEST_CONDITION_REQUIRED(
00102 myTransferFunction->GetColorTransferFunction()->GetSize() == 5,
00103 "Adding new point/value to color transfer function via MITK interface" );
00104
00105
00106
00107
00108 double v1, v2;
00109 v1 = myTransferFunction->GetScalarOpacityFunction()->GetValue( 3.0 );
00110 v2 = myTransferFunction->GetScalarOpacityFunction()->GetValue( 10.0 );
00111 MITK_TEST_CONDITION_REQUIRED(
00112 (fabs( v1 - 0.2 ) < 1.0e-5) && (fabs( v2 - 1.0 ) < 1.0e-5),
00113 "Retrieving values at two points from scalar opacity transfer function" );
00114
00115
00116 v1 = myTransferFunction->GetGradientOpacityFunction()->GetValue( 0.0 );
00117 v2 = myTransferFunction->GetGradientOpacityFunction()->GetValue( 19.0 );
00118 MITK_TEST_CONDITION_REQUIRED(
00119 (fabs( v1 - 0.2 ) < 1.0e-5) && (fabs( v2 - 1.0 ) < 1.0e-5),
00120 "Retrieving values at two points from gradient opacity transfer function" );
00121
00122
00123 vtkFloatingPointType vrgb1[3], vrgb2[3];
00124 myTransferFunction->GetColorTransferFunction()->GetColor( 1.0, vrgb1 );
00125 myTransferFunction->GetColorTransferFunction()->GetColor( 4.0, vrgb2 );
00126 std::cout << vrgb2[0] << ", " << vrgb2[1] << ", " << vrgb2[2] << std::endl;
00127 MITK_TEST_CONDITION_REQUIRED(
00128 (fabs( vrgb1[0] - 0.0 ) < 1.0e-5)
00129 && (fabs( vrgb1[1] - 0.1 ) < 1.0e-5)
00130 && (fabs( vrgb1[2] - 0.2 ) < 1.0e-5)
00131 && (fabs( vrgb2[0] - 0.6 ) < 1.0e-5)
00132 && (fabs( vrgb2[1] - 0.5 ) < 1.0e-5)
00133 && (fabs( vrgb2[2] - 0.4 ) < 1.0e-5),
00134 "Retrieving values at two points from color transfer function" );
00135
00136
00137
00138
00139
00140 MITK_TEST_CONDITION_REQUIRED(
00141 myTransferFunction->RemoveScalarOpacityPoint( 3.0 ) == 1,
00142 "Removing point from scalar opacity transfer function (should return point index)" );
00143
00144
00145
00146 MITK_TEST_CONDITION_REQUIRED(
00147 myTransferFunction->RemoveGradientOpacityPoint( 0.0 ) == 0,
00148 "Removing point from gradient opacity transfer function (should return point index)" );
00149
00150
00151
00152 MITK_TEST_CONDITION_REQUIRED(
00153 myTransferFunction->RemoveRGBPoint( 5.0 ) == 4,
00154 "Removing point from color transfer function (should return point ndex)" );
00155
00156
00157
00158
00159 MITK_TEST_CONDITION_REQUIRED(
00160 myTransferFunction->RemoveScalarOpacityPoint( 2.5 ) == -1,
00161 "Trying to remove non-existing point from scalar opacity transfer function (should return -1)" );
00162
00163
00164 MITK_TEST_CONDITION_REQUIRED(
00165 myTransferFunction->RemoveGradientOpacityPoint( 2.5 ) == -1,
00166 "Trying to remove non-existing point from gradient opacity transfer function (should return -1)" );
00167
00168
00169 MITK_TEST_CONDITION_REQUIRED(
00170 myTransferFunction->RemoveRGBPoint( 2.5 ) == -1,
00171 "Trying to remove non-existing point from color transfer function (should return -1)" );
00172
00173
00174
00175
00176 mitk::TransferFunction::ControlPoints newScalarOpacityPoints =
00177 myTransferFunction->GetScalarOpacityPoints();
00178 MITK_TEST_CONDITION_REQUIRED(
00179 (newScalarOpacityPoints.size() == 3)
00180 && (fabs(newScalarOpacityPoints[2].first - 10.0) < 1.0e-5)
00181 && (fabs(newScalarOpacityPoints[2].second - 1.0) < 1.0e-5),
00182 "Retrieving copy of scalar opacity points (checking for correct content and size)" );
00183
00184
00185 mitk::TransferFunction::ControlPoints newGradientOpacityPoints =
00186 myTransferFunction->GetGradientOpacityPoints();
00187 MITK_TEST_CONDITION_REQUIRED(
00188 (newGradientOpacityPoints.size() == 4)
00189 && (fabs(newGradientOpacityPoints[3].first - 19.0) < 1.0e-5)
00190 && (fabs(newGradientOpacityPoints[3].second - 1.0) < 1.0e-5),
00191 "Retrieving copy of gradient opacity points (checking for correct content and size)" );
00192
00193
00194 mitk::TransferFunction::RGBControlPoints newRGBPoints =
00195 myTransferFunction->GetRGBPoints();
00196 MITK_TEST_CONDITION_REQUIRED(
00197 (newRGBPoints.size() == 4)
00198 && (fabs(newRGBPoints[3].first - 4.0) < 1.0e-5)
00199 && (fabs(newRGBPoints[3].second[0] - 0.6) < 1.0e-5)
00200 && (fabs(newRGBPoints[3].second[1] - 0.5) < 1.0e-5)
00201 && (fabs(newRGBPoints[3].second[2] - 0.4) < 1.0e-5),
00202 "Retrieving copy of color transfer function points (checking for correct content and size)" );
00203
00204
00205
00206
00207 myTransferFunction->ClearScalarOpacityPoints();
00208 MITK_TEST_CONDITION_REQUIRED(
00209 myTransferFunction->GetScalarOpacityPoints().size() == 0,
00210 "Clearing scalar opacity points (resulting array should be empty)" );
00211
00212 myTransferFunction->ClearGradientOpacityPoints();
00213 MITK_TEST_CONDITION_REQUIRED(
00214 myTransferFunction->GetGradientOpacityPoints().size() == 0,
00215 "Clearing gradient opacity points (resulting array should be empty)" );
00216
00217 myTransferFunction->ClearRGBPoints();
00218 MITK_TEST_CONDITION_REQUIRED(
00219 myTransferFunction->GetRGBPoints().size() == 0,
00220 "Clearing color transfer function points (resulting array should be empty)" );
00221
00222
00223 mitk::TransferFunction::Pointer dummyTransferFunction = mitk::TransferFunction::New();
00224 mitk::TransferFunctionInitializer::Pointer transferInit = mitk::TransferFunctionInitializer::New(dummyTransferFunction);
00225 MITK_TEST_CONDITION_REQUIRED(
00226 transferInit->GetTransferFunction().IsNotNull(),
00227 "Testing if Transferfunction is set" );
00228 MITK_TEST_CONDITION_REQUIRED(
00229 transferInit->GetTransferFunction() == dummyTransferFunction,
00230 "Testing if Transferfunction is the correct one" );
00231
00232 transferInit->SetTransferFunction(myTransferFunction);
00233
00234 MITK_TEST_CONDITION_REQUIRED(
00235 transferInit->GetTransferFunction().IsNotNull(),
00236 "Testing if Set Transferfunction works" );
00237 MITK_TEST_CONDITION_REQUIRED(
00238 transferInit->GetTransferFunction() == myTransferFunction,
00239 "Testing if Set Transferfunction sets the correct one" );
00240
00241 const int size = 8;
00242 int arPointNumbers[size][3] = {{3,1,6},
00243 {2,1,2},
00244 {4,1,5},
00245 {3,1,5},
00246 {4,1,7},
00247 {4,2,7},
00248 {4,1,4},
00249 {6,2,6}};
00250
00251 std::string names[size] = {"SetDefaultMode",
00252 "SetCtBlackWhiteMode",
00253 "SetCtThoraxLargeMode",
00254 "SetCtThoraxSmallMode",
00255 "SetCtBoneMode",
00256 "SetCtBoneGradientMode",
00257 "SetCtCardiacMode",
00258 "SetMrGenericMode"};
00259
00260 for(int i =0; i<size; i++)
00261 {
00262 transferInit->SetTransferFunctionMode(i);
00263
00264 std::cout << "Punkte: " << myTransferFunction->GetScalarOpacityFunction()->GetSize() << std::endl;
00265 MITK_TEST_CONDITION_REQUIRED(
00266 myTransferFunction->GetScalarOpacityFunction()->GetSize() == arPointNumbers[i][0],
00267 "Testing if in " << names[i] << " the Scalar Opacity Function is set" );
00268 MITK_TEST_CONDITION_REQUIRED(
00269 myTransferFunction->GetGradientOpacityFunction()->GetSize() == arPointNumbers[i][1],
00270 "Testing if in " << names[i] << " the Gradient Opacity Function is set" );
00271 MITK_TEST_CONDITION_REQUIRED(
00272 myTransferFunction->GetColorTransferFunction()->GetSize() == arPointNumbers[i][2],
00273 "Testing if in " << names[i] << " the Color Transfer Function is set" );
00274 }
00275
00276 MITK_TEST_END()
00277 }
00278