]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
Support #1768 CREATIS Licence insertion
[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                         wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
258                         wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
259                         spliter -> SplitHorizontally( wxwindow1 , wxwindow2  );
260                         wxwindow = spliter;
261                 }else if (nTypeView->size()==3)
262                 {
263                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
264                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
265                         spliter->SetMinimumPaneSize(1);
266                         spliterA->SetMinimumPaneSize(1);
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
281                         spliter -> SplitVertically( spliterA , spliterB   );
282                         
283                         
284 //EED 21 mars 2012  FLIP probleme  ..PLOP..                     
285 //                      wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0], mvtkmprbasedata);
286 //                      wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
287 //                      wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2], mvtkmprbasedata);
288 //                      wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3], mvtkmprbasedata);
289 //                      spliterA-> SplitHorizontally( wxwindow1 , wxwindow2  );
290 //                      spliterB-> SplitHorizontally( wxwindow3 , wxwindow4  );
291                         
292                         wxwindow1 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[0], mvtkmprbasedata);
293                         wxwindow2 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[1], mvtkmprbasedata);
294                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
295                         wxwindow4 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[3], mvtkmprbasedata);
296                         spliterA-> SplitHorizontally( wxwindow3 , wxwindow4  );
297                         spliterB-> SplitHorizontally( wxwindow2 , wxwindow1  );
298                         
299                         wxwindow = spliter;
300                 }
301
302
303                 //panel->SetDimension()
304                 sizer->Add( wxwindow , 1, wxGROW);
305                 sizer->Layout();
306                 //_currentwxw = wxwindow;
307                 //_currentwxw->Show(true);
308
309                 //this->Layout();
310                 //this->Refresh();
311
312
313 // I don't undestand how this works and not the opposite ...
314                 if (wxwindow4!=NULL) {wxwindow4->ConfigureVTK(); }
315                 if (wxwindow3!=NULL) {wxwindow3->ConfigureVTK(); }
316                 if (wxwindow2!=NULL) {wxwindow2->ConfigureVTK(); }
317                 if (wxwindow1!=NULL) {wxwindow1->ConfigureVTK(); }
318  }
319
320
321 //-----------------------------------------------------------------------------------
322  void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
323          nTypeView = type;
324  }
325
326
327
328 //-----------------------------------------------------------------------------------
329  void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image  )
330  {
331          if (wxwindow1!=NULL) { wxwindow1->SetImage(image); }
332          if (wxwindow2!=NULL) { wxwindow2->SetImage(image); }
333          if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
334          if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
335          
336 //       ConfigureVTK();
337  }
338
339
340 //-----------------------------------------------------------------------------------
341  void wxMaracas_N_ViewersWidget::ConfigureVTK()
342  {
343          if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
344          if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
345          if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
346          if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
347  }
348
349 //-----------------------------------------------------------------------------------
350 double wxMaracas_N_ViewersWidget :: GetX()
351 {
352         invariant();
353         return mvtkmprbasedata->GetX();
354 //      return wxwindow1->GetX();
355 }
356
357 //-----------------------------------------------------------------------------------
358 double wxMaracas_N_ViewersWidget :: GetY()
359 {
360         invariant();
361         return mvtkmprbasedata->GetY();
362 //      return wxwindow1->GetY();
363 }
364
365
366 //-----------------------------------------------------------------------------------
367 double wxMaracas_N_ViewersWidget :: GetZ()
368 {
369         invariant();
370         return mvtkmprbasedata->GetZ();
371 //      return wxwindow1->GetZ();
372 }
373
374 //-----------------------------------------------------------------------------------
375 void wxMaracas_N_ViewersWidget :: invariant()
376 {
377         if(mvtkmprbasedata == 0)
378         {
379                 throw "The image has not been set in the viewer";
380         }
381 }
382
383 //-----------------------------------------------------------------------------------
384 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
385 {
386     if (wxwindow1!=NULL) 
387         {
388                 wxwindow1->setColorTransferFunction(colortable);
389         }
390         
391         if (wxwindow2!=NULL) 
392         {
393                 wxwindow2->setColorTransferFunction(colortable);
394         }
395         
396         if (wxwindow3!=NULL) 
397         {
398                 wxwindow3->setColorTransferFunction(colortable);
399         }
400         
401         if (wxwindow4!=NULL) 
402         {
403                 wxwindow4->setColorTransferFunction(colortable);
404         }
405 }
406
407 //-----------------------------------------------------------------------------------
408 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
409 {
410         if (wxwindow1!=NULL) 
411         {
412                 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
413         }
414         
415         if (wxwindow2!=NULL) 
416         {
417                 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
418         }
419         
420         if (wxwindow3!=NULL) 
421         {
422                 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
423         }
424         
425         if (wxwindow4!=NULL) 
426         {
427                 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);
428         }
429         RefreshView();
430 }
431