1 /*=========================================================================
4 Module: $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
6 Date: $Date: 2012/05/30 17:23:12 $
7 Version: $Revision: 1.21 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
18 //------------------------------------------------------------------------------------------------------------
19 // Definition includes
20 //------------------------------------------------------------------------------------------------------------
21 #include "wxMaracas_N_ViewersWidget.h"
23 //------------------------------------------------------------------------------------------------------------
25 //------------------------------------------------------------------------------------------------------------
28 //------------------------------------------------------------------------------------------------------------
29 // Constructors & Destructors
30 //------------------------------------------------------------------------------------------------------------
33 BEGIN_EVENT_TABLE( wxMaracas_N_ViewersWidget, wxPanel )
34 EVT_MENU( 12121, wxMaracas_N_ViewersWidget::OnRefreshView )
35 EVT_MENU( 12122, wxMaracas_N_ViewersWidget::OnDClickLeft )
39 //------------------------------------------------------------------------------------------------------------
40 // Constructors & Destructors
41 //------------------------------------------------------------------------------------------------------------
45 wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata, std::vector<int> *nTypeView)
46 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
53 mvtkmprbasedata = NULL;
55 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
56 this->SetSizer(sizer);
57 this->SetAutoLayout(true);
60 if(imagedata!=NULL && nTypeView!=NULL ){
61 this->SetType(nTypeView);
62 this->UpdateLayout(imagedata);
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
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
75 wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata)
76 : wxPanel( parent, -1){
82 mvtkmprbasedata = NULL;
84 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
85 this->SetSizer(sizer);
86 this->SetAutoLayout(true);
88 this->SetType(nTypeView);
90 /*if(imagedata==NULL){
103 imagedata = vtkImageData::New();
104 imagedata->SetSpacing(spc);
105 imagedata->SetExtent(extent);
106 imagedata->SetScalarTypeToUnsignedChar();
107 imagedata->AllocateScalars();
110 this->UpdateLayout(imagedata);
112 //-------------------------------------------------------------------------
114 wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
116 if (mvtkmprbasedata!=NULL)
118 delete mvtkmprbasedata;
122 //------------------------------------------------------------------------------------------------------------
124 //------------------------------------------------------------------------------------------------------------
127 //-------------------------------------------------------------------------
129 void wxMaracas_N_ViewersWidget::Update()
131 //wxvtkrenderwindowinteractor->Render();
132 // wxvtkrenderwindowinteractor->Refresh();
136 //-------------------------------------------------------------------------
138 void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event)
142 //----------------------------------------------------------------------------
143 void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
148 //-------------------------------------------------------------------------
150 vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
152 return NULL; //renderer;
155 void wxMaracas_N_ViewersWidget::RefreshView()
158 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
159 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
160 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
161 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
164 //-------------------------------------------------------------------------
165 wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
167 wxMaracas_ViewerWidget *tmpWin=NULL;
187 //-------------------------------------------------------------------------
188 wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
190 wxVtkBaseView *wxvtkbaseview=NULL;
191 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
192 if (tmpWin!=NULL){ wxvtkbaseview = tmpWin->GetwxVtkBaseView(); }
193 return wxvtkbaseview;
196 //-------------------------------------------------------------------------
197 void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
199 wxPanel::Refresh(false);
202 //-------------------------------------------------------------------------
203 void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
205 wxWindow *wxwindow = NULL;
206 wxSizer *sizer = this->GetSizer();
208 if (mvtkmprbasedata!=NULL)
210 delete mvtkmprbasedata;
213 marImageData *marimagedata = new marImageData( imagedata );
214 mvtkmprbasedata = new vtkMPRBaseData();
215 mvtkmprbasedata->SetMarImageData(marimagedata);
217 if(_currentwxw != NULL){
218 _currentwxw->Show(false);
220 //sizer->Remove(currentwxwindow);
221 //delete currentwxwindow;
224 //std::cout<<"size "<<nTypeView->size()<<std::endl;
225 if (nTypeView->size()==1)
227 wxwindow1 = new wxMaracas_ViewerWidget(this, imagedata, (*nTypeView)[0], mvtkmprbasedata);
228 wxwindow = wxwindow1;
229 }else if (nTypeView->size()==2) {
230 wxSplitterWindow *spliter = new wxSplitterWindow( this , -1);
231 spliter->SetMinimumPaneSize(1);
232 wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
233 wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
234 spliter -> SplitHorizontally( wxwindow1 , wxwindow2 );
236 }else if (nTypeView->size()==3)
238 wxSplitterWindow *spliter = new wxSplitterWindow( this , -1);
239 wxSplitterWindow *spliterA = new wxSplitterWindow( spliter , -1);
240 spliter->SetMinimumPaneSize(1);
241 spliterA->SetMinimumPaneSize(1);
242 wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0], mvtkmprbasedata);
243 wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
244 wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
245 spliter -> SplitVertically( wxwindow1 , spliterA );
246 spliterA-> SplitHorizontally( wxwindow2 , wxwindow3 );
248 }else if (nTypeView->size()>=4){
249 wxSplitterWindow *spliter = new wxSplitterWindow( this , -1);
250 wxSplitterWindow *spliterA = new wxSplitterWindow( spliter , -1);
251 wxSplitterWindow *spliterB = new wxSplitterWindow( spliter , -1);
252 spliter->SetMinimumPaneSize(1);
253 spliterA->SetMinimumPaneSize(1);
254 spliterB->SetMinimumPaneSize(1);
256 spliter -> SplitVertically( spliterA , spliterB );
259 //EED 21 mars 2012 FLIP probleme ..PLOP..
260 // wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0], mvtkmprbasedata);
261 // wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
262 // wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2], mvtkmprbasedata);
263 // wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3], mvtkmprbasedata);
264 // spliterA-> SplitHorizontally( wxwindow1 , wxwindow2 );
265 // spliterB-> SplitHorizontally( wxwindow3 , wxwindow4 );
267 wxwindow1 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[0], mvtkmprbasedata);
268 wxwindow2 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[1], mvtkmprbasedata);
269 wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
270 wxwindow4 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[3], mvtkmprbasedata);
271 spliterA-> SplitHorizontally( wxwindow3 , wxwindow4 );
272 spliterB-> SplitHorizontally( wxwindow2 , wxwindow1 );
278 //panel->SetDimension()
279 sizer->Add( wxwindow , 1, wxGROW);
281 //_currentwxw = wxwindow;
282 //_currentwxw->Show(true);
288 // I don't undestand how this works and not the opposite ...
289 if (wxwindow4!=NULL) {wxwindow4->ConfigureVTK(); }
290 if (wxwindow3!=NULL) {wxwindow3->ConfigureVTK(); }
291 if (wxwindow2!=NULL) {wxwindow2->ConfigureVTK(); }
292 if (wxwindow1!=NULL) {wxwindow1->ConfigureVTK(); }
296 //-----------------------------------------------------------------------------------
297 void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
303 //-----------------------------------------------------------------------------------
304 void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image )
306 if (wxwindow1!=NULL) { wxwindow1->SetImage(image); }
307 if (wxwindow2!=NULL) { wxwindow2->SetImage(image); }
308 if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
309 if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
314 //-----------------------------------------------------------------------------------
315 void wxMaracas_N_ViewersWidget::ConfigureVTK()
317 if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
318 if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
319 if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
320 if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
323 //-----------------------------------------------------------------------------------
324 double wxMaracas_N_ViewersWidget :: GetX()
327 return mvtkmprbasedata->GetX();
328 // return wxwindow1->GetX();
331 //-----------------------------------------------------------------------------------
332 double wxMaracas_N_ViewersWidget :: GetY()
335 return mvtkmprbasedata->GetY();
336 // return wxwindow1->GetY();
340 //-----------------------------------------------------------------------------------
341 double wxMaracas_N_ViewersWidget :: GetZ()
344 return mvtkmprbasedata->GetZ();
345 // return wxwindow1->GetZ();
348 void wxMaracas_N_ViewersWidget :: invariant(){
349 if(mvtkmprbasedata == 0){
350 throw "The image has not been set in the viewer";
354 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){
355 if (wxwindow1!=NULL) {
356 wxwindow1->setColorTransferFunction(colortable);
358 if (wxwindow2!=NULL) {
359 wxwindow2->setColorTransferFunction(colortable);
361 if (wxwindow3!=NULL) {
362 wxwindow3->setColorTransferFunction(colortable);
364 if (wxwindow4!=NULL) {
365 wxwindow4->setColorTransferFunction(colortable);
369 void wxMaracas_N_ViewersWidget::setWindowLevel(double level){
370 if (wxwindow1!=NULL) {
371 wxwindow1->setWindowLevel(level);
373 if (wxwindow2!=NULL) {
374 wxwindow2->setWindowLevel(level);
376 if (wxwindow3!=NULL) {
377 wxwindow3->setWindowLevel(level);
379 if (wxwindow4!=NULL) {
380 wxwindow4->setWindowLevel(level);
383 void wxMaracas_N_ViewersWidget::setColorLevel(double level){
384 if (wxwindow1!=NULL) {
385 wxwindow1->setColorLevel(level);
387 if (wxwindow2!=NULL) {
388 wxwindow2->setColorLevel(level);
390 if (wxwindow3!=NULL) {
391 wxwindow3->setColorLevel(level);
393 if (wxwindow4!=NULL) {
394 wxwindow4->setColorLevel(level);