Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkLookupTable.h"
00020 #include <itkProcessObject.h>
00021 #include <itkSmartPointerForwardReference.txx>
00022
00023 #include <vtkColorTransferFunction.h>
00024 #include <vtkPiecewiseFunction.h>
00025
00026 mitk::LookupTable::LookupTable()
00027 {
00028 m_LookupTable = vtkLookupTable::New();
00029 this->SetRequestedRegionToLargestPossibleRegion();
00030 }
00031
00032
00033 mitk::LookupTable::~LookupTable()
00034 {
00035 if ( m_LookupTable )
00036 {
00037 m_LookupTable->Delete();
00038 m_LookupTable = NULL;
00039 }
00040 }
00041
00042 void mitk::LookupTable::SetVtkLookupTable( vtkLookupTable* lut )
00043 {
00044
00045 if(m_LookupTable == lut)
00046 {
00047 return;
00048 }
00049
00050 if(m_LookupTable)
00051 {
00052 m_LookupTable->UnRegister(NULL);
00053 m_LookupTable = NULL;
00054 }
00055
00056 if(lut)
00057 {
00058 lut->Register(NULL);
00059 }
00060
00061 m_LookupTable = lut;
00062 this->Modified();
00063
00064 }
00065
00066
00067
00068 void mitk::LookupTable::ChangeOpacityForAll( float opacity )
00069 {
00070
00071 int noValues = m_LookupTable->GetNumberOfTableValues ();
00072
00073 vtkFloatingPointType rgba[ 4 ];
00074
00075 for ( int i = 0;i < noValues;i++ )
00076 {
00077 m_LookupTable->GetTableValue ( i, rgba );
00078 rgba[ 3 ] = opacity;
00079 m_LookupTable->SetTableValue ( i, rgba );
00080 }
00081 this->Modified();
00082 }
00083
00084 void mitk::LookupTable::ChangeOpacity(int index, float opacity )
00085 {
00086
00087 int noValues = m_LookupTable->GetNumberOfTableValues ();
00088 if (index>noValues)
00089 {
00090 MITK_INFO << "could not change opacity. index exceed size of lut ... " << std::endl;
00091 return;
00092 }
00093
00094 vtkFloatingPointType rgba[ 4 ];
00095
00096 m_LookupTable->GetTableValue ( index, rgba );
00097 rgba[ 3 ] = opacity;
00098 m_LookupTable->SetTableValue ( index, rgba );
00099
00100 this->Modified();
00101 }
00102
00103
00104 vtkLookupTable* mitk::LookupTable::GetVtkLookupTable() const
00105 {
00106 return m_LookupTable;
00107 };
00108
00109 mitk::LookupTable::RawLookupTableType * mitk::LookupTable::GetRawLookupTable() const
00110 {
00111
00112 if (m_LookupTable==NULL) MITK_INFO << "uuups..." << std::endl;
00113 return m_LookupTable->GetPointer( 0 );
00114 };
00115
00119 bool mitk::LookupTable::operator==( const mitk::LookupTable& other ) const
00120 {
00121 if ( m_LookupTable == other.GetVtkLookupTable())
00122 return true;
00123 vtkLookupTable* olut = other.GetVtkLookupTable();
00124 if (olut == NULL)
00125 return false;
00126
00127 bool equal = (m_LookupTable->GetNumberOfColors() == olut->GetNumberOfColors())
00128 && (m_LookupTable->GetTableRange()[0] == olut->GetTableRange()[0])
00129 && (m_LookupTable->GetTableRange()[1] == olut->GetTableRange()[1])
00130 && (m_LookupTable->GetHueRange()[0] == olut->GetHueRange()[0])
00131 && (m_LookupTable->GetHueRange()[1] == olut->GetHueRange()[1])
00132 && (m_LookupTable->GetSaturationRange()[0] == olut->GetSaturationRange()[0])
00133 && (m_LookupTable->GetSaturationRange()[1] == olut->GetSaturationRange()[1])
00134 && (m_LookupTable->GetValueRange()[0] == olut->GetValueRange()[0])
00135 && (m_LookupTable->GetValueRange()[1] == olut->GetValueRange()[1])
00136 && (m_LookupTable->GetAlphaRange()[0] == olut->GetAlphaRange()[0])
00137 && (m_LookupTable->GetAlphaRange()[1] == olut->GetAlphaRange()[1])
00138 && (m_LookupTable->GetRamp() == olut->GetRamp())
00139 && (m_LookupTable->GetScale() == olut->GetScale())
00140 && (m_LookupTable->GetAlpha() == olut->GetAlpha())
00141 && (m_LookupTable->GetTable()->GetNumberOfTuples() == olut->GetTable()->GetNumberOfTuples());
00142 if (equal == false)
00143 return false;
00144
00145
00146
00147
00148
00149 for (vtkIdType i=0; i < m_LookupTable->GetNumberOfTableValues(); i++)
00150 {
00151 bool tvequal = (m_LookupTable->GetTableValue(i)[0] == olut->GetTableValue(i)[0])
00152 && (m_LookupTable->GetTableValue(i)[1] == olut->GetTableValue(i)[1])
00153 && (m_LookupTable->GetTableValue(i)[2] == olut->GetTableValue(i)[2])
00154 && (m_LookupTable->GetTableValue(i)[3] == olut->GetTableValue(i)[3]);
00155 if (tvequal == false)
00156 return false;
00157 }
00158 return true;
00159 }
00160
00164 bool mitk::LookupTable::operator!=( const mitk::LookupTable& other ) const
00165 {
00166 return !(*this == other);
00167 }
00168
00172 mitk::LookupTable& mitk::LookupTable::operator=( const mitk::LookupTable& LookupTable )
00173 {
00174 if ( this == &LookupTable )
00175 {
00176 return * this;
00177 }
00178 else
00179 {
00180 m_LookupTable = LookupTable.GetVtkLookupTable();
00181 return *this;
00182 }
00183 }
00184
00185 void mitk::LookupTable::UpdateOutputInformation( )
00186 {
00187 if ( this->GetSource( ) )
00188 {
00189 this->GetSource( ) ->UpdateOutputInformation( );
00190 }
00191 }
00192
00193
00194 void mitk::LookupTable::SetRequestedRegionToLargestPossibleRegion( )
00195 {}
00196
00197
00198 bool mitk::LookupTable::RequestedRegionIsOutsideOfTheBufferedRegion( )
00199 {
00200 return false;
00201 }
00202
00203
00204 bool mitk::LookupTable::VerifyRequestedRegion( )
00205 {
00206
00207
00208
00209
00210 return true;
00211 }
00212
00213
00214 void mitk::LookupTable::SetRequestedRegion( itk::DataObject *)
00215 {
00216
00217
00218 }
00219
00220 void mitk::LookupTable::CreateColorTransferFunction(vtkColorTransferFunction*& colorFunction)
00221 {
00222 if(colorFunction==NULL)
00223 colorFunction = vtkColorTransferFunction::New();
00224
00225 mitk::LookupTable::RawLookupTableType *rgba = GetRawLookupTable();
00226 int i, num_of_values=m_LookupTable->GetNumberOfTableValues();
00227
00228
00229 vtkFloatingPointType *cols;
00230 vtkFloatingPointType *colsHead;
00231 colsHead=cols=(vtkFloatingPointType *)malloc(sizeof(vtkFloatingPointType)*num_of_values*3);
00232
00233 for(i=0;i<num_of_values;++i)
00234 {
00235 *cols=*rgba/255.0; ++cols; ++rgba;
00236 *cols=*rgba/255.0; ++cols; ++rgba;
00237 *cols=*rgba/255.0; ++cols; ++rgba;
00238 ++rgba;
00239 }
00240 colorFunction->BuildFunctionFromTable(m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values-1, colsHead);
00241
00242 free(colsHead);
00243 }
00244
00245 void mitk::LookupTable::CreateOpacityTransferFunction(vtkPiecewiseFunction*& opacityFunction)
00246 {
00247 if(opacityFunction==NULL)
00248 opacityFunction = vtkPiecewiseFunction::New();
00249
00250 mitk::LookupTable::RawLookupTableType *rgba = GetRawLookupTable();
00251 int i, num_of_values=m_LookupTable->GetNumberOfTableValues();
00252
00253 vtkFloatingPointType *alphas;
00254 vtkFloatingPointType *alphasHead;
00255 alphasHead=alphas=(vtkFloatingPointType*)malloc(sizeof(vtkFloatingPointType)*num_of_values);
00256
00257 rgba+=3;
00258 for(i=0;i<num_of_values;++i)
00259 {
00260 *alphas=*rgba * 1024.0; ++alphas; rgba+=4;
00261 }
00262
00263 opacityFunction->BuildFunctionFromTable(m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values-1, alphasHead);
00264
00265 free(alphasHead);
00266 }
00267
00268 void mitk::LookupTable::CreateGradientTransferFunction(vtkPiecewiseFunction*& gradientFunction)
00269 {
00270 if(gradientFunction==NULL)
00271 gradientFunction = vtkPiecewiseFunction::New();
00272
00273 mitk::LookupTable::RawLookupTableType *rgba = GetRawLookupTable();
00274 int i, num_of_values=m_LookupTable->GetNumberOfTableValues();
00275
00276 vtkFloatingPointType *alphas;
00277 vtkFloatingPointType *alphasHead;
00278 alphasHead=alphas=(vtkFloatingPointType*)malloc(sizeof(vtkFloatingPointType)*num_of_values);
00279
00280 rgba+=3;
00281 for(i=0;i<num_of_values;++i)
00282 {
00283 *alphas=*rgba * 1024.0; ++alphas; rgba+=4;
00284 }
00285
00286 gradientFunction->BuildFunctionFromTable(m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values-1, alphasHead);
00287
00288 free(alphasHead);
00289 }