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 wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
258 wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
259 spliter -> SplitHorizontally( wxwindow1 , wxwindow2 );
261 }else if (nTypeView->size()==3)
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 );
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);
281 spliter -> SplitVertically( spliterA , spliterB );
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 );
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 );
303 //panel->SetDimension()
304 sizer->Add( wxwindow , 1, wxGROW);
306 //_currentwxw = wxwindow;
307 //_currentwxw->Show(true);
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(); }
321 //-----------------------------------------------------------------------------------
322 void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
328 //-----------------------------------------------------------------------------------
329 void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image )
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); }
340 //-----------------------------------------------------------------------------------
341 void wxMaracas_N_ViewersWidget::ConfigureVTK()
343 if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
344 if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
345 if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
346 if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
349 //-----------------------------------------------------------------------------------
350 double wxMaracas_N_ViewersWidget :: GetX()
353 return mvtkmprbasedata->GetX();
354 // return wxwindow1->GetX();
357 //-----------------------------------------------------------------------------------
358 double wxMaracas_N_ViewersWidget :: GetY()
361 return mvtkmprbasedata->GetY();
362 // return wxwindow1->GetY();
366 //-----------------------------------------------------------------------------------
367 double wxMaracas_N_ViewersWidget :: GetZ()
370 return mvtkmprbasedata->GetZ();
371 // return wxwindow1->GetZ();
374 //-----------------------------------------------------------------------------------
375 void wxMaracas_N_ViewersWidget :: invariant()
377 if(mvtkmprbasedata == 0)
379 throw "The image has not been set in the viewer";
383 //-----------------------------------------------------------------------------------
384 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable)
388 wxwindow1->setColorTransferFunction(colortable);
393 wxwindow2->setColorTransferFunction(colortable);
398 wxwindow3->setColorTransferFunction(colortable);
403 wxwindow4->setColorTransferFunction(colortable);
407 //-----------------------------------------------------------------------------------
408 void wxMaracas_N_ViewersWidget::SetColorWindowLevel(double colorWindow, double colorLevel)
412 wxwindow1->SetColorWindowLevel(colorWindow, colorLevel);
417 wxwindow2->SetColorWindowLevel(colorWindow, colorLevel);
422 wxwindow3->SetColorWindowLevel(colorWindow, colorLevel);
427 wxwindow4->SetColorWindowLevel(colorWindow, colorLevel);