1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
31 Date: $Date: 2012/11/15 14:14:35 $
32 Version: $Revision: 1.24 $
34 Copyright: (c) 2002, 2003
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.
41 =========================================================================*/
43 //------------------------------------------------------------------------------------------------------------
44 // Definition includes
45 //------------------------------------------------------------------------------------------------------------
46 #include "wxMaracas_N_ViewersWidget.h"
48 //------------------------------------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------------------------------------
53 //------------------------------------------------------------------------------------------------------------
54 // Constructors & Destructors
55 //------------------------------------------------------------------------------------------------------------
58 BEGIN_EVENT_TABLE( wxMaracas_N_ViewersWidget, wxPanel )
59 EVT_MENU( 12121, wxMaracas_N_ViewersWidget::OnRefreshView )
60 EVT_MENU( 12122, wxMaracas_N_ViewersWidget::OnDClickLeft )
64 //------------------------------------------------------------------------------------------------------------
65 // Constructors & Destructors
66 //------------------------------------------------------------------------------------------------------------
70 wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata, std::vector<int> *nTypeView)
71 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
78 mvtkmprbasedata = NULL;
80 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
81 this->SetSizer(sizer);
82 this->SetAutoLayout(true);
85 if(imagedata!=NULL && nTypeView!=NULL ){
86 this->SetType(nTypeView);
87 this->UpdateLayout(imagedata);
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
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
100 wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata)
101 : wxPanel( parent, -1){
107 mvtkmprbasedata = NULL;
109 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
110 this->SetSizer(sizer);
111 this->SetAutoLayout(true);
113 this->SetType(nTypeView);
115 /*if(imagedata==NULL){
128 imagedata = vtkImageData::New();
129 imagedata->SetSpacing(spc);
130 imagedata->SetExtent(extent);
131 imagedata->SetScalarTypeToUnsignedChar();
132 imagedata->AllocateScalars();
135 this->UpdateLayout(imagedata);
137 //-------------------------------------------------------------------------
139 wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
141 if (mvtkmprbasedata!=NULL)
143 delete mvtkmprbasedata;
147 //------------------------------------------------------------------------------------------------------------
149 //------------------------------------------------------------------------------------------------------------
152 //-------------------------------------------------------------------------
154 void wxMaracas_N_ViewersWidget::Update()
156 //wxvtkrenderwindowinteractor->Render();
157 // wxvtkrenderwindowinteractor->Refresh();
161 //-------------------------------------------------------------------------
163 void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event)
167 //----------------------------------------------------------------------------
168 void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
173 //-------------------------------------------------------------------------
175 vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
177 return NULL; //renderer;
180 void wxMaracas_N_ViewersWidget::RefreshView()
183 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
184 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
185 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
186 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
189 //-------------------------------------------------------------------------
190 wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
192 wxMaracas_ViewerWidget *tmpWin=NULL;
212 //-------------------------------------------------------------------------
213 wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
215 wxVtkBaseView *wxvtkbaseview=NULL;
216 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
217 if (tmpWin!=NULL){ wxvtkbaseview = tmpWin->GetwxVtkBaseView(); }
218 return wxvtkbaseview;
221 //-------------------------------------------------------------------------
222 void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
224 wxPanel::Refresh(false);
227 //-------------------------------------------------------------------------
228 void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
230 wxWindow *wxwindow = NULL;
231 wxSizer *sizer = this->GetSizer();
233 if (mvtkmprbasedata!=NULL)
235 delete mvtkmprbasedata;
238 marImageData *marimagedata = new marImageData( imagedata );
239 mvtkmprbasedata = new vtkMPRBaseData();
240 mvtkmprbasedata->SetMarImageData(marimagedata);
242 if(_currentwxw != NULL){
243 _currentwxw->Show(false);
245 //sizer->Remove(currentwxwindow);
246 //delete currentwxwindow;
249 //std::cout<<"size "<<nTypeView->size()<<std::endl;
250 if (nTypeView->size()==1)
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 );
263 }else if (nTypeView->size()==3)
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 );
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);
290 spliter -> SplitVertically( spliterA , spliterB );
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 );
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 );
312 //panel->SetDimension()
313 sizer->Add( wxwindow , 1, wxGROW);
315 //_currentwxw = wxwindow;
316 //_currentwxw->Show(true);
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(); }
330 //-----------------------------------------------------------------------------------
331 void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
337 //-----------------------------------------------------------------------------------
338 void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image )
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); }
349 //-----------------------------------------------------------------------------------
350 void wxMaracas_N_ViewersWidget::ConfigureVTK()
352 if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
353 if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
354 if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
355 if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
358 //-----------------------------------------------------------------------------------
359 double wxMaracas_N_ViewersWidget :: GetX()
362 return mvtkmprbasedata->GetX();
363 // return wxwindow1->GetX();
366 //-----------------------------------------------------------------------------------
367 double wxMaracas_N_ViewersWidget :: GetY()
370 return mvtkmprbasedata->GetY();
371 // return wxwindow1->GetY();
375 //-----------------------------------------------------------------------------------
376 double wxMaracas_N_ViewersWidget :: GetZ()
379 return mvtkmprbasedata->GetZ();
380 // return wxwindow1->GetZ();
383 //-----------------------------------------------------------------------------------
384 void wxMaracas_N_ViewersWidget :: invariant()
386 if(mvtkmprbasedata == 0)
388 throw "The image has not been set in the viewer";
392 //-----------------------------------------------------------------------------------
393 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
397 wxwindow1->setColorTransferFunction(colortable);
402 wxwindow2->setColorTransferFunction(colortable);
407 wxwindow3->setColorTransferFunction(colortable);
412 wxwindow4->setColorTransferFunction(colortable);
416 //-----------------------------------------------------------------------------------
417 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
421 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
426 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
431 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
436 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);
441 //-----------------------------------------------------------------------------------
442 void wxMaracas_N_ViewersWidget::SetInterpolate(bool interpolate)
444 mvtkmprbasedata->SetInterpolate(interpolate);