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 "mitkUSLookupTableSource.h"
00020 #include <mitkIpPic.h>
00021 #include <vtkLookupTable.h>
00022 #include <fstream>
00023
00024
00025 extern "C"
00026 {
00027 #include "uscfunctions/usc.h"
00028 }
00029
00030
00031 mitk::USLookupTableSource::~USLookupTableSource()
00032 {}
00033
00034
00035 mitk::USLookupTableSource::USLookupTableSource() : mitk::LookupTableSource()
00036 {
00037
00038 std::cout << "creating USLookupTableSource ... " << std::endl;
00039 m_Mode = DefaultLUT;
00040 m_LookupTable = NULL;
00041
00042 this->Modified();
00043 std::cout << "creating USLookupTableSource OK! " << std::endl;
00044 }
00045
00046
00047 void mitk::USLookupTableSource::GenerateData()
00048 {
00049 std::cout << "USLookupTableSource::generate data!" << std::endl;
00050 OutputType::Pointer output = this->GetOutput();
00051 output->SetVtkLookupTable( this->BuildVtkLookupTable( ) );
00052 }
00053
00054 vtkLookupTable* mitk::USLookupTableSource::BuildDSRDopplerLookupTable()
00055 {
00056
00057 std::cout << " creating HP LookupTable ... " << std::endl;
00058
00059 mitkIpPicDescriptor *HPMap;
00060
00061 char MapFilename[ 20 ] = "a.map";
00062 int failed ;
00063
00064 ifstream infile ( MapFilename, ios::in );
00065 failed = infile.fail() ;
00066 infile.close() ;
00067
00068 if ( !failed )
00069 {
00070 std::cout << " reading a.map ... " << std::endl;
00071 HPMap = usReadMap( "a.map", ".", -1000, -1000 );
00072
00073 vtkLookupTable *vtkLookupTable = vtkLookupTable::New();
00074 mitkIpUInt1_t *data = ( ( mitkIpUInt1_t * ) HPMap->data );
00075
00076 vtkLookupTable->SetTableRange(0,255);
00077
00078 int LookupTablesize = 256;
00079 vtkFloatingPointType rgba[ 4 ];
00080
00081 vtkLookupTable->SetNumberOfColors( LookupTablesize );
00082 for ( int i = 0; i < LookupTablesize; i++ )
00083 {
00084 rgba[ 0 ] = ( ( mitkIpUInt1_t * ) data ) [ 0 + i * 3 * LookupTablesize ] / 255.0f;
00085 rgba[ 1 ] = ( ( mitkIpUInt1_t * ) data ) [ 1 + i * 3 * LookupTablesize ] / 255.0f ;
00086 rgba[ 2 ] = ( ( mitkIpUInt1_t * ) data ) [ 2 + i * 3 * LookupTablesize ] / 255.0f ;
00087 rgba[ 3 ] = 1;
00088 vtkLookupTable->SetTableValue ( i, rgba );
00089 }
00090
00091 return ( vtkLookupTable );
00092
00093 }
00094
00095
00096 else
00097 {
00098 std::cout << " no a.map available! creating custom Doppler LookUpTable ... " << std::endl;
00099
00100 vtkLookupTable *vtkLookupTable = vtkLookupTable::New();
00101 vtkLookupTable->SetTableRange(0,255);
00102
00103 int size = 256;
00104 int lutSize = 256;
00105 int repeats = lutSize / size;
00106
00107 int factor = 1;
00108 int i, n;
00109
00110 vtkFloatingPointType rgba[ 4 ];
00111
00112
00113
00114
00115 int quartalSize = size / 4;
00116
00117 int index;
00118
00119 for ( i = 1; i <= quartalSize ; i++ )
00120 {
00121 for ( n = 0; n < repeats ; n++ )
00122 {
00123
00124 index = ( i - 1 ) * repeats + n;
00125 rgba[ 0 ] = 0;
00126 rgba[ 1 ] = 1 - i / 2.0 / quartalSize;
00127 rgba[ 2 ] = 1;
00128 rgba[ 3 ] = factor * 1;
00129 vtkLookupTable->SetTableValue ( index, rgba );
00130 }
00131 }
00132
00133
00134 for ( i = 1; i <= quartalSize ; i++ )
00135 {
00136 for ( n = 0; n < repeats ; n++ )
00137 {
00138
00139 index = ( i - 1 ) * repeats + repeats * quartalSize + n;
00140 rgba[ 0 ] = 0;
00141 rgba[ 1 ] = 0.5 - i / 2.0 / quartalSize;
00142 rgba[ 2 ] = 1 - i / ( float ) ( 2 * quartalSize );
00143 rgba[ 3 ] = factor * 1;
00144 vtkLookupTable->SetTableValue ( index, rgba );
00145 }
00146 }
00147
00148
00149
00150
00151 for ( i = 1; i <= quartalSize ; i++ )
00152 {
00153 for ( n = 0; n < repeats ; n++ )
00154 {
00155
00156 index = ( i - 1 ) * repeats + ( 2 * repeats * quartalSize ) + n;
00157 rgba[ 0 ] = 0.5 + i / ( float ) ( 2 * quartalSize );
00158 rgba[ 1 ] = i / 2.0 / quartalSize;
00159 rgba[ 2 ] = 0;
00160 rgba[ 3 ] = factor * 1;
00161 vtkLookupTable->SetTableValue ( index, rgba );
00162 }
00163 }
00164
00165
00166
00167 for ( i = 1; i <= quartalSize ; i++ )
00168 {
00169 for ( n = 0; n < repeats ; n++ )
00170 {
00171
00172 index = ( i - 1 ) * repeats + ( 3 * repeats * quartalSize ) + n;
00173 rgba[ 0 ] = 1;
00174 rgba[ 1 ] = 0.5 + i / 2.0 / quartalSize;
00175 rgba[ 2 ] = 0;
00176 rgba[ 3 ] = factor * 1;
00177 vtkLookupTable->SetTableValue ( index, rgba );
00178 }
00179 }
00180
00181
00182
00183 index = 0;
00184 rgba[ 0 ] = 0;
00185 rgba[ 1 ] = 0;
00186 rgba[ 2 ] = 0;
00187 rgba[ 3 ] = factor * 1;
00188 vtkLookupTable->SetTableValue( index, rgba );
00189
00190 int mapZeroVelocityToBlack = 1;
00191 if ( mapZeroVelocityToBlack == 1 )
00192 {
00193
00194
00195 rgba[ 0 ] = 0;
00196 rgba[ 1 ] = 0;
00197 rgba[ 2 ] = 0;
00198 rgba[ 3 ] = factor * 1;
00199 index = lutSize / 2 ;
00200 vtkLookupTable->SetTableValue( index, rgba );
00201
00202
00203
00204 vtkLookupTable->SetTableValue( index, rgba );
00205 }
00206
00207
00208
00209
00210
00211
00212
00213 return( vtkLookupTable );
00214
00215 }
00216 }
00217
00218
00219 vtkLookupTable* mitk::USLookupTableSource::BuildStrainRateLookupTable()
00220 {
00221 std::cout << " creating StrainRate LookupTable ... " << std::endl;
00222 vtkLookupTable *vtkLookupTable = vtkLookupTable::New();
00223
00224 vtkLookupTable->SetTableRange(0,255);
00225
00226 int lutSize = 256;
00227 vtkLookupTable->SetNumberOfTableValues(lutSize);
00228
00229
00230
00231 vtkFloatingPointType rgba[ 4 ];
00232
00233 float quartal = lutSize / 8.0f;
00234
00235 float sizeQuartal1 = 3 * quartal;
00236
00237 float sizeQuartal2 = 0.9375 * quartal;
00238 float sizeZeroStrain = 0.125 * quartal;
00239 float sizeQuartal3 = 0.9375 * quartal;
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 float sizeQuartal4 = 3 * quartal;
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 int factor = 1;
00261 int i;
00262
00263
00264 for ( i = 1; i <= sizeQuartal1; i++ )
00265 {
00266 int index = i - 1;
00267 rgba[ 0 ] = factor * ( 0.5 + i / ( 2 * sizeQuartal1 ) );
00268 rgba[ 1 ] = factor * 0;
00269 rgba[ 2 ] = factor * 0;
00270 rgba[ 3 ] = factor * 1;
00271 vtkLookupTable->SetTableValue ( index, rgba );
00272 }
00273
00274
00275 for ( i = 1 ; i <= sizeQuartal2 ; i++ )
00276 {
00277 int index = ( i - 1 ) + ( int ) sizeQuartal1;
00278 rgba[ 0 ] = factor * 1;
00279 rgba[ 1 ] = factor * ( i / sizeQuartal2 );
00280 rgba[ 2 ] = factor * 0;
00281 rgba[ 3 ] = factor * 1;
00282 vtkLookupTable->SetTableValue ( index, rgba );
00283 }
00284
00285
00286
00287 for ( i = 1 ; i <= sizeZeroStrain ; i++ )
00288 {
00289 int index = ( i - 1 ) + ( int ) ( sizeQuartal1 + sizeQuartal2 );
00290 rgba[ 0 ] = factor * 0;
00291 rgba[ 1 ] = factor * 1;
00292 rgba[ 2 ] = factor * 0;
00293 rgba[ 3 ] = factor * 1;
00294 vtkLookupTable->SetTableValue ( index, rgba );
00295 }
00296
00297
00298
00299 for ( i = 1 ; i <= sizeQuartal3; i++ )
00300 {
00301 int index = ( i - 1 ) + ( int ) ( sizeQuartal1 + sizeQuartal2 + sizeZeroStrain );
00302 rgba[ 0 ] = factor * 0;
00303 rgba[ 1 ] = factor * ( 1 - i / sizeQuartal3 );
00304 rgba[ 2 ] = factor * 1;
00305 rgba[ 3 ] = factor * 1;
00306 vtkLookupTable->SetTableValue ( index, rgba );
00307 }
00308
00309
00310 for ( i = 1 ; i <= sizeQuartal4 ; i++ )
00311 {
00312 int index = ( i - 1 ) + ( int ) ( sizeQuartal1 + sizeQuartal2 + sizeQuartal3 + sizeZeroStrain );
00313 rgba[ 0 ] = factor * 0;
00314 rgba[ 1 ] = factor * 0;
00315 rgba[ 2 ] = factor * ( 1 - i / sizeQuartal4 );
00316 rgba[ 3 ] = factor * 1;
00317 vtkLookupTable->SetTableValue ( index, rgba );
00318
00319 }
00320
00321
00322
00323 int index = 0;
00324 rgba[ 0 ] = 0;
00325 rgba[ 1 ] = 0;
00326 rgba[ 2 ] = 0;
00327 rgba[ 3 ] = factor * 1;
00328 vtkLookupTable->SetTableValue ( index, rgba );
00329 vtkLookupTable->SetTableValue ( index + 1, rgba );
00330
00331 bool mapZeroStrainRateToBlack = true;
00332 if ( mapZeroStrainRateToBlack )
00333 {
00334
00335
00336 rgba[ 0 ] = 0;
00337 rgba[ 1 ] = 0;
00338 rgba[ 2 ] = 0;
00339 rgba[ 3 ] = factor * 1;
00340
00341
00342 index = 128 ;
00343 std::cout << " setting table value " << index << " to zero " << std::endl;
00344
00345 vtkLookupTable->SetTableValue( index, rgba );
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 return( vtkLookupTable );
00371
00372 }
00373
00374 vtkLookupTable* mitk::USLookupTableSource::BuildDefaultLookupTable(){
00375
00376 std::cout << " creating default LookupTable... " << std::endl;
00377 vtkLookupTable *vtkLookupTable = vtkLookupTable::New();
00378 int size = 256;
00379 vtkLookupTable->SetTableRange(0,255);
00380 vtkLookupTable->SetNumberOfColors( size );
00381 vtkLookupTable->Build();
00382 return( vtkLookupTable );
00383
00384 }
00385
00386
00387 vtkLookupTable* mitk::USLookupTableSource::BuildVtkLookupTable()
00388 {
00389
00390 std::cout << "mitk::USLookupTableSource::BuildVtkLookupTable() ... " << std::endl;
00391
00392 if ( m_Mode == DSRDoppler )
00393 {
00394 return BuildDSRDopplerLookupTable();
00395 }
00396 else if ( m_Mode == StrainRate )
00397 {
00398 return BuildStrainRateLookupTable();
00399 }
00400 else
00401 {
00402 return BuildDefaultLookupTable();
00403 }
00404
00405
00406 }
00407
00408
00409