]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/LUTImageActor.cxx
Windows compilation: 3/3
[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 >= ( 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( );
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 // TODO: !!!!!
103 #include <vtkImageCast.h>
104
105 // -------------------------------------------------------------------------
106 unsigned int cpExtensions::Visualization::LUTImageActor::
107 AddImage( vtkImageData* image, double r, double g, double b, double a )
108 {
109   static vtkSmartPointer< vtkImageCast > cast;
110   cast = vtkSmartPointer< vtkImageCast >::New( );
111
112   if( image != NULL )
113   {
114     cast->SetOutputScalarTypeToUnsignedChar( );
115     cast->SetInputData( image );
116     cast->Update( );
117
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( );
122
123     if( this->m_Images.size( ) == 1 )
124     {
125       this->m_ImageMap->
126         SetInputConnection( this->m_Blender->GetOutputPort( ) );
127       this->m_Mapper->
128         SetInputConnection( this->m_ImageMap->GetOutputPort( ) );
129
130     } // fi
131     this->Modified( );
132
133     this->GetProperty( )->SetInterpolationTypeToNearest( );
134
135   } // fi
136   return( this->m_Images.size( ) );
137 }
138
139 // -------------------------------------------------------------------------
140 cpExtensions::Visualization::LUTImageActor::
141 LUTImageActor( )
142   : Superclass( )
143 {
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 );
148
149   this->m_Blender = vtkSmartPointer< _TImageBlender >::New( );
150   this->m_ImageMap = vtkSmartPointer< vtkImageMapToColors >::New( );
151   this->m_ImageMap->SetLookupTable( this->m_LUT );
152 }
153
154 // -------------------------------------------------------------------------
155 cpExtensions::Visualization::LUTImageActor::
156 ~LUTImageActor( )
157 {
158 }
159
160 // eof - $RCSfile$