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);
45 //------------------------------------------------------------------------------
48 //------------------------------------------------------------------------------
49 vvROIActor::~vvROIActor()
52 //------------------------------------------------------------------------------
55 //------------------------------------------------------------------------------
56 void vvROIActor::SetROI(clitk::DicomRT_ROI * s)
60 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
64 void vvROIActor::SetContourWidth(int n) {
67 //------------------------------------------------------------------------------
70 //------------------------------------------------------------------------------
71 void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
74 //------------------------------------------------------------------------------
77 //------------------------------------------------------------------------------
78 void vvROIActor::UpdateImage()
80 mOverlayActors.clear();
81 mImageContour.clear();
82 Initialize(mDepth, mIsVisible);
83 Update(); // No Render
85 //------------------------------------------------------------------------------
88 //------------------------------------------------------------------------------
89 void vvROIActor::SetVisible(bool b)
92 if (!b) { // remove actor
93 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
94 mOverlayActors[i]->HideActors();
96 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
97 mOverlayActors[i]->ShowActors();
99 Update(); // No Render
101 //------------------------------------------------------------------------------
104 //------------------------------------------------------------------------------
105 void vvROIActor::SetContourVisible(bool b) {
106 mIsContourVisible = b;
107 if (!b) { // remove actor
108 for(unsigned int i= 0; i<mImageContour.size(); i++) {
109 mImageContour[i]->HideActors();
113 for(unsigned int i= 0; i<mImageContour.size(); i++) {
114 mImageContour[i]->ShowActors();
117 Update(); // No Render
119 //------------------------------------------------------------------------------
122 //------------------------------------------------------------------------------
123 bool vvROIActor::IsVisible() {
126 //------------------------------------------------------------------------------
129 //------------------------------------------------------------------------------
130 bool vvROIActor::IsContourVisible() {
131 return mIsContourVisible;
133 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
137 void vvROIActor::Initialize(double depth, bool IsVisible) {
138 if (mROI->GetImage()) {
139 mImageContour.clear();
140 mOverlayActors.clear();
142 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
144 mImageContour.push_back(vvImageContour::New());
145 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
146 mImageContour[i]->SetImage(mROI->GetImage());
147 mContourColor[0] = mROI->GetDisplayColor()[0];
148 mContourColor[1] = mROI->GetDisplayColor()[1];
149 mContourColor[2] = mROI->GetDisplayColor()[2];
150 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
151 mImageContour[i]->SetLineWidth(mContourWidth);
152 mImageContour[i]->SetPreserveMemoryModeEnabled(true);
153 mImageContour[i]->SetDepth(mDepth);
154 //mImageContour[i]->SetPreserveMemoryModeEnabled(false); // SEG FAULT !!!
155 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
156 mImageContour[i]->HideActors();
158 mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
162 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
165 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
169 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
170 mROI->GetDisplayColor()[1],
171 mROI->GetDisplayColor()[2]);
172 mOverlayActors[i]->SetOpacity(mOpacity);
173 mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
174 mOverlayActors[i]->Initialize(IsVisible);
175 mOverlayActors[i]->SetDepth(mDepth);
178 connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
179 //connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
180 connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
183 //------------------------------------------------------------------------------
186 //------------------------------------------------------------------------------
187 void vvROIActor::SetDepth(double d)
190 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
191 mOverlayActors[i]->SetDepth(d);
192 mImageContour[i]->SetDepth(d);
196 //------------------------------------------------------------------------------
199 //------------------------------------------------------------------------------
200 void vvROIActor::Update(bool force)
202 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
203 UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice(), force);
206 //------------------------------------------------------------------------------
209 //------------------------------------------------------------------------------
210 void vvROIActor::UpdateSlice(int slicer, int slices, bool force)
212 if (!mROI->GetImage()) return;
213 if ((!mIsVisible) && (!mIsContourVisible)) return;
214 if (!mSlicerManager) {
215 std::cerr << "Error. No mSlicerManager ?" << std::endl;
219 if (mIsContourVisible) {
220 mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1);
224 mOverlayActors[slicer]->UpdateSlice(slicer, slices, force);
226 //------------------------------------------------------------------------------
229 //------------------------------------------------------------------------------
230 void vvROIActor::SetOpacity(double d)
234 //------------------------------------------------------------------------------
237 //------------------------------------------------------------------------------
238 void vvROIActor::SetContourColor(double r, double v, double b) {
239 mContourColor[0] = r;
240 mContourColor[1] = v;
241 mContourColor[2] = b;
243 //------------------------------------------------------------------------------
246 //------------------------------------------------------------------------------
247 std::vector<double> & vvROIActor::GetContourColor() {
248 return mContourColor;
250 //------------------------------------------------------------------------------
253 //------------------------------------------------------------------------------
254 void vvROIActor::UpdateColor() {
255 for(unsigned int i=0; i<mOverlayActors.size(); i++) {
256 mOverlayActors[i]->SetOpacity(mOpacity);
257 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
258 mROI->GetDisplayColor()[1],
259 mROI->GetDisplayColor()[2]);
260 mOverlayActors[i]->UpdateColor();
262 for(unsigned int i=0; i<mImageContour.size(); i++) {
263 mImageContour[i]->SetLineWidth(mContourWidth);
264 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
265 if (mIsContourVisible)
266 mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
269 //------------------------------------------------------------------------------
272 //------------------------------------------------------------------------------
273 double vvROIActor::GetOpacity()
277 //------------------------------------------------------------------------------
280 //------------------------------------------------------------------------------
281 void vvROIActor::SetSelected(bool b)
285 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
286 mImageContour[i]->SetLineWidth(3.0);
287 mImageContour[i]->ShowActors();
290 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
291 mImageContour[i]->HideActors();
295 //------------------------------------------------------------------------------