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;
79 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
80 this->SetSizer(sizer);
81 this->SetAutoLayout(true);
82 if(imagedata!=NULL && nTypeView!=NULL )
84 this->SetType(nTypeView);
85 this->UpdateLayout(imagedata);
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
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
96 wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata)
97 : wxPanel( parent, -1){
103 mvtkmprbasedata = NULL;
105 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
106 this->SetSizer(sizer);
107 this->SetAutoLayout(true);
109 this->SetType(nTypeView);
111 /*if(imagedata==NULL){
124 imagedata = vtkImageData::New();
125 imagedata->SetSpacing(spc);
126 imagedata->SetExtent(extent);
127 imagedata->SetScalarTypeToUnsignedChar();
128 imagedata->AllocateScalars();
131 this->UpdateLayout(imagedata);
133 //-------------------------------------------------------------------------
135 wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
137 if (mvtkmprbasedata!=NULL)
139 delete mvtkmprbasedata;
143 //------------------------------------------------------------------------------------------------------------
145 //------------------------------------------------------------------------------------------------------------
148 //-------------------------------------------------------------------------
150 void wxMaracas_N_ViewersWidget::Update()
152 //wxvtkrenderwindowinteractor->Render();
153 // wxvtkrenderwindowinteractor->Refresh();
157 //-------------------------------------------------------------------------
159 void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event)
163 //----------------------------------------------------------------------------
164 void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
169 //-------------------------------------------------------------------------
171 vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
173 return NULL; //renderer;
176 void wxMaracas_N_ViewersWidget::RefreshView()
179 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
180 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
181 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
182 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
185 //-------------------------------------------------------------------------
186 wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
188 wxMaracas_ViewerWidget *tmpWin=NULL;
208 //-------------------------------------------------------------------------
209 wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
211 wxVtkBaseView *wxvtkbaseview=NULL;
212 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
213 if (tmpWin!=NULL){ wxvtkbaseview = tmpWin->GetwxVtkBaseView(); }
214 return wxvtkbaseview;
217 //-------------------------------------------------------------------------
218 void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
220 wxPanel::Refresh(false);
223 //-------------------------------------------------------------------------
224 void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
226 wxWindow *wxwindow = NULL;
227 wxSizer *sizer = this->GetSizer();
229 if (mvtkmprbasedata!=NULL)
231 delete mvtkmprbasedata;
234 marImageData *marimagedata = new marImageData( imagedata );
235 mvtkmprbasedata = new vtkMPRBaseData();
236 mvtkmprbasedata->SetMarImageData(marimagedata);
238 if(_currentwxw != NULL){
239 _currentwxw->Show(false);
241 //sizer->Remove(currentwxwindow);
242 //delete currentwxwindow;
245 //std::cout<<"size "<<nTypeView->size()<<std::endl;
246 if (nTypeView->size()==1)
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 );
259 }else if (nTypeView->size()==3)
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 );
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);
286 spliter -> SplitVertically( spliterA , spliterB );
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 );
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 );
308 //panel->SetDimension()
309 sizer->Add( wxwindow , 1, wxGROW);
311 //_currentwxw = wxwindow;
312 //_currentwxw->Show(true);
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(); }
325 //-----------------------------------------------------------------------------------
326 void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
332 //-----------------------------------------------------------------------------------
333 void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image )
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); }
343 //-----------------------------------------------------------------------------------
344 void wxMaracas_N_ViewersWidget::ConfigureVTK()
346 if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
347 if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
348 if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
349 if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
352 //-----------------------------------------------------------------------------------
353 double wxMaracas_N_ViewersWidget :: GetX()
356 return mvtkmprbasedata->GetX();
357 // return wxwindow1->GetX();
360 //-----------------------------------------------------------------------------------
361 double wxMaracas_N_ViewersWidget :: GetY()
364 return mvtkmprbasedata->GetY();
365 // return wxwindow1->GetY();
369 //-----------------------------------------------------------------------------------
370 double wxMaracas_N_ViewersWidget :: GetZ()
373 return mvtkmprbasedata->GetZ();
374 // return wxwindow1->GetZ();
377 //-----------------------------------------------------------------------------------
378 void wxMaracas_N_ViewersWidget :: invariant()
380 if(mvtkmprbasedata == 0)
382 throw "The image has not been set in the viewer";
386 //-----------------------------------------------------------------------------------
387 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
391 wxwindow1->setColorTransferFunction(colortable);
396 wxwindow2->setColorTransferFunction(colortable);
401 wxwindow3->setColorTransferFunction(colortable);
406 wxwindow4->setColorTransferFunction(colortable);
410 //-----------------------------------------------------------------------------------
411 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
415 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
420 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
425 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
430 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);
435 //-----------------------------------------------------------------------------------
436 void wxMaracas_N_ViewersWidget::SetInterpolate(bool interpolate)
438 mvtkmprbasedata->SetInterpolate(interpolate);