1 /*=========================================================================
4 Module: $RCSfile: vtk2DQuantSliceWidget.cxx,v $
6 Date: $Date: 2009/05/14 13:54:57 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
17 #include "vtk2DQuantSliceWidget.h"
18 #include <vtkProperty.h>
19 #include <vtkRenderer.h>
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:
26 * http://public.kitware.com/pipermail/vtkusers/2003-August/019548.html
27 * http://www.creatis.insa-lyon.fr/~malaterre/vtk/wheel.patch
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)
40 _diameterMinvtkActor = NULL;
41 _diameterMinvtkPolyLine = NULL;
42 _diameterMinvtkDataSetMapper = NULL;
43 _diameterMinvtkUnstructuredGrid = NULL;
46 _diameterMaxvtkActor = NULL;
47 _diameterMaxvtkPolyLine = NULL;
48 _diameterMaxvtkDataSetMapper = NULL;
49 _diameterMaxvtkUnstructuredGrid = NULL;
53 vtk2DQuantSliceWidget::~vtk2DQuantSliceWidget( )
56 if( _cntActor ) _cntActor->Delete();
57 if( _cntMapper ) _cntMapper->Delete();
60 if( _diameterMinvtkActor ) _diameterMinvtkActor->Delete();
61 if( _diameterMinvtkPolyLine ) _diameterMinvtkPolyLine->Delete();
62 if( _diameterMinvtkDataSetMapper ) _diameterMinvtkDataSetMapper->Delete();
63 if( _diameterMinvtkUnstructuredGrid ) _diameterMinvtkUnstructuredGrid->Delete();
66 if( _diameterMaxvtkActor ) _diameterMaxvtkActor->Delete();
67 if( _diameterMaxvtkPolyLine ) _diameterMaxvtkPolyLine->Delete();
68 if( _diameterMaxvtkDataSetMapper ) _diameterMaxvtkDataSetMapper->Delete();
69 if( _diameterMaxvtkUnstructuredGrid ) _diameterMaxvtkUnstructuredGrid->Delete();
72 //----------------------------------------------------------------------------
74 //void vtk2DQuantSliceWidget::SetContour( vtkUnstructuredGrid *cnt )
75 void vtk2DQuantSliceWidget::SetContour( vtkPolyData *cnt )
77 // _cntMapper = vtkDataSetMapper::New( );
78 // _cntMapper = vtkDataSetMapper::New( );
83 _cntMapper = vtkPolyDataMapper::New( );
84 _cntMapper->ScalarVisibilityOff( );
85 _cntMapper->ImmediateModeRenderingOn();
87 _cntMapper->SetInput( _cnt );
88 // _cntMapper->SetInput( _cnt->GetOutput( ) );
91 _cntActor = vtkActor::New( );
92 _cntActor->SetMapper( _cntMapper );
93 (_cntActor->GetProperty( ))->SetColor( 0 , 1 , 0 );
94 (_cntActor->GetProperty( ))->SetLineWidth( 2 );
95 (_cntActor->GetProperty( ))->BackfaceCullingOff( );
98 _imageViewer->GetRenderer()->RemoveActor( _cntActor );
101 _cntActor->SetPosition(0,0,100);
102 _imageViewer->GetRenderer()->AddActor( _cntActor );
103 _imageViewer->Render( );
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();
116 _diameterMinvtkActor = vtkActor::New();
117 _diameterMinvtkPolyLine = vtkPolyLine::New();
118 _diameterMinvtkDataSetMapper = vtkDataSetMapper::New();
119 _diameterMinvtkUnstructuredGrid = vtkUnstructuredGrid::New();
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);
135 if (showActor==true) _imageViewer->GetRenderer()->AddActor( _diameterMinvtkActor );
137 _imageViewer->Render( );
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();
147 _diameterMaxvtkActor = vtkActor::New();
148 _diameterMaxvtkPolyLine = vtkPolyLine::New();
149 _diameterMaxvtkDataSetMapper = vtkDataSetMapper::New();
150 _diameterMaxvtkUnstructuredGrid = vtkUnstructuredGrid::New();
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);
166 if (showActor==true) _imageViewer->GetRenderer()->AddActor( _diameterMaxvtkActor );
168 _imageViewer->Render( );
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( );
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( );
185 //----------------------------------------------------------------------------
186 /*BEGIN_EVENT_TABLE( vtk2DQuantSliceWidget, wxVTKRenderWindowInteractor )
187 EVT_LEFT_DCLICK( vtk2DQuantSliceWidget::OnLeftDClick )