]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
#3347 creaMaracasVisu Bug New Normal - ViewerMPR2D Reset back position when set...
[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                 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
179                 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
180                 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
181                 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
182         }
183
184         //-------------------------------------------------------------------------
185         wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
186         {
187                 wxMaracas_ViewerWidget *tmpWin=NULL;
188                 if  (iWin==1)
189                 {
190                         tmpWin=wxwindow1;
191                 }
192                 if  (iWin==2)
193                 {
194                         tmpWin=wxwindow2;
195                 }
196                 if  (iWin==3)
197                 {
198                         tmpWin=wxwindow3;
199                 }
200                 if  (iWin==4)
201                 {
202                         tmpWin=wxwindow4;
203                 }
204                 return tmpWin;
205         }
206
207         //-------------------------------------------------------------------------
208         wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
209         {
210                 wxVtkBaseView *wxvtkbaseview=NULL;
211                 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
212                 if (tmpWin!=NULL){  wxvtkbaseview = tmpWin->GetwxVtkBaseView();  }
213                 return wxvtkbaseview;
214         }
215
216         //-------------------------------------------------------------------------
217         void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
218         {
219                 wxPanel::Refresh(false);
220         }
221
222         //-------------------------------------------------------------------------
223         void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
224         {
225                 wxWindow                                *wxwindow       = NULL;
226                 wxSizer *sizer                                          = this->GetSizer();
227
228                 if (mvtkmprbasedata!=NULL)
229                 {
230                         delete mvtkmprbasedata;
231                 }
232
233                 marImageData    *marimagedata   = new marImageData( imagedata );
234                 mvtkmprbasedata                                 = new vtkMPRBaseData();
235                 mvtkmprbasedata->SetMarImageData(marimagedata);
236
237                 if(_currentwxw != NULL){
238                         _currentwxw->Show(false);
239                         delete _currentwxw;
240                         //sizer->Remove(currentwxwindow);
241                         //delete currentwxwindow;
242                 }
243
244                 //std::cout<<"size "<<nTypeView->size()<<std::endl;
245                 if (nTypeView->size()==1)
246                 {
247                         wxwindow1 = new wxMaracas_ViewerWidget(this, imagedata, (*nTypeView)[0], mvtkmprbasedata);
248                         wxwindow = wxwindow1;
249                 }else   if (nTypeView->size()==2)       {
250                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
251                         spliter->SetMinimumPaneSize(1);
252                         //RaC Nov2012 Correctly resize internal panels with the window resize event
253                         spliter->SetSashGravity(0.5);
254                         wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
255                         wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
256                         spliter -> SplitHorizontally( wxwindow1 , wxwindow2  );
257                         wxwindow = spliter;
258                 }else if (nTypeView->size()==3)
259                 {
260                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
261                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
262                         spliter->SetMinimumPaneSize(1);
263                         spliterA->SetMinimumPaneSize(1);
264                         //RaC Nov2012 Correctly resize internal panels with the window resize event
265                         spliter->SetSashGravity(0.5);
266                         spliterA->SetSashGravity(0.5);
267                         wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0], mvtkmprbasedata);
268                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
269                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
270                         spliter -> SplitVertically( wxwindow1 , spliterA   );
271                         spliterA-> SplitHorizontally( wxwindow2 , wxwindow3  );
272                         wxwindow = spliter;
273                 }else if (nTypeView->size()>=4){
274                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
275                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
276                         wxSplitterWindow        *spliterB       = new wxSplitterWindow( spliter , -1);
277                         spliter->SetMinimumPaneSize(1);
278                         spliterA->SetMinimumPaneSize(1);
279                         spliterB->SetMinimumPaneSize(1);
280                         //RaC Nov2012 Correctly resize internal panels with the window resize event
281                         spliter->SetSashGravity(0.5);
282                         spliterA->SetSashGravity(0.5);
283                         spliterB->SetSashGravity(0.5);
284
285                         spliter -> SplitVertically( spliterA , spliterB   );
286                         
287                         
288 //EED 21 mars 2012  FLIP probleme  ..PLOP..                     
289 //                      wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0], mvtkmprbasedata);
290 //                      wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
291 //                      wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2], mvtkmprbasedata);
292 //                      wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3], mvtkmprbasedata);
293 //                      spliterA-> SplitHorizontally( wxwindow1 , wxwindow2  );
294 //                      spliterB-> SplitHorizontally( wxwindow3 , wxwindow4  );
295                         
296                         wxwindow1 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[0], mvtkmprbasedata);
297                         wxwindow2 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[1], mvtkmprbasedata);
298                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
299                         wxwindow4 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[3], mvtkmprbasedata);
300                         spliterA-> SplitHorizontally( wxwindow3 , wxwindow4  );
301                         spliterB-> SplitHorizontally( wxwindow2 , wxwindow1  );
302                         
303                         wxwindow = spliter;
304                 }
305
306
307                 //panel->SetDimension()
308                 sizer->Add( wxwindow , 1, wxGROW);
309                 sizer->Layout();
310                 //_currentwxw = wxwindow;
311                 //_currentwxw->Show(true);
312
313                 //this->Layout();
314                 //this->Refresh();
315
316 // I don't undestand how this works and not the opposite ...
317                 if (wxwindow4!=NULL) {wxwindow4->ConfigureVTK(); }
318                 if (wxwindow3!=NULL) {wxwindow3->ConfigureVTK(); }
319                 if (wxwindow2!=NULL) {wxwindow2->ConfigureVTK(); }
320                 if (wxwindow1!=NULL) {wxwindow1->ConfigureVTK(); }
321  }
322
323
324 //-----------------------------------------------------------------------------------
325  void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
326          nTypeView = type;
327  }
328
329
330
331 //-----------------------------------------------------------------------------------
332  void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image  )
333  {
334          if (wxwindow1!=NULL) { wxwindow1->SetImage(image); }
335          if (wxwindow2!=NULL) { wxwindow2->SetImage(image); }
336          if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
337          if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
338 //       ConfigureVTK();
339  }
340
341
342 //-----------------------------------------------------------------------------------
343  void wxMaracas_N_ViewersWidget::ConfigureVTK()
344  {
345          if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
346          if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
347          if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
348          if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
349  }
350
351 //-----------------------------------------------------------------------------------
352 double wxMaracas_N_ViewersWidget :: GetX()
353 {
354         invariant();
355         return mvtkmprbasedata->GetX();
356 //      return wxwindow1->GetX();
357 }
358
359 //-----------------------------------------------------------------------------------
360 double wxMaracas_N_ViewersWidget :: GetY()
361 {
362         invariant();
363         return mvtkmprbasedata->GetY();
364 //      return wxwindow1->GetY();
365 }
366
367
368 //-----------------------------------------------------------------------------------
369 double wxMaracas_N_ViewersWidget :: GetZ()
370 {
371         invariant();
372         return mvtkmprbasedata->GetZ();
373 //      return wxwindow1->GetZ();
374 }
375
376 //-----------------------------------------------------------------------------------
377 void wxMaracas_N_ViewersWidget :: invariant()
378 {
379         if(mvtkmprbasedata == 0)
380         {
381                 throw "The image has not been set in the viewer";
382         }
383 }
384
385 //-----------------------------------------------------------------------------------
386 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
387 {
388     if (wxwindow1!=NULL) 
389         {
390                 wxwindow1->setColorTransferFunction(colortable);
391         }
392         
393         if (wxwindow2!=NULL) 
394         {
395                 wxwindow2->setColorTransferFunction(colortable);
396         }
397         
398         if (wxwindow3!=NULL) 
399         {
400                 wxwindow3->setColorTransferFunction(colortable);
401         }
402         
403         if (wxwindow4!=NULL) 
404         {
405                 wxwindow4->setColorTransferFunction(colortable);
406         }
407 }
408
409 //-----------------------------------------------------------------------------------
410 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
411 {
412         if (wxwindow1!=NULL) 
413         {
414                 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
415         }
416         
417         if (wxwindow2!=NULL) 
418         {
419                 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
420         }
421         
422         if (wxwindow3!=NULL) 
423         {
424                 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
425         }
426         
427         if (wxwindow4!=NULL) 
428         {
429                 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);
430         }
431         RefreshView();
432 }
433
434 //-----------------------------------------------------------------------------------
435 void wxMaracas_N_ViewersWidget::SetInterpolate(bool interpolate)
436 {
437         mvtkmprbasedata->SetInterpolate(interpolate);
438         RefreshView();
439 }
440
441
442