]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/LUTImageActor.cxx
1c9f9fac49cfbdfa6628f99ee96747d9d6753794
[cpPlugins.git] / lib / cpExtensions / Visualization / LUTImageActor.cxx
1 #include <cpExtensions/Visualization/LUTImageActor.h>
2 #include <cpExtensions/Visualization/ImageSliceMapper.h>
3
4 #include <vtkImageData.h>
5 #include <vtkImageMapToColors.h>
6 #include <vtkImageProperty.h>
7 #include <vtkLookupTable.h>
8 #include <cpExtensions/Algorithms/ImageBlender.h>
9
10 // -------------------------------------------------------------------------
11 cpExtensions::Visualization::LUTImageActor::
12 Self* cpExtensions::Visualization::LUTImageActor::
13 New( )
14 {
15   return( new Self( ) );
16 }
17
18 // -------------------------------------------------------------------------
19 unsigned int cpExtensions::Visualization::LUTImageActor::
20 GetNumberOfImages( ) const
21 {
22   return( this->m_Images.size( ) );
23 }
24
25 // -------------------------------------------------------------------------
26 vtkImageData* cpExtensions::Visualization::LUTImageActor::
27 GetImage( unsigned int id )
28 {
29   if( id < this->m_Images.size( ) )
30     return( this->m_Images[ id ] );
31   else
32     return( NULL );
33 }
34
35 // -------------------------------------------------------------------------
36 const vtkImageData* cpExtensions::Visualization::LUTImageActor::
37 GetImage( unsigned int id ) const
38 {
39   if( id < this->m_Images.size( ) )
40     return( this->m_Images[ id ] );
41   else
42     return( NULL );
43 }
44
45 // -------------------------------------------------------------------------
46 unsigned int cpExtensions::Visualization::LUTImageActor::
47 GetImageId( vtkImageData* image ) const
48 {
49   unsigned int i = 0;
50   bool f = false;
51   while( i < this->m_Images.size( ) && !f )
52   {
53     if( this->m_Images[ i ].GetPointer( ) == image )
54       f = true;
55     else
56       i++;
57
58   } // elihw
59   return( i );
60 }
61
62 // -------------------------------------------------------------------------
63 void cpExtensions::Visualization::LUTImageActor::
64 GetLUTColor(
65   unsigned int id, double& r, double& g, double& b, double& a
66   ) const
67 {
68   double rgba[ 4 ];
69   this->m_LUT->GetTableValue( id, rgba );
70   r = rgba[ 0 ];
71   g = rgba[ 1 ];
72   b = rgba[ 2 ];
73   a = rgba[ 3 ];
74 }
75
76 // -------------------------------------------------------------------------
77 void cpExtensions::Visualization::LUTImageActor::
78 GetLUTColor(
79   vtkImageData* image, double& r, double& g, double& b, double& a
80   ) const
81 {
82   this->GetLUTColor( this->GetImageId( image ), r, g, b, a );
83 }
84
85 // -------------------------------------------------------------------------
86 void cpExtensions::Visualization::LUTImageActor::
87 SetLUTColor( unsigned int id, double r, double g, double b, double a )
88 {
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( );
93 }
94
95 // -------------------------------------------------------------------------
96 void cpExtensions::Visualization::LUTImageActor::
97 SetLUTColor( vtkImageData* image, double r, double g, double b, double a )
98 {
99   this->SetLUTColor( this->GetImageId( image ), r, g, b, a );
100 }
101
102 // -------------------------------------------------------------------------
103 unsigned int cpExtensions::Visualization::LUTImageActor::
104 AddImage( vtkImageData* image, double r, double g, double b, double a )
105 {
106   if( image != NULL )
107   {
108     this->m_Images.push_back( image );
109     this->SetLUTColor( this->m_Images.size( ), r, g, b, a );
110     this->m_Blender->AddInputData( image );
111
112     if( this->m_Images.size( ) == 1 )
113     {
114       this->m_ImageMap->
115         SetInputConnection( this->m_Blender->GetOutputPort( ) );
116       this->m_Mapper->
117         SetInputConnection( this->m_ImageMap->GetOutputPort( ) );
118
119     } // fi
120     this->m_Blender->Modified( );
121     this->m_ImageMap->Modified( );
122     this->Modified( );
123
124     this->GetProperty( )->SetInterpolationTypeToNearest( );
125
126   } // fi
127   return( this->m_Images.size( ) );
128 }
129
130 // -------------------------------------------------------------------------
131 cpExtensions::Visualization::LUTImageActor::
132 LUTImageActor( )
133   : Superclass( )
134 {
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 );
139
140   this->m_Blender = vtkSmartPointer< _TImageBlender >::New( );
141   this->m_ImageMap = vtkSmartPointer< vtkImageMapToColors >::New( );
142   this->m_ImageMap->SetLookupTable( this->m_LUT );
143 }
144
145 // -------------------------------------------------------------------------
146 cpExtensions::Visualization::LUTImageActor::
147 ~LUTImageActor( )
148 {
149 }
150
151 // eof - $RCSfile$