1 /*=========================================================================
4 Module: $RCSfile: vvImageContour.cxx,v $
6 Date: $Date: 2010/03/01 07:37:25 $
7 Version: $Revision: 1.4 $
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::hideActors() {
89 mSlice = mSlicer->GetSlice();
90 for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
91 mSquaresActorList[i]->VisibilityOff();
94 //------------------------------------------------------------------------------
97 //------------------------------------------------------------------------------
98 void vvImageContour::showActors() {
100 mSlice = mSlicer->GetSlice();
101 mTSlice = mSlicer->GetTSlice();
102 // for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
103 mSquaresActorList[mTSlice]->VisibilityOn();
107 //------------------------------------------------------------------------------
110 //------------------------------------------------------------------------------
111 void vvImageContour::update(int value) {
113 if (!mSlicer) return;
115 // how to not update if not visible ?
117 mSlice = mSlicer->GetSlice();
118 // Only change actor visibility if tslice change
119 if (mTSlice != mSlicer->GetTSlice()) {
121 mSquaresActorList[mTSlice]->VisibilityOff();
122 mTSlice = mSlicer->GetTSlice();
123 mSquaresActorList[mTSlice]->VisibilityOn();
126 vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
127 vtkImageClip * mClipper = mClipperList[mTSlice];
128 vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
131 mSquares->SetValue(0,value);
133 int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
134 mClipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
135 extent[3],extent[4],extent[5]);
137 for (i = 0; i < 6;i = i+2) {
138 if (extent[i] == extent[i+1]) {
146 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > mSlice)
148 mSquaresActor->SetPosition(1,0,0);
152 mSquaresActor->SetPosition(-1,0,0);
156 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > mSlice)
158 mSquaresActor->SetPosition(0,1,0);
162 mSquaresActor->SetPosition(0,-1,0);
166 if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > mSlice)
168 mSquaresActor->SetPosition(0,0,1);
172 mSquaresActor->SetPosition(0,0,-1);
178 //------------------------------------------------------------------------------