1 /*=========================================================================
4 Module: $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
6 Date: $Date: 2010/05/03 13:46:48 $
7 Version: $Revision: 1.17 $
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);
67 //-------------------------------------------------------------------------
69 wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
71 if (mvtkmprbasedata!=NULL)
73 delete mvtkmprbasedata;
77 //------------------------------------------------------------------------------------------------------------
79 //------------------------------------------------------------------------------------------------------------
82 //-------------------------------------------------------------------------
84 void wxMaracas_N_ViewersWidget::Update()
86 //wxvtkrenderwindowinteractor->Render();
87 // wxvtkrenderwindowinteractor->Refresh();
91 //-------------------------------------------------------------------------
93 void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event)
97 //----------------------------------------------------------------------------
98 void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event)
103 //-------------------------------------------------------------------------
105 vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
107 return NULL; //renderer;
110 void wxMaracas_N_ViewersWidget::RefreshView()
112 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
113 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
114 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
115 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
118 //-------------------------------------------------------------------------
119 wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)
121 wxMaracas_ViewerWidget *tmpWin=NULL;
141 //-------------------------------------------------------------------------
142 wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
144 wxVtkBaseView *wxvtkbaseview=NULL;
145 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
146 if (tmpWin!=NULL){ wxvtkbaseview = tmpWin->GetwxVtkBaseView(); }
147 return wxvtkbaseview;
150 //-------------------------------------------------------------------------
151 void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
153 wxPanel::Refresh(false);
156 //-------------------------------------------------------------------------
157 void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
160 wxWindow *wxwindow = NULL;
161 wxSizer *sizer = this->GetSizer();
163 if (mvtkmprbasedata!=NULL)
165 delete mvtkmprbasedata;
168 marImageData *marimagedata = new marImageData( imagedata );
169 mvtkmprbasedata = new vtkMPRBaseData();
170 mvtkmprbasedata->SetMarImageData(marimagedata);
172 if(_currentwxw != NULL){
173 _currentwxw->Show(false);
175 //sizer->Remove(currentwxwindow);
176 //delete currentwxwindow;
179 //std::cout<<"size "<<nTypeView->size()<<std::endl;
180 if (nTypeView->size()==1)
182 wxwindow1 = new wxMaracas_ViewerWidget(this, imagedata, (*nTypeView)[0], mvtkmprbasedata);
184 wxwindow1->ConfigureVTK();
185 wxwindow = wxwindow1;
186 }else if (nTypeView->size()==2) {
187 wxSplitterWindow *spliter = new wxSplitterWindow( this , -1);
188 spliter->SetMinimumPaneSize(1);
189 wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
190 wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
191 wxwindow1->ConfigureVTK();
192 wxwindow2->ConfigureVTK();
193 spliter -> SplitVertically( wxwindow1 , wxwindow2 );
195 }else if (nTypeView->size()==3)
197 wxSplitterWindow *spliter = new wxSplitterWindow( this , -1);
198 wxSplitterWindow *spliterA = new wxSplitterWindow( spliter , -1);
199 spliter->SetMinimumPaneSize(1);
200 spliterA->SetMinimumPaneSize(1);
201 wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0], mvtkmprbasedata);
202 wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
203 wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
204 wxwindow1->ConfigureVTK();
205 wxwindow2->ConfigureVTK();
206 wxwindow3->ConfigureVTK();
207 spliter -> SplitVertically( wxwindow1 , spliterA );
208 spliterA-> SplitHorizontally( wxwindow2 , wxwindow3 );
210 }else if (nTypeView->size()>=4){
211 wxSplitterWindow *spliter = new wxSplitterWindow( this , -1);
212 wxSplitterWindow *spliterA = new wxSplitterWindow( spliter , -1);
213 wxSplitterWindow *spliterB = new wxSplitterWindow( spliter , -1);
214 spliter->SetMinimumPaneSize(1);
215 spliterA->SetMinimumPaneSize(1);
216 spliterB->SetMinimumPaneSize(1);
217 wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0], mvtkmprbasedata);
218 wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
219 wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2], mvtkmprbasedata);
220 wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3], mvtkmprbasedata);
221 wxwindow1->ConfigureVTK();
222 wxwindow2->ConfigureVTK();
223 wxwindow3->ConfigureVTK();
224 wxwindow4->ConfigureVTK();
225 spliter -> SplitVertically( spliterA , spliterB );
226 spliterA-> SplitHorizontally( wxwindow1 , wxwindow2 );
227 spliterB-> SplitHorizontally( wxwindow3 , wxwindow4 );
231 //panel->SetDimension()
232 sizer->Add( wxwindow , 1, wxEXPAND);
234 _currentwxw = wxwindow;
235 _currentwxw->Show(true);
242 //-----------------------------------------------------------------------------------
243 void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
249 //-----------------------------------------------------------------------------------
250 void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image )
252 if (wxwindow1!=NULL) { wxwindow1->SetImage(image); }
253 if (wxwindow2!=NULL) { wxwindow2->SetImage(image); }
254 if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
255 if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
258 //-----------------------------------------------------------------------------------
259 void wxMaracas_N_ViewersWidget::ConfigureVTK()
261 if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
262 if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
263 if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
264 if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
267 //-----------------------------------------------------------------------------------
268 double wxMaracas_N_ViewersWidget :: GetX()
271 return mvtkmprbasedata->GetX();
272 // return wxwindow1->GetX();
275 //-----------------------------------------------------------------------------------
276 double wxMaracas_N_ViewersWidget :: GetY()
279 return mvtkmprbasedata->GetY();
280 // return wxwindow1->GetY();
284 //-----------------------------------------------------------------------------------
285 double wxMaracas_N_ViewersWidget :: GetZ()
288 return mvtkmprbasedata->GetZ();
289 // return wxwindow1->GetZ();
292 void wxMaracas_N_ViewersWidget :: invariant(){
293 if(mvtkmprbasedata == 0){
294 throw "The image has not been set in the viewer";
298 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){
299 if (wxwindow1!=NULL) {
300 wxwindow1->setColorTransferFunction(colortable);
302 if (wxwindow2!=NULL) {
303 wxwindow2->setColorTransferFunction(colortable);
305 if (wxwindow3!=NULL) {
306 wxwindow3->setColorTransferFunction(colortable);
308 if (wxwindow4!=NULL) {
309 wxwindow4->setColorTransferFunction(colortable);
313 void wxMaracas_N_ViewersWidget::setWindowLevel(double level){
314 if (wxwindow1!=NULL) {
315 wxwindow1->setWindowLevel(level);
317 if (wxwindow2!=NULL) {
318 wxwindow2->setWindowLevel(level);
320 if (wxwindow3!=NULL) {
321 wxwindow3->setWindowLevel(level);
323 if (wxwindow4!=NULL) {
324 wxwindow4->setWindowLevel(level);
327 void wxMaracas_N_ViewersWidget::setColorLevel(double level){
328 if (wxwindow1!=NULL) {
329 wxwindow1->setColorLevel(level);
331 if (wxwindow2!=NULL) {
332 wxwindow2->setColorLevel(level);
334 if (wxwindow3!=NULL) {
335 wxwindow3->setColorLevel(level);
337 if (wxwindow4!=NULL) {
338 wxwindow4->setColorLevel(level);