1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
20 #include "vvROIActor.h"
21 #include "vvSlicerManager.h"
24 #include <vtkImageActor.h>
25 #include <vtkCamera.h>
26 #include <vtkRenderer.h>
27 #include <vtkMarchingSquares.h>
28 #include <vtkImageClip.h>
29 #include <vtkImageData.h>
30 #include <vtkPolyDataMapper.h>
31 #include <vtkProperty.h>
33 //------------------------------------------------------------------------------
34 vvROIActor::vvROIActor()
37 mIsContourVisible = false;
41 mContourColor.resize(3);
50 //------------------------------------------------------------------------------
53 //------------------------------------------------------------------------------
54 vvROIActor::~vvROIActor()
57 //------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------
61 void vvROIActor::RemoveActors()
63 for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
64 mOverlayActors[i]->RemoveActors();
67 for(unsigned int i= 0; i<mImageContour.size(); i++) {
68 mImageContour[i]->RemoveActors();
72 //mImageContour.clear();
73 //mOverlayActors.clear();
75 //------------------------------------------------------------------------------
78 //------------------------------------------------------------------------------
79 void vvROIActor::SetROI(clitk::DicomRT_ROI * s)
83 //------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------
87 void vvROIActor::SetContourWidth(int n)
91 //------------------------------------------------------------------------------
94 //------------------------------------------------------------------------------
95 void vvROIActor::SetSlicerManager(vvSlicerManager * s)
99 //------------------------------------------------------------------------------
102 //------------------------------------------------------------------------------
103 void vvROIActor::UpdateImage()
105 mOverlayActors.clear();
106 mImageContour.clear();
107 Initialize(mDepth, mIsVisible);
108 Update(); // No Render
110 //------------------------------------------------------------------------------
113 //------------------------------------------------------------------------------
114 void vvROIActor::SetVisible(bool b)
117 if (!b) { // remove actor
118 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
119 mOverlayActors[i]->HideActors();
121 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
122 mOverlayActors[i]->ShowActors();
124 //Update(); // No Render
126 //------------------------------------------------------------------------------
129 //------------------------------------------------------------------------------
130 void vvROIActor::SetContourVisible(bool b)
132 mIsContourVisible = b;
133 if (!b) { // remove actor
134 for(unsigned int i= 0; i<mImageContour.size(); i++) {
135 mImageContour[i]->HideActors();
139 for(unsigned int i= 0; i<mImageContour.size(); i++) {
140 mImageContour[i]->ShowActors();
143 //Update(); // No Render
145 //------------------------------------------------------------------------------
148 //------------------------------------------------------------------------------
149 bool vvROIActor::IsVisible()
153 //------------------------------------------------------------------------------
156 //------------------------------------------------------------------------------
157 bool vvROIActor::IsContourVisible()
159 return mIsContourVisible;
161 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165 void vvROIActor::Initialize(double depth, bool IsVisible)
167 if (mROI->GetImage()) {
168 mImageContour.clear();
169 mOverlayActors.clear();
171 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
172 mImageContour.push_back(vvImageContour::New());
173 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
174 mImageContour[i]->SetImage(mROI->GetImage());
175 // Color of the contour is same of roi color
176 mContourColor[0] = mROI->GetDisplayColor()[0];
177 mContourColor[1] = mROI->GetDisplayColor()[1];
178 mContourColor[2] = mROI->GetDisplayColor()[2];
179 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
180 mImageContour[i]->SetLineWidth(mContourWidth);
181 mImageContour[i]->SetPreserveMemoryModeEnabled(true);
182 mImageContour[i]->SetDepth(mDepth+0.5);
183 mImageContour[i]->ShowActors();
185 mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
189 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
192 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
196 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
197 mROI->GetDisplayColor()[1],
198 mROI->GetDisplayColor()[2]);
199 mOverlayActors[i]->SetOpacity(mOpacity);
200 mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
201 mOverlayActors[i]->Initialize(IsVisible);
202 mOverlayActors[i]->SetDepth(mDepth);
204 connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
205 connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int,int)),this,SLOT(UpdateSlice(int, int, int)));
206 connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
209 //------------------------------------------------------------------------------
212 //------------------------------------------------------------------------------
213 void vvROIActor::SetDepth(double d)
216 if (!mSlicerManager) return;
217 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
218 mOverlayActors[i]->SetDepth(d);
219 mImageContour[i]->SetDepth(d+0.5);
223 //------------------------------------------------------------------------------
226 //------------------------------------------------------------------------------
227 void vvROIActor::Update(bool force)
229 if (!mSlicerManager) return;
230 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
231 UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice(), force);
234 //------------------------------------------------------------------------------
237 //------------------------------------------------------------------------------
238 void vvROIActor::UpdateSlice(int slicer, int slices, int force)
240 if (!mROI->GetImage()) return;
241 if ((!mIsVisible) && (!mIsContourVisible)) return;
242 if (!mSlicerManager) {
243 std::cerr << "Error. No mSlicerManager ?" << std::endl;
247 if (mIsContourVisible) {
248 mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1);
253 mOverlayActors[slicer]->UpdateSlice(slicer, slices, force);
255 //mSlicerManager->GetSlicer(slicer)->Render();
257 //------------------------------------------------------------------------------
260 //------------------------------------------------------------------------------
261 void vvROIActor::SetOpacity(double d)
265 //------------------------------------------------------------------------------
268 //------------------------------------------------------------------------------
269 void vvROIActor::SetContourColor(double r, double v, double b)
271 mContourColor[0] = r;
272 mContourColor[1] = v;
273 mContourColor[2] = b;
275 //------------------------------------------------------------------------------
278 //------------------------------------------------------------------------------
279 void vvROIActor::SetOverlayColor(double r, double v, double b)
282 mROI->SetDisplayColor(r,v,b);
284 //------------------------------------------------------------------------------
287 //------------------------------------------------------------------------------
288 std::vector<double> & vvROIActor::GetContourColor()
290 return mContourColor;
292 //------------------------------------------------------------------------------
295 //------------------------------------------------------------------------------
296 std::vector<double> & vvROIActor::GetOverlayColor()
298 return mROI->GetDisplayColor();
300 //------------------------------------------------------------------------------
303 //------------------------------------------------------------------------------
304 void vvROIActor::UpdateColor()
306 for(unsigned int i=0; i<mOverlayActors.size(); i++) {
307 mOverlayActors[i]->SetOpacity(mOpacity);
308 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
309 mROI->GetDisplayColor()[1],
310 mROI->GetDisplayColor()[2]);
311 mOverlayActors[i]->UpdateColor();
313 for(unsigned int i=0; i<mImageContour.size(); i++) {
314 mImageContour[i]->SetLineWidth(mContourWidth);
315 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
316 if (mIsContourVisible)
317 mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
320 //------------------------------------------------------------------------------
323 //------------------------------------------------------------------------------
324 double vvROIActor::GetOpacity()
328 //------------------------------------------------------------------------------
331 //------------------------------------------------------------------------------
332 void vvROIActor::SetSelected(bool b)
336 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
337 mImageContour[i]->SetLineWidth(3.0);
338 mImageContour[i]->ShowActors();
341 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
342 mImageContour[i]->HideActors();
346 //------------------------------------------------------------------------------
349 //------------------------------------------------------------------------------
350 void vvROIActor::CopyParameters(QSharedPointer<vvROIActor> roi)
353 SetVisible(roi->IsVisible());
354 SetOpacity(roi->GetOpacity());
355 SetOverlayColor(roi->GetOverlayColor()[0], roi->GetOverlayColor()[1], roi->GetOverlayColor()[2]);
358 SetContourVisible(roi->IsContourVisible());
359 SetContourWidth(roi->GetContourWidth());
360 SetContourColor(roi->GetContourColor()[0], roi->GetContourColor()[1], roi->GetContourColor()[2]);
363 SetDepth(roi->GetDepth());
365 //------------------------------------------------------------------------------