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