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