]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxWidgetMesure2D_Plane.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxWidgetMesure2D_Plane.cxx
1 #include "wxWidgetMesure2D_Plane.h"
2
3 #include "vtkPlane2DView.h"
4
5 wxWidgetMesure2D_Plane::wxWidgetMesure2D_Plane(wxWindow *parent)
6 : wxWidgetMesure2D(parent)
7 {
8         // Circle 1
9         _ptsCircle1             = NULL;
10         _circle1Actor   = NULL;
11         _circle1Mapper  = NULL;
12     _pdCircle1          = NULL;
13         // Circle 2
14         _ptsCircle2             = NULL;
15         _circle2Actor   = NULL;
16         _circle2Mapper  = NULL;
17     _pdCircle2          = NULL;
18         // line reference 1
19         _ptsLineRef1    = NULL;
20         _lineRef1Actor  = NULL;
21         _lineRef1Mapper = NULL;
22     _pdLineRef1         = NULL;
23         // line reference 2
24         _ptsLineRef2    = NULL;
25         _lineRef2Actor  = NULL;
26         _lineRef2Mapper = NULL;
27     _pdLineRef2         = NULL;
28
29 }
30
31 //-------------------------------------------------------------------
32
33 wxWidgetMesure2D_Plane::~wxWidgetMesure2D_Plane()
34 {
35         // Circle 1
36     if (        _ptsCircle1             != NULL){       _ptsCircle1                     -> Delete(); }
37     if (        _circle1Actor   != NULL){       _circle1Actor           -> Delete(); }
38     if (        _circle1Mapper  != NULL){       _circle1Mapper          -> Delete(); }
39     if (    _pdCircle1          != NULL){       _pdCircle1                      -> Delete(); }
40         // Circle 2
41     if (        _ptsCircle2             != NULL){       _ptsCircle2                     -> Delete(); }
42     if (        _circle2Actor   != NULL){       _circle2Actor           -> Delete(); }
43     if (        _circle2Mapper  != NULL){       _circle2Mapper          -> Delete(); }
44     if (    _pdCircle2          != NULL){       _pdCircle2                      -> Delete(); }
45         // line reference 1
46     if (        _ptsLineRef1    != NULL){       _ptsLineRef1            -> Delete(); }
47     if (        _lineRef1Actor  != NULL){       _lineRef1Actor          -> Delete(); }
48     if (        _lineRef1Mapper != NULL){       _lineRef1Mapper         -> Delete(); }
49      if (   _pdLineRef1         != NULL){       _pdLineRef1                     -> Delete(); }
50         // line reference 2
51     if (        _ptsLineRef2    != NULL){       _ptsLineRef2            -> Delete(); }
52     if (        _lineRef2Actor  != NULL){       _lineRef2Actor          -> Delete(); }
53     if (        _lineRef2Mapper != NULL){       _lineRef2Mapper         -> Delete(); }
54     if (    _pdLineRef2         != NULL){       _pdLineRef2                     -> Delete(); }
55 }
56
57 //-------------------------------------------------------------------
58
59 wxWindow *wxWidgetMesure2D_Plane::CreateWin1a(wxWindow *parent) // virtual
60 {
61         wxPanel *panel = new wxPanel(parent,-1);
62
63         _cb_circle              = new wxCheckBox(panel,-1,_T("Circle        ")); 
64         _cb_line                = new wxCheckBox(panel,-1,_T("Rotation Axe ")); 
65
66
67         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
68         sizerA->Add(_cb_circle);
69         sizerA->Add(_cb_line);
70
71
72         wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
73         sizer->Add( sizerA );
74         sizer->Add( wxWidgetMesure2D::CreateWin1a(panel) );
75
76         panel->SetAutoLayout(true);
77         panel->SetSizer(sizer);
78         panel->SetSize(400,30);
79         panel->Layout();
80 //EEDxx2.4
81 //      panel->FitInside();
82
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            );
85
86         return panel;
87 }
88
89
90 //-------------------------------------------------------------------
91 void wxWidgetMesure2D_Plane::OnActiveCirlcle(wxCommandEvent& event)
92 {
93         SetVisibleCircle( _cb_circle->GetValue() );
94         _wxvtk2Dbaseview->RefreshView();
95 }
96
97 //-------------------------------------------------------------------
98 void wxWidgetMesure2D_Plane::SetVisibleCircle( bool ok )
99 {
100         double opacity;
101         if (ok==true)
102         {
103                 opacity=1;
104         } else {
105                 opacity=0;
106         } 
107         _lineRef1Actor->GetProperty()->SetOpacity( opacity );
108         _lineRef2Actor->GetProperty()->SetOpacity( opacity );
109         _circle1Actor->GetProperty()->SetOpacity( opacity );
110         _circle2Actor->GetProperty()->SetOpacity( opacity );
111 }
112 //-------------------------------------------------------------------
113 void wxWidgetMesure2D_Plane::OnActiveLine(wxCommandEvent& event)
114 {
115         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
116         vtkplane2Dview->SetVisibleLine( _cb_line->GetValue() );
117         _wxvtk2Dbaseview->RefreshView();
118 }
119
120
121 //-------------------------------------------------------------------
122 void wxWidgetMesure2D_Plane::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
123 {
124         wxWidgetMesure2D::ConfigureA(wxvtk2Dbaseview);
125         CircleLine();
126         ConfigureCircleLine();
127         SetVisibleCircle(false);        
128 }
129
130
131 //-------------------------------------------------------------------
132 void wxWidgetMesure2D_Plane::ConfigureCircleLine()
133 {
134         double ang;
135
136         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
137         int sizeIma = vtkplane2Dview->GetImgSize();
138
139         double i,maxPts=20;
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++)
143         {
144                 x=cos( k*i ) ;
145                 y=sin( k*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 );
148         }
149
150         //
151         ang=(45) * (3.1416/180);
152         x=cos( ang ) ;
153         y=sin( ang ) ;
154         _ptsLineRef1->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
155         
156         ang=(45+180) * (3.1416/180);
157         x=cos( ang ) ;
158         y=sin( ang ) ;
159         _ptsLineRef1->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
160
161         //
162         ang=(135) * (3.1416/180);
163         x=cos( ang ) ;
164         y=sin( ang ) ;
165         _ptsLineRef2->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
166         
167         ang=(135+180) * (3.1416/180);
168         x=cos( ang ) ;
169         y=sin( ang ) ;
170         _ptsLineRef2->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
171 }
172
173
174
175 //-------------------------------------------------------------------
176 void wxWidgetMesure2D_Plane::CircleLine()
177 {
178         int i,maxPts=20;
179         vtkCellArray *lines;
180
181         vtkImageViewer2_XYZ *imageViewer2XYZ = _wxvtk2Dbaseview->_imageViewer2XYZ;
182         
183
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++)
190         {
191                 lines->InsertCellPoint(i);
192                 _ptsCircle1->SetPoint(i, 0      , 0     , 0 );
193         }
194         lines->InsertCellPoint(0);
195         _ptsCircle1->SetPoint(0, -1000  , -1000 , -1000 );
196         _ptsCircle1->SetPoint(1,  1000  ,  1000 ,  1000 );
197
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 );
211
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++)
218         {
219                 lines->InsertCellPoint(i);
220                 _ptsCircle2->SetPoint(i, 0      , 0     , 0 );
221         }
222         _ptsCircle2->SetPoint(0, -1000  , -1000 , -1000 );
223         _ptsCircle2->SetPoint(1,  1000  ,  1000 ,  1000 );
224
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 );
238
239 // Line Referance 1
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);
248
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 );
262
263 // Line Referance 2
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);
272
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 );
286
287
288 }
289