1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "wxWidgetMesure2D_Plane.h"
28 #include "vtkPlane2DView.h"
30 wxWidgetMesure2D_Plane::wxWidgetMesure2D_Plane(wxWindow *parent)
31 : wxWidgetMesure2D(parent)
36 _circle1Mapper = NULL;
41 _circle2Mapper = NULL;
45 _lineRef1Actor = NULL;
46 _lineRef1Mapper = NULL;
50 _lineRef2Actor = NULL;
51 _lineRef2Mapper = NULL;
56 //-------------------------------------------------------------------
58 wxWidgetMesure2D_Plane::~wxWidgetMesure2D_Plane()
61 if ( _ptsCircle1 != NULL){ _ptsCircle1 -> Delete(); }
62 if ( _circle1Actor != NULL){ _circle1Actor -> Delete(); }
63 if ( _circle1Mapper != NULL){ _circle1Mapper -> Delete(); }
64 if ( _pdCircle1 != NULL){ _pdCircle1 -> Delete(); }
66 if ( _ptsCircle2 != NULL){ _ptsCircle2 -> Delete(); }
67 if ( _circle2Actor != NULL){ _circle2Actor -> Delete(); }
68 if ( _circle2Mapper != NULL){ _circle2Mapper -> Delete(); }
69 if ( _pdCircle2 != NULL){ _pdCircle2 -> Delete(); }
71 if ( _ptsLineRef1 != NULL){ _ptsLineRef1 -> Delete(); }
72 if ( _lineRef1Actor != NULL){ _lineRef1Actor -> Delete(); }
73 if ( _lineRef1Mapper != NULL){ _lineRef1Mapper -> Delete(); }
74 if ( _pdLineRef1 != NULL){ _pdLineRef1 -> Delete(); }
76 if ( _ptsLineRef2 != NULL){ _ptsLineRef2 -> Delete(); }
77 if ( _lineRef2Actor != NULL){ _lineRef2Actor -> Delete(); }
78 if ( _lineRef2Mapper != NULL){ _lineRef2Mapper -> Delete(); }
79 if ( _pdLineRef2 != NULL){ _pdLineRef2 -> Delete(); }
82 //-------------------------------------------------------------------
84 wxWindow *wxWidgetMesure2D_Plane::CreateWin1a(wxWindow *parent) // virtual
86 wxPanel *panel = new wxPanel(parent,-1);
88 _cb_circle = new wxCheckBox(panel,-1,_T("Circle "));
89 _cb_line = new wxCheckBox(panel,-1,_T("Rotation Axe "));
92 wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
93 sizerA->Add(_cb_circle);
94 sizerA->Add(_cb_line);
97 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
99 sizer->Add( wxWidgetMesure2D::CreateWin1a(panel) );
101 panel->SetAutoLayout(true);
102 panel->SetSizer(sizer);
103 panel->SetSize(400,30);
106 // panel->FitInside();
108 Connect(_cb_line->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveLine );
109 Connect(_cb_circle->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveCirlcle );
115 //-------------------------------------------------------------------
116 void wxWidgetMesure2D_Plane::OnActiveCirlcle(wxCommandEvent& event)
118 SetVisibleCircle( _cb_circle->GetValue() );
119 _wxvtk2Dbaseview->RefreshView();
122 //-------------------------------------------------------------------
123 void wxWidgetMesure2D_Plane::SetVisibleCircle( bool ok )
132 _lineRef1Actor->GetProperty()->SetOpacity( opacity );
133 _lineRef2Actor->GetProperty()->SetOpacity( opacity );
134 _circle1Actor->GetProperty()->SetOpacity( opacity );
135 _circle2Actor->GetProperty()->SetOpacity( opacity );
137 //-------------------------------------------------------------------
138 void wxWidgetMesure2D_Plane::OnActiveLine(wxCommandEvent& event)
140 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
141 vtkplane2Dview->SetVisibleLine( _cb_line->GetValue() );
142 _wxvtk2Dbaseview->RefreshView();
146 //-------------------------------------------------------------------
147 void wxWidgetMesure2D_Plane::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
149 wxWidgetMesure2D::ConfigureA(wxvtk2Dbaseview);
151 ConfigureCircleLine();
152 SetVisibleCircle(false);
156 //-------------------------------------------------------------------
157 void wxWidgetMesure2D_Plane::ConfigureCircleLine()
161 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
162 int sizeIma = vtkplane2Dview->GetImgSize();
165 double k=(360/(maxPts-1)) * (3.1416/180);
166 double x,y,r1=5,r2=10,r3=15;
167 for (i=0;i<maxPts;i++)
171 _ptsCircle1->SetPoint( (int)i , (sizeIma/2) + x*r1 , (sizeIma/2) + y*r1 , 1 );
172 _ptsCircle2->SetPoint( (int)i , (sizeIma/2) + x*r2 , (sizeIma/2) + y*r2 , 1 );
176 ang=(45) * (3.1416/180);
179 _ptsLineRef1->SetPoint( 0 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
181 ang=(45+180) * (3.1416/180);
184 _ptsLineRef1->SetPoint( 1 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
187 ang=(135) * (3.1416/180);
190 _ptsLineRef2->SetPoint( 0 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
192 ang=(135+180) * (3.1416/180);
195 _ptsLineRef2->SetPoint( 1 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
200 //-------------------------------------------------------------------
201 void wxWidgetMesure2D_Plane::CircleLine()
206 vtkImageViewer2_XYZ *imageViewer2XYZ = _wxvtk2Dbaseview->_imageViewer2XYZ;
209 // Circle 1 Horizontal
210 _ptsCircle1 = vtkPoints::New();
211 _ptsCircle1->SetNumberOfPoints(maxPts);
212 lines = vtkCellArray::New();
213 lines->InsertNextCell(maxPts);
214 for (i=0;i<maxPts;i++)
216 lines->InsertCellPoint(i);
217 _ptsCircle1->SetPoint(i, 0 , 0 , 0 );
219 lines->InsertCellPoint(0);
220 _ptsCircle1->SetPoint(0, -1000 , -1000 , -1000 );
221 _ptsCircle1->SetPoint(1, 1000 , 1000 , 1000 );
223 _pdCircle1 = vtkPolyData::New();
224 _pdCircle1->SetPoints( _ptsCircle1 );
225 _pdCircle1->SetLines( lines );
226 lines->Delete(); //do not delete lines ??
227 _circle1Actor = vtkActor::New();
228 _circle1Mapper = vtkPolyDataMapper::New();
230 //EED 2017-01-01 Migration VTK7
231 #if VTK_MAJOR_VERSION <= 5
232 _circle1Mapper->SetInput(_pdCircle1);
233 _circle1Mapper->ImmediateModeRenderingOn();
235 _circle1Mapper->SetInputData(_pdCircle1);
237 _circle1Actor->SetMapper(_circle1Mapper);
238 _circle1Actor->GetProperty()->BackfaceCullingOn();
239 _circle1Actor->GetProperty()->SetDiffuseColor(0,0,1);
240 _circle1Actor->GetProperty()->SetLineWidth(2);
241 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle1Actor );
243 // Circle 2 Horizontal
244 _ptsCircle2 = vtkPoints::New();
245 _ptsCircle2->SetNumberOfPoints(maxPts);
246 lines = vtkCellArray::New();
247 lines->InsertNextCell(maxPts);
248 for (i=0;i<maxPts;i++)
250 lines->InsertCellPoint(i);
251 _ptsCircle2->SetPoint(i, 0 , 0 , 0 );
253 _ptsCircle2->SetPoint(0, -1000 , -1000 , -1000 );
254 _ptsCircle2->SetPoint(1, 1000 , 1000 , 1000 );
256 _pdCircle2 = vtkPolyData::New();
257 _pdCircle2->SetPoints( _ptsCircle2 );
258 _pdCircle2->SetLines( lines );
259 lines->Delete(); //do not delete lines ??
260 _circle2Actor = vtkActor::New();
261 _circle2Mapper = vtkPolyDataMapper::New();
262 //EED 2017-01-01 Migration VTK7
263 #if VTK_MAJOR_VERSION <= 5
264 _circle2Mapper->SetInput(_pdCircle2);
265 _circle2Mapper->ImmediateModeRenderingOn();
267 _circle2Mapper->SetInputData(_pdCircle2);
269 _circle2Actor->SetMapper(_circle2Mapper);
270 _circle2Actor->GetProperty()->BackfaceCullingOn();
271 _circle2Actor->GetProperty()->SetDiffuseColor(0,0,1);
272 _circle2Actor->GetProperty()->SetLineWidth(2);
273 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle2Actor );
276 _ptsLineRef1 = vtkPoints::New();
277 _ptsLineRef1->SetNumberOfPoints(2);
278 _ptsLineRef1->SetPoint(0, -1000 , -1000 , -1000 );
279 _ptsLineRef1->SetPoint(1, 1000 , 1000 , 1000 );
280 lines = vtkCellArray::New();
281 lines->InsertNextCell(2);
282 lines->InsertCellPoint(0);
283 lines->InsertCellPoint(1);
285 _pdLineRef1 = vtkPolyData::New();
286 _pdLineRef1->SetPoints( _ptsLineRef1 );
287 _pdLineRef1->SetLines( lines );
288 lines->Delete(); //do not delete lines ??
289 _lineRef1Actor = vtkActor::New();
290 _lineRef1Mapper = vtkPolyDataMapper::New();
292 //EED 2017-01-01 Migration VTK7
293 #if VTK_MAJOR_VERSION <= 5
294 _lineRef1Mapper->SetInput(_pdLineRef1);
295 _lineRef1Mapper->ImmediateModeRenderingOn();
297 _lineRef1Mapper->SetInputData(_pdLineRef1);
300 _lineRef1Actor->SetMapper(_lineRef1Mapper);
301 _lineRef1Actor->GetProperty()->BackfaceCullingOn();
302 _lineRef1Actor->GetProperty()->SetDiffuseColor(0,0,1);
303 _lineRef1Actor->GetProperty()->SetLineWidth(2);
304 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef1Actor );
307 _ptsLineRef2 = vtkPoints::New();
308 _ptsLineRef2->SetNumberOfPoints(2);
309 _ptsLineRef2->SetPoint(0, -1000 , -1000 , -1000 );
310 _ptsLineRef2->SetPoint(1, 1000 , 1000 , 1000 );
311 lines = vtkCellArray::New();
312 lines->InsertNextCell(2);
313 lines->InsertCellPoint(0);
314 lines->InsertCellPoint(1);
316 _pdLineRef2 = vtkPolyData::New();
317 _pdLineRef2->SetPoints( _ptsLineRef2 );
318 _pdLineRef2->SetLines( lines );
319 lines->Delete(); //do not delete lines ??
320 _lineRef2Actor = vtkActor::New();
321 _lineRef2Mapper = vtkPolyDataMapper::New();
323 //EED 2017-01-01 Migration VTK7
324 #if VTK_MAJOR_VERSION <= 5
325 _lineRef2Mapper->SetInput(_pdLineRef2);
326 _lineRef2Mapper->ImmediateModeRenderingOn();
328 _lineRef2Mapper->SetInputData(_pdLineRef2);
331 _lineRef2Actor->SetMapper(_lineRef2Mapper);
332 _lineRef2Actor->GetProperty()->BackfaceCullingOn();
333 _lineRef2Actor->GetProperty()->SetDiffuseColor(0,0,1);
334 _lineRef2Actor->GetProperty()->SetLineWidth(2);
335 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef2Actor );