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) {
90 //------------------------------------------------------------------------------
93 //------------------------------------------------------------------------------
94 void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
97 //------------------------------------------------------------------------------
100 //------------------------------------------------------------------------------
101 void vvROIActor::UpdateImage()
103 mOverlayActors.clear();
104 mImageContour.clear();
105 Initialize(mDepth, mIsVisible);
106 Update(); // No Render
108 //------------------------------------------------------------------------------
111 //------------------------------------------------------------------------------
112 void vvROIActor::SetVisible(bool b)
115 if (!b) { // remove actor
116 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
117 mOverlayActors[i]->HideActors();
119 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
120 mOverlayActors[i]->ShowActors();
122 Update(); // No Render
124 //------------------------------------------------------------------------------
127 //------------------------------------------------------------------------------
128 void vvROIActor::SetContourVisible(bool b) {
129 mIsContourVisible = b;
130 if (!b) { // remove actor
131 for(unsigned int i= 0; i<mImageContour.size(); i++) {
132 mImageContour[i]->HideActors();
136 for(unsigned int i= 0; i<mImageContour.size(); i++) {
137 mImageContour[i]->ShowActors();
140 Update(); // No Render
142 //------------------------------------------------------------------------------
145 //------------------------------------------------------------------------------
146 bool vvROIActor::IsVisible() {
149 //------------------------------------------------------------------------------
152 //------------------------------------------------------------------------------
153 bool vvROIActor::IsContourVisible() {
154 return mIsContourVisible;
156 //------------------------------------------------------------------------------
159 //------------------------------------------------------------------------------
160 void vvROIActor::Initialize(double depth, bool IsVisible) {
161 if (mROI->GetImage()) {
162 mImageContour.clear();
163 mOverlayActors.clear();
165 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
166 mImageContour.push_back(vvImageContour::New());
167 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
168 mImageContour[i]->SetImage(mROI->GetImage());
169 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
170 mImageContour[i]->SetLineWidth(mContourWidth);
171 mImageContour[i]->SetPreserveMemoryModeEnabled(true);
172 mImageContour[i]->SetDepth(mDepth+0.5);
173 mImageContour[i]->HideActors();
175 mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
179 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
182 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
186 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
187 mROI->GetDisplayColor()[1],
188 mROI->GetDisplayColor()[2]);
189 mOverlayActors[i]->SetOpacity(mOpacity);
190 mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
191 mOverlayActors[i]->Initialize(IsVisible);
192 mOverlayActors[i]->SetDepth(mDepth);
195 connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
196 //connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
197 connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
200 //------------------------------------------------------------------------------
203 //------------------------------------------------------------------------------
204 void vvROIActor::SetDepth(double d)
207 if (!mSlicerManager) return;
208 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
209 mOverlayActors[i]->SetDepth(d);
210 mImageContour[i]->SetDepth(d+0.5);
214 //------------------------------------------------------------------------------
217 //------------------------------------------------------------------------------
218 void vvROIActor::Update(bool force)
220 if (!mSlicerManager) return;
221 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
222 UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice(), force);
225 //------------------------------------------------------------------------------
228 //------------------------------------------------------------------------------
229 void vvROIActor::UpdateSlice(int slicer, int slices, bool force)
231 if (!mROI->GetImage()) return;
232 if ((!mIsVisible) && (!mIsContourVisible)) return;
233 if (!mSlicerManager) {
234 std::cerr << "Error. No mSlicerManager ?" << std::endl;
238 if (mIsContourVisible) {
239 mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1);
243 mOverlayActors[slicer]->UpdateSlice(slicer, slices, force);
245 //------------------------------------------------------------------------------
248 //------------------------------------------------------------------------------
249 void vvROIActor::SetOpacity(double d)
253 //------------------------------------------------------------------------------
256 //------------------------------------------------------------------------------
257 void vvROIActor::SetContourColor(double r, double v, double b) {
258 mContourColor[0] = r;
259 mContourColor[1] = v;
260 mContourColor[2] = b;
262 //------------------------------------------------------------------------------
265 //------------------------------------------------------------------------------
266 void vvROIActor::SetOverlayColor(double r, double v, double b) {
268 mROI->SetDisplayColor(r,v,b);
270 //------------------------------------------------------------------------------
273 //------------------------------------------------------------------------------
274 std::vector<double> & vvROIActor::GetContourColor() {
275 return mContourColor;
277 //------------------------------------------------------------------------------
280 //------------------------------------------------------------------------------
281 std::vector<double> & vvROIActor::GetOverlayColor() {
282 return mROI->GetDisplayColor();
284 //------------------------------------------------------------------------------
287 //------------------------------------------------------------------------------
288 void vvROIActor::UpdateColor() {
289 for(unsigned int i=0; i<mOverlayActors.size(); i++) {
290 mOverlayActors[i]->SetOpacity(mOpacity);
291 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
292 mROI->GetDisplayColor()[1],
293 mROI->GetDisplayColor()[2]);
294 mOverlayActors[i]->UpdateColor();
296 for(unsigned int i=0; i<mImageContour.size(); i++) {
297 mImageContour[i]->SetLineWidth(mContourWidth);
298 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
299 if (mIsContourVisible)
300 mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
303 //------------------------------------------------------------------------------
306 //------------------------------------------------------------------------------
307 double vvROIActor::GetOpacity()
311 //------------------------------------------------------------------------------
314 //------------------------------------------------------------------------------
315 void vvROIActor::SetSelected(bool b)
319 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
320 mImageContour[i]->SetLineWidth(3.0);
321 mImageContour[i]->ShowActors();
324 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
325 mImageContour[i]->HideActors();
329 //------------------------------------------------------------------------------
332 //------------------------------------------------------------------------------
333 void vvROIActor::CopyParameters(QSharedPointer<vvROIActor> roi)
336 SetVisible(roi->IsVisible());
337 SetOpacity(roi->GetOpacity());
338 SetOverlayColor(roi->GetOverlayColor()[0], roi->GetOverlayColor()[1], roi->GetOverlayColor()[2]);
341 SetContourVisible(roi->IsContourVisible());
342 SetContourWidth(roi->GetContourWidth());
343 SetContourColor(roi->GetContourColor()[0], roi->GetContourColor()[1], roi->GetContourColor()[2]);
346 SetDepth(roi->GetDepth());
348 //------------------------------------------------------------------------------