]> 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         _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()
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
80 //----------------------------------------------------------------------------
81 void LayerImageBase::onThreshold()
82 {
83         int     z = GetZ();
84         
85         if (!GetActorPresent())
86         {                               
87                 if (_thresholdTable==NULL)
88                 {
89                         //Lookup Table
90                         _thresholdTable = vtkLookupTable::New();
91                 } // _thresholdTable
92                 
93                 if (_thresholdMapper==NULL)
94                 {
95                         _thresholdMapper = vtkImageMapToColors::New( );
96                 }
97                 
98                 if (_thresholdActor==NULL)
99                 {
100                         _thresholdActor = vtkImageActor::New( );
101                         _thresholdActor->SetOpacity( 0.6 );
102                         _thresholdActor->InterpolateOn(  );
103                         _thresholdActor->SetPosition( 0,0, 900-1 );
104                 } // _thresholdActor
105                 
106                 
107                 _baseView->GetRenderer()->AddActor( _thresholdActor );
108                 _actorPresent = true;           
109         }  // !GetActorPresent()
110
111         ConfigLookupTable();  // virtual method
112         _imageReslicer->SetInput( GetImage() );
113         _imageReslicer->SetInformationInput( GetImage() );                      
114         _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
115         _imageReslicer->SetOutputDimensionality(2);
116         _imageReslicer->SetInterpolationModeToLinear();
117         _imageReslicer->SetResliceAxesOrigin(0,0,z);
118
119         vtkImageData *img = _imageReslicer->GetOutput();
120         img->Update();
121         img->UpdateInformation();
122
123         _thresholdMapper->SetInput( img );
124         _thresholdMapper->SetLookupTable( _thresholdTable );
125         _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
126 }
127
128
129
130 //----------------------------------------------------------------------------
131 void LayerImageBase::onThresholdChange()
132 {
133         if (_actorPresent)
134         {
135                 onThreshold();
136         }
137 }
138
139 //----------------------------------------------------------------------------
140 void LayerImageBase::onThresholdInterpolation(bool interpolate)
141 {
142         if (_thresholdActor!=NULL)
143         {
144                 if (interpolate)
145                 {
146                         _thresholdActor->InterpolateOn( );
147                 }
148                 else
149                 {
150                         _thresholdActor->InterpolateOff( );
151                 }               
152         }
153 }
154
155 //----------------------------------------------------------------------------
156 void LayerImageBase::onThresholdChangeOpacity (int opacity)
157 {
158         if (_actorPresent)
159         {
160                 _thresholdActor->SetOpacity(opacity*0.1);
161         }
162 }
163
164 //----------------------------------------------------------------------------
165 void LayerImageBase::onThresholdRemove()
166 {
167         if (_actorPresent)
168         {
169                 wxVtkBaseView * baseView = _baseView;
170                 baseView->GetRenderer()->RemoveActor( _thresholdActor );
171                 _actorPresent = false;
172         }       
173 }
174
175
176
177
178 // EOF
179