1 /*=========================================================================
4 Module: $RCSfile: vvImageContour.cxx,v $
6 Date: $Date: 2010/02/07 12:00:59 $
7 Version: $Revision: 1.2 $
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 <vtkMarchingSquares.h>
32 #include <vtkImageClip.h>
33 #include <vtkImageData.h>
35 //------------------------------------------------------------------------------
36 vvImageContour::vvImageContour() {
40 //------------------------------------------------------------------------------
43 //------------------------------------------------------------------------------
44 vvImageContour::~vvImageContour() {
45 for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) {
46 mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]);
48 mSquaresActorList.clear();
52 //------------------------------------------------------------------------------
55 //------------------------------------------------------------------------------
56 void vvImageContour::setSlicer(vvSlicer * slicer) {
59 for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) {
61 vtkImageClip * mClipper = vtkImageClip::New();
62 vtkMarchingSquares * mSquares = vtkMarchingSquares::New();
63 vtkPolyDataMapper * mSquaresMapper = vtkPolyDataMapper::New();
64 vtkActor * mSquaresActor = vtkActor::New();
66 mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
67 mSquares->SetInput(mClipper->GetOutput());
68 mSquaresMapper->SetInput(mSquares->GetOutput());
69 mSquaresMapper->ScalarVisibilityOff();
70 mSquaresActor->SetMapper(mSquaresMapper);
71 mSquaresActor->GetProperty()->SetColor(1.0,0,0);
72 mSquaresActor->SetPickable(0);
73 mSquaresActor->VisibilityOff();
74 mSlicer->GetRenderer()->AddActor(mSquaresActor);
76 mSquaresActorList.push_back(mSquaresActor);
77 mSquaresList.push_back(mSquares);
78 mClipperList.push_back(mClipper);
83 //------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------
87 void vvImageContour::update(int value) {
88 mSlice = mSlicer->GetSlice();
90 // Only change actor visibility if tslice change
91 if (mTSlice != mSlicer->GetTSlice()) {
93 mSquaresActorList[mTSlice]->VisibilityOff();
94 mTSlice = mSlicer->GetTSlice();
95 mSquaresActorList[mTSlice]->VisibilityOn();
98 vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
99 vtkImageClip * mClipper = mClipperList[mTSlice];
100 vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
103 mSquares->SetValue(0,value);
105 int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
106 mClipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
107 extent[3],extent[4],extent[5]);
109 for (i = 0; i < 6;i = i+2) {
110 if (extent[i] == extent[i+1]) {
118 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > mSlice)
120 mSquaresActor->SetPosition(1,0,0);
121 // mSquaresActor2->SetPosition(1,0,0);
125 mSquaresActor->SetPosition(-1,0,0);
126 // mSquaresActor2->SetPosition(-1,0,0);
130 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > mSlice)
132 mSquaresActor->SetPosition(0,1,0);
133 // mSquaresActor2->SetPosition(0,1,0);
137 mSquaresActor->SetPosition(0,-1,0);
138 // mSquaresActor2->SetPosition(0,-1,0);
142 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > mSlice)
144 mSquaresActor->SetPosition(0,0,1);
145 // mSquaresActor2->SetPosition(0,0,1);
149 mSquaresActor->SetPosition(0,0,-1);
150 // mSquaresActor2->SetPosition(0,0,-1);
156 //------------------------------------------------------------------------------