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 >= 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 );
102 // -------------------------------------------------------------------------
103 unsigned int cpExtensions::Visualization::LUTImageActor::
104 AddImage( vtkImageData* image, double r, double g, double b, double a )
108 this->m_Images.push_back( image );
109 this->SetLUTColor( this->m_Images.size( ), r, g, b, a );
110 this->m_Blender->AddInputData( image );
112 if( this->m_Images.size( ) == 1 )
115 SetInputConnection( this->m_Blender->GetOutputPort( ) );
117 SetInputConnection( this->m_ImageMap->GetOutputPort( ) );
120 this->m_Blender->Modified( );
121 this->m_ImageMap->Modified( );
124 this->GetProperty( )->SetInterpolationTypeToNearest( );
127 return( this->m_Images.size( ) );
130 // -------------------------------------------------------------------------
131 cpExtensions::Visualization::LUTImageActor::
135 this->m_LUT = vtkSmartPointer< vtkLookupTable >::New( );
136 this->m_LUT->SetNumberOfTableValues( 1 );
137 this->m_LUT->SetNanColor( 0, 0, 0, 0 );
138 this->m_LUT->SetTableValue( 0, 0, 0, 0, 0 );
140 this->m_Blender = vtkSmartPointer< _TImageBlender >::New( );
141 this->m_ImageMap = vtkSmartPointer< vtkImageMapToColors >::New( );
142 this->m_ImageMap->SetLookupTable( this->m_LUT );
145 // -------------------------------------------------------------------------
146 cpExtensions::Visualization::LUTImageActor::