]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxWidgetMesure2D_Plane.cxx
6ffd82d2dfe0c32f17d26bbc80aed4f29b2b86fe
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxWidgetMesure2D_Plane.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "wxWidgetMesure2D_Plane.h"
27
28 #include "vtkPlane2DView.h"
29
30 wxWidgetMesure2D_Plane::wxWidgetMesure2D_Plane(wxWindow *parent)
31 : wxWidgetMesure2D(parent)
32 {
33         // Circle 1
34         _ptsCircle1             = NULL;
35         _circle1Actor   = NULL;
36         _circle1Mapper  = NULL;
37     _pdCircle1          = NULL;
38         // Circle 2
39         _ptsCircle2             = NULL;
40         _circle2Actor   = NULL;
41         _circle2Mapper  = NULL;
42     _pdCircle2          = NULL;
43         // line reference 1
44         _ptsLineRef1    = NULL;
45         _lineRef1Actor  = NULL;
46         _lineRef1Mapper = NULL;
47     _pdLineRef1         = NULL;
48         // line reference 2
49         _ptsLineRef2    = NULL;
50         _lineRef2Actor  = NULL;
51         _lineRef2Mapper = NULL;
52     _pdLineRef2         = NULL;
53
54 }
55
56 //-------------------------------------------------------------------
57
58 wxWidgetMesure2D_Plane::~wxWidgetMesure2D_Plane()
59 {
60         // Circle 1
61     if (        _ptsCircle1             != NULL){       _ptsCircle1                     -> Delete(); }
62     if (        _circle1Actor   != NULL){       _circle1Actor           -> Delete(); }
63     if (        _circle1Mapper  != NULL){       _circle1Mapper          -> Delete(); }
64     if (    _pdCircle1          != NULL){       _pdCircle1                      -> Delete(); }
65         // Circle 2
66     if (        _ptsCircle2             != NULL){       _ptsCircle2                     -> Delete(); }
67     if (        _circle2Actor   != NULL){       _circle2Actor           -> Delete(); }
68     if (        _circle2Mapper  != NULL){       _circle2Mapper          -> Delete(); }
69     if (    _pdCircle2          != NULL){       _pdCircle2                      -> Delete(); }
70         // line reference 1
71     if (        _ptsLineRef1    != NULL){       _ptsLineRef1            -> Delete(); }
72     if (        _lineRef1Actor  != NULL){       _lineRef1Actor          -> Delete(); }
73     if (        _lineRef1Mapper != NULL){       _lineRef1Mapper         -> Delete(); }
74      if (   _pdLineRef1         != NULL){       _pdLineRef1                     -> Delete(); }
75         // line reference 2
76     if (        _ptsLineRef2    != NULL){       _ptsLineRef2            -> Delete(); }
77     if (        _lineRef2Actor  != NULL){       _lineRef2Actor          -> Delete(); }
78     if (        _lineRef2Mapper != NULL){       _lineRef2Mapper         -> Delete(); }
79     if (    _pdLineRef2         != NULL){       _pdLineRef2                     -> Delete(); }
80 }
81
82 //-------------------------------------------------------------------
83
84 wxWindow *wxWidgetMesure2D_Plane::CreateWin1a(wxWindow *parent) // virtual
85 {
86         wxPanel *panel = new wxPanel(parent,-1);
87
88         _cb_circle              = new wxCheckBox(panel,-1,_T("Circle        ")); 
89         _cb_line                = new wxCheckBox(panel,-1,_T("Rotation Axe ")); 
90
91
92         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
93         sizerA->Add(_cb_circle);
94         sizerA->Add(_cb_line);
95
96
97         wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
98         sizer->Add( sizerA );
99         sizer->Add( wxWidgetMesure2D::CreateWin1a(panel) );
100
101         panel->SetAutoLayout(true);
102         panel->SetSizer(sizer);
103         panel->SetSize(400,30);
104         panel->Layout();
105 //EEDxx2.4
106 //      panel->FitInside();
107
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            );
110
111         return panel;
112 }
113
114
115 //-------------------------------------------------------------------
116 void wxWidgetMesure2D_Plane::OnActiveCirlcle(wxCommandEvent& event)
117 {
118         SetVisibleCircle( _cb_circle->GetValue() );
119         _wxvtk2Dbaseview->RefreshView();
120 }
121
122 //-------------------------------------------------------------------
123 void wxWidgetMesure2D_Plane::SetVisibleCircle( bool ok )
124 {
125         double opacity;
126         if (ok==true)
127         {
128                 opacity=1;
129         } else {
130                 opacity=0;
131         } 
132         _lineRef1Actor->GetProperty()->SetOpacity( opacity );
133         _lineRef2Actor->GetProperty()->SetOpacity( opacity );
134         _circle1Actor->GetProperty()->SetOpacity( opacity );
135         _circle2Actor->GetProperty()->SetOpacity( opacity );
136 }
137 //-------------------------------------------------------------------
138 void wxWidgetMesure2D_Plane::OnActiveLine(wxCommandEvent& event)
139 {
140         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
141         vtkplane2Dview->SetVisibleLine( _cb_line->GetValue() );
142         _wxvtk2Dbaseview->RefreshView();
143 }
144
145
146 //-------------------------------------------------------------------
147 void wxWidgetMesure2D_Plane::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
148 {
149         wxWidgetMesure2D::ConfigureA(wxvtk2Dbaseview);
150         CircleLine();
151         ConfigureCircleLine();
152         SetVisibleCircle(false);        
153 }
154
155
156 //-------------------------------------------------------------------
157 void wxWidgetMesure2D_Plane::ConfigureCircleLine()
158 {
159         double ang;
160
161         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
162         int sizeIma = vtkplane2Dview->GetImgSize();
163
164         double i,maxPts=20;
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++)
168         {
169                 x=cos( k*i ) ;
170                 y=sin( k*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 );
173         }
174
175         //
176         ang=(45) * (3.1416/180);
177         x=cos( ang ) ;
178         y=sin( ang ) ;
179         _ptsLineRef1->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
180         
181         ang=(45+180) * (3.1416/180);
182         x=cos( ang ) ;
183         y=sin( ang ) ;
184         _ptsLineRef1->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
185
186         //
187         ang=(135) * (3.1416/180);
188         x=cos( ang ) ;
189         y=sin( ang ) ;
190         _ptsLineRef2->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
191         
192         ang=(135+180) * (3.1416/180);
193         x=cos( ang ) ;
194         y=sin( ang ) ;
195         _ptsLineRef2->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
196 }
197
198
199
200 //-------------------------------------------------------------------
201 void wxWidgetMesure2D_Plane::CircleLine()
202 {
203         int i,maxPts=20;
204         vtkCellArray *lines;
205
206         vtkImageViewer2_XYZ *imageViewer2XYZ = _wxvtk2Dbaseview->_imageViewer2XYZ;
207         
208
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++)
215         {
216                 lines->InsertCellPoint(i);
217                 _ptsCircle1->SetPoint(i, 0      , 0     , 0 );
218         }
219         lines->InsertCellPoint(0);
220         _ptsCircle1->SetPoint(0, -1000  , -1000 , -1000 );
221         _ptsCircle1->SetPoint(1,  1000  ,  1000 ,  1000 );
222
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();
229         _circle1Mapper->SetInput(_pdCircle1);
230         _circle1Mapper->ImmediateModeRenderingOn();
231         _circle1Actor->SetMapper(_circle1Mapper);
232         _circle1Actor->GetProperty()->BackfaceCullingOn();
233         _circle1Actor->GetProperty()->SetDiffuseColor(0,0,1);
234         _circle1Actor->GetProperty()->SetLineWidth(2);
235     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle1Actor );
236
237 // Circle 2 Horizontal
238         _ptsCircle2 = vtkPoints::New();
239         _ptsCircle2->SetNumberOfPoints(maxPts);
240         lines = vtkCellArray::New();
241         lines->InsertNextCell(maxPts);
242         for (i=0;i<maxPts;i++)
243         {
244                 lines->InsertCellPoint(i);
245                 _ptsCircle2->SetPoint(i, 0      , 0     , 0 );
246         }
247         _ptsCircle2->SetPoint(0, -1000  , -1000 , -1000 );
248         _ptsCircle2->SetPoint(1,  1000  ,  1000 ,  1000 );
249
250         _pdCircle2 = vtkPolyData::New();
251     _pdCircle2->SetPoints( _ptsCircle2 );
252     _pdCircle2->SetLines( lines );
253         lines->Delete();  //do not delete lines ??
254         _circle2Actor                                   =       vtkActor::New();
255     _circle2Mapper                                      =       vtkPolyDataMapper::New();
256         _circle2Mapper->SetInput(_pdCircle2);
257         _circle2Mapper->ImmediateModeRenderingOn();
258         _circle2Actor->SetMapper(_circle2Mapper);
259         _circle2Actor->GetProperty()->BackfaceCullingOn();
260         _circle2Actor->GetProperty()->SetDiffuseColor(0,0,1);
261         _circle2Actor->GetProperty()->SetLineWidth(2);
262     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle2Actor );
263
264 // Line Referance 1
265         _ptsLineRef1 = vtkPoints::New();
266         _ptsLineRef1->SetNumberOfPoints(2);
267         _ptsLineRef1->SetPoint(0, -1000 , -1000 , -1000 );
268         _ptsLineRef1->SetPoint(1,  1000 ,  1000 ,  1000 );
269         lines = vtkCellArray::New();
270         lines->InsertNextCell(2);
271         lines->InsertCellPoint(0);
272         lines->InsertCellPoint(1);
273
274         _pdLineRef1 = vtkPolyData::New();
275     _pdLineRef1->SetPoints( _ptsLineRef1 );
276     _pdLineRef1->SetLines( lines );
277         lines->Delete();  //do not delete lines ??
278         _lineRef1Actor                                  =       vtkActor::New();
279     _lineRef1Mapper                                     =       vtkPolyDataMapper::New();
280         _lineRef1Mapper->SetInput(_pdLineRef1);
281         _lineRef1Mapper->ImmediateModeRenderingOn();
282         _lineRef1Actor->SetMapper(_lineRef1Mapper);
283         _lineRef1Actor->GetProperty()->BackfaceCullingOn();
284         _lineRef1Actor->GetProperty()->SetDiffuseColor(0,0,1);
285         _lineRef1Actor->GetProperty()->SetLineWidth(2);
286     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef1Actor );
287
288 // Line Referance 2
289         _ptsLineRef2 = vtkPoints::New();
290         _ptsLineRef2->SetNumberOfPoints(2);
291         _ptsLineRef2->SetPoint(0, -1000 , -1000 , -1000 );
292         _ptsLineRef2->SetPoint(1,  1000 ,  1000 ,  1000 );
293         lines = vtkCellArray::New();
294         lines->InsertNextCell(2);
295         lines->InsertCellPoint(0);
296         lines->InsertCellPoint(1);
297
298         _pdLineRef2 = vtkPolyData::New();
299     _pdLineRef2->SetPoints( _ptsLineRef2 );
300     _pdLineRef2->SetLines( lines );
301         lines->Delete();  //do not delete lines ??
302         _lineRef2Actor                                  =       vtkActor::New();
303     _lineRef2Mapper                                     =       vtkPolyDataMapper::New();
304         _lineRef2Mapper->SetInput(_pdLineRef2);
305         _lineRef2Mapper->ImmediateModeRenderingOn();
306         _lineRef2Actor->SetMapper(_lineRef2Mapper);
307         _lineRef2Actor->GetProperty()->BackfaceCullingOn();
308         _lineRef2Actor->GetProperty()->SetDiffuseColor(0,0,1);
309         _lineRef2Actor->GetProperty()->SetLineWidth(2);
310     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef2Actor );
311
312
313 }
314