1 #include "wxWidgetMesure2D_Plane.h"
3 #include "vtkPlane2DView.h"
5 wxWidgetMesure2D_Plane::wxWidgetMesure2D_Plane(wxWindow *parent)
6 : wxWidgetMesure2D(parent)
11 _circle1Mapper = NULL;
16 _circle2Mapper = NULL;
20 _lineRef1Actor = NULL;
21 _lineRef1Mapper = NULL;
25 _lineRef2Actor = NULL;
26 _lineRef2Mapper = NULL;
31 //-------------------------------------------------------------------
33 wxWidgetMesure2D_Plane::~wxWidgetMesure2D_Plane()
36 if ( _ptsCircle1 != NULL){ _ptsCircle1 -> Delete(); }
37 if ( _circle1Actor != NULL){ _circle1Actor -> Delete(); }
38 if ( _circle1Mapper != NULL){ _circle1Mapper -> Delete(); }
39 if ( _pdCircle1 != NULL){ _pdCircle1 -> Delete(); }
41 if ( _ptsCircle2 != NULL){ _ptsCircle2 -> Delete(); }
42 if ( _circle2Actor != NULL){ _circle2Actor -> Delete(); }
43 if ( _circle2Mapper != NULL){ _circle2Mapper -> Delete(); }
44 if ( _pdCircle2 != NULL){ _pdCircle2 -> Delete(); }
46 if ( _ptsLineRef1 != NULL){ _ptsLineRef1 -> Delete(); }
47 if ( _lineRef1Actor != NULL){ _lineRef1Actor -> Delete(); }
48 if ( _lineRef1Mapper != NULL){ _lineRef1Mapper -> Delete(); }
49 if ( _pdLineRef1 != NULL){ _pdLineRef1 -> Delete(); }
51 if ( _ptsLineRef2 != NULL){ _ptsLineRef2 -> Delete(); }
52 if ( _lineRef2Actor != NULL){ _lineRef2Actor -> Delete(); }
53 if ( _lineRef2Mapper != NULL){ _lineRef2Mapper -> Delete(); }
54 if ( _pdLineRef2 != NULL){ _pdLineRef2 -> Delete(); }
57 //-------------------------------------------------------------------
59 wxWindow *wxWidgetMesure2D_Plane::CreateWin1a(wxWindow *parent) // virtual
61 wxPanel *panel = new wxPanel(parent,-1);
63 _cb_circle = new wxCheckBox(panel,-1,_T("Circle "));
64 _cb_line = new wxCheckBox(panel,-1,_T("Rotation Axe "));
67 wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
68 sizerA->Add(_cb_circle);
69 sizerA->Add(_cb_line);
72 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
74 sizer->Add( wxWidgetMesure2D::CreateWin1a(panel) );
76 panel->SetAutoLayout(true);
77 panel->SetSizer(sizer);
78 panel->SetSize(400,30);
81 // panel->FitInside();
83 Connect(_cb_line->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveLine );
84 Connect(_cb_circle->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveCirlcle );
90 //-------------------------------------------------------------------
91 void wxWidgetMesure2D_Plane::OnActiveCirlcle(wxCommandEvent& event)
93 SetVisibleCircle( _cb_circle->GetValue() );
94 _wxvtk2Dbaseview->RefreshView();
97 //-------------------------------------------------------------------
98 void wxWidgetMesure2D_Plane::SetVisibleCircle( bool ok )
107 _lineRef1Actor->GetProperty()->SetOpacity( opacity );
108 _lineRef2Actor->GetProperty()->SetOpacity( opacity );
109 _circle1Actor->GetProperty()->SetOpacity( opacity );
110 _circle2Actor->GetProperty()->SetOpacity( opacity );
112 //-------------------------------------------------------------------
113 void wxWidgetMesure2D_Plane::OnActiveLine(wxCommandEvent& event)
115 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
116 vtkplane2Dview->SetVisibleLine( _cb_line->GetValue() );
117 _wxvtk2Dbaseview->RefreshView();
121 //-------------------------------------------------------------------
122 void wxWidgetMesure2D_Plane::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
124 wxWidgetMesure2D::ConfigureA(wxvtk2Dbaseview);
126 ConfigureCircleLine();
127 SetVisibleCircle(false);
131 //-------------------------------------------------------------------
132 void wxWidgetMesure2D_Plane::ConfigureCircleLine()
136 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
137 int sizeIma = vtkplane2Dview->GetImgSize();
140 double k=(360/(maxPts-1)) * (3.1416/180);
141 double x,y,r1=5,r2=10,r3=15;
142 for (i=0;i<maxPts;i++)
146 _ptsCircle1->SetPoint( (int)i , (sizeIma/2) + x*r1 , (sizeIma/2) + y*r1 , 1 );
147 _ptsCircle2->SetPoint( (int)i , (sizeIma/2) + x*r2 , (sizeIma/2) + y*r2 , 1 );
151 ang=(45) * (3.1416/180);
154 _ptsLineRef1->SetPoint( 0 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
156 ang=(45+180) * (3.1416/180);
159 _ptsLineRef1->SetPoint( 1 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
162 ang=(135) * (3.1416/180);
165 _ptsLineRef2->SetPoint( 0 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
167 ang=(135+180) * (3.1416/180);
170 _ptsLineRef2->SetPoint( 1 , (sizeIma/2) + x*r3 , (sizeIma/2) + y*r3 , 1 );
175 //-------------------------------------------------------------------
176 void wxWidgetMesure2D_Plane::CircleLine()
181 vtkImageViewer2_XYZ *imageViewer2XYZ = _wxvtk2Dbaseview->_imageViewer2XYZ;
184 // Circle 1 Horizontal
185 _ptsCircle1 = vtkPoints::New();
186 _ptsCircle1->SetNumberOfPoints(maxPts);
187 lines = vtkCellArray::New();
188 lines->InsertNextCell(maxPts);
189 for (i=0;i<maxPts;i++)
191 lines->InsertCellPoint(i);
192 _ptsCircle1->SetPoint(i, 0 , 0 , 0 );
194 lines->InsertCellPoint(0);
195 _ptsCircle1->SetPoint(0, -1000 , -1000 , -1000 );
196 _ptsCircle1->SetPoint(1, 1000 , 1000 , 1000 );
198 _pdCircle1 = vtkPolyData::New();
199 _pdCircle1->SetPoints( _ptsCircle1 );
200 _pdCircle1->SetLines( lines );
201 lines->Delete(); //do not delete lines ??
202 _circle1Actor = vtkActor::New();
203 _circle1Mapper = vtkPolyDataMapper::New();
204 _circle1Mapper->SetInput(_pdCircle1);
205 _circle1Mapper->ImmediateModeRenderingOn();
206 _circle1Actor->SetMapper(_circle1Mapper);
207 _circle1Actor->GetProperty()->BackfaceCullingOn();
208 _circle1Actor->GetProperty()->SetDiffuseColor(0,0,1);
209 _circle1Actor->GetProperty()->SetLineWidth(2);
210 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle1Actor );
212 // Circle 2 Horizontal
213 _ptsCircle2 = vtkPoints::New();
214 _ptsCircle2->SetNumberOfPoints(maxPts);
215 lines = vtkCellArray::New();
216 lines->InsertNextCell(maxPts);
217 for (i=0;i<maxPts;i++)
219 lines->InsertCellPoint(i);
220 _ptsCircle2->SetPoint(i, 0 , 0 , 0 );
222 _ptsCircle2->SetPoint(0, -1000 , -1000 , -1000 );
223 _ptsCircle2->SetPoint(1, 1000 , 1000 , 1000 );
225 _pdCircle2 = vtkPolyData::New();
226 _pdCircle2->SetPoints( _ptsCircle2 );
227 _pdCircle2->SetLines( lines );
228 lines->Delete(); //do not delete lines ??
229 _circle2Actor = vtkActor::New();
230 _circle2Mapper = vtkPolyDataMapper::New();
231 _circle2Mapper->SetInput(_pdCircle2);
232 _circle2Mapper->ImmediateModeRenderingOn();
233 _circle2Actor->SetMapper(_circle2Mapper);
234 _circle2Actor->GetProperty()->BackfaceCullingOn();
235 _circle2Actor->GetProperty()->SetDiffuseColor(0,0,1);
236 _circle2Actor->GetProperty()->SetLineWidth(2);
237 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle2Actor );
240 _ptsLineRef1 = vtkPoints::New();
241 _ptsLineRef1->SetNumberOfPoints(2);
242 _ptsLineRef1->SetPoint(0, -1000 , -1000 , -1000 );
243 _ptsLineRef1->SetPoint(1, 1000 , 1000 , 1000 );
244 lines = vtkCellArray::New();
245 lines->InsertNextCell(2);
246 lines->InsertCellPoint(0);
247 lines->InsertCellPoint(1);
249 _pdLineRef1 = vtkPolyData::New();
250 _pdLineRef1->SetPoints( _ptsLineRef1 );
251 _pdLineRef1->SetLines( lines );
252 lines->Delete(); //do not delete lines ??
253 _lineRef1Actor = vtkActor::New();
254 _lineRef1Mapper = vtkPolyDataMapper::New();
255 _lineRef1Mapper->SetInput(_pdLineRef1);
256 _lineRef1Mapper->ImmediateModeRenderingOn();
257 _lineRef1Actor->SetMapper(_lineRef1Mapper);
258 _lineRef1Actor->GetProperty()->BackfaceCullingOn();
259 _lineRef1Actor->GetProperty()->SetDiffuseColor(0,0,1);
260 _lineRef1Actor->GetProperty()->SetLineWidth(2);
261 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef1Actor );
264 _ptsLineRef2 = vtkPoints::New();
265 _ptsLineRef2->SetNumberOfPoints(2);
266 _ptsLineRef2->SetPoint(0, -1000 , -1000 , -1000 );
267 _ptsLineRef2->SetPoint(1, 1000 , 1000 , 1000 );
268 lines = vtkCellArray::New();
269 lines->InsertNextCell(2);
270 lines->InsertCellPoint(0);
271 lines->InsertCellPoint(1);
273 _pdLineRef2 = vtkPolyData::New();
274 _pdLineRef2->SetPoints( _ptsLineRef2 );
275 _pdLineRef2->SetLines( lines );
276 lines->Delete(); //do not delete lines ??
277 _lineRef2Actor = vtkActor::New();
278 _lineRef2Mapper = vtkPolyDataMapper::New();
279 _lineRef2Mapper->SetInput(_pdLineRef2);
280 _lineRef2Mapper->ImmediateModeRenderingOn();
281 _lineRef2Actor->SetMapper(_lineRef2Mapper);
282 _lineRef2Actor->GetProperty()->BackfaceCullingOn();
283 _lineRef2Actor->GetProperty()->SetDiffuseColor(0,0,1);
284 _lineRef2Actor->GetProperty()->SetLineWidth(2);
285 imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef2Actor );