]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/include/vtk2DQuantSliceWidget.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / include / vtk2DQuantSliceWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: vtk2DQuantSliceWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/05/14 13:54:57 $
7   Version:   $Revision: 1.1 $
8
9   Copyright: (c) 2002, 2003
10   License:
11   
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17 #include "vtk2DQuantSliceWidget.h"
18 #include <vtkProperty.h>
19 #include <vtkRenderer.h>
20
21 /**
22  * Again wxVTK is an hybrid class, double click was done using wxWindows, simply
23  * because VTK doesn't provide such facility (as opposed to wheel support that is
24  * supposed to be merged in VTK trunk sooner or later:
25  *
26  * http://public.kitware.com/pipermail/vtkusers/2003-August/019548.html
27  * http://www.creatis.insa-lyon.fr/~malaterre/vtk/wheel.patch
28  */
29
30 vtk2DQuantSliceWidget::vtk2DQuantSliceWidget( wxWindow* parent, wxWindowID id,
31                                              const wxPoint& pos, const wxSize& size,
32                                              long style, const wxString& name)
33                                              : wxImageViewerWidget( parent, id, pos, size, style, name)
34 {
35         // Contour
36         _cntActor                                               = NULL;
37         _cntMapper                                              = NULL;
38
39         // Diameter Min
40         _diameterMinvtkActor                    = NULL;
41         _diameterMinvtkPolyLine                 = NULL;
42         _diameterMinvtkDataSetMapper    = NULL;
43         _diameterMinvtkUnstructuredGrid = NULL;
44
45         // Diameter Max
46         _diameterMaxvtkActor                    = NULL;
47         _diameterMaxvtkPolyLine                 = NULL;
48         _diameterMaxvtkDataSetMapper    = NULL;
49         _diameterMaxvtkUnstructuredGrid = NULL;
50 }
51
52
53 vtk2DQuantSliceWidget::~vtk2DQuantSliceWidget( )
54 {
55         // Contour
56         if( _cntActor )                                                 _cntActor->Delete();
57         if( _cntMapper )                                                _cntMapper->Delete();
58
59         // Diameter Min
60         if( _diameterMinvtkActor )                              _diameterMinvtkActor->Delete();
61         if( _diameterMinvtkPolyLine )                   _diameterMinvtkPolyLine->Delete();
62         if( _diameterMinvtkDataSetMapper )              _diameterMinvtkDataSetMapper->Delete();
63         if( _diameterMinvtkUnstructuredGrid )   _diameterMinvtkUnstructuredGrid->Delete();
64
65         // Diameter Max
66         if( _diameterMaxvtkActor )                              _diameterMaxvtkActor->Delete();
67         if( _diameterMaxvtkPolyLine )                   _diameterMaxvtkPolyLine->Delete();
68         if( _diameterMaxvtkDataSetMapper )              _diameterMaxvtkDataSetMapper->Delete();
69         if( _diameterMaxvtkUnstructuredGrid )   _diameterMaxvtkUnstructuredGrid->Delete();
70 }
71
72 //----------------------------------------------------------------------------
73
74 //void vtk2DQuantSliceWidget::SetContour( vtkUnstructuredGrid *cnt )
75 void vtk2DQuantSliceWidget::SetContour( vtkPolyData *cnt )
76 {
77 //  _cntMapper = vtkDataSetMapper::New( ); 
78 //  _cntMapper = vtkDataSetMapper::New( );
79   
80   _cnt = cnt;
81
82   if( !_cntMapper ) {
83     _cntMapper = vtkPolyDataMapper::New( );
84     _cntMapper->ScalarVisibilityOff( );
85     _cntMapper->ImmediateModeRenderingOn();
86   }
87   _cntMapper->SetInput( _cnt );
88 //  _cntMapper->SetInput( _cnt->GetOutput( ) );
89
90   if( !_cntActor ) {
91     _cntActor = vtkActor::New( );
92     _cntActor->SetMapper( _cntMapper );
93     (_cntActor->GetProperty( ))->SetColor( 0 , 1 , 0 );
94     (_cntActor->GetProperty( ))->SetLineWidth( 2 );
95     (_cntActor->GetProperty( ))->BackfaceCullingOff( );
96   }
97   else{
98     _imageViewer->GetRenderer()->RemoveActor( _cntActor );
99   }
100
101   _cntActor->SetPosition(0,0,100);
102   _imageViewer->GetRenderer()->AddActor( _cntActor );
103   _imageViewer->Render( );
104
105 }
106
107
108 //----------------------------------------------------------------------------
109 void vtk2DQuantSliceWidget::SetDiameterMin(vtkPoints *diameterMin, bool showActor){
110         if (_diameterMinvtkActor!=NULL)                         _imageViewer->GetRenderer()->RemoveActor( _diameterMinvtkActor );
111         if (_diameterMinvtkActor!=NULL)                         _diameterMinvtkActor->Delete();
112         if (_diameterMinvtkPolyLine!=NULL)                      _diameterMinvtkPolyLine->Delete();
113         if (_diameterMinvtkDataSetMapper!=NULL)         _diameterMinvtkDataSetMapper->Delete();
114         if (_diameterMinvtkUnstructuredGrid!=NULL)      _diameterMinvtkUnstructuredGrid->Delete();
115
116         _diameterMinvtkActor                    =       vtkActor::New();
117         _diameterMinvtkPolyLine                 =       vtkPolyLine::New();
118         _diameterMinvtkDataSetMapper    =       vtkDataSetMapper::New();
119         _diameterMinvtkUnstructuredGrid =       vtkUnstructuredGrid::New();
120
121         // generate new actor
122         (_diameterMinvtkPolyLine->GetPointIds() )->SetNumberOfIds(2);
123         ( _diameterMinvtkPolyLine->GetPointIds() )->SetId(0,0);
124         ( _diameterMinvtkPolyLine->GetPointIds() )->SetId(1,1);
125         _diameterMinvtkUnstructuredGrid->Allocate(1,1);
126         _diameterMinvtkUnstructuredGrid->InsertNextCell(_diameterMinvtkPolyLine->GetCellType() , 
127                                                          _diameterMinvtkPolyLine->GetPointIds() );
128         _diameterMinvtkUnstructuredGrid->SetPoints( diameterMin );
129         _diameterMinvtkDataSetMapper->SetInput(_diameterMinvtkUnstructuredGrid);
130         _diameterMinvtkDataSetMapper->ImmediateModeRenderingOn();
131         _diameterMinvtkActor->SetMapper(_diameterMinvtkDataSetMapper);
132         _diameterMinvtkActor->GetProperty()->BackfaceCullingOn();
133         _diameterMinvtkActor->GetProperty()->SetDiffuseColor(1,0,0);
134         // add new actor
135         if (showActor==true) _imageViewer->GetRenderer()->AddActor( _diameterMinvtkActor );
136         // Refresh Widget
137         _imageViewer->Render( );
138 }
139 //----------------------------------------------------------------------------
140 void vtk2DQuantSliceWidget::SetDiameterMax(vtkPoints *diameterMax, bool showActor){
141         if (_diameterMaxvtkActor!=NULL)                         _imageViewer->GetRenderer()->RemoveActor( _diameterMaxvtkActor );
142         if (_diameterMaxvtkActor!=NULL)                         _diameterMaxvtkActor->Delete();
143         if (_diameterMaxvtkPolyLine!=NULL)                      _diameterMaxvtkPolyLine->Delete();
144         if (_diameterMaxvtkDataSetMapper!=NULL)         _diameterMaxvtkDataSetMapper->Delete();
145         if (_diameterMaxvtkUnstructuredGrid!=NULL)      _diameterMaxvtkUnstructuredGrid->Delete();
146
147         _diameterMaxvtkActor                    =       vtkActor::New();
148         _diameterMaxvtkPolyLine                 =       vtkPolyLine::New();
149         _diameterMaxvtkDataSetMapper    =       vtkDataSetMapper::New();
150         _diameterMaxvtkUnstructuredGrid =       vtkUnstructuredGrid::New();
151
152         // generate new actor
153         (_diameterMaxvtkPolyLine->GetPointIds() )->SetNumberOfIds(2);
154         ( _diameterMaxvtkPolyLine->GetPointIds() )->SetId(0,0);
155         ( _diameterMaxvtkPolyLine->GetPointIds() )->SetId(1,1);
156         _diameterMaxvtkUnstructuredGrid->Allocate(1,1);
157         _diameterMaxvtkUnstructuredGrid->InsertNextCell(_diameterMaxvtkPolyLine->GetCellType() , 
158                                                                                                                          _diameterMaxvtkPolyLine->GetPointIds() );
159         _diameterMaxvtkUnstructuredGrid->SetPoints( diameterMax );
160         _diameterMaxvtkDataSetMapper->SetInput(_diameterMaxvtkUnstructuredGrid);
161         _diameterMaxvtkDataSetMapper->ImmediateModeRenderingOn();
162         _diameterMaxvtkActor->SetMapper(_diameterMaxvtkDataSetMapper);
163         _diameterMaxvtkActor->GetProperty()->BackfaceCullingOn();
164         _diameterMaxvtkActor->GetProperty()->SetDiffuseColor(0,0,1);
165         // add new actor
166         if (showActor==true) _imageViewer->GetRenderer()->AddActor( _diameterMaxvtkActor );
167         // Refresh Widget
168         _imageViewer->Render( );
169 }
170 //----------------------------------------------------------------------------
171 void vtk2DQuantSliceWidget::Show2DContourDiameters( ){
172   if (_cntActor!=NULL)                          _imageViewer->GetRenderer()->AddActor( _cntActor );
173   if (_diameterMinvtkActor!=NULL)       _imageViewer->GetRenderer()->AddActor( _diameterMinvtkActor );
174   if (_diameterMaxvtkActor!=NULL)       _imageViewer->GetRenderer()->AddActor( _diameterMaxvtkActor );
175   _imageViewer->Render( );
176 }
177 //----------------------------------------------------------------------------
178 void vtk2DQuantSliceWidget::Hide2DContourDiameters( ){
179         if ( _cntActor                          != NULL ) { _imageViewer->GetRenderer()->RemoveActor( _cntActor );            }
180         if ( _diameterMinvtkActor       != NULL ) { _imageViewer->GetRenderer()->RemoveActor( _diameterMinvtkActor ); }
181         if ( _diameterMaxvtkActor       != NULL ) { _imageViewer->GetRenderer()->RemoveActor( _diameterMaxvtkActor ); }
182   _imageViewer->Render( );
183 }
184
185 //----------------------------------------------------------------------------
186 /*BEGIN_EVENT_TABLE( vtk2DQuantSliceWidget, wxVTKRenderWindowInteractor )
187     EVT_LEFT_DCLICK( vtk2DQuantSliceWidget::OnLeftDClick )
188 END_EVENT_TABLE( );
189 */