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