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://oncora1.lyon.fnclcc.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 "vvImageContour.h"
22 #include "vvSlicerManager.h"
23 #include "vvBinaryImageOverlayActor.h"
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>
35 //------------------------------------------------------------------------------
36 vvROIActor::vvROIActor()
38 mImageContour.clear();
39 mOverlayActors.clear();
41 mIsContourVisible = false;
45 mContourColor.resize(3);
48 //------------------------------------------------------------------------------
51 //------------------------------------------------------------------------------
52 vvROIActor::~vvROIActor()
54 for(uint i= 0; i<mImageContour.size(); i++) delete mImageContour[i];
55 for(uint i= 0; i<mOverlayActors.size(); i++) delete mOverlayActors[i];
57 //------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------
61 void vvROIActor::SetROI(clitk::DicomRT_ROI * s)
65 //------------------------------------------------------------------------------
68 //------------------------------------------------------------------------------
69 void vvROIActor::SetContourWidth(int n) {
72 //------------------------------------------------------------------------------
75 //------------------------------------------------------------------------------
76 void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
79 //------------------------------------------------------------------------------
82 //------------------------------------------------------------------------------
83 void vvROIActor::UpdateImage()
85 for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
86 mOverlayActors[i]->HideActors();
87 delete mOverlayActors[i];
89 for(unsigned int i= 0; i<mImageContour.size(); i++) {
90 mImageContour[i]->HideActors();
91 delete mImageContour[i];
93 Initialize(mIsVisible);
94 Update(); // No Render
96 //------------------------------------------------------------------------------
99 //------------------------------------------------------------------------------
100 void vvROIActor::SetVisible(bool b)
103 if (!b) { // remove actor
104 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
105 mOverlayActors[i]->HideActors();
107 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
108 mOverlayActors[i]->ShowActors();
110 Update(); // No Render
112 //------------------------------------------------------------------------------
115 //------------------------------------------------------------------------------
116 void vvROIActor::SetContourVisible(bool b) {
117 mIsContourVisible = b;
118 if (!b) { // remove actor
119 for(unsigned int i= 0; i<mImageContour.size(); i++) {
120 mImageContour[i]->HideActors();
124 for(unsigned int i= 0; i<mImageContour.size(); i++) {
125 mImageContour[i]->ShowActors();
128 Update(); // No Render
130 //------------------------------------------------------------------------------
133 //------------------------------------------------------------------------------
134 bool vvROIActor::IsVisible() {
137 //------------------------------------------------------------------------------
140 //------------------------------------------------------------------------------
141 bool vvROIActor::IsContourVisible() {
142 return mIsContourVisible;
144 //------------------------------------------------------------------------------
147 //------------------------------------------------------------------------------
148 void vvROIActor::Initialize(bool IsVisible) {
149 if (mROI->GetImage()) {
150 mImageContour.clear();
151 mOverlayActors.clear();
152 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
154 mImageContour.push_back(new vvImageContour);
155 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
156 mImageContour[i]->SetImage(mROI->GetImage());
157 mContourColor[0] = mROI->GetDisplayColor()[0];
158 mContourColor[1] = mROI->GetDisplayColor()[1];
159 mContourColor[2] = mROI->GetDisplayColor()[2];
160 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
161 mImageContour[i]->SetLineWidth(mContourWidth);
162 mImageContour[i]->SetPreserveMemoryModeEnabled(true);
163 //mImageContour[i]->SetPreserveMemoryModeEnabled(false); // SEG FAULT !!!
164 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
165 mImageContour[i]->HideActors();
167 mOverlayActors.push_back(new vvBinaryImageOverlayActor);
171 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
174 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
178 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
179 mROI->GetDisplayColor()[1],
180 mROI->GetDisplayColor()[2]);
181 mOverlayActors[i]->SetOpacity(mOpacity);
182 mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
183 mOverlayActors[i]->Initialize(IsVisible);
186 connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
187 //connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
188 connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
191 //------------------------------------------------------------------------------
194 //------------------------------------------------------------------------------
195 void vvROIActor::Update()
197 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
198 UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice());
201 //------------------------------------------------------------------------------
204 //------------------------------------------------------------------------------
205 void vvROIActor::UpdateSlice(int slicer, int slices)
207 if (!mROI->GetImage()) return;
208 if ((!mIsVisible) && (!mIsContourVisible)) return;
209 if (!mSlicerManager) {
210 std::cerr << "Error. No mSlicerManager ?" << std::endl;
214 if (mIsContourVisible) {
215 mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1);
219 mOverlayActors[slicer]->UpdateSlice(slicer, slices);
221 //------------------------------------------------------------------------------
224 //------------------------------------------------------------------------------
225 void vvROIActor::SetOpacity(double d)
229 //------------------------------------------------------------------------------
232 //------------------------------------------------------------------------------
233 void vvROIActor::SetContourColor(double r, double v, double b) {
234 mContourColor[0] = r;
235 mContourColor[1] = v;
236 mContourColor[2] = b;
238 //------------------------------------------------------------------------------
241 //------------------------------------------------------------------------------
242 std::vector<double> & vvROIActor::GetContourColor() {
243 return mContourColor;
245 //------------------------------------------------------------------------------
248 //------------------------------------------------------------------------------
249 void vvROIActor::UpdateColor() {
250 for(unsigned int i=0; i<mOverlayActors.size(); i++) {
251 mOverlayActors[i]->SetOpacity(mOpacity);
252 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
253 mROI->GetDisplayColor()[1],
254 mROI->GetDisplayColor()[2]);
255 mOverlayActors[i]->UpdateColor();
257 for(unsigned int i=0; i<mImageContour.size(); i++) {
258 mImageContour[i]->SetLineWidth(mContourWidth);
259 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
260 if (mIsContourVisible)
261 mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
264 //------------------------------------------------------------------------------
267 //------------------------------------------------------------------------------
268 double vvROIActor::GetOpacity()
272 //------------------------------------------------------------------------------
275 //------------------------------------------------------------------------------
276 void vvROIActor::SetSelected(bool b)
280 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
281 mImageContour[i]->SetLineWidth(3.0);
282 mImageContour[i]->ShowActors();
285 for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
286 mImageContour[i]->HideActors();
290 //------------------------------------------------------------------------------