]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
ed4001b153edb3f1896b98ab3b283a5507ef475e
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracas_N_ViewersWidget.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 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:14:35 $
32   Version:   $Revision: 1.24 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42
43 //------------------------------------------------------------------------------------------------------------
44 // Definition includes
45 //------------------------------------------------------------------------------------------------------------
46 #include "wxMaracas_N_ViewersWidget.h"
47
48 //------------------------------------------------------------------------------------------------------------
49 // Other includes
50 //------------------------------------------------------------------------------------------------------------
51
52
53         //------------------------------------------------------------------------------------------------------------
54         // Constructors & Destructors
55         //------------------------------------------------------------------------------------------------------------
56
57
58         BEGIN_EVENT_TABLE( wxMaracas_N_ViewersWidget, wxPanel )
59                 EVT_MENU( 12121, wxMaracas_N_ViewersWidget::OnRefreshView )
60                 EVT_MENU( 12122, wxMaracas_N_ViewersWidget::OnDClickLeft  )
61         END_EVENT_TABLE( );
62
63
64         //------------------------------------------------------------------------------------------------------------
65         // Constructors & Destructors
66         //------------------------------------------------------------------------------------------------------------
67
68
69
70         wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata, std::vector<int> *nTypeView)
71                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
72         {
73                 wxwindow1               = NULL;
74                 wxwindow2               = NULL;
75                 wxwindow3               = NULL;
76                 wxwindow4               = NULL;
77                 _currentwxw             = NULL;
78                 mvtkmprbasedata = NULL;
79
80                 wxSizer *sizer  = new wxBoxSizer(wxVERTICAL);
81                 this->SetSizer(sizer);
82                 this->SetAutoLayout(true);
83
84
85                 if(imagedata!=NULL && nTypeView!=NULL ){
86                         this->SetType(nTypeView);
87                         this->UpdateLayout(imagedata);
88                 }
89
90
91         }
92         /**
93         *       @pre A wxWindow* object must be provided as a parent for the viewer and the type of layout for the viewer
94         *       @post The layout of the viewer is initialized, if no image is provided at first, a default image is
95         *               used
96         *       @param wxWindow* parent of the window
97         *       @param std::vector<int>* vector of the type for the viewer
98         *       @param vtkImageData* imagedata of the viewer
99         */
100         wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata)
101         : wxPanel( parent, -1){
102                 wxwindow1               = NULL;
103                 wxwindow2               = NULL;
104                 wxwindow3               = NULL;
105                 wxwindow4               = NULL;
106                 _currentwxw             = NULL;
107                 mvtkmprbasedata = NULL;
108
109                 wxSizer *sizer  = new wxBoxSizer(wxVERTICAL);
110                 this->SetSizer(sizer);
111                 this->SetAutoLayout(true);
112
113                 this->SetType(nTypeView);
114
115                 /*if(imagedata==NULL){
116                         double spc[3];
117                         spc[0] = 1;
118                         spc[1] = 1;
119                         spc[2] = 1;
120                         int extent[6];
121                         extent[0] = 0;
122                         extent[1] = 1;
123                         extent[2] = 0;
124                         extent[3] = 1;
125                         extent[4] = 0;
126                         extent[5] = 0;
127
128                         imagedata = vtkImageData::New();
129                         imagedata->SetSpacing(spc);
130                         imagedata->SetExtent(extent);
131                         imagedata->SetScalarTypeToUnsignedChar();
132                         imagedata->AllocateScalars();
133                 }*/
134
135                 this->UpdateLayout(imagedata);
136         }
137         //-------------------------------------------------------------------------
138
139         wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
140         {
141                 if (mvtkmprbasedata!=NULL)
142                 {
143                         delete mvtkmprbasedata;
144                 }
145
146         }
147         //------------------------------------------------------------------------------------------------------------
148         // Methods
149         //------------------------------------------------------------------------------------------------------------
150
151
152         //-------------------------------------------------------------------------
153
154         void wxMaracas_N_ViewersWidget::Update()
155         {
156                 //wxvtkrenderwindowinteractor->Render();
157         //    wxvtkrenderwindowinteractor->Refresh();
158         //    Refresh();
159         }
160
161         //-------------------------------------------------------------------------
162
163         void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event)
164         {
165                 RefreshView();
166         }
167         //----------------------------------------------------------------------------
168         void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
169         {
170                 RefreshView();
171         }
172
173                 //-------------------------------------------------------------------------
174
175         vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
176         {
177                 return NULL; //renderer;
178         }
179
180         void wxMaracas_N_ViewersWidget::RefreshView()
181         {
182
183                 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
184                 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
185                 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
186                 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
187         }
188
189         //-------------------------------------------------------------------------
190         wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
191         {
192                 wxMaracas_ViewerWidget *tmpWin=NULL;
193                 if  (iWin==1)
194                 {
195                         tmpWin=wxwindow1;
196                 }
197                 if  (iWin==2)
198                 {
199                         tmpWin=wxwindow2;
200                 }
201                 if  (iWin==3)
202                 {
203                         tmpWin=wxwindow3;
204                 }
205                 if  (iWin==4)
206                 {
207                         tmpWin=wxwindow4;
208                 }
209                 return tmpWin;
210         }
211
212         //-------------------------------------------------------------------------
213         wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
214         {
215                 wxVtkBaseView *wxvtkbaseview=NULL;
216                 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
217                 if (tmpWin!=NULL){  wxvtkbaseview = tmpWin->GetwxVtkBaseView();  }
218                 return wxvtkbaseview;
219         }
220
221         //-------------------------------------------------------------------------
222         void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
223         {
224                 wxPanel::Refresh(false);
225         }
226
227         //-------------------------------------------------------------------------
228         void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
229         {
230                 wxWindow                                *wxwindow       = NULL;
231                 wxSizer *sizer                                          = this->GetSizer();
232
233                 if (mvtkmprbasedata!=NULL)
234                 {
235                         delete mvtkmprbasedata;
236                 }
237
238                 marImageData    *marimagedata   = new marImageData( imagedata );
239                 mvtkmprbasedata                                 = new vtkMPRBaseData();
240                 mvtkmprbasedata->SetMarImageData(marimagedata);
241
242                 if(_currentwxw != NULL){
243                         _currentwxw->Show(false);
244                         delete _currentwxw;
245                         //sizer->Remove(currentwxwindow);
246                         //delete currentwxwindow;
247                 }
248
249                 //std::cout<<"size "<<nTypeView->size()<<std::endl;
250                 if (nTypeView->size()==1)
251                 {
252                         wxwindow1 = new wxMaracas_ViewerWidget(this, imagedata, (*nTypeView)[0], mvtkmprbasedata);
253                         wxwindow = wxwindow1;
254                 }else   if (nTypeView->size()==2)       {
255                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
256                         spliter->SetMinimumPaneSize(1);
257                         //RaC Nov2012 Correctly resize internal panels with the window resize event
258                         spliter->SetSashGravity(0.5);
259                         wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
260                         wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
261                         spliter -> SplitHorizontally( wxwindow1 , wxwindow2  );
262                         wxwindow = spliter;
263                 }else if (nTypeView->size()==3)
264                 {
265                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
266                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
267                         spliter->SetMinimumPaneSize(1);
268                         spliterA->SetMinimumPaneSize(1);
269                         //RaC Nov2012 Correctly resize internal panels with the window resize event
270                         spliter->SetSashGravity(0.5);
271                         spliterA->SetSashGravity(0.5);
272                         wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0], mvtkmprbasedata);
273                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
274                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
275                         spliter -> SplitVertically( wxwindow1 , spliterA   );
276                         spliterA-> SplitHorizontally( wxwindow2 , wxwindow3  );
277                         wxwindow = spliter;
278                 }else if (nTypeView->size()>=4){
279                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
280                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
281                         wxSplitterWindow        *spliterB       = new wxSplitterWindow( spliter , -1);
282                         spliter->SetMinimumPaneSize(1);
283                         spliterA->SetMinimumPaneSize(1);
284                         spliterB->SetMinimumPaneSize(1);
285                         //RaC Nov2012 Correctly resize internal panels with the window resize event
286                         spliter->SetSashGravity(0.5);
287                         spliterA->SetSashGravity(0.5);
288                         spliterB->SetSashGravity(0.5);
289
290                         spliter -> SplitVertically( spliterA , spliterB   );
291                         
292                         
293 //EED 21 mars 2012  FLIP probleme  ..PLOP..                     
294 //                      wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0], mvtkmprbasedata);
295 //                      wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
296 //                      wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2], mvtkmprbasedata);
297 //                      wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3], mvtkmprbasedata);
298 //                      spliterA-> SplitHorizontally( wxwindow1 , wxwindow2  );
299 //                      spliterB-> SplitHorizontally( wxwindow3 , wxwindow4  );
300                         
301                         wxwindow1 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[0], mvtkmprbasedata);
302                         wxwindow2 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[1], mvtkmprbasedata);
303                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
304                         wxwindow4 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[3], mvtkmprbasedata);
305                         spliterA-> SplitHorizontally( wxwindow3 , wxwindow4  );
306                         spliterB-> SplitHorizontally( wxwindow2 , wxwindow1  );
307                         
308                         wxwindow = spliter;
309                 }
310
311
312                 //panel->SetDimension()
313                 sizer->Add( wxwindow , 1, wxGROW);
314                 sizer->Layout();
315                 //_currentwxw = wxwindow;
316                 //_currentwxw->Show(true);
317
318                 //this->Layout();
319                 //this->Refresh();
320
321
322 // I don't undestand how this works and not the opposite ...
323                 if (wxwindow4!=NULL) {wxwindow4->ConfigureVTK(); }
324                 if (wxwindow3!=NULL) {wxwindow3->ConfigureVTK(); }
325                 if (wxwindow2!=NULL) {wxwindow2->ConfigureVTK(); }
326                 if (wxwindow1!=NULL) {wxwindow1->ConfigureVTK(); }
327  }
328
329
330 //-----------------------------------------------------------------------------------
331  void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
332          nTypeView = type;
333  }
334
335
336
337 //-----------------------------------------------------------------------------------
338  void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image  )
339  {
340          if (wxwindow1!=NULL) { wxwindow1->SetImage(image); }
341          if (wxwindow2!=NULL) { wxwindow2->SetImage(image); }
342          if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
343          if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
344          
345 //       ConfigureVTK();
346  }
347
348
349 //-----------------------------------------------------------------------------------
350  void wxMaracas_N_ViewersWidget::ConfigureVTK()
351  {
352          if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
353          if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
354          if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
355          if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
356  }
357
358 //-----------------------------------------------------------------------------------
359 double wxMaracas_N_ViewersWidget :: GetX()
360 {
361         invariant();
362         return mvtkmprbasedata->GetX();
363 //      return wxwindow1->GetX();
364 }
365
366 //-----------------------------------------------------------------------------------
367 double wxMaracas_N_ViewersWidget :: GetY()
368 {
369         invariant();
370         return mvtkmprbasedata->GetY();
371 //      return wxwindow1->GetY();
372 }
373
374
375 //-----------------------------------------------------------------------------------
376 double wxMaracas_N_ViewersWidget :: GetZ()
377 {
378         invariant();
379         return mvtkmprbasedata->GetZ();
380 //      return wxwindow1->GetZ();
381 }
382
383 //-----------------------------------------------------------------------------------
384 void wxMaracas_N_ViewersWidget :: invariant()
385 {
386         if(mvtkmprbasedata == 0)
387         {
388                 throw "The image has not been set in the viewer";
389         }
390 }
391
392 //-----------------------------------------------------------------------------------
393 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
394 {
395     if (wxwindow1!=NULL) 
396         {
397                 wxwindow1->setColorTransferFunction(colortable);
398         }
399         
400         if (wxwindow2!=NULL) 
401         {
402                 wxwindow2->setColorTransferFunction(colortable);
403         }
404         
405         if (wxwindow3!=NULL) 
406         {
407                 wxwindow3->setColorTransferFunction(colortable);
408         }
409         
410         if (wxwindow4!=NULL) 
411         {
412                 wxwindow4->setColorTransferFunction(colortable);
413         }
414 }
415
416 //-----------------------------------------------------------------------------------
417 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
418 {
419         if (wxwindow1!=NULL) 
420         {
421                 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
422         }
423         
424         if (wxwindow2!=NULL) 
425         {
426                 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
427         }
428         
429         if (wxwindow3!=NULL) 
430         {
431                 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
432         }
433         
434         if (wxwindow4!=NULL) 
435         {
436                 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);
437         }
438         RefreshView();
439 }
440