]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracas_N_ViewersWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/09/15 11:25:07 $
7   Version:   $Revision: 1.12 $
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_N_ViewersWidget.h"
22
23 //------------------------------------------------------------------------------------------------------------
24 // Other includes
25 //------------------------------------------------------------------------------------------------------------
26
27
28         //------------------------------------------------------------------------------------------------------------
29         // Constructors & Destructors
30         //------------------------------------------------------------------------------------------------------------
31
32
33         BEGIN_EVENT_TABLE( wxMaracas_N_ViewersWidget, wxPanel )
34                 EVT_MENU( 12121, wxMaracas_N_ViewersWidget::OnRefreshView )
35                 EVT_MENU( 12122, wxMaracas_N_ViewersWidget::OnDClickLeft  )
36         END_EVENT_TABLE( );
37
38         
39         //------------------------------------------------------------------------------------------------------------
40         // Constructors & Destructors
41         //------------------------------------------------------------------------------------------------------------
42
43
44
45         wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata, std::vector<int> *nTypeView)
46                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
47         {
48                 wxwindow1               = NULL;
49                 wxwindow2               = NULL;
50                 wxwindow3               = NULL;
51                 wxwindow4               = NULL;
52                 _currentwxw             = NULL;
53                 mvtkmprbasedata = NULL;
54                 
55                 wxSizer *sizer  = new wxBoxSizer(wxVERTICAL);
56                 this->SetSizer(sizer);
57                 this->SetAutoLayout(true);
58                 
59                 
60                 if(imagedata!=NULL && nTypeView!=NULL ){
61                         this->SetType(nTypeView);
62                         this->UpdateLayout(imagedata);
63                 }
64
65                 
66         }
67         //-------------------------------------------------------------------------
68           
69         wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
70         {
71                 if (mvtkmprbasedata!=NULL)
72                 {
73                         delete mvtkmprbasedata;
74                 }
75
76         }
77         //------------------------------------------------------------------------------------------------------------
78         // Methods
79         //------------------------------------------------------------------------------------------------------------
80
81
82         //-------------------------------------------------------------------------
83
84         void wxMaracas_N_ViewersWidget::Update()
85         {
86                 //wxvtkrenderwindowinteractor->Render();
87         //    wxvtkrenderwindowinteractor->Refresh();
88         //    Refresh();
89         }
90
91         //-------------------------------------------------------------------------
92
93         void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event) 
94         {
95                 RefreshView();
96         }
97         //----------------------------------------------------------------------------
98         void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event) 
99         {
100                 RefreshView();
101         }
102
103                 //-------------------------------------------------------------------------
104
105         vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
106         {
107                 return NULL; //renderer;
108         }
109
110         void wxMaracas_N_ViewersWidget::RefreshView()
111         {               
112                 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
113                 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
114                 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
115                 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
116         }
117
118         //-------------------------------------------------------------------------
119         wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)  
120         {
121                 wxMaracas_ViewerWidget *tmpWin=NULL;
122                 if  (iWin==1)
123                 {
124                         tmpWin=wxwindow1;
125                 }
126                 if  (iWin==2)
127                 {
128                         tmpWin=wxwindow2;
129                 }
130                 if  (iWin==3)
131                 {
132                         tmpWin=wxwindow3;
133                 }
134                 if  (iWin==4)
135                 {
136                         tmpWin=wxwindow4;
137                 }
138                 return tmpWin;
139         }
140
141         //-------------------------------------------------------------------------
142         wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
143         { 
144                 wxVtkBaseView *wxvtkbaseview=NULL;
145                 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
146                 if (tmpWin!=NULL){  wxvtkbaseview = tmpWin->GetwxVtkBaseView();  }
147                 return wxvtkbaseview;
148         }
149    
150         //-------------------------------------------------------------------------
151         void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
152         {
153                 wxPanel::Refresh(false);
154         }
155
156         //-------------------------------------------------------------------------
157         void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
158         {
159
160                 wxWindow                                *wxwindow       = NULL;
161                 wxSizer *sizer                                          = this->GetSizer();     
162                 
163                 if (mvtkmprbasedata!=NULL)
164                 {
165                         delete mvtkmprbasedata;
166                 }
167                 
168                 marImageData    *marimagedata   = new marImageData( imagedata );                        
169                 mvtkmprbasedata                                 = new vtkMPRBaseData(); 
170                 mvtkmprbasedata->SetMarImageData(marimagedata);
171                 
172                 if(_currentwxw != NULL){
173                         _currentwxw->Show(false);
174                         delete _currentwxw;
175                         //sizer->Remove(currentwxwindow);                       
176                         //delete currentwxwindow;
177                 }
178
179                 //std::cout<<"size "<<nTypeView->size()<<std::endl;
180                 if (nTypeView->size()==1)
181                 {
182                         wxwindow1 = new wxMaracas_ViewerWidget(this, imagedata, (*nTypeView)[0],mvtkmprbasedata);
183
184                         wxwindow1->ConfigureVTK();
185                         wxwindow = wxwindow1;
186                 }else   if (nTypeView->size()==2)       {
187                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
188                         spliter->SetMinimumPaneSize(1);
189                         wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0],mvtkmprbasedata);
190                         wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1],mvtkmprbasedata);
191                         wxwindow1->ConfigureVTK();
192                         wxwindow2->ConfigureVTK();
193                         spliter -> SplitVertically( wxwindow1 , wxwindow2  );
194                         wxwindow = spliter;
195                 }else if (nTypeView->size()==3)
196                 {
197                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
198                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
199                         spliter->SetMinimumPaneSize(1);
200                         spliterA->SetMinimumPaneSize(1);
201                         wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0],mvtkmprbasedata);
202                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1],mvtkmprbasedata);
203                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2],mvtkmprbasedata);
204                         wxwindow1->ConfigureVTK();
205                         wxwindow2->ConfigureVTK();
206                         wxwindow3->ConfigureVTK();
207                         spliter -> SplitVertically( wxwindow1 , spliterA   );
208                         spliterA-> SplitHorizontally( wxwindow2 , wxwindow3  );
209                         wxwindow = spliter;
210                 }else if (nTypeView->size()>=4){
211                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
212                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
213                         wxSplitterWindow        *spliterB       = new wxSplitterWindow( spliter , -1);
214                         spliter->SetMinimumPaneSize(1);
215                         spliterA->SetMinimumPaneSize(1);
216                         spliterB->SetMinimumPaneSize(1);
217                         wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0],mvtkmprbasedata);
218                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1],mvtkmprbasedata);
219                         wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2],mvtkmprbasedata);
220                         wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3],mvtkmprbasedata);
221                         wxwindow1->ConfigureVTK();
222                         wxwindow2->ConfigureVTK();
223                         wxwindow3->ConfigureVTK();
224                         wxwindow4->ConfigureVTK();
225                         spliter -> SplitVertically( spliterA , spliterB   );
226                         spliterA-> SplitHorizontally( wxwindow1 , wxwindow2  );
227                         spliterB-> SplitHorizontally( wxwindow3 , wxwindow4  );
228                         wxwindow = spliter;
229                 }
230                 
231                 //panel->SetDimension()
232                 sizer->Add( wxwindow , 1, wxEXPAND);
233                 sizer->Layout();
234                 _currentwxw = wxwindow;         
235                 _currentwxw->Show(true);
236                 
237                 this->Layout();
238                 this->Refresh();
239  }
240
241
242 //-----------------------------------------------------------------------------------
243  void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
244          nTypeView = type;
245  }
246
247
248
249 //-----------------------------------------------------------------------------------
250  void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image  )
251  {
252          if (wxwindow1!=NULL) { 
253                  
254                 wxwindow1->SetImage(image); 
255         }
256          if (wxwindow2!=NULL) { wxwindow2->SetImage(image); } 
257          if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
258          if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
259
260
261  }
262
263 //-----------------------------------------------------------------------------------
264 double wxMaracas_N_ViewersWidget :: GetX()
265 {
266         return mvtkmprbasedata->GetX();
267 //      return wxwindow1->GetX();
268 }
269
270 //-----------------------------------------------------------------------------------
271 double wxMaracas_N_ViewersWidget :: GetY()
272 {
273         return mvtkmprbasedata->GetY();
274 //      return wxwindow1->GetY();
275 }
276
277
278 //-----------------------------------------------------------------------------------
279 double wxMaracas_N_ViewersWidget :: GetZ()
280 {
281         return mvtkmprbasedata->GetZ();
282 //      return wxwindow1->GetZ();
283 }
284
285 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){
286     if (wxwindow1!=NULL) {
287                 wxwindow1->setColorTransferFunction(colortable);
288         }
289         if (wxwindow2!=NULL) {
290                 wxwindow2->setColorTransferFunction(colortable);
291         }
292         if (wxwindow3!=NULL) {
293                 wxwindow3->setColorTransferFunction(colortable);
294         }
295         if (wxwindow4!=NULL) {
296                 wxwindow4->setColorTransferFunction(colortable);
297         }
298 }
299
300 void wxMaracas_N_ViewersWidget::setWindowLevel(double level){
301         if (wxwindow1!=NULL) {
302                 wxwindow1->setWindowLevel(level);
303         }
304         if (wxwindow2!=NULL) {
305                 wxwindow2->setWindowLevel(level);
306         }
307         if (wxwindow3!=NULL) {
308                 wxwindow3->setWindowLevel(level);
309         }
310         if (wxwindow4!=NULL) {
311                 wxwindow4->setWindowLevel(level);
312         }
313 }
314 void wxMaracas_N_ViewersWidget::setColorLevel(double level){
315         if (wxwindow1!=NULL) {
316                 wxwindow1->setColorLevel(level);
317         }
318         if (wxwindow2!=NULL) {
319                 wxwindow2->setColorLevel(level);
320         }
321         if (wxwindow3!=NULL) {
322                 wxwindow3->setColorLevel(level);
323         }
324         if (wxwindow4!=NULL) {
325                 wxwindow4->setColorLevel(level);
326         }
327 }
328