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 // Color of the contour is same of roi color
170 mContourColor[0] = mROI->GetDisplayColor()[0];
171 mContourColor[1] = mROI->GetDisplayColor()[1];
172 mContourColor[2] = mROI->GetDisplayColor()[2];
173 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
174 mImageContour[i]->SetLineWidth(mContourWidth);
175 mImageContour[i]->SetPreserveMemoryModeEnabled(true);
176 mImageContour[i]->SetDepth(mDepth+0.5);
177 mImageContour[i]->HideActors();
179 mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
183 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
186 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
190 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
191 mROI->GetDisplayColor()[1],
192 mROI->GetDisplayColor()[2]);
193 mOverlayActors[i]->SetOpacity(mOpacity);
194 mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
195 mOverlayActors[i]->Initialize(IsVisible);
196 mOverlayActors[i]->SetDepth(mDepth);
199 connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
200 //connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
201 connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
204 //------------------------------------------------------------------------------
207 //------------------------------------------------------------------------------
208 void vvROIActor::SetDepth(double d)
211 if (!mSlicerManager) return;
212 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
213 mOverlayActors[i]->SetDepth(d);
214 mImageContour[i]->SetDepth(d+0.5);
218 //------------------------------------------------------------------------------
221 //------------------------------------------------------------------------------
222 void vvROIActor::Update(bool force)
224 if (!mSlicerManager) return;
225 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
226 UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice(), force);
229 //------------------------------------------------------------------------------
232 //------------------------------------------------------------------------------
233 void vvROIActor::UpdateSlice(int slicer, int slices, bool force)
235 if (!mROI->GetImage()) return;
236 if ((!mIsVisible) && (!mIsContourVisible)) return;
237 if (!mSlicerManager) {
238 std::cerr << "Error. No mSlicerManager ?" << std::endl;
242 if (mIsContourVisible) {
243 mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1);
247 mOverlayActors[slicer]->UpdateSlice(slicer, slices, force);
249 //------------------------------------------------------------------------------
252 //------------------------------------------------------------------------------
253 void vvROIActor::SetOpacity(double d)
257 //------------------------------------------------------------------------------
260 //------------------------------------------------------------------------------
261 void vvROIActor::SetContourColor(double r, double v, double b) {
262 mContourColor[0] = r;
263 mContourColor[1] = v;
264 mContourColor[2] = b;
266 //------------------------------------------------------------------------------
269 //------------------------------------------------------------------------------
270 void vvROIActor::SetOverlayColor(double r, double v, double b) {
272 mROI->SetDisplayColor(r,v,b);
274 //------------------------------------------------------------------------------
277 //------------------------------------------------------------------------------
278 std::vector<double> & vvROIActor::GetContourColor() {
279 return mContourColor;
281 //------------------------------------------------------------------------------
284 //------------------------------------------------------------------------------
285 std::vector<double> & vvROIActor::GetOverlayColor() {
286 return mROI->GetDisplayColor();
288 //------------------------------------------------------------------------------
291 //------------------------------------------------------------------------------
292 void vvROIActor::UpdateColor() {
293 for(unsigned int i=0; i<mOverlayActors.size(); i++) {
294 mOverlayActors[i]->SetOpacity(mOpacity);
295 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
296 mROI->GetDisplayColor()[1],
297 mROI->GetDisplayColor()[2]);
298 mOverlayActors[i]->UpdateColor();
300 for(unsigned int i=0; i<mImageContour.size(); i++) {
301 mImageContour[i]->SetLineWidth(mContourWidth);
302 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
303 if (mIsContourVisible)
304 mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
307 //------------------------------------------------------------------------------
310 //------------------------------------------------------------------------------
311 double vvROIActor::GetOpacity()
315 //------------------------------------------------------------------------------
318 //------------------------------------------------------------------------------
319 void vvROIActor::SetSelected(bool b)
323 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
324 mImageContour[i]->SetLineWidth(3.0);
325 mImageContour[i]->ShowActors();
328 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
329 mImageContour[i]->HideActors();
333 //------------------------------------------------------------------------------
336 //------------------------------------------------------------------------------
337 void vvROIActor::CopyParameters(QSharedPointer<vvROIActor> roi)
340 SetVisible(roi->IsVisible());
341 SetOpacity(roi->GetOpacity());
342 SetOverlayColor(roi->GetOverlayColor()[0], roi->GetOverlayColor()[1], roi->GetOverlayColor()[2]);
345 SetContourVisible(roi->IsContourVisible());
346 SetContourWidth(roi->GetContourWidth());
347 SetContourColor(roi->GetContourColor()[0], roi->GetContourColor()[1], roi->GetContourColor()[2]);
350 SetDepth(roi->GetDepth());
352 //------------------------------------------------------------------------------