]> Creatis software - clitk.git/blob - vv/vvROIActor.cxx
Fusion windows level is now 4 decimals
[clitk.git] / vv / vvROIActor.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 // vv
20 #include "vvROIActor.h"
21 #include "vvImageContour.h"
22 #include "vvSlicerManager.h"
23 #include "vvBinaryImageOverlayActor.h"
24
25 // vtk
26 #include <vtkImageActor.h>
27 #include <vtkCamera.h>
28 #include <vtkRenderer.h>
29 #include <vtkMarchingSquares.h>
30 #include <vtkImageClip.h>
31 #include <vtkImageData.h>
32 #include <vtkPolyDataMapper.h>
33 #include <vtkProperty.h>
34
35 //------------------------------------------------------------------------------
36 vvROIActor::vvROIActor()
37 {
38   mImageContour.clear();
39   mOverlayActors.clear();
40   mIsVisible = true;
41   mIsContourVisible = false;
42   mOpacity = 0.7;
43   mIsSelected = false;
44   mContourWidth = 1;
45   mContourColor.resize(3);
46   m_modeBG = true;
47 }
48 //------------------------------------------------------------------------------
49
50
51 //------------------------------------------------------------------------------
52 vvROIActor::~vvROIActor()
53 {
54 }
55 //------------------------------------------------------------------------------
56
57
58 //------------------------------------------------------------------------------
59 void vvROIActor::SetROI(clitk::DicomRT_ROI * s)
60 {
61   mROI = s;
62 }
63 //------------------------------------------------------------------------------
64
65
66 //------------------------------------------------------------------------------
67 void vvROIActor::SetContourWidth(int n) {
68   mContourWidth = n;
69 }
70 //------------------------------------------------------------------------------
71
72
73 //------------------------------------------------------------------------------
74 void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
75   mSlicerManager = s;
76 }
77 //------------------------------------------------------------------------------
78
79
80 //------------------------------------------------------------------------------
81 void vvROIActor::UpdateImage()
82 {
83   for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
84     mOverlayActors[i]->HideActors();
85     delete mOverlayActors[i];
86   }
87   for(unsigned int i= 0; i<mImageContour.size(); i++) {
88     mImageContour[i]->HideActors();
89     delete mImageContour[i];
90   }
91   Initialize();
92   Update(); // No Render
93 }
94 //------------------------------------------------------------------------------
95
96
97 //------------------------------------------------------------------------------
98 void vvROIActor::SetVisible(bool b)
99 {
100   mIsVisible = b;
101   if (!b) { // remove actor
102     for(unsigned int i= 0; i<mOverlayActors.size(); i++)
103       mOverlayActors[i]->HideActors();
104   } else {
105     for(unsigned int i= 0; i<mOverlayActors.size(); i++)
106       mOverlayActors[i]->ShowActors();
107   }
108   Update(); // No Render
109 }
110 //------------------------------------------------------------------------------
111
112
113 //------------------------------------------------------------------------------
114 void vvROIActor::SetContourVisible(bool b) {
115   mIsContourVisible = b;
116   if (!b) { // remove actor
117     for(unsigned int i= 0; i<mImageContour.size(); i++) {
118       mImageContour[i]->HideActors();
119     }
120   }
121   else {
122     for(unsigned int i= 0; i<mImageContour.size(); i++) {
123       mImageContour[i]->ShowActors();
124     }
125   }
126   Update(); // No Render
127 }
128 //------------------------------------------------------------------------------
129
130
131 //------------------------------------------------------------------------------
132 bool vvROIActor::IsVisible() {
133   return mIsVisible;
134 }
135 //------------------------------------------------------------------------------
136
137
138 //------------------------------------------------------------------------------
139 bool vvROIActor::IsContourVisible() {
140   return mIsContourVisible;
141 }
142 //------------------------------------------------------------------------------
143
144
145 //------------------------------------------------------------------------------
146 void vvROIActor::Initialize() {
147   if (mROI->GetImage()) {
148     mImageContour.clear();
149     mOverlayActors.clear();
150     for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
151       mImageContour.push_back(new vvImageContour);
152       mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
153       mImageContour[i]->SetImage(mROI->GetImage());
154       mContourColor[0] = mROI->GetDisplayColor()[0];
155       mContourColor[1] = mROI->GetDisplayColor()[1];
156       mContourColor[2] = mROI->GetDisplayColor()[2];
157       mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
158       mImageContour[i]->SetLineWidth(mContourWidth);
159       mImageContour[i]->SetPreserveMemoryModeEnabled(true);
160       mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
161       mImageContour[i]->HideActors();
162       
163       mOverlayActors.push_back(new vvBinaryImageOverlayActor);
164
165       // BG or FG
166       if (m_modeBG) {
167         mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
168       }
169       else {
170         mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
171       }
172
173
174       mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
175                                   mROI->GetDisplayColor()[1],
176                                   mROI->GetDisplayColor()[2]);
177       mOverlayActors[i]->SetOpacity(mOpacity);
178       mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
179       mOverlayActors[i]->Initialize();
180     }
181
182     connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
183     //connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
184     connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
185   }
186 }
187 //------------------------------------------------------------------------------
188
189
190 //------------------------------------------------------------------------------
191 void vvROIActor::Update()
192 {
193   for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
194     UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice());
195   }
196 }
197 //------------------------------------------------------------------------------
198
199
200 //------------------------------------------------------------------------------
201 void vvROIActor::UpdateSlice(int slicer, int slices)
202 {
203   if (!mROI->GetImage())  return;
204   if ((!mIsVisible) && (!mIsContourVisible)) return; 
205   if (!mSlicerManager) {
206     std::cerr << "Error. No mSlicerManager ?" << std::endl;
207     exit(0);
208   }
209
210   if (mIsContourVisible) {
211     mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1); 
212   }
213
214   // Refresh overlays
215   mOverlayActors[slicer]->UpdateSlice(slicer, slices);
216 }
217 //------------------------------------------------------------------------------
218
219
220 //------------------------------------------------------------------------------
221 void vvROIActor::SetOpacity(double d)
222 {
223   mOpacity = d;
224 }
225 //------------------------------------------------------------------------------
226
227
228 //------------------------------------------------------------------------------
229 void vvROIActor::SetContourColor(double r, double v, double b) {
230   mContourColor[0] = r;
231   mContourColor[1] = v;
232   mContourColor[2] = b;  
233 }
234 //------------------------------------------------------------------------------
235
236
237 //------------------------------------------------------------------------------
238 std::vector<double> & vvROIActor::GetContourColor() { 
239   return mContourColor; 
240 }
241 //------------------------------------------------------------------------------
242
243
244 //------------------------------------------------------------------------------
245 void vvROIActor::UpdateColor() {
246   for(unsigned int i=0; i<mOverlayActors.size(); i++) {
247     mOverlayActors[i]->SetOpacity(mOpacity);
248     mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
249                                 mROI->GetDisplayColor()[1],
250                                 mROI->GetDisplayColor()[2]);
251     mOverlayActors[i]->UpdateColor();
252   }
253   for(unsigned int i=0; i<mImageContour.size(); i++) {
254     mImageContour[i]->SetLineWidth(mContourWidth);
255     mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
256     if (mIsContourVisible)
257       mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
258   }
259 }
260 //------------------------------------------------------------------------------
261
262
263 //------------------------------------------------------------------------------
264 double vvROIActor::GetOpacity()
265 {
266   return mOpacity;
267 }
268 //------------------------------------------------------------------------------
269
270
271 //------------------------------------------------------------------------------
272 void vvROIActor::SetSelected(bool b)
273 {
274   DD(" Not used yet");
275   mIsSelected = b;
276   if (b) {
277     for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
278       mImageContour[i]->SetLineWidth(3.0);
279       mImageContour[i]->ShowActors();
280     }
281   } else {
282     for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
283       mImageContour[i]->HideActors();
284     }
285   }
286 }
287 //------------------------------------------------------------------------------
288