1 #include <cpExtensions/Visualization/LUTImageActor.h>
2 #include <cpExtensions/Visualization/ImageSliceMapper.h>
4 #include <vtkImageData.h>
5 #include <vtkImageMapToColors.h>
6 #include <vtkImageProperty.h>
7 #include <vtkLookupTable.h>
8 #include <cpExtensions/Algorithms/ImageBlender.h>
10 // -------------------------------------------------------------------------
11 cpExtensions::Visualization::LUTImageActor::
12 Self* cpExtensions::Visualization::LUTImageActor::
15 return( new Self( ) );
18 // -------------------------------------------------------------------------
19 unsigned int cpExtensions::Visualization::LUTImageActor::
20 GetNumberOfImages( ) const
22 return( this->m_Images.size( ) );
25 // -------------------------------------------------------------------------
26 vtkImageData* cpExtensions::Visualization::LUTImageActor::
27 GetImage( unsigned int id )
29 if( id < this->m_Images.size( ) )
30 return( this->m_Images[ id ] );
35 // -------------------------------------------------------------------------
36 const vtkImageData* cpExtensions::Visualization::LUTImageActor::
37 GetImage( unsigned int id ) const
39 if( id < this->m_Images.size( ) )
40 return( this->m_Images[ id ] );
45 // -------------------------------------------------------------------------
46 unsigned int cpExtensions::Visualization::LUTImageActor::
47 GetImageId( vtkImageData* image ) const
51 while( i < this->m_Images.size( ) && !f )
53 if( this->m_Images[ i ].GetPointer( ) == image )
62 // -------------------------------------------------------------------------
63 void cpExtensions::Visualization::LUTImageActor::
65 unsigned int id, double& r, double& g, double& b, double& a
69 this->m_LUT->GetTableValue( id, rgba );
76 // -------------------------------------------------------------------------
77 void cpExtensions::Visualization::LUTImageActor::
79 vtkImageData* image, double& r, double& g, double& b, double& a
82 this->GetLUTColor( this->GetImageId( image ), r, g, b, a );
85 // -------------------------------------------------------------------------
86 void cpExtensions::Visualization::LUTImageActor::
87 SetLUTColor( unsigned int id, double r, double g, double b, double a )
89 if( id >= ( unsigned int )( this->m_LUT->GetNumberOfTableValues( ) ) )
90 this->m_LUT->SetNumberOfTableValues( id + 1 );
91 this->m_LUT->SetTableValue( id, r, g, b, a );
92 this->m_LUT->Modified( );
95 // -------------------------------------------------------------------------
96 void cpExtensions::Visualization::LUTImageActor::
97 SetLUTColor( vtkImageData* image, double r, double g, double b, double a )
99 this->SetLUTColor( this->GetImageId( image ), r, g, b, a );
103 #include <vtkImageCast.h>
105 // -------------------------------------------------------------------------
106 unsigned int cpExtensions::Visualization::LUTImageActor::
107 AddImage( vtkImageData* image, double r, double g, double b, double a )
109 static vtkSmartPointer< vtkImageCast > cast;
110 cast = vtkSmartPointer< vtkImageCast >::New( );
114 cast->SetOutputScalarTypeToUnsignedChar( );
115 cast->SetInputData( image );
118 this->m_Images.push_back( image );
119 this->SetLUTColor( this->m_Images.size( ), r, g, b, a );
120 this->m_Blender->AddInputData( cast->GetOutput( ) );
121 this->m_Blender->Update( );
123 if( this->m_Images.size( ) == 1 )
126 SetInputConnection( this->m_Blender->GetOutputPort( ) );
128 SetInputConnection( this->m_ImageMap->GetOutputPort( ) );
133 this->GetProperty( )->SetInterpolationTypeToNearest( );
136 return( this->m_Images.size( ) );
139 // -------------------------------------------------------------------------
140 cpExtensions::Visualization::LUTImageActor::
144 this->m_LUT = vtkSmartPointer< vtkLookupTable >::New( );
145 this->m_LUT->SetNumberOfTableValues( 1 );
146 this->m_LUT->SetNanColor( 0, 0, 0, 0 );
147 this->m_LUT->SetTableValue( 0, 0, 0, 0, 0 );
149 this->m_Blender = vtkSmartPointer< _TImageBlender >::New( );
150 this->m_ImageMap = vtkSmartPointer< vtkImageMapToColors >::New( );
151 this->m_ImageMap->SetLookupTable( this->m_LUT );
154 // -------------------------------------------------------------------------
155 cpExtensions::Visualization::LUTImageActor::