- static const double _0 = double( 0 );
- static const double _1 = double( 1 );
- static const double _2 = double( 2 );
- static const double _4 = double( 4 );
- static const double _6 = double( 6 );
- static const double _OPACITY = double( 0.6 );
-
- // Configure LUT
- vtkSmartPointer< vtkImageMapToColors > new_map( NULL );
- if( data->GetNumberOfScalarComponents( ) == 1 )
- {
- double range[ 2 ];
- data->GetScalarRange( range );
- if( lut_t == Self::LUTType_WindowLevel )
- {
- vtkSmartPointer< vtkWindowLevelLookupTable > lut =
- vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
- lut->SetScaleToLinear( );
- lut->SetTableRange( range );
- lut->SetWindow( range[ 1 ] - range[ 0 ] );
- lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) );
- lut->Build( );
-
- new_map = vtkSmartPointer< vtkImageMapToColors >::New( );
- new_map->SetLookupTable( lut );
- }
- else if( lut_t == LUTType_Colors )
- {
- // Get HSV from display color
- double r = 1, g = 0, b = 0;
- double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax;
- double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin;
- double d = cmax - cmin;
-
- double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0;
- double value = cmax;
- double hue = _0;
- if( d > _0 )
- {
- if( r == cmax )
- hue = std::fmod( ( g - b ) / d, _6 );
- else if( g == cmax )
- hue = ( ( b - r ) / d ) + _2;
- else if( b == cmax )
- hue = ( ( r - g ) / d ) + _4;
- hue *= _1 / _6;
-
- } // fi
-
- // Define new lookup table
- vtkSmartPointer< vtkLookupTable > lut =
- vtkSmartPointer< vtkLookupTable >::New( );
- lut->SetScaleToLinear( );
- lut->SetNanColor( _0, _0, _0, _0 );
- lut->SetTableRange( range[ 0 ], range[ 1 ] );
- lut->SetAlphaRange( _0, _OPACITY );
- lut->SetHueRange( _0, hue );
- lut->SetSaturationRange( _0, saturation );
- lut->SetValueRange( _0, value );
- lut->Build( );
-
- new_map = vtkSmartPointer< vtkImageMapToColors >::New( );
- new_map->SetLookupTable( lut );
-
- } // fi
-
- } // fi
- this->ImageMaps.push_back( new_map );