wxMaracas_N_ViewersWidget.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2010/08/25 17:51:12 $
00007   Version:   $Revision: 1.19 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011   
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 
00018 //------------------------------------------------------------------------------------------------------------
00019 // Definition includes
00020 //------------------------------------------------------------------------------------------------------------
00021 #include "wxMaracas_N_ViewersWidget.h"
00022 
00023 //------------------------------------------------------------------------------------------------------------
00024 // Other includes
00025 //------------------------------------------------------------------------------------------------------------
00026 
00027 
00028         //------------------------------------------------------------------------------------------------------------
00029         // Constructors & Destructors
00030         //------------------------------------------------------------------------------------------------------------
00031 
00032 
00033         BEGIN_EVENT_TABLE( wxMaracas_N_ViewersWidget, wxPanel )
00034                 EVT_MENU( 12121, wxMaracas_N_ViewersWidget::OnRefreshView )
00035                 EVT_MENU( 12122, wxMaracas_N_ViewersWidget::OnDClickLeft  )
00036         END_EVENT_TABLE( );
00037 
00038         
00039         //------------------------------------------------------------------------------------------------------------
00040         // Constructors & Destructors
00041         //------------------------------------------------------------------------------------------------------------
00042 
00043 
00044 
00045         wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata, std::vector<int> *nTypeView)
00046                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
00047         {
00048                 wxwindow1               = NULL;
00049                 wxwindow2               = NULL;
00050                 wxwindow3               = NULL;
00051                 wxwindow4               = NULL;
00052                 _currentwxw             = NULL;
00053                 mvtkmprbasedata = NULL;
00054                 
00055                 wxSizer *sizer  = new wxBoxSizer(wxVERTICAL);
00056                 this->SetSizer(sizer);
00057                 this->SetAutoLayout(true);
00058                 
00059                 
00060                 if(imagedata!=NULL && nTypeView!=NULL ){
00061                         this->SetType(nTypeView);
00062                         this->UpdateLayout(imagedata);
00063                 }
00064 
00065                 
00066         }
00075         wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata)
00076         : wxPanel( parent, -1){
00077                 wxwindow1               = NULL;
00078                 wxwindow2               = NULL;
00079                 wxwindow3               = NULL;
00080                 wxwindow4               = NULL;
00081                 _currentwxw             = NULL;
00082                 mvtkmprbasedata = NULL;
00083                 
00084                 wxSizer *sizer  = new wxBoxSizer(wxVERTICAL);
00085                 this->SetSizer(sizer);
00086                 this->SetAutoLayout(true);
00087                 
00088                 this->SetType(nTypeView);
00089                 
00090                 /*if(imagedata==NULL){
00091                         double spc[3];
00092                         spc[0] = 1;
00093                         spc[1] = 1;
00094                         spc[2] = 1;
00095                         int extent[6];
00096                         extent[0] = 0;
00097                         extent[1] = 1;
00098                         extent[2] = 0;
00099                         extent[3] = 1;
00100                         extent[4] = 0;
00101                         extent[5] = 0;
00102                         
00103                         imagedata = vtkImageData::New();
00104                         imagedata->SetSpacing(spc);
00105                         imagedata->SetExtent(extent);
00106                         imagedata->SetScalarTypeToUnsignedChar();
00107                         imagedata->AllocateScalars();
00108                 }*/
00109                 
00110                 this->UpdateLayout(imagedata);
00111         }
00112         //-------------------------------------------------------------------------
00113           
00114         wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
00115         {
00116                 if (mvtkmprbasedata!=NULL)
00117                 {
00118                         delete mvtkmprbasedata;
00119                 }
00120 
00121         }
00122         //------------------------------------------------------------------------------------------------------------
00123         // Methods
00124         //------------------------------------------------------------------------------------------------------------
00125 
00126 
00127         //-------------------------------------------------------------------------
00128 
00129         void wxMaracas_N_ViewersWidget::Update()
00130         {
00131                 //wxvtkrenderwindowinteractor->Render();
00132         //    wxvtkrenderwindowinteractor->Refresh();
00133         //    Refresh();
00134         }
00135 
00136         //-------------------------------------------------------------------------
00137 
00138         void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event) 
00139         {
00140                 RefreshView();
00141         }
00142         //----------------------------------------------------------------------------
00143         void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event) 
00144         {
00145                 RefreshView();
00146         }
00147 
00148                 //-------------------------------------------------------------------------
00149 
00150         vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
00151         {
00152                 return NULL; //renderer;
00153         }
00154 
00155         void wxMaracas_N_ViewersWidget::RefreshView()
00156         {               
00157                 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
00158                 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
00159                 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
00160                 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
00161         }
00162 
00163         //-------------------------------------------------------------------------
00164         wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)  
00165         {
00166                 wxMaracas_ViewerWidget *tmpWin=NULL;
00167                 if  (iWin==1)
00168                 {
00169                         tmpWin=wxwindow1;
00170                 }
00171                 if  (iWin==2)
00172                 {
00173                         tmpWin=wxwindow2;
00174                 }
00175                 if  (iWin==3)
00176                 {
00177                         tmpWin=wxwindow3;
00178                 }
00179                 if  (iWin==4)
00180                 {
00181                         tmpWin=wxwindow4;
00182                 }
00183                 return tmpWin;
00184         }
00185 
00186         //-------------------------------------------------------------------------
00187         wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
00188         { 
00189                 wxVtkBaseView *wxvtkbaseview=NULL;
00190                 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
00191                 if (tmpWin!=NULL){  wxvtkbaseview = tmpWin->GetwxVtkBaseView();  }
00192                 return wxvtkbaseview;
00193         }
00194    
00195         //-------------------------------------------------------------------------
00196         void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
00197         {
00198                 wxPanel::Refresh(false);
00199         }
00200 
00201         //-------------------------------------------------------------------------
00202         void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata)
00203         {
00204 
00205                 wxWindow                                *wxwindow       = NULL;
00206                 wxSizer *sizer                                          = this->GetSizer();     
00207                 
00208                 if (mvtkmprbasedata!=NULL)
00209                 {
00210                         delete mvtkmprbasedata;
00211                 }
00212                 
00213                 marImageData    *marimagedata   = new marImageData( imagedata );                        
00214                 mvtkmprbasedata                                 = new vtkMPRBaseData(); 
00215                 mvtkmprbasedata->SetMarImageData(marimagedata);
00216                 
00217                 if(_currentwxw != NULL){
00218                         _currentwxw->Show(false);
00219                         delete _currentwxw;
00220                         //sizer->Remove(currentwxwindow);                       
00221                         //delete currentwxwindow;
00222                 }
00223 
00224                 //std::cout<<"size "<<nTypeView->size()<<std::endl;
00225                 if (nTypeView->size()==1)
00226                 {
00227                         wxwindow1 = new wxMaracas_ViewerWidget(this, imagedata, (*nTypeView)[0], mvtkmprbasedata);
00228 
00229                         wxwindow1->ConfigureVTK();
00230                         wxwindow = wxwindow1;
00231                 }else   if (nTypeView->size()==2)       {
00232                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
00233                         spliter->SetMinimumPaneSize(1);
00234                         wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0], mvtkmprbasedata);
00235                         wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1], mvtkmprbasedata);
00236                         wxwindow1->ConfigureVTK();
00237                         wxwindow2->ConfigureVTK();
00238                         spliter -> SplitVertically( wxwindow1 , wxwindow2  );
00239                         wxwindow = spliter;                     
00240                 }else if (nTypeView->size()==3)
00241                 {
00242                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
00243                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
00244                         spliter->SetMinimumPaneSize(1);
00245                         spliterA->SetMinimumPaneSize(1);
00246                         wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0], mvtkmprbasedata);
00247                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
00248                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2], mvtkmprbasedata);
00249                         wxwindow1->ConfigureVTK();
00250                         wxwindow2->ConfigureVTK();
00251                         wxwindow3->ConfigureVTK();
00252                         spliter -> SplitVertically( wxwindow1 , spliterA   );
00253                         spliterA-> SplitHorizontally( wxwindow2 , wxwindow3  );
00254                         wxwindow = spliter;
00255                 }else if (nTypeView->size()>=4){
00256                         wxSplitterWindow        *spliter        = new wxSplitterWindow( this , -1);
00257                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
00258                         wxSplitterWindow        *spliterB       = new wxSplitterWindow( spliter , -1);
00259                         spliter->SetMinimumPaneSize(1);
00260                         spliterA->SetMinimumPaneSize(1);
00261                         spliterB->SetMinimumPaneSize(1);
00262                         wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0], mvtkmprbasedata);
00263                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1], mvtkmprbasedata);
00264                         wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2], mvtkmprbasedata);
00265                         wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3], mvtkmprbasedata);
00266                         wxwindow1->ConfigureVTK();
00267                         wxwindow2->ConfigureVTK();
00268                         wxwindow3->ConfigureVTK();
00269                         wxwindow4->ConfigureVTK();
00270                         spliter -> SplitVertically( spliterA , spliterB   );
00271                         spliterA-> SplitHorizontally( wxwindow1 , wxwindow2  );
00272                         spliterB-> SplitHorizontally( wxwindow3 , wxwindow4  );
00273                         wxwindow = spliter;
00274                 }
00275                 
00276                 //panel->SetDimension()
00277                 sizer->Add( wxwindow , 1, wxGROW);
00278                 sizer->Layout();
00279                 //_currentwxw = wxwindow;               
00280                 //_currentwxw->Show(true);
00281                 
00282                 //this->Layout();
00283                 //this->Refresh();
00284  }
00285 
00286 
00287 //-----------------------------------------------------------------------------------
00288  void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
00289          nTypeView = type;
00290  }
00291 
00292 
00293 
00294 //-----------------------------------------------------------------------------------
00295  void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image  )
00296  {      
00297          if (wxwindow1!=NULL) { wxwindow1->SetImage(image); }
00298          if (wxwindow2!=NULL) { wxwindow2->SetImage(image); } 
00299          if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
00300          if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
00301          ConfigureVTK();
00302          
00303  }
00304 
00305 //-----------------------------------------------------------------------------------
00306  void wxMaracas_N_ViewersWidget::ConfigureVTK()
00307  {
00308          if (wxwindow1!=NULL) { wxwindow1->ConfigureVTK(); }
00309          if (wxwindow2!=NULL) { wxwindow2->ConfigureVTK(); }
00310          if (wxwindow3!=NULL) { wxwindow3->ConfigureVTK(); }
00311          if (wxwindow4!=NULL) { wxwindow4->ConfigureVTK(); }
00312  }
00313 
00314 //-----------------------------------------------------------------------------------
00315 double wxMaracas_N_ViewersWidget :: GetX()
00316 {       
00317         invariant();
00318         return mvtkmprbasedata->GetX();
00319 //      return wxwindow1->GetX();
00320 }
00321 
00322 //-----------------------------------------------------------------------------------
00323 double wxMaracas_N_ViewersWidget :: GetY()
00324 {
00325         invariant();
00326         return mvtkmprbasedata->GetY();
00327 //      return wxwindow1->GetY();
00328 }
00329 
00330 
00331 //-----------------------------------------------------------------------------------
00332 double wxMaracas_N_ViewersWidget :: GetZ()
00333 {
00334         invariant();
00335         return mvtkmprbasedata->GetZ();
00336 //      return wxwindow1->GetZ();
00337 }
00338 
00339 void wxMaracas_N_ViewersWidget :: invariant(){
00340         if(mvtkmprbasedata == 0){
00341                 throw "The image has not been set in the viewer";
00342         }
00343 }
00344 
00345 void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){
00346     if (wxwindow1!=NULL) {
00347                 wxwindow1->setColorTransferFunction(colortable);
00348         }
00349         if (wxwindow2!=NULL) {
00350                 wxwindow2->setColorTransferFunction(colortable);
00351         }
00352         if (wxwindow3!=NULL) {
00353                 wxwindow3->setColorTransferFunction(colortable);
00354         }
00355         if (wxwindow4!=NULL) {
00356                 wxwindow4->setColorTransferFunction(colortable);
00357         }
00358 }
00359 
00360 void wxMaracas_N_ViewersWidget::setWindowLevel(double level){
00361         if (wxwindow1!=NULL) {
00362                 wxwindow1->setWindowLevel(level);
00363         }
00364         if (wxwindow2!=NULL) {
00365                 wxwindow2->setWindowLevel(level);
00366         }
00367         if (wxwindow3!=NULL) {
00368                 wxwindow3->setWindowLevel(level);
00369         }
00370         if (wxwindow4!=NULL) {
00371                 wxwindow4->setWindowLevel(level);
00372         }
00373 }
00374 void wxMaracas_N_ViewersWidget::setColorLevel(double level){
00375         if (wxwindow1!=NULL) {
00376                 wxwindow1->setColorLevel(level);
00377         }
00378         if (wxwindow2!=NULL) {
00379                 wxwindow2->setColorLevel(level);
00380         }
00381         if (wxwindow3!=NULL) {
00382                 wxwindow3->setColorLevel(level);
00383         }
00384         if (wxwindow4!=NULL) {
00385                 wxwindow4->setColorLevel(level);
00386         }
00387 }
00388 

Generated on 20 Oct 2010 for creaMaracasVisu_lib by  doxygen 1.6.1