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()
178 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
179 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
180 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
181 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
184 //-------------------------------------------------------------------------
185 wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
187 wxMaracas_ViewerWidget *tmpWin=NULL;
207 //-------------------------------------------------------------------------
208 wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
210 wxVtkBaseView *wxvtkbaseview=NULL;
211 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
212 if (tmpWin!=NULL){ wxvtkbaseview = tmpWin->GetwxVtkBaseView(); }
213 return wxvtkbaseview;
216 //-------------------------------------------------------------------------
217 void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
219 wxPanel::Refresh(false);
222 //-------------------------------------------------------------------------
223 void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
225 wxWindow *wxwindow = NULL;
226 wxSizer *sizer = this->GetSizer();
228 if (mvtkmprbasedata!=NULL)
230 delete mvtkmprbasedata;
233 marImageData *marimagedata = new marImageData( imagedata );
234 mvtkmprbasedata = new vtkMPRBaseData();
235 mvtkmprbasedata->SetMarImageData(marimagedata);
237 if(_currentwxw != NULL){
238 _currentwxw->Show(false);
240 //sizer->Remove(currentwxwindow);
241 //delete currentwxwindow;
244 //std::cout<<"size "<<nTypeView->size()<<std::endl;
245 if (nTypeView->size()==1)
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 );
258 }else if (nTypeView->size()==3)
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 );
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);
285 spliter -> SplitVertically( spliterA , spliterB );
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 );
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 );
307 //panel->SetDimension()
308 sizer->Add( wxwindow , 1, wxGROW);
310 //_currentwxw = wxwindow;
311 //_currentwxw->Show(true);
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(); }
324 //-----------------------------------------------------------------------------------
325 void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
331 //-----------------------------------------------------------------------------------
332 void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image )
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); }
342 //-----------------------------------------------------------------------------------
343 void wxMaracas_N_ViewersWidget::ConfigureVTK()
345 if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
346 if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
347 if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
348 if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
351 //-----------------------------------------------------------------------------------
352 double wxMaracas_N_ViewersWidget :: GetX()
355 return mvtkmprbasedata->GetX();
356 // return wxwindow1->GetX();
359 //-----------------------------------------------------------------------------------
360 double wxMaracas_N_ViewersWidget :: GetY()
363 return mvtkmprbasedata->GetY();
364 // return wxwindow1->GetY();
368 //-----------------------------------------------------------------------------------
369 double wxMaracas_N_ViewersWidget :: GetZ()
372 return mvtkmprbasedata->GetZ();
373 // return wxwindow1->GetZ();
376 //-----------------------------------------------------------------------------------
377 void wxMaracas_N_ViewersWidget :: invariant()
379 if(mvtkmprbasedata == 0)
381 throw "The image has not been set in the viewer";
385 //-----------------------------------------------------------------------------------
386 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
390 wxwindow1->setColorTransferFunction(colortable);
395 wxwindow2->setColorTransferFunction(colortable);
400 wxwindow3->setColorTransferFunction(colortable);
405 wxwindow4->setColorTransferFunction(colortable);
409 //-----------------------------------------------------------------------------------
410 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
414 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
419 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
424 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
429 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);
434 //-----------------------------------------------------------------------------------
435 void wxMaracas_N_ViewersWidget::SetInterpolate(bool interpolate)
437 mvtkmprbasedata->SetInterpolate(interpolate);