]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
c079604b5debfe8a5eecf4536ee736a64003267f
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
1
2 /**
3  *  \file 
4  *  \brief Class bbtk::ThresholdImageView . 
5  */
6
7 #include "LayerImageBase.h"
8
9 LayerImageBase::LayerImageBase()
10 {
11         _actorPresent                   =       false;
12         _Z                                              =       0;
13         _thresholdTable                 =       NULL;
14         _thresholdMapper                =       NULL;
15         _thresholdActor                 =       NULL;
16         _image                                  =       NULL;
17         _imageReslicer                  =       vtkImageReslice::New();
18
19 }
20
21 //----------------------------------------------------------------------------
22   LayerImageBase::~LayerImageBase()
23   {
24   }
25
26 //----------------------------------------------------------------------------
27 void LayerImageBase::SetZ(int z)
28 {
29         _Z = z;
30 }
31
32 //----------------------------------------------------------------------------
33 int LayerImageBase::GetZ()  // virtual
34 {
35         return _Z;
36 }
37
38 //----------------------------------------------------------------------------
39 vtkImageData* LayerImageBase::GetImage()
40 {
41         return _image;
42 }
43
44 //----------------------------------------------------------------------------
45 bool LayerImageBase::GetActorPresent()
46 {
47         return _actorPresent;
48 }
49
50
51
52 //----------------------------------------------------------------------------
53 void LayerImageBase::SetImage(vtkImageData* image)
54 {
55         _image = image;
56 }
57
58 //----------------------------------------------------------------------------
59 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
60 {
61         _baseView = baseview;
62 }
63
64 //----------------------------------------------------------------------------
65 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
66 {
67         return _baseView;
68 }
69
70
71
72 //----------------------------------------------------------------------------
73 vtkLookupTable* LayerImageBase::GetThresholdTable()
74 {
75         return _thresholdTable;
76 }
77
78 //----------------------------------------------------------------------------
79 int LayerImageBase::CleanZ(int z)
80
81         int ext[6];
82         _image->GetWholeExtent(ext);
83
84         if (z<0)
85         {
86                 z=0;
87         }
88
89         if ( z > (ext[5]-ext[4]) )
90         {
91                 z=ext[5]-ext[4];
92         }
93
94         return z;
95 }
96
97 //----------------------------------------------------------------------------
98 void LayerImageBase::onThreshold()
99 {
100
101         if (_image!=NULL)
102         {
103                 int z=CleanZ( GetZ() );
104
105                 if (!GetActorPresent())
106                 {                               
107                         if (_thresholdTable==NULL)
108                         {
109                                 //Lookup Table
110                                 _thresholdTable = vtkLookupTable::New();
111                         } // _thresholdTable
112                         
113                         if (_thresholdMapper==NULL)
114                         {
115                                 _thresholdMapper = vtkImageMapToColors::New( );
116                         }
117                         
118                         if (_thresholdActor==NULL)
119                         {
120                                 _thresholdActor = vtkImageActor::New( );
121                                 _thresholdActor->SetOpacity( 0.6 );
122                                 _thresholdActor->InterpolateOn(  );
123                                 _thresholdActor->SetPosition( 0,0, 900-1 );
124                         } // _thresholdActor                    
125                         _baseView->GetRenderer()->AddActor( _thresholdActor );
126                         _actorPresent = true;           
127                 }  // !GetActorPresent()
128
129                 ConfigLookupTable();  // virtual method
130                 _imageReslicer->SetInput( GetImage() );
131                 _imageReslicer->SetInformationInput( GetImage() );                      
132                 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
133                 _imageReslicer->SetOutputDimensionality(2);
134                 _imageReslicer->SetInterpolationModeToLinear();
135                 _imageReslicer->SetResliceAxesOrigin(0,0,z);
136
137                 vtkImageData *img = _imageReslicer->GetOutput();
138                 img->Update();
139                 img->UpdateInformation();
140
141                 _thresholdMapper->SetInput( img );
142                 _thresholdMapper->SetLookupTable( _thresholdTable );
143                 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
144                 } // _image
145 }
146
147
148
149 //----------------------------------------------------------------------------
150 void LayerImageBase::onThresholdChange()
151 {
152         if (_actorPresent)
153         {
154                 onThreshold();
155         }
156 }
157
158 //----------------------------------------------------------------------------
159 void LayerImageBase::onThresholdInterpolation(bool interpolate)
160 {
161         if (_thresholdActor!=NULL)
162         {
163                 if (interpolate)
164                 {
165                         _thresholdActor->InterpolateOn( );
166                 }
167                 else
168                 {
169                         _thresholdActor->InterpolateOff( );
170                 }               
171         }
172 }
173
174 //----------------------------------------------------------------------------
175 void LayerImageBase::onThresholdChangeOpacity (int opacity)
176 {
177         if (_actorPresent)
178         {
179                 _thresholdActor->SetOpacity(opacity*0.1);
180         }
181 }
182
183 //----------------------------------------------------------------------------
184 void LayerImageBase::onThresholdRemove()
185 {
186         if (_actorPresent)
187         {
188                 wxVtkBaseView * baseView = _baseView;
189                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
190                 _actorPresent = false;
191         }       
192 }
193
194
195
196
197 // EOF
198