]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracas_ViewerWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracas_ViewerWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/10/31 16:32:42 $
7   Version:   $Revision: 1.1 $
8
9   Copyright: (c) 2002, 2003
10   License:
11   
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.
15
16 =========================================================================*/
17
18 //------------------------------------------------------------------------------------------------------------
19 // Definition includes
20 //------------------------------------------------------------------------------------------------------------
21 #include "wxMaracas_ViewerWidget.h"
22
23 //------------------------------------------------------------------------------------------------------------
24 // Other includes
25 //------------------------------------------------------------------------------------------------------------
26
27
28         //------------------------------------------------------------------------------------------------------------
29         // Constructors & Destructors
30         //------------------------------------------------------------------------------------------------------------
31
32
33         wxMaracas_ViewerWidget::wxMaracas_ViewerWidget(wxWindow *parent, vtkImageData* imagedata, int type)
34                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
35         {
36                 wxPanel *panel = this;
37                 wxWindow *wxwindow = NULL;
38
39                 mType = type;
40
41         marImageData    *marimagedata   = new marImageData( imagedata );                        
42                 mvtkmprbasedata                                 = new vtkMPRBaseData(); 
43                 mvtkmprbasedata->SetMarImageData(marimagedata);
44
45                 mvtk2Dbaseview                          = NULL;
46                 mvtkmpr2Dview_X                         = NULL;
47                 mvtkmpr2Dview_Y                         = NULL;
48                 mvtkmpr2Dview_Z                         = NULL;
49                 mvtkplane2Dview                         = NULL;
50                 mwidgetMesure                           = NULL;
51                 mwxsphereview                           = NULL;
52                 mwxvtkclipping3Dview            = NULL;
53                 mwxvtk3Dbaseview_Clipping3D     = NULL;
54                 mwxvtkmpr3Dview                         = NULL; 
55
56                 if (type==-1)
57                 {
58                         mvtk2Dbaseview  = new wxVtk2DBaseView(panel);
59                         mvtk2Dbaseview->SetVtkBaseData(mvtkmprbasedata);
60                         wxwindow                = mvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
61                 }
62
63
64                 if (type==0)
65                 {
66                         mvtkmpr2Dview_Z = new wxVtkMPR2DView(panel,0);
67                         mvtkmpr2Dview_Z->SetVtkBaseData(mvtkmprbasedata);
68                         wxwindow                = mvtkmpr2Dview_Z->GetWxVTKRenderWindowInteractor();
69                 }
70                 if (type==1)
71                 {
72                         mvtkmpr2Dview_X = new wxVtkMPR2DView(panel,1);
73                         mvtkmpr2Dview_X->SetVtkBaseData(mvtkmprbasedata);
74                         wxwindow                =       mvtkmpr2Dview_X->GetWxVTKRenderWindowInteractor();
75                 }
76                 if (type==2)
77                 {
78                         mvtkmpr2Dview_Y = new wxVtkMPR2DView(panel,2);
79                         mvtkmpr2Dview_Y->SetVtkBaseData(mvtkmprbasedata);
80                         wxwindow                = mvtkmpr2Dview_Y->GetWxVTKRenderWindowInteractor();
81                 }
82
83
84                 if (type==3)
85                 {
86                         mwidgetMesure           = new wxWidgetMesure2D_Plane_in_MPR(panel);
87                         mvtkplane2Dview         = new vtkPlane2DView( mwidgetMesure->GetWindow2());
88                         mwidgetMesure   -> SetVtkPlane2DView( mvtkplane2Dview );
89                         mvtkplane2Dview -> SetImgSize( 200 );
90                         mvtkplane2Dview -> SetVtkBaseData(mvtkmprbasedata);
91                         wxwindow                        = mwidgetMesure;
92                 }
93                 if (type==4)
94                 {
95                         mwxsphereview           = new wxSphereView( panel , mvtkmprbasedata, mvtkmprbasedata->GetImageData() );
96                         wxwindow=mwxsphereview->GetWxVTKRenderWindowInteractor();
97                 }
98
99
100                 if (type==5)
101                 {
102                         wxSplitterWindow        *panelClipping3D        = new wxSplitterWindow( panel , -1);
103                         mwxvtk3Dbaseview_Clipping3D                             = new wxVtk3DBaseView( panelClipping3D );
104
105                         mwxvtkclipping3Dview                                            = new wxVtkClipping3DView(mwxvtk3Dbaseview_Clipping3D);
106                         vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
107                         vtkclipping3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
108                         vtkclipping3Ddataviewer->Configure();
109                         mwxvtkclipping3Dview->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
110
111                         mwxvtkmpr3Dview                                                 = new wxVtkMPR3DView( mwxvtk3Dbaseview_Clipping3D );
112                         vtkMPR3DDataViewer *vtkmpr3Ddataviewer  = new vtkMPR3DDataViewer(); 
113                         vtkmpr3Ddataviewer->SetVtkMPRBaseData(mvtkmprbasedata);
114                         vtkmpr3Ddataviewer->Configure();
115                         mwxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
116
117                         wxWindow        *window3D                                       = mwxvtk3Dbaseview_Clipping3D->GetWxVTKRenderWindowInteractor();
118
119                         wxPanel                 *panelControl                   = new wxPanel(panelClipping3D,-1);      
120                         wxPanel                 *controlPanelMPR3D              = mwxvtkmpr3Dview->CreateControlPanel(panelControl);
121                         wxPanel                 *controlPanelClipping3D = mwxvtkclipping3Dview->CreateControlPanel(panelControl);
122         //                               mbtnCutImageData               = new wxCheckBox(panelControl,-1,_T("Cut Module"));
123         //              Connect(_btnCutImageData->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED  , (wxObjectEventFunction) &wxMPRWidget::OnCutImagaData );
124
125                         wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
126                         sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
127                         sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
128         //              sizerCtrol->Add( mbtnCutImageData               , 1, wxALL, 2);
129
130                         panelControl->SetAutoLayout(true);
131                         panelControl->SetSizer(sizerCtrol);
132                         panelControl->SetSize(400,350);
133                         panelControl->Layout();
134                         panelClipping3D -> SetMinimumPaneSize( 5 );
135                         panelClipping3D -> SplitHorizontally( panelControl , window3D , 10  );
136                         wxwindow=panelClipping3D;
137                 }
138
139         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
140         sizer->Add( wxwindow , 1, wxEXPAND, 0);
141         panel->SetSizer(sizer);
142         panel->SetAutoLayout(true);
143         panel->Layout();
144
145         //   mbbtkViewerMaracas= NULL;
146         }
147         //-------------------------------------------------------------------------
148           
149         wxMaracas_ViewerWidget::~wxMaracas_ViewerWidget()
150         {
151
152         }
153             
154         //------------------------------------------------------------------------------------------------------------
155         // Methods
156         //------------------------------------------------------------------------------------------------------------
157
158         //-------------------------------------------------------------------------
159
160         void wxMaracas_ViewerWidget::ConfigureVTK()
161         {
162                 int x=0,y=0,z=0;
163
164                 if ( mvtk2Dbaseview                             !=NULL ) { mvtk2Dbaseview                               ->      Configure();                            }
165                 if ( mvtkmpr2Dview_X                    !=NULL ) { mvtkmpr2Dview_X                              ->      Configure();                            }
166                 if ( mvtkmpr2Dview_Y                    !=NULL ) { mvtkmpr2Dview_Y                              ->      Configure();                            }
167                 if ( mvtkmpr2Dview_Z                    !=NULL ) { mvtkmpr2Dview_Z                              ->      Configure();                            }
168                 if ( mvtkplane2Dview                    !=NULL ) { mvtkplane2Dview                              ->      Configure();                            }
169                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      ConfigureA(mvtkplane2Dview);}
170                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      ConfigureA(mvtkplane2Dview);}
171                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      SetActiveLink(true);            }
172                 if ( mwidgetMesure                              !=NULL ) { mwidgetMesure                                ->      SetMesureScale( 1 );            }
173                 if ( mwxsphereview                              !=NULL ) { mwxsphereview                                ->      Configure();                            }
174
175                 if (mwxvtk3Dbaseview_Clipping3D !=NULL) { mwxvtk3Dbaseview_Clipping3D   ->      Configure();                            }
176                 if (mwxvtkmpr3Dview                             !=NULL) { mwxvtkmpr3Dview                               ->      Configure();                            }
177                 if (mwxvtkclipping3Dview                !=NULL) { mwxvtkclipping3Dview                  ->      Configure();                            }
178
179                 if (mvtkmprbasedata!=NULL)
180                 {
181                         x = mvtkmprbasedata     ->      GetMaxPositionX()/2;
182                         y = mvtkmprbasedata     ->      GetMaxPositionY()/2;
183                         z = mvtkmprbasedata     ->      GetMaxPositionZ()/2;
184                         mvtkmprbasedata->SetX( x );
185                         mvtkmprbasedata->SetY( y );
186                         mvtkmprbasedata->SetZ( z );
187                 }
188                 RefreshView();
189         }
190
191         //-------------------------------------------------------------------------
192
193   void wxMaracas_ViewerWidget::Refresh(bool eraseBackground ,const wxRect* rect  )  // virtual  eraseBackground=true , rect=NULL
194   {
195     wxPanel::Refresh(false);
196   }
197
198         //-------------------------------------------------------------------------
199         void wxMaracas_ViewerWidget::RefreshView()
200         {
201                         if (mvtk2Dbaseview                              !=NULL ){ mvtk2Dbaseview                                -> Refresh();           }
202                         if (mvtkmpr2Dview_X                             !=NULL ){ mvtkmpr2Dview_X                               -> Refresh();           }
203                         if (mvtkmpr2Dview_Y                             !=NULL ){ mvtkmpr2Dview_Y                               -> Refresh();           }
204                         if (mvtkmpr2Dview_Z                             !=NULL ){ mvtkmpr2Dview_Z                               -> Refresh();           }
205                         if (mvtkplane2Dview                             !=NULL ){ mvtkplane2Dview                               -> Refresh();           }
206                         if (mwxsphereview                               !=NULL ){ mwxsphereview                                 -> Refresh();           }
207
208                         if (mwxvtkmpr3Dview                             !=NULL ){ mwxvtkmpr3Dview                               -> RefreshView();       }
209                         if (mwxvtkclipping3Dview                !=NULL ){ mwxvtkclipping3Dview                  -> Refresh();           }
210                         if (mwxvtk3Dbaseview_Clipping3D !=NULL ){ mwxvtk3Dbaseview_Clipping3D   -> Refresh();           }
211         }
212
213         //-------------------------------------------------------------------------
214
215         wxVtkBaseView *wxMaracas_ViewerWidget::GetwxVtkBaseView()
216         {
217                 wxVtkBaseView *wxvtkbaseview=NULL;
218                 if (mvtk2Dbaseview!=NULL)                               { wxvtkbaseview = mvtk2Dbaseview;                       }
219                 if (mvtkmpr2Dview_X!=NULL)                              { wxvtkbaseview = mvtkmpr2Dview_X;                      }
220                 if (mvtkmpr2Dview_Y!=NULL)                              { wxvtkbaseview = mvtkmpr2Dview_Y;                      }
221                 if (mvtkmpr2Dview_Z!=NULL)                              { wxvtkbaseview = mvtkmpr2Dview_Z;                      }
222                 if (mvtkplane2Dview!=NULL)                              { wxvtkbaseview = mvtkplane2Dview;                      }
223                 if (mwxsphereview!=NULL)                                { wxvtkbaseview = mwxsphereview;                        }
224                 if (mwxvtk3Dbaseview_Clipping3D!=NULL)  { wxvtkbaseview = mwxvtk3Dbaseview_Clipping3D;}
225                 return wxvtkbaseview   ;
226         }
227
228         void wxMaracas_ViewerWidget::SetImage( vtkImageData *image      )
229         {
230                 printf("EED wxMaracas_ViewerWidget::SetImage   IMPORTANT this methode is missing \n");
231         }
232
233         double wxMaracas_ViewerWidget :: GetX()
234         {
235                 return mvtkmprbasedata->GetX();
236         }
237
238         double wxMaracas_ViewerWidget :: GetY()
239         {
240                 return mvtkmprbasedata->GetY();
241         }
242
243         double wxMaracas_ViewerWidget :: GetZ()
244         {
245                 return mvtkmprbasedata->GetZ();
246 //              return mvtk2Dbaseview->GetVtkBaseData()->GetZ();
247         }
248