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()
55 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 void vvROIActor::SetROI(clitk::DicomRT_ROI * s)
63 //------------------------------------------------------------------------------
66 //------------------------------------------------------------------------------
67 void vvROIActor::SetContourWidth(int n) {
70 //------------------------------------------------------------------------------
73 //------------------------------------------------------------------------------
74 void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
77 //------------------------------------------------------------------------------
80 //------------------------------------------------------------------------------
81 void vvROIActor::UpdateImage()
83 for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
84 mOverlayActors[i]->HideActors();
85 delete mOverlayActors[i];
87 for(unsigned int i= 0; i<mImageContour.size(); i++) {
88 mImageContour[i]->HideActors();
89 delete mImageContour[i];
92 Update(); // No Render
94 //------------------------------------------------------------------------------
97 //------------------------------------------------------------------------------
98 void vvROIActor::SetVisible(bool b)
101 if (!b) { // remove actor
102 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
103 mOverlayActors[i]->HideActors();
105 for(unsigned int i= 0; i<mOverlayActors.size(); i++)
106 mOverlayActors[i]->ShowActors();
108 Update(); // No Render
110 //------------------------------------------------------------------------------
113 //------------------------------------------------------------------------------
114 void vvROIActor::SetContourVisible(bool b) {
115 mIsContourVisible = b;
116 if (!b) { // remove actor
117 for(unsigned int i= 0; i<mImageContour.size(); i++) {
118 mImageContour[i]->HideActors();
122 for(unsigned int i= 0; i<mImageContour.size(); i++) {
123 mImageContour[i]->ShowActors();
126 Update(); // No Render
128 //------------------------------------------------------------------------------
131 //------------------------------------------------------------------------------
132 bool vvROIActor::IsVisible() {
135 //------------------------------------------------------------------------------
138 //------------------------------------------------------------------------------
139 bool vvROIActor::IsContourVisible() {
140 return mIsContourVisible;
142 //------------------------------------------------------------------------------
145 //------------------------------------------------------------------------------
146 void vvROIActor::Initialize() {
147 if (mROI->GetImage()) {
148 mImageContour.clear();
149 mOverlayActors.clear();
150 for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
151 mImageContour.push_back(new vvImageContour);
152 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
153 mImageContour[i]->SetImage(mROI->GetImage());
154 mContourColor[0] = mROI->GetDisplayColor()[0];
155 mContourColor[1] = mROI->GetDisplayColor()[1];
156 mContourColor[2] = mROI->GetDisplayColor()[2];
157 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
158 mImageContour[i]->SetLineWidth(mContourWidth);
159 mImageContour[i]->SetPreserveMemoryModeEnabled(true);
160 mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
161 mImageContour[i]->HideActors();
163 mOverlayActors.push_back(new vvBinaryImageOverlayActor);
167 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetBackgroundValueLabelImage());
170 mOverlayActors[i]->SetImage(mROI->GetImage(), mROI->GetForegroundValueLabelImage(), false);
174 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
175 mROI->GetDisplayColor()[1],
176 mROI->GetDisplayColor()[2]);
177 mOverlayActors[i]->SetOpacity(mOpacity);
178 mOverlayActors[i]->SetSlicer(mSlicerManager->GetSlicer(i));
179 mOverlayActors[i]->Initialize();
182 connect(mSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
183 //connect(mSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
184 connect(mSlicerManager, SIGNAL(AVerticalSliderHasChanged(int, int)), SLOT(UpdateSlice(int, int)));
187 //------------------------------------------------------------------------------
190 //------------------------------------------------------------------------------
191 void vvROIActor::Update()
193 for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
194 UpdateSlice(i, mSlicerManager->GetSlicer(i)->GetSlice());
197 //------------------------------------------------------------------------------
200 //------------------------------------------------------------------------------
201 void vvROIActor::UpdateSlice(int slicer, int slices)
203 if (!mROI->GetImage()) return;
204 if ((!mIsVisible) && (!mIsContourVisible)) return;
205 if (!mSlicerManager) {
206 std::cerr << "Error. No mSlicerManager ?" << std::endl;
210 if (mIsContourVisible) {
211 mImageContour[slicer]->Update(mROI->GetBackgroundValueLabelImage()+1);
215 mOverlayActors[slicer]->UpdateSlice(slicer, slices);
217 //------------------------------------------------------------------------------
220 //------------------------------------------------------------------------------
221 void vvROIActor::SetOpacity(double d)
225 //------------------------------------------------------------------------------
228 //------------------------------------------------------------------------------
229 void vvROIActor::SetContourColor(double r, double v, double b) {
230 mContourColor[0] = r;
231 mContourColor[1] = v;
232 mContourColor[2] = b;
234 //------------------------------------------------------------------------------
237 //------------------------------------------------------------------------------
238 std::vector<double> & vvROIActor::GetContourColor() {
239 return mContourColor;
241 //------------------------------------------------------------------------------
244 //------------------------------------------------------------------------------
245 void vvROIActor::UpdateColor() {
246 for(unsigned int i=0; i<mOverlayActors.size(); i++) {
247 mOverlayActors[i]->SetOpacity(mOpacity);
248 mOverlayActors[i]->SetColor(mROI->GetDisplayColor()[0],
249 mROI->GetDisplayColor()[1],
250 mROI->GetDisplayColor()[2]);
251 mOverlayActors[i]->UpdateColor();
253 for(unsigned int i=0; i<mImageContour.size(); i++) {
254 mImageContour[i]->SetLineWidth(mContourWidth);
255 mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
256 if (mIsContourVisible)
257 mImageContour[i]->Update(mROI->GetBackgroundValueLabelImage()+1);
260 //------------------------------------------------------------------------------
263 //------------------------------------------------------------------------------
264 double vvROIActor::GetOpacity()
268 //------------------------------------------------------------------------------
271 //------------------------------------------------------------------------------
272 void vvROIActor::SetSelected(bool b)
277 for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
278 mImageContour[i]->SetLineWidth(3.0);
279 mImageContour[i]->ShowActors();
282 for(int i=0; i<mSlicerManager->NumberOfSlicers(); i++) {
283 mImageContour[i]->HideActors();
287 //------------------------------------------------------------------------------