1 /*=========================================================================
4 Module: $RCSfile: vvImageContour.cxx,v $
6 Date: $Date: 2010/02/24 11:42:42 $
7 Version: $Revision: 1.3 $
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);
82 //------------------------------------------------------------------------------
85 //------------------------------------------------------------------------------
86 void vvImageContour::removeActors() {
87 // DD("removeActors");
89 mSlice = mSlicer->GetSlice();
91 for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
92 mSquaresActorList[i]->VisibilityOff();
93 //mSquaresActorList[i]->Update();
96 //------------------------------------------------------------------------------
99 //------------------------------------------------------------------------------
100 void vvImageContour::update(int value) {
102 if (!mSlicer) return;
103 mSlice = mSlicer->GetSlice();
105 // Only change actor visibility if tslice change
106 if (mTSlice != mSlicer->GetTSlice()) {
108 mSquaresActorList[mTSlice]->VisibilityOff();
109 mTSlice = mSlicer->GetTSlice();
110 mSquaresActorList[mTSlice]->VisibilityOn();
113 vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
114 vtkImageClip * mClipper = mClipperList[mTSlice];
115 vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
118 mSquares->SetValue(0,value);
120 int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
121 mClipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
122 extent[3],extent[4],extent[5]);
124 for (i = 0; i < 6;i = i+2) {
125 if (extent[i] == extent[i+1]) {
133 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > mSlice)
135 mSquaresActor->SetPosition(1,0,0);
136 // mSquaresActor2->SetPosition(1,0,0);
140 mSquaresActor->SetPosition(-1,0,0);
141 // mSquaresActor2->SetPosition(-1,0,0);
145 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > mSlice)
147 mSquaresActor->SetPosition(0,1,0);
148 // mSquaresActor2->SetPosition(0,1,0);
152 mSquaresActor->SetPosition(0,-1,0);
153 // mSquaresActor2->SetPosition(0,-1,0);
157 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > mSlice)
159 mSquaresActor->SetPosition(0,0,1);
160 // mSquaresActor2->SetPosition(0,0,1);
164 mSquaresActor->SetPosition(0,0,-1);
165 // mSquaresActor2->SetPosition(0,0,-1);
171 //------------------------------------------------------------------------------