NIREP

NIREPDisplayManager.cxx

Go to the documentation of this file.
00001 // For compilers that support precompilation, includes "wx/wx.h".
00002 #include "wx/wxprec.h"
00003 
00004 #ifdef __BORLANDC__
00005 #pragma hdrstop
00006 #endif
00007 
00008 #ifndef WX_PRECOMP
00009 #include "wx/wx.h"
00010 #endif
00011 #include "Interface.h"
00012 
00013 #include "NIREPDisplayManager.h"
00014 
00015 #include <vtkImageData.h>
00016 
00017 //#include "NIREPResourceDatabase.h"
00018 #include "NIREPDataManager.h"
00019 
00020 
00021 #include "itkImageToVTKImageFilter.h"
00022 #include "NIREPwxVTKRenderWindowInteractor.h"
00023 #include <vtkImageMathematics.h>
00024 
00025 #include <vector>
00026 #include <list>
00027 #include <map>
00028 #include <time.h>
00029 //#include "wxImageThumbnail.h"
00030 
00031 #include <iostream>
00032 #include <fstream>
00033 
00034 #include "DisplayDescription.h"
00035 
00036 
00037 NIREPDisplayManager::NIREPDisplayManager(void) : num(0)
00038 {
00039         //AtoI["a"] = 0;
00040         //AtoI["b"] = 1;
00041         //AtoI["c"] = 2;
00042         //AtoI["d"] = 3;
00043         //AtoI["e"] = 4;
00044         //AtoI["f"] = 5;
00045         //AtoI["g"] = 6;
00046         //AtoI["h"] = 7;
00047         //AtoI["0"] = 0;
00048         //AtoI["1"] = 1;
00049         //AtoI["2"] = 2;
00050         //AtoI["3"] = 3;
00051         //AtoI["4"] = 4;
00052         //AtoI["5"] = 5;
00053         //AtoI["6"] = 6;
00054         //AtoI["7"] = 7;
00055 
00056 //  DataManager = NULL;
00057 }
00058 
00059 NIREPDisplayManager::~NIREPDisplayManager(void)
00060 {
00061         for(int i = 0; i < info.size(); i++)
00062         {
00063                 if(info[i]) delete info[i];
00064         }
00065   //if(!ResourceDatabase)
00066   //  ResourceDatabase->Delete();
00067 //  if(!ResourceDisplay)
00068 //    ResourceDisplay->Delete();
00069 }
00070 NIREPDisplayManager::DisplayInfo::DisplayInfo(void) : id(0)
00071 {
00072 }
00073 
00080 NIREPDisplayManager::DisplayInfo::~DisplayInfo(void)
00081 {
00082         for(int i = 0; i < m_pVTKWindow.size(); i++)
00083         {
00084                 if(m_pVTKWindow[i]) m_pVTKWindow[i]->Delete();
00085         }
00086 }
00087 
00088 
00110 wxWindow *  NIREPDisplayManager::AddDisplay(const char * WidgetPath,const char * EvaluatorPath, wxWindow * aui, wxWindow * win, int pagecount, std::string & title)
00111 {
00112   //wxImageThumbnail *panel = new wxImageThumbnail(aui, wxID_ANY, wxDefaultPosition, win->GetSize(), wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL);
00113         //wxPanel * panel = new wxPanel(aui, wxID_ANY, wxDefaultPosition, win->GetSize(), wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL);
00114 
00115         //ResourceDisplay = NIREPResourceDisplay::New();
00116         //ResourceDisplay->SetFileName(path);
00117         //ResourceDisplay->Parse();
00118 
00119 //  panel->SetDataManager(DataManager);
00120   wxString bob = WidgetPath;
00121 //  DisplayDescription *temp = new DisplayDescription();
00122  // temp->Read(WidgetPath);
00123  // panel->ParseWidgetList(&bob);
00124   wxString bobTwo = EvaluatorPath;
00125  // panel->ParseEvalutorList(&bobTwo);
00126         
00127         //ResourceDatabase = NIREPResourceDatabase::New();
00128         //
00129         //for(int i = 0; i < ResourceDisplay->include.size(); i++)
00130         //{
00131         //      ResourceDatabase->SetFileName(ResourceDisplay->include[i].c_str());
00132         //      ResourceDatabase->Parse();
00133         //}
00134 
00135  // ResourceDisplay = NIREPResourceDisplay::New();
00136         //ResourceDisplay->SetFileName(path);
00137         //ResourceDisplay->Parse();
00138 
00139   //for(int i = 0; i < ResourceDisplay->include.size(); i++)
00140         //{
00141   //  DataManager->ReadResourceFile(ResourceDisplay->include[i].c_str());
00142   //}
00143 
00144         
00145         //int rowsize = atoi(ResourceDisplay->table[0].rowsize.c_str());
00146         //int colsize = atoi(ResourceDisplay->table[0].columnsize.c_str());
00147 
00148   //title = ResourceDisplay->table[0].title;
00149 
00150 
00151   //panel->SetColumns(colsize);
00152   
00153 
00154     //Resource Display
00155  // vector<NIREPCell> list_cell(panel->GetWidgetList().size());
00156 
00157   //get parameters
00158  // int row, col; string param;
00159         //for(int i = 0; i < ResourceDisplay->table[0].cell.size(); i++)
00160         //{
00161         //      row = atoi(ResourceDisplay->table[0].cell[i].row.c_str()) - 1;
00162         //      //col = AtoI[ResourceDisplay->table[0].cell[i].column];
00163  //   int number = 0;
00164  //   for(int j=0; j<ResourceDisplay->table[0].cell[i].column.size();j++)
00165  //   {
00166  //     number  = int(ResourceDisplay->table[0].cell[i].column[j])+number;
00167  //   }
00168  //   col = number -97;
00169 
00170         //      list_cell[row*colsize+col] = ResourceDisplay->table[0].cell[i];
00171         //}
00172   //std::map<std::string,std::string> tempSix = panel->GetWidgetList();
00173   //std::map<std::string,std::string>::iterator temp = tempSix.begin();
00174   //for(; temp != panel->GetWidgetList().end();temp++)
00175   //{
00176   //  std::string tempTwo = temp->second;
00177   //  size_t tempThree = tempTwo.find_first_of("(");
00178   //  size_t tempFour = tempTwo.find_first_of(",");
00179   //  std::string tempFive(tempTwo,tempThree,tempFour);
00180   //  panel->AddImage(DataManager->GetImageData(tempFive,0,3),"bob");
00181   //}
00182   //panel->Layout();
00183         //wxFlexGridSizer* itemGridSizer = new wxFlexGridSizer(2*rowsize + 1, colsize + 1, 0, 0);
00184  // wxFlexGridSizer* itemGridSizer = new wxFlexGridSizer(rowsize + 1, colsize + 1, 0, 0);
00185 
00186  // for(int i = 0; i<rowsize ;i++ )
00187  // {
00188  //   itemGridSizer->AddGrowableRow(i+1);
00189  // }
00190  // for(int j = 0; j<colsize ;j++ )
00191  // {
00192  //   itemGridSizer->AddGrowableCol(j+1);
00193  // }
00194 
00195         //panel->SetSizer(itemGridSizer);
00196 
00197   //spacer
00198   //itemGridSizer->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00199 
00200   //column title
00201   //for(int i=0; i<colsize ;i++)
00202   //{
00203     //wxStaticText* itemStaticText = new wxStaticText( panel, wxID_STATIC, ResourceDisplay->table[0].column[i].label, wxDefaultPosition, wxDefaultSize, 0 );
00204     //itemStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, wxT("Tahoma")));
00205 //    itemGridSizer->Add(itemStaticText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00206   //}
00207 
00208   //Resource Display
00209 //  vector<NIREPCell> list_cell(rowsize*colsize);
00210 //
00211 //  //get parameters
00212 //  int row, col; string param;
00213 //      for(int i = 0; i < ResourceDisplay->table[0].cell.size(); i++)
00214 //      {
00215 //              row = atoi(ResourceDisplay->table[0].cell[i].row.c_str()) - 1;
00216 //              //col = AtoI[ResourceDisplay->table[0].cell[i].column];
00217 //    int number = 0;
00218 //    for(int j=0; j<ResourceDisplay->table[0].cell[i].column.size();j++)
00219 //    {
00220 //      number  = int(ResourceDisplay->table[0].cell[i].column[j])+number;
00221 //    }
00222 //    col = number -97;
00223 //
00224 //              list_cell[row*colsize+col] = ResourceDisplay->table[0].cell[i];
00225 //      }
00226 //  DisplayInfo * item = new DisplayInfo;
00227 //
00228 //  //run through the rows and columns placing the correct widget into the right place
00229   //for(int j=0; j<rowsize ;j++)
00230   //{
00231 //    wxStaticText* itemStaticText = new wxStaticText( panel, wxID_STATIC, ResourceDisplay->table[0].row[j].label.c_str(), wxDefaultPosition, wxDefaultSize, 0 );
00232 //    itemStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, wxT("Tahoma")));
00234 //
00235           //for(int i=0; i<colsize ;i++)
00236           //{
00237       //itemGridSizer->Add(new wxVTKRenderWindowInteractor(panel, wxID_ANY),0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 0);
00238 
00239 //        WidgetInfo *widgetInformation = new WidgetInfo;
00240 //                item->m_pVTKWindow.push_back(new wxVTKRenderWindowInteractor(panel, wxID_ANY));
00241 //                item->m_pVTKWindow[i]->UseCaptureMouseOn();
00242 //        
00243 //              wxBoxSizer* itemBoxSizer = new wxBoxSizer(wxVERTICAL);
00245 //        itemBoxSizer->Add(item->m_pVTKWindow[i],1, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL,0);
00246 //                //itemGridSizer->Add(item->m_pVTKWindow[i], 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 0);
00247 //        
00248 //        //figure out the type of widget the user wishes to display
00249 //        if(!list_cell[j*colsize+i].display.type.compare("image") )
00250 //        {
00251 //          widgetInformation->widget = NIREPSimpleViewer::New();
00252 //        }
00253 //        else if(!list_cell[j*colsize+i].display.type.compare("object") )
00254 //        {
00255 //          widgetInformation->widget = NIREPSimpleViewer::New();
00256 //        } 
00257 //        else if(!list_cell[j*colsize+i].display.type.compare("difference") )
00258 //        {
00259 //          widgetInformation->widget =NIREPDifference::New();
00260 //        }
00261 //        else if(!list_cell[j*colsize+i].display.type.compare("overlay") )
00262 //        {
00263 //          widgetInformation->widget = NIREPTwoImageOverlap::New();
00264 //        }
00265 //
00266 //        //Set the corresponding wxVTKRenderWindowInteractor to the widget
00267 //        widgetInformation->widget->SetWindow(item->m_pVTKWindow[i]);
00268 //
00269 //        //figure out the orientation of the image
00270 //        if( !list_cell[j*colsize+i].display.ori.compare("transverse") )
00271 //        {
00272 //          widgetInformation->orientation = 0;
00273 //        }
00274 //        else if( !list_cell[j*colsize+i].display.ori.compare("coronal") )
00275 //        {
00276 //          widgetInformation->orientation = 2;
00277 //        }
00278 //        else if( !list_cell[j*colsize+i].display.ori.compare("sagittal") )
00279 //        {
00280 //          widgetInformation->orientation = 1;
00281 //        }
00282 //        //set the information about the widget into widgetInformation
00283 //        widgetInformation->sliceNumber = atoi(list_cell[j*colsize+i].display.slice.c_str());
00284 //        widgetInformation->dimension = 2;
00285 //
00286 //        if(list_cell[j*colsize+i].display.DorT == 0)
00287 //        {
00288 //          //,widgetInformation->orientation,widgetInformation->dimension,widgetInformation->sliceNumber)
00289 //          widgetInformation->widget->SetInput(DisplacmentManager->GetDisplacment(atoi(list_cell[j*colsize+i].display.displacment.source.c_str()),atoi(list_cell[j*colsize+i].display.displacment.target.c_str()),atoi(list_cell[j*colsize+i].display.displacment.algorithm.c_str()),list_cell[j*colsize+i].display.displacment.style,widgetInformation->orientation,widgetInformation->dimension,widgetInformation->sliceNumber));
00290 //        }
00291 //        else if(list_cell[j*colsize+i].display.DorT == 1)
00292 //        {
00293 //          //,widgetInformation->orientation,widgetInformation->dimension,widgetInformation->sliceNumber)
00294 //          //widgetInformation->widget->SetInput(Evaluator->GetTransform);
00295 //        }
00296 //        else
00297 //        {
00298 //          //Set the inputs to the widget
00299 //          for(int n= 0; n< list_cell[j*colsize+i].display.param.size();n++)
00300 //          {
00301 //            widgetInformation->ids.push_back(list_cell[j*colsize+i].display.param[n]);
00302 //            widgetInformation->widget->SetInput(DataManager->GetImageData(list_cell[j*colsize+i].display.param[n],widgetInformation->orientation,widgetInformation->dimension,widgetInformation->sliceNumber));
00303 //          }
00304 //        }
00305 //
00306 //        //make the widget
00307 //        widgetInformation->widget->Make();
00308 //        
00309 //        //create the slider bar and set the corresponding information needed for the slider bar
00310 //        widgetInformation->m_pwxSlider = new wxSlider( panel, wxID_ANY, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
00311 //        //need to figure out the max size of the images
00312 //        widgetInformation->m_pwxSlider->SetRange(0,255);
00313 //        widgetInformation->m_pwxSlider->SetValue(widgetInformation->sliceNumber);
00314 //        widgetInformation->m_pwxSlider->Show();
00315 //        //itemGridSizer->Add(widgetInformation->m_pwxSlider, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 0);
00316 //        itemBoxSizer->Add(widgetInformation->m_pwxSlider, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5);
00317 //        
00318 //        
00319 //
00320 //        //we need the location of the widget information, so that later on we can update the information when a slider bar is changed
00321 //        Location *loc = new Location;
00322 //        loc->loc = info.size();
00323 //        loc->locTwo = item->m_pWidgetsInfo.size();
00324 //
00325 //        //need to add the widget information after we get the size of m_pWidgetsInfo, we could add it before but then we would have to subract one from locTwo in loc
00326 //        item->m_pWidgetsInfo.push_back(widgetInformation);
00327 //
00328 //
00329 //        //We will use the Id of the slider bar to correspond the slider with a widget 
00330 //        LocationOfInfo[widgetInformation->m_pwxSlider->GetId()] = loc;
00331 //
00332 //
00333 //        //set up the event handling for the slider bar
00334 //        win->Connect(widgetInformation->m_pwxSlider->GetId(),0,wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction)
00335 //        (wxEventFunction)
00336 //        (wxCommandEventFunction) &NIREPDisplayManager::OnDynamic,NULL,this);
00337 //    
00338 //
00339 //        }
00340 //  }
00341 //  item->id = pagecount;
00342 //  info.push_back( item );
00343 //
00345 //
00346 //  panel->Layout();
00347 //  panel->SetSize(win->GetClientSize());
00348 //
00349 //  //ResourceDatabase->Delete();
00350 //  ResourceDisplay->Delete();
00351 
00352  // return panel;
00353 return NULL;
00354 }
00355 
00362 //void NIREPDisplayManager::UpdateDiplay()
00363 //{
00364 //      for(int i = 0; i < info.size(); i++)
00365 //      {
00366 //              for(int j = 0; j < info[i]->win_info.size(); j++)
00367 //              {
00368 //                      info[i]->m_pVTKWindow[j]->Render();
00369 //                      string str = info[i]->win_info[j]["SetSlice"];
00370 //                      //info[i]->m_pVTKViewer[j]->SetSlice( atoi(str.c_str()) );
00371 //              }
00372 //      }
00373 //}     
00374 
00381 //bool  NIREPDisplayManager::RemoveDisplay(int id)
00382 //{
00383 //      for(int i = 0; i < info.size(); i++)
00384 //      {
00385 //          if(info[i]->id == id)
00386 //          {
00387 //            delete info[i];
00388 //            info.erase(info.begin() + i);
00389 //          }
00390 //      }
00391 //
00392 //  //reorder pages
00393 //  for(int i = 0; i < info.size(); i++)
00394 //      {
00395 //    info[i]->id = i;
00396 //      }
00397 //  return true;
00398 //}
00399 
00406 //void NIREPDisplayManager::RefreshDisplay()
00407 //{
00408 //      for(int i = 0; i < info.size(); i++)
00409 //      {
00410 //              for(int j = 0; j < info[i]->win_info.size(); j++)
00411 //              {
00412 //                      wxPaintEvent pnt;
00413 //                      info[i]->m_pVTKWindow[j]->OnPaint(pnt);
00414 //              }
00415 //      }
00416 //}
00417 
00424 //void NIREPDisplayManager::RefreshADisplay(int id)
00425 //{
00426 //      for(int i = 0; i < info.size(); i++)
00427 //      {
00428 //          if(info[i]->id == id)
00429 //          {
00430 //                        for(int j = 0; j < info[i]->win_info.size(); j++)
00431 //                        {
00432 //                                wxPaintEvent pnt;
00433 //                                info[i]->m_pVTKWindow[j]->OnPaint(pnt);
00434 //                        }
00435 //          }
00436 //      }
00437 //}
00438 
00445 //void NIREPDisplayManager::RemoveAllDisplay()
00446 //{
00447 //      for(int i = 0; i < info.size(); i++)
00448 //      {       
00449 //              RemoveDisplay(0);
00450 //      }       
00451 //}
00452 
00459 //void NIREPDisplayManager::GetActiveDisplays(vector<string> & list)
00460 //{
00461 //      for(int i = 0; i < info.size(); i++)
00462 //      {
00463 //              list.push_back(info[i]->path);
00464 //      }
00465 //}
00466 
00473 //void NIREPDisplayManager::OnDynamic(wxCommandEvent& event)
00474 //{
00475 //  //We use the Id of the slider bar to figure out which widget to update
00476 //  const int id = event.GetId();
00477 //
00478 //  //we then take the id of the slider bar and get the location instance so that we can quickly go through info to get to the right widget
00479 //  Location *loc = LocationOfInfo[id];
00480 //  if(loc == NULL)
00481 //  {
00482 //    return;
00483 //  }
00484 //  
00485 //  for(int i=0; i<info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->ids.size();i++)
00486 //  {
00487 //    //Reduce the hit count of the image in the datamanager, this way if the image is no longer being used it can be deleted
00488 //  DataManager->ReduceHitCount(info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->ids[i].c_str(), 2,info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->dimension,info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->orientation, info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->sliceNumber);
00489 // //get the new image from the datamanager and place it into the widget
00490 //  info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->widget->SetInput(DataManager->GetImageData(info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->ids[i].c_str(),info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->orientation,info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->dimension,event.GetInt()),i);
00491 // 
00492 //  }
00493 //  //set the sliceNumber to the number corresponding to the slider
00494 //  info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->sliceNumber = event.GetInt();
00495 //  //update the widget
00496 //  info.at(loc->loc)->m_pWidgetsInfo.at(loc->locTwo)->widget->Update();
00497 //}
00498 
00499 //void NIREPDisplayManager::SetDataManager(NIREPDataManager *dataManager)
00500 //{
00501 //  DataManager = dataManager;
00502 //}
00503 
00504 //void NIREPDisplayManager::SetDispManager(DispManager *dispManager)
00505 //{
00506 //  DisplacmentManager = dispManager;
00507 //}
00508 
00509 
00510 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines