]> Creatis software - clitk.git/blob - vv/vvImageContour.cxx
binarize
[clitk.git] / vv / vvImageContour.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvImageContour.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/02/07 09:24:46 $
7   Version:   $Revision: 1.1 $
8   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
9
10   Copyright (C) 2010
11   Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12   CREATIS                   http://www.creatis.insa-lyon.fr
13
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.
17
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.
22
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/>.
25
26   =========================================================================*/
27
28 #include "vvImageContour.h"
29
30 //------------------------------------------------------------------------------
31 vvImageContour::vvImageContour() {
32   mClipper = vtkImageClip::New();
33   mSquares = vtkMarchingSquares::New();
34   mSquaresMapper = vtkPolyDataMapper::New();
35   mSquaresActor = vtkActor::New();
36 }
37 //------------------------------------------------------------------------------
38
39
40 //------------------------------------------------------------------------------
41 vvImageContour::~vvImageContour() {
42
43 }
44 //------------------------------------------------------------------------------
45
46
47 //------------------------------------------------------------------------------
48 void vvImageContour::setSlicer(vvSlicer * slicer) {
49   mSlicer = slicer;
50   mClipper->SetInput(slicer->GetImage()->GetFirstVTKImageData());
51   mSquares->SetInput(mClipper->GetOutput());
52   mSquaresMapper->SetInput(mSquares->GetOutput());
53   mSquaresMapper->ScalarVisibilityOff();
54   mSquaresActor->SetMapper(mSquaresMapper);
55   mSquaresActor->GetProperty()->SetColor(1.0,0,0);
56   mSquaresActor->SetPickable(0);
57   mSlicer->GetRenderer()->AddActor(mSquaresActor1);
58   mSquares->Update();
59 }
60 //------------------------------------------------------------------------------
61
62
63 //------------------------------------------------------------------------------
64 void vvImageContour::update() {
65   int slice = mSlicer->GetSlice();
66   int tslice = mCurrentSliceManager->GetSlicer(0)->GetTSlice();
67   DD(tslice);
68   DD(slice);
69
70   //  mClipper->SetInput(mCurrentSliceManager->GetSlicer(0)->GetInput());
71
72   int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
73   mClipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
74                                  extent[3],extent[4],extent[5]);
75   int i;
76   for (i = 0; i < 6;i = i+2) {
77     if (extent[i] == extent[i+1]) {
78       break;
79     }
80   }
81   
82   switch (i)
83     {
84     case 0:
85       if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice)
86         {
87           mSquaresActor->SetPosition(1,0,0);
88           // mSquaresActor2->SetPosition(1,0,0);
89         }
90       else
91         {
92           mSquaresActor->SetPosition(-1,0,0);
93           // mSquaresActor2->SetPosition(-1,0,0);
94         }
95       break;
96     case 2:
97       if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice)
98         {
99           mSquaresActor->SetPosition(0,1,0);
100           //   mSquaresActor2->SetPosition(0,1,0);
101         }
102       else
103         {
104           mSquaresActor->SetPosition(0,-1,0);
105           // mSquaresActor2->SetPosition(0,-1,0);
106         }
107       break;
108     case 4:
109       if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice)
110         {
111           mSquaresActor->SetPosition(0,0,1);
112           // mSquaresActor2->SetPosition(0,0,1);
113         }
114       else
115         {
116           mSquaresActor->SetPosition(0,0,-1);
117           // mSquaresActor2->SetPosition(0,0,-1);
118         }
119       break;
120     }
121   mSquares->Update();
122   //  mSquares2->Update();
123 }
124 //------------------------------------------------------------------------------
125