1 /*=========================================================================
4 Module: $RCSfile: vvImageContour.cxx,v $
6 Date: $Date: 2010/03/05 10:32:33 $
7 Version: $Revision: 1.5 $
8 Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
28 #include "vvImageContour.h"
29 #include <vtkImageActor.h>
30 #include <vtkCamera.h>
31 #include <vtkRenderer.h>
32 #include <vtkMarchingSquares.h>
33 #include <vtkImageClip.h>
34 #include <vtkImageData.h>
35 #include <vtkPolyDataMapper.h>
36 #include <vtkProperty.h>
38 //------------------------------------------------------------------------------
39 vvImageContour::vvImageContour() {
43 //------------------------------------------------------------------------------
46 //------------------------------------------------------------------------------
47 vvImageContour::~vvImageContour() {
48 for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) {
49 mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]);
51 mSquaresActorList.clear();
55 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 void vvImageContour::setSlicer(vvSlicer * slicer) {
62 for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) {
63 vtkImageClip * mClipper = vtkImageClip::New();
64 vtkMarchingSquares * mSquares = vtkMarchingSquares::New();
65 vtkPolyDataMapper * mSquaresMapper = vtkPolyDataMapper::New();
66 vtkActor * mSquaresActor = vtkActor::New();
68 mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
69 mSquares->SetInput(mClipper->GetOutput());
70 mSquaresMapper->SetInput(mSquares->GetOutput());
71 mSquaresMapper->ScalarVisibilityOff();
72 mSquaresActor->SetMapper(mSquaresMapper);
73 mSquaresActor->GetProperty()->SetColor(1.0,0,0);
74 mSquaresActor->SetPickable(0);
75 mSquaresActor->VisibilityOff();
76 mSlicer->GetRenderer()->AddActor(mSquaresActor);
78 mSquaresActorList.push_back(mSquaresActor);
79 mSquaresList.push_back(mSquares);
80 mClipperList.push_back(mClipper);
83 //------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------
87 void vvImageContour::setColor(double r, double g, double b) {
88 for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
89 mSquaresActorList[i]->GetProperty()->SetColor(r,g,b);
92 //------------------------------------------------------------------------------
95 //------------------------------------------------------------------------------
96 void vvImageContour::hideActors() {
98 mSlice = mSlicer->GetSlice();
99 for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
100 mSquaresActorList[i]->VisibilityOff();
103 //------------------------------------------------------------------------------
106 //------------------------------------------------------------------------------
107 void vvImageContour::showActors() {
108 if (!mSlicer) return;
109 mSlice = mSlicer->GetSlice();
110 mTSlice = mSlicer->GetTSlice();
111 // for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
112 mSquaresActorList[mTSlice]->VisibilityOn();
116 //------------------------------------------------------------------------------
119 //------------------------------------------------------------------------------
120 void vvImageContour::update(double value) {
122 if (!mSlicer) return;
124 // how to not update if not visible ?
126 mSlice = mSlicer->GetSlice();
127 // Only change actor visibility if tslice change
128 if (mTSlice != mSlicer->GetTSlice()) {
130 mSquaresActorList[mTSlice]->VisibilityOff();
131 mTSlice = mSlicer->GetTSlice();
132 mSquaresActorList[mTSlice]->VisibilityOn();
135 vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
136 vtkImageClip * mClipper = mClipperList[mTSlice];
137 vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
140 mSquares->SetValue(0,value);
142 int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
143 mClipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
144 extent[3],extent[4],extent[5]);
146 for (i = 0; i < 6;i = i+2) {
147 if (extent[i] == extent[i+1]) {
155 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > mSlice)
157 mSquaresActor->SetPosition(1,0,0);
161 mSquaresActor->SetPosition(-1,0,0);
165 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > mSlice)
167 mSquaresActor->SetPosition(0,1,0);
171 mSquaresActor->SetPosition(0,-1,0);
175 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > mSlice)
177 mSquaresActor->SetPosition(0,0,1);
181 mSquaresActor->SetPosition(0,0,-1);
187 //------------------------------------------------------------------------------