wxContourMainFrame.cxx

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------------------------------------------
00002 // Class definition include
00003 //----------------------------------------------------------------------------------------------------------------
00004 #include "wxContourMainFrame.h"
00005 
00006 
00007 
00008 //----------------------------------------------------------------------------------------------------------------
00009 // Includes
00010 //----------------------------------------------------------------------------------------------------------------
00011 
00012 
00013 #include "NameWrapper.h"
00014 #include "wx/artprov.h"
00015 #include "ConceptDataWrap.h"
00016 #include <creaWx.h>
00017 
00018 #include <string>
00019 using namespace std;
00020 
00021 //----------------------------------------------------------------------------------------------------------------
00022 // Class implementation
00023 //----------------------------------------------------------------------------------------------------------------
00026         //------------------------------------------------------------------------------------------------------------
00027         // Constructors & Destructors
00028         //------------------------------------------------------------------------------------------------------------
00029 
00030 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
00031 char wxContourMainFrame::COPY = 'C';
00032 
00033         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
00034                 //: wxPanel(parent, id, title, pos, size, style)
00035                 //: wxWindow(parent, id, pos, size, style)
00036                 : wxPanel(parent, id, pos, size, style)
00037         {
00038                 m_mgr.SetManagedWindow(this);
00039                 _contourGroup                           = 1;
00040                 _creatingContoursActive         = false;
00041                 _theViewPanel                           = NULL;
00042 //              _modelManager                           = NULL;
00043                 _instantPanel                           = NULL;
00044 //              _buttonsBar                                     = NULL;
00045 //              _gridPanel                                      = NULL;
00046 //              _drawToolsPanel                         = NULL;
00047 //              _operationsToolsPanel           = NULL;
00048                 //_autoFormsPanel                               = NULL;
00049 //              _standardToolsPanel                     = NULL;
00050 //              _editionToolsPanel                      = NULL;
00051 //              _listViewPanel                          = NULL;
00052 //              _sceneManager                           = NULL;
00053                 //_actualInstant                                = NULL;
00054                 _numberOfVariablesStatistics = 6+1;
00055 
00056                 _refLineControl                         = NULL;
00057                 _refLineModel                           = NULL;
00058                 _refLineView                            = NULL;
00059 //              _actorPresent                           = false;
00060 
00061                 // set up default notebook style
00062 //              m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
00063 //              m_notebook_theme = 0;
00064                 //wxContour_ActionCommandsID a;
00065 
00066                 _contourextractdata                     = NULL;
00067                 _viewMaskImage                          = NULL;
00068                 _viewMaskImagePanel                     = NULL;
00069                 _viewThresholdImage                     = NULL;
00070                 _viewThresholdImagePanel        = NULL;
00071                 _viewColorLayerImage            = NULL;
00072                 _viewColorLayerImagePanel       = NULL;
00073         }
00074 
00075         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
00076                 : wxPanel(parent, id, pos, size, style)
00077         {
00078                 m_mgr.SetManagedWindow(this);
00079                 _contourGroup                           = 1;
00080                 _creatingContoursActive         = false;
00081                 _theViewPanel                           = NULL;
00082 
00083                 _instantPanel                           = NULL;
00084                 _refLineControl                         = NULL;
00085                 _refLineModel                           = NULL;
00086                 _refLineView                            = NULL;
00087 //              _actorPresent                           = false;
00088                 _viewMaskImage                          = NULL;
00089                 _viewMaskImagePanel                     = NULL;
00090                 _viewThresholdImage                     = NULL;
00091                 _viewThresholdImagePanel        = NULL;
00092                 _viewColorLayerImage            = NULL;
00093                 _viewColorLayerImagePanel       = NULL;
00094 
00095                 // set up default notebook style
00096                 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
00097                 m_notebook_theme = 0;
00098                 //wxContour_ActionCommandsID a;
00099                 _numberOfVariablesStatistics = 7;
00100 
00101                 _datadir = datadir;
00102 
00103 
00104                 inredo = 0;
00105                 inundo = 0;
00106 
00107                 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
00108                 _performingOperation = new PerformingOperation();
00109 
00110                 if(images.size() > 0)
00111                 {
00112                         this->setVectImages(images);
00113                 }
00114 
00115                 _contourextractdata                     = NULL;
00116 }
00117 
00118 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
00119 {
00120 
00121         _images = imgs;
00122 
00123         #if defined(__GNUC__)
00124                 std::string str_home(getenv("HOME"));
00125         #elif defined(_WIN32)
00126                         std::string str_home(getenv("USERPROFILE"));
00127         #endif
00128                 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
00129 
00130         std::vector<std::string> conceptNameVect;
00131         std::vector<int> conceptSizeVect;
00132 
00133         notebook = this->createNotebook();
00134 
00135 
00136         kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
00137 
00138 
00139         _instantPanel                           = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
00140         _theViewPanel                           = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
00141 
00142 //-------------------------------------------------------------
00143         kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
00144         _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
00145 
00146 
00147         double val = _theViewPanel->getCurrentDeep();
00148         _instantPanel->setConceptValue( "Axe Depth", (int)val );
00149         //JCP _instantPanel->setConceptValue("time", num de imagenes);
00150         ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
00151         //*******************changeInstant();
00152         _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(),  data->getMaxShowedValue(), data->getActualValue() );
00153 
00154         this->configurePanels( );
00155 
00156 }
00157 
00158 
00159         wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
00160         {
00161                 if(instance == NULL){
00162                         instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
00163                 }
00164                 return instance;
00165         }
00166 
00167         std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
00168         {
00169                 return kernelManager->getVectImages();
00170         }
00171 
00172         wxContourMainFrame* wxContourMainFrame :: getInstance()
00173         {
00174                 return instance;
00175         }
00176 
00177         void wxContourMainFrame :: resetInstance()
00178         {
00179                 instance->Destroy();
00180         }
00181 
00182         wxContourMainFrame :: ~wxContourMainFrame()
00183         {
00184                 delete _contourextractdata;
00185                 deleteAllContours();
00186                 _pannew->Close();
00187                 interfMainPanel::resetInstance();
00188                 delete kernelManager;
00189                 instance = NULL;
00190                 //_pannew->Destroy();
00191                 //delete _pannew;
00192 
00193                 m_mgr.UnInit();
00194                 //delete m_mgr;
00195 
00196                 //El problema al cerrar la aplicacion puede estar asociado
00197                 //a que  wxAUINotebook esta en la aplicacion
00198                 //principal (wxContourGUIExample)tambien
00199                 //EED????               delete _theViewPanel;
00200                 //EED????               delete _instantPanel;
00201                 //EED????               delete _buttonsBar;
00202                 //EED????               delete _actualInstant;
00203                 //EED????               delete _sceneManager;
00204         }
00205 
00206 
00207         //------------------------------------------------------------------------------------------------------------
00208         // Creational and initialization methods using WxAui
00209         //------------------------------------------------------------------------------------------------------------
00210         //
00211         wxAuiNotebook * wxContourMainFrame :: createNotebook()
00212         {
00213                 wxSize client_size = GetClientSize();
00214                 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
00215                 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
00216                 return noteBook;
00217         }
00218 
00219 
00220         //------------------------------------------------------------------------------------------------------------
00221         // Creational and initialization methods
00222         //------------------------------------------------------------------------------------------------------------
00223         bool wxContourMainFrame :: configurePanels( )
00224         {
00225                 bool configured = _theViewPanel!=NULL;
00226 
00227                 configured &= _theViewPanel!=NULL;
00228                 if( _theViewPanel!=NULL )
00229                 {
00230                         notebook->AddPage( _theViewPanel, wxT("       View       ") );
00231                         m_mgr.Update();
00232                 }
00233 
00234 
00235                 if( configured )
00236                 {
00237                         notebook->AddPage( _instantPanel, wxT("Instant Page") );
00238                         m_mgr.Update();
00239                 }
00240 
00241                 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
00242                 m_mgr.Update();
00243 
00244                 SetMinSize(wxSize(300,300));
00245                 m_mgr.Update();
00246                 return configured;
00247         }
00248 
00249 
00250         bool wxContourMainFrame::addNewPanel(wxPanel* panel)
00251                 {
00252                 bool configured = panel!=NULL;
00253                 configured &= panel!=NULL;
00254 
00255                 if( configured )
00256                 {
00257                         notebook->AddPage( panel, wxT("       Viewer       "), true );
00258                         m_mgr.Update();
00259                 }
00260                 return configured;
00261         }
00262 
00263         //------------------------------------------------------------------------------------------------------------
00264         //  Attributes getters and setters
00265         //------------------------------------------------------------------------------------------------------------
00266 
00267 
00268 
00269         void wxContourMainFrame :: setInstantChooserPanel(  wxInstantChooserPanel * theInstantChooserPanel )
00270         {
00271                 _instantPanel = theInstantChooserPanel;
00272         }
00273 
00274 //      void wxContourMainFrame :: setButtonsBar(  wxContour_ButtonsBar * theButtonsBar )
00275 //      {
00276 //              _buttonsBar = theButtonsBar;
00277 //      }
00278 
00279 //      void wxContourMainFrame :: setGrid(  wxContour_Grid * theGridPanel )
00280 //      {
00281 //              _gridPanel = theGridPanel;
00282 //      }
00283 
00284 //      void wxContourMainFrame :: setDrawToolsPanel(  wxContour_DrawToolsPanel * theDrawToolsPanel )
00285 //      {
00286 //              _drawToolsPanel = theDrawToolsPanel;
00287 //      }
00288 
00289 //      void wxContourMainFrame :: setOperationsToolsPanel(  wxContour_OperationsToolsPanel * theOperationsToolsPanel )
00290 //      {
00291 //              _operationsToolsPanel = theOperationsToolsPanel;
00292 //      }
00293 
00294 //      void wxContourMainFrame :: setAutomaticFormsPanel(  wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
00295 //      {
00296 //              _autoFormsPanel = theAutoFormsPanel;
00297 //      }
00298 
00299 //      void wxContourMainFrame :: setStandardToolsPanel(  wxContour_StandardToolsPanel * theStandardToolsPanel )
00300 //      {
00301 //              _standardToolsPanel= theStandardToolsPanel;
00302 //      }
00303 
00304 //      void wxContourMainFrame :: setEditionToolsPanel(  wxContour_EdtionToolsPanel * theEditionToolsPanel )
00305 //      {
00306 //              _editionToolsPanel =  theEditionToolsPanel;
00307 //      }
00308 
00309 //      void wxContourMainFrame :: setListViewPanel(  wxContour_ListViewPanel * theListViewPanel )
00310 //      {
00311 //              _listViewPanel = theListViewPanel;
00312 //      }
00313 
00314 
00315 
00316 void wxContourMainFrame::onCreateContourSpline( ){
00317 
00318         //JCP 20-10-08 Undo redo implementation
00319         saveState();
00320         //JCP 20-10-08 Undo redo implementation
00321         createContour( 1 );
00322 
00323 }
00324 void wxContourMainFrame::onCreateContourRectangle( ){
00325     //JCP 20-10-08 Undo redo implementation
00326         saveState();
00327         //JCP 20-10-08 Undo redo implementation
00328         createContour( 2 );
00329 }
00330 void wxContourMainFrame::onCreateContourCircle( ){
00331     //JCP 20-10-08 Undo redo implementation
00332         saveState();
00333         //JCP 20-10-08 Undo redo implementation
00334         createContour( 3 );
00335 }
00336 
00337 void wxContourMainFrame::onCreateContourLine( ){
00338     //JCP 20-10-08 Undo redo implementation
00339         saveState();
00340         //JCP 20-10-08 Undo redo implementation
00341         createContour( 6 );
00342 }
00343 
00344 // RaC 09-09 --------------------------------------
00345 void wxContourMainFrame::onCreateContourPoints( ){
00346     //JCP 20-10-08 Undo redo implementation
00347         saveState();
00348         //JCP 20-10-08 Undo redo implementation
00349         createContour( 7 );
00350 }
00351 // RaC 09-09 --------------------------------------
00352 
00353 // RaC 10-09 --------------------------------------
00354 void wxContourMainFrame::onCreateContourPolygon( ){
00355     //JCP 20-10-08 Undo redo implementation
00356         saveState();
00357         //JCP 20-10-08 Undo redo implementation
00358         createContour( 10 );
00359 }
00360 // RaC 10-09 --------------------------------------
00361 
00362 //------------------------------------------------------------------------------------------------------------
00363 
00364 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
00365 {
00366         //Creating the manualBaseModel and including in the model
00367         manualBaseModel * manModelContour = factoryManualContourModel(panel );
00368 
00369         std::vector<int> instantVector;
00370         _instantPanel->getInstant( instantVector );
00371         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
00372 
00373         /*std::vector<int> instantVector;
00374         _instantPanel->getInstant( instantVector );
00375         std::string theName;
00376         theName= _modelManager->createOutline( manModelContour, instantVector );*/
00377         bool addedModel = theName.compare("") != 0;//??
00378 
00379         if( addedModel )
00380         {
00381                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
00382                 _theViewPanel->getSpacing(spc);
00383                 //Adding the manualContourControler to interface objects structure
00384                 //Adding the manualViewContour to interface objects structure
00385                 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
00386                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
00387         }
00388 }
00389 void wxContourMainFrame :: createContour( int typeContour )
00390 {
00391         //Creating the manualContourModel and including in the model
00392         manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
00393 
00394         std::vector<int> instantVector;
00395         _instantPanel->getInstant( instantVector );
00396         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
00397 
00398         /*std::vector<int> instantVector;
00399         _instantPanel->getInstant( instantVector );
00400         std::string theName;
00401         theName= _modelManager->createOutline( manModelContour, instantVector );*/
00402         bool addedModel = theName.compare("") != 0;//??
00403         if( addedModel )
00404         {
00405                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
00406                 _theViewPanel->getSpacing(spc);
00407                 //Adding the manualContourControler to interface objects structure
00408                 //Adding the manualViewContour to interface objects structure
00409                 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
00410                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
00411         }
00412 
00413 }
00414 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
00415 
00416         manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
00417         manualBaseModel *manModelContour=NULL;
00418         manModelContour = manModelContourBullEye;
00419         if (panel!=NULL){
00420                 int iCrown,sizeCrowns,iSector,sizeSectors;
00421                 double radioA,radioB,ang,angDelta ;
00422                 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
00423                 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
00424                 {
00425                         sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
00426                         radioB  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
00427                         if (iCrown==sizeCrowns-1)
00428                         {
00429                                 radioA  = 0;
00430                         } else {
00431                                 radioA  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
00432                         }
00433                         radioA=radioA/100.0;
00434                         radioB=radioB/100.0;
00435                         for ( iSector=0 ; iSector<sizeSectors  ; iSector++ )
00436                         {
00437                                 ang             = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
00438                                 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
00439                                 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
00440                         } // for iSector
00441                 } // for iCrown
00442         } // if _panelBullEyeOptions
00443 
00444         return manModelContour;
00445 }
00446 void wxContourMainFrame :: saveState(){
00447 
00448         std::string temp = kernelManager->saveState();
00449         saveFileWithContours(temp);
00450 }
00451 
00452 void wxContourMainFrame::onDeleteContour(){
00453         //JCP 20-10-08 Undo redo implementation
00454                 saveState();
00455                 //JCP 20-10-08 Undo redo implementation
00456 
00457                 std::vector<std::string> lstKeyNameToBeErase;
00458                 lstKeyNameToBeErase             = _theViewPanel->getSceneManager()->getSelectedObjects();
00459                 deleteContours( lstKeyNameToBeErase );
00460 /*JCP 19 - 11 - 08
00461                 int i,size=_sceneManager->getSelectedObjects().size();
00462                 for(i=0;i<size;i++)
00463                 {
00464                         std::string keyName             = _sceneManager->getSelectedObjects()[i];
00465                         int ispartofstaticlist  = this->_modelManager->IsPartOfStaticList( keyName );
00466                         if ( ispartofstaticlist>=0 )
00467                         {
00468                                 std::vector<int> tempVector;
00469                                 _instantPanel->getInstant( tempVector );
00470                                 Instant instant(&tempVector);
00471                                 this->_modelManager->ChangeContourOfList(keyName, &instant);
00472                         }
00473                 }
00474 
00475                 std::vector<std::string> lstKeyName;
00476                 std::vector<std::string> lstKeyNameActualSlice;
00477                 std::vector<std::string> lstKeyNameToBeErase;
00478 
00479                 lstKeyNameToBeErase             = _sceneManager->getSelectedObjects();
00480                 lstKeyNameActualSlice   = _sceneManager->GetlstContoursNameActualSlice();
00481                 int k,kSize=lstKeyNameToBeErase.size();
00482                 int j,jSize=lstKeyNameActualSlice.size();
00483                 bool ok;
00484                 for (k=0;k<kSize; k++)
00485                 {
00486                         ok=false;
00487                         for (j=0;j<jSize; j++)
00488                         {
00489                                 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
00490                                 {
00491                                         ok=true;
00492                                 }
00493                         } // for j
00494                         if (ok==true)
00495                         {
00496                                 lstKeyName.push_back( lstKeyNameToBeErase[k] );
00497                         } // if ok
00498                 } // for k
00499 
00500                 deleteContours( lstKeyName );
00501 JCP 19 - 11 - 08*/
00502 }
00503 
00504 void wxContourMainFrame :: deleteContours( std::vector<std::string>  keyNamesVector )
00505 {
00506         int i,size=keyNamesVector.size();
00507         for (i=0;i<size;i++)
00508         {
00509                 deleteContour( keyNamesVector[i] );
00510         }
00511 }
00512 
00513 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
00514         /*
00515         manualContourModel                      * cModel;
00516         manualViewBaseContour           * cViewer;
00517         manualContourBaseControler      * cControler;
00518 
00519         ContourWrap_ViewControl *conwrapviewControl =  _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
00520         cControler      = conwrapviewControl->getControler();*/
00521 
00522         //JCP 21 - 11 - 2008
00523         bool isedit = _theViewPanel->isEditableCControler(theKeyName);
00524         bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
00525 
00526         if (isedit  && ispartofstaticlst)
00527         {
00528                 _theViewPanel->removeFromScene(theKeyName);
00529 
00530                 kernelManager->deleteCModel(theKeyName);
00531                 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
00532                 //cViewer               = conwrapviewControl->getViewer();
00533                 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
00534                 //cControler* conwrapviewControl->getControler();
00535         //      delete cModel;
00536         //      delete cViewer;
00537         //      delete cControler;
00538         } // if editable
00539 //JCP 21 - 11 - 08
00540 }
00541 
00542 void wxContourMainFrame::onDeleteContoursActSlice(){
00543         //JCP 20-10-08 Undo redo implementation
00544         saveState();
00545         //JCP 20-10-08 Undo redo implementation
00546         deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
00547 }
00548 void wxContourMainFrame::onDeleteAllContours(){
00549         //JCP 20-10-08 Undo redo implementation
00550         saveState();
00551         deleteAllContours();
00552 }
00553 void wxContourMainFrame::deleteAllContours(){
00554         //JCP 20-10-08 Undo redo implementation
00555 
00556         wxBusyCursor wait;
00557         std::vector<int> tempVector;
00558         _instantPanel->getInstant( tempVector );
00559 
00560 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
00561 //              the values in GetStart and GetEnd will then not be initialize also.
00562 //              We use instead the values given when initializing the _deletepanel.
00563 
00564         //int minZ = _mbarrangeDeleteAll->GetStart();
00565         //int maxZ = _mbarrangeDeleteAll->GetEnd();
00566         int minZ, maxZ;
00567 
00568         minZ = 0;
00569         maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
00570 
00571 //JCP --08-09-2008
00572 
00573         _theViewPanel->getSceneManager()->removeSceneContours( );
00574         _theViewPanel->getSceneManager()->removeAllOutlines();
00575         kernelManager->removeAllOutlines();
00576 //JCP --08-09-2008
00577         /*
00578         if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
00579         {
00580                 _theViewPanel->getSceneManager()->removeSceneContours( );
00581                 _modelManager->removeAllOutlines();
00582                 _theViewPanel->getSceneManager()->removeAllOutlines();
00583 
00584         } else {
00585                 for ( z=minZ ; z<=maxZ ; z++)
00586                 {
00587                         tempVector[1]=z;
00588                         Instant instant(&tempVector);
00589                         std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
00590 
00591                         sizeLstContourThings = lstContourThings.size();
00592                         for (ii=0 ; ii<sizeLstContourThings ; ii++)
00593                         {
00594                                 ContourThing **contourthing = lstContourThings[ii];
00595                                 deleteContour( (*contourthing)->getName() );
00596                         } //for ii
00597                 }// for z
00598         } // if
00599 JCP --08-09-2008 */
00600 }
00601 
00602 void wxContourMainFrame::setConceptValue( std::string name, int value ){
00603         _instantPanel->setConceptValue(name, value);
00604 }
00605 
00606 
00607 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
00608         return _instantPanel->getLastConceptData();
00609 }
00610 
00611 
00612 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
00613         return _instantPanel->getIfConceptCheckedAt( name, pos );
00614 }
00615 
00616 
00617 
00618 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
00619 {
00620         vtkImageData * mask;
00621         vtkImageData * value;
00622         this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
00623 
00624         std::vector<int> nTypeView;
00625         nTypeView.push_back(5);
00626         nTypeView.push_back(1);
00627         nTypeView.push_back(2);
00628         nTypeView.push_back(0);
00629 
00630         wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
00631         wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
00632         m_mgr_noteBookViewerResult->SetManagedWindow(frame);
00633 
00634         wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
00635         m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
00636 
00637         wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
00638         wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
00639 
00640 
00641         noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
00642         noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
00643         m_mgr_noteBookViewerResult->Update();
00644         frame->Show();
00645 }
00646 
00647 
00648 
00649 
00650 void wxContourMainFrame::changeInstant()
00651 {
00652                 std::vector<int> instantVect;
00653                 _instantPanel->getInstant( instantVect );
00654                 int actualSlice = instantVect[1];
00655 
00656                 kernelManager->setInstant(instantVect);
00657 
00658             // Refresh Mask image
00659                 if(_viewMaskImage!=NULL){
00660                         _viewMaskImage->SetZ(actualSlice);
00661                         if (_viewMaskImagePanel->IsVisible()==true)
00662                         {
00663                                 vtkImageData *mask, *value;
00664                                 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
00665                                 _viewMaskImage->onThreshold();
00666                         }
00667                 }
00668 
00669         // Refresh Threshold image
00670                 if(_viewThresholdImage!=NULL){
00671                         _viewThresholdImage->SetZ(actualSlice);
00672                         if (_viewThresholdImagePanel->IsVisible()==true){
00673                                 _viewThresholdImage->onThreshold();
00674                         }
00675                 }
00676 
00677         // Refresh Threshold image
00678                 if(_viewColorLayerImage!=NULL){
00679                         _viewColorLayerImage->SetZ(actualSlice);
00680                         if (_viewColorLayerImagePanel->IsVisible()==true){
00681                                 _viewColorLayerImage->onThreshold();
00682                         }
00683                 }
00684 
00685                 updateInstantOutlines();
00686                 updateInstantImageData();
00687                 updateInstantAxes();
00688 }
00689 
00690 
00691 
00692 void wxContourMainFrame :: updateInstantOutlines()
00693 {
00694         _theViewPanel->removeSceneContours();
00695         _theViewPanel->addNameWrapperToScene();
00696 
00697         //for( int i=0; i<size; i++)
00698         //{
00699         //      _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
00700         //}
00701 }
00702 
00703 int wxContourMainFrame::getNamesWrappingSize(){
00704         return kernelManager->getNamesWrappingSize();
00705 }
00706 std::string wxContourMainFrame::getNameWrapping(int i){
00707         return kernelManager->getNameWrapping(i);
00708 }
00709 
00710 void wxContourMainFrame::updateInstantImageData()
00711 {
00712         std::vector<int> inst;
00713         _instantPanel->getInstant(inst);
00714 
00715         vtkImageData* img = kernelManager->getImageAtInstant(inst);
00716         if(img!=NULL){
00717                 _theViewPanel->changeImage(img);
00718                 showAxis(false);
00719         }else{
00720                 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
00721                 _theViewPanel->setImageSlice(z);
00722         }
00723 }
00724 
00725 void wxContourMainFrame::updateInstantAxes()
00726 {
00727 }
00728 
00729 
00730 void wxContourMainFrame::onChangeDeep(int val){
00731         _instantPanel->setConceptValue( "Axe Depth", (int)val );
00732         changeInstant();
00733 }
00734 
00735 
00736 void wxContourMainFrame::onCopy(){
00737         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
00738 
00739         std::vector<int> tempVector;
00740         _instantPanel->getInstant( tempVector );
00741     _performingOperation->reset();
00742         _performingOperation->setStartCommand( COPY );
00743         _performingOperation->setStartOperationInstantVector( tempVector );
00744         _performingOperation->setKeyNamesOperationElems( currentSelection );
00745 }
00746 
00747 void wxContourMainFrame::onPaste(){
00748 
00749 
00750         char theStartCommand = _performingOperation->getStartCommand();
00751         if (  theStartCommand == COPY )
00752         {
00753                 //JCP 20-10-08 Undo redo implementation
00754                 saveState();
00755                 //JCP 20-10-08 Undo redo implementation
00756                 std::vector<int> tempVector;
00757                 _instantPanel->getInstant( tempVector );
00758                 _performingOperation->setEndOperationInstantVector ( tempVector );
00759                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
00760                 int i,size = elems.size();
00761                 for( i=0; i<size; i++ )
00762                 {
00763                         createCopyContourOf( elems[i], tempVector, i>0 );
00764                 }
00765         }
00766 }
00767 void wxContourMainFrame::onUndo(){
00768         std::string filename;
00769         if(kernelManager->onUndoSaveFile(filename)){
00770                 saveFileWithContours(filename);
00771         }
00772         if(kernelManager->onUndo(filename)){
00773                 loadState(filename);
00774         }
00775 }
00776 void wxContourMainFrame::onRedo(){
00777         std::string filename;
00778         if(kernelManager->onRedo(filename)){
00779                 loadState(filename);
00780         }
00781 
00782 }
00783 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
00784 {
00785         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
00786         manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
00787         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
00788 }
00789 
00791 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
00792 {
00793         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
00794         manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
00795 
00796         manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
00797         manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
00798 
00799         double pnt1X = refPoint1->GetX();
00800         double pnt1Y = refPoint1->GetY();
00801 //      double pnt1Z = refPoint1->GetZ();
00802         double pnt2X = refPoint2->GetX();
00803         double pnt2Y = refPoint2->GetY();
00804 //      double pnt2Z = refPoint2->GetZ();
00805 
00806         double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
00807         vtkTransform *t = vtkTransform::New();
00808 
00809         t->PostMultiply();
00810         t->Identity();
00811         t->Translate(-pnt1X, -pnt1Y, 0);
00812         t->RotateZ(-angle);
00813         t->Scale(-1,1,1);
00814         t->RotateZ(angle);
00815         t->Translate(pnt1X, pnt1Y, 0);
00816         t->Update();
00817 
00818         int i,size=manualModel->GetSizeLstPoints();
00819         for (i=0;i<size;i++)
00820         {
00821                 manualPoint * mp = manualModel->GetManualPoint(i);
00822                 float vecIn[3];
00823                 float vecOut[3];
00824                 vecIn[0]=mp->GetX();
00825                 vecIn[1]=mp->GetY();
00826                 vecIn[2]=mp->GetZ();
00827                 t->TransformPoint( vecIn, vecOut );
00828                 mp->SetPointX( vecOut[0] );
00829                 mp->SetPointY( vecOut[1] );
00830                 mp->SetPointZ( vecOut[2] );
00831         }
00832 
00833         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
00834 }
00835 
00836 //EED04
00837 void wxContourMainFrame ::loadState(std::string filename){
00838 
00839         deleteAllContours();
00840         onLoadContours(filename,false);
00841 
00842         /* EED Borrame
00843         char tmp[255];
00844         FILE *pFile=fopen(filename.c_str(),"r+");
00845 
00846         fscanf(pFile,"%s",tmp); // --CreaContour--
00847 
00848         fscanf(pFile,"%s",tmp); // Version
00849         fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
00850 
00851         deleteAllContours();
00852 
00853         loadContours(pFile, false);
00854         loadContours(pFile, true);
00855 
00856         fclose(pFile);
00857         */
00858 }
00859 
00860 
00861 //EED03
00862 /*EED Borrame
00863 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
00864 {
00865         char tmp[255];
00866 
00867         if (staticContour==false)
00868         {
00869                 fscanf(pFile,"%s",tmp); // ImageDimensions
00870                 fscanf(pFile,"%s",tmp); // X
00871                 fscanf(pFile,"%s",tmp); // Y
00872                 fscanf(pFile,"%s",tmp); // Z
00873 
00874                 fscanf(pFile,"%s",tmp); // ImageSpacing
00875                 fscanf(pFile,"%s",tmp); // X
00876                 fscanf(pFile,"%s",tmp); // Y
00877                 fscanf(pFile,"%s",tmp); // Z
00878         }
00879 
00880         fscanf(pFile,"%s",tmp); // NumberOfContours
00881         fscanf(pFile,"%s",tmp); // ##
00882         int numberOfContours = atoi(tmp);
00883 
00884         std::vector<int> instantVector;
00885         int typeContourModel;
00886         manualBaseModel *manModelContour;
00887         int typeView;
00888 
00889         int i;
00890         for (i=0;i<numberOfContours;i++)
00891         {
00892                 instantVector.clear();
00893                 fscanf(pFile,"%s",tmp); // Instant
00894                 fscanf(pFile,"%s",tmp); // 1
00895                 instantVector.push_back( atoi(tmp) );
00896                 fscanf(pFile,"%s",tmp); // 2
00897                 instantVector.push_back( atoi(tmp) );
00898                 fscanf(pFile,"%s",tmp); // 3
00899                 instantVector.push_back( atoi(tmp) );
00900                 fscanf(pFile,"%s",tmp); // 4
00901                 instantVector.push_back( atoi(tmp) );
00902                 fscanf(pFile,"%s",tmp); // 5
00903                 instantVector.push_back( atoi(tmp) );
00904                 fscanf(pFile,"%s",tmp); // 6
00905                 instantVector.push_back( atoi(tmp) );
00906 
00907                 fscanf(pFile,"%s",tmp); // TypeContourModel
00908                 fscanf(pFile,"%s",tmp); // ##
00909                 typeContourModel = atoi(tmp);
00910 
00911                 manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
00912                 manModelContour->Open(pFile);
00913 
00914                 fscanf(pFile,"%s",tmp); // TypeView
00915                 fscanf(pFile,"%s",tmp); // ##
00916                 typeView = atoi(tmp);
00917 
00918                 std::string theName;
00919                 theName = kernelManager->createOutline( manModelContour, instantVector );
00920                 bool addedModel = theName.compare("") != 0;
00921                 if( addedModel )
00922                 {
00923                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
00924                         _theViewPanel->getSpacing(spc);
00925                         //Adding the manualContourControler to interface objects structure
00926                         //Adding the manualViewContour to interface objects structure
00927                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
00928                         _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
00929                 }
00930 
00931                 if (staticContour==true)
00932                 {
00933                         Instant instant(&instantVector);
00934                         kernelManager->changeContourOfManager( theName , &instant );
00935                 }
00936         }// for  numberOfContours
00937 }
00938 */
00939 
00940 
00941 void wxContourMainFrame::onLoad()
00942 {
00943         std::string fileNameContourROI = GetFileLocation();
00944 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
00945         if(GetFileLocation().empty())
00946         {
00947 //------------------------------------------------------------------------------------------------------------
00948                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
00949                 if (dialog.ShowModal() == wxID_OK)
00950                 {
00951                         fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
00952                 }
00953         }
00954 
00955         onLoadContours(fileNameContourROI,true);
00956 }
00957 
00958 
00959 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
00960 {
00961         char tmp[255];
00962         char tmpD[255];
00963 
00964         FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
00965 
00966 
00967 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
00968         if(pFile != NULL)
00969         {
00970 //------------------------------------------------------------------------------------------------------------
00971         fileNameContourROI.append("data");
00972                 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
00973                 if(pFileData != NULL)
00974                 {
00975                         fscanf(pFileData,"%s",tmpD); // --CreaContour--
00976                         fscanf(pFileData,"%s",tmpD); // Version
00977                         fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
00978 
00979                         fscanf(pFileData,"%s",tmpD); // onePixelSize
00980                         fscanf(pFileData,"%s",tmpD); // #
00981                         _onePixelSize = atof(tmpD);
00982                         fscanf(pFileData,"%s",tmpD); // NumberOfContours
00983                         fscanf(pFileData,"%s",tmpD); // #
00984                 }
00985 
00986                 fscanf(pFile,"%s",tmp); // --CreaContour--
00987 
00988                 fscanf(pFile,"%s",tmp); // Version
00989                 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
00990                 std::string version(tmp);
00991 
00992                 //AD:02-06-09
00993         _tmpReadFileTypeOfTransformation=-1;
00994                 if (version=="1.0.3")
00995                 {
00996                     readDimSpc(pFile,interactiveInterface);   // DimSpc interactive ON
00997                         openContours(pFile,pFileData,false);
00998                         openContours(pFile,pFileData,true);     //Load StaticContours
00999                 }
01000 
01001                 if (version=="1.0.2")
01002                 {
01003 //EED001
01004                     readDimSpc(pFile,interactiveInterface);  // DimSpc interactive ON
01005                         openContours(pFile,pFileData,false);
01006                     readDimSpc(pFile,false);  // DimSpc interactive OFF
01007                         openContours(pFile,pFileData,true);     //Load StaticContours
01008                 }
01009 
01010                 //AD:02-06-09
01011                 else if (version=="1.0.1")
01012                 {
01013                         openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
01014                         openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
01015                 }
01016 
01017                 //AD:02-06-09
01018                 else if (version=="1.0.0")
01019                 {
01020                         openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
01021                 }
01022 
01023                 fclose(pFile);
01024 
01025                 if(pFileData != NULL)
01026                 {
01027                         fclose(pFileData);
01028                 }
01029         }
01030         _theViewPanel->getSceneManager()->removeSceneContours();
01031         changeInstant();
01032 
01033 }
01034 
01035 
01036 
01037 void wxContourMainFrame::onImport(){
01038         std::string filename, filenamecontours;
01039         wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
01040 
01041         if (dialog.ShowModal() == wxID_OK)
01042         {
01043                 filename = dialog.GetPath().mb_str();
01044                 filenamecontours = kernelManager->parseOsirixFile(filename);
01045 
01046                 if(filenamecontours.compare("") != 0){
01047                         onLoadContours(filenamecontours,true);
01048                 }
01049 
01050         }
01051 }
01052 void wxContourMainFrame::onTest(){
01053         std::string filename, filenamecontours;
01054         wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
01055 
01056         if (dialog.ShowModal() == wxID_OK)
01057         {
01058                 filename = dialog.GetPath().mb_str();
01059                 std::cout << "This is the filename: " << filename << std::endl;
01060         }
01061 }
01062 
01063 
01064 //AD: 29-05-09
01065 void wxContourMainFrame::onSave(){
01066 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01067         if(GetFileLocation().empty())
01068         {
01069 //------------------------------------------------------------------------------------------------------------
01070                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
01071                 if (dialog.ShowModal() == wxID_OK)
01072                 {
01073                         std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
01074                         kernelManager->setCurrentFileName(fileNameContourROI);
01075                         saveFileWithContours( fileNameContourROI );
01076                 }
01077         }
01078 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01079         else
01080         {
01081                 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
01082                 std::string fileNameContourROI = GetFileLocation();
01083                 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
01084                 kernelManager->setCurrentFileName(fileNameContourROI);
01085                 saveFileWithContours( fileNameContourROI);
01086         }
01087 //------------------------------------------------------------------------------------------------------------
01088 }
01089 
01090 //AD: 29-05-09
01091 void wxContourMainFrame::saveFileWithContours( std::string filename )
01092 {
01093 
01094         FILE *pFile=fopen(filename.c_str(),"w+");
01095 
01096 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01097         filename.append("data");
01098         std::cout<<"Nombre del archivo: "<<filename<<std::endl;
01099         FILE *pFileData=fopen(filename.c_str(),"w+");
01100 //------------------------------------------------------------------------------------------------------------
01101 
01102         std::vector< std::string > lstNameThings;
01103         int i,sizeLstNameThings;
01104 
01105         fprintf(pFile,"--CreaContour--\n");
01106         fprintf(pFile,"Version %s\n", "1.0.3" );
01107 
01108 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01109         fprintf(pFileData,"--CreaContour--\n");
01110         fprintf(pFileData,"Version %s\n", "1.0.3" );
01111         fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
01112 
01113 //------------------------------------------------------------------------------------------------------------
01114 
01115         vtkImageData *image = _images[0];
01116 
01117         int dimRange[3];
01118         image->GetDimensions(dimRange);
01119 
01120         fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
01121 
01122         double spaRange[3];
01123         image->GetSpacing(spaRange);
01124 
01125         fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
01126 
01127         // Normal Contours
01128 
01129         lstNameThings           = kernelManager->GetLstNameThings();
01130         sizeLstNameThings       = lstNameThings.size();
01131         fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
01132 
01133 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01134         fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
01135 //------------------------------------------------------------------------------------------------------------
01136 
01137         for (i=0 ; i<sizeLstNameThings ; i++)
01138         {
01139 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01140                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
01141                 double sizeInPixel = manualModel ->GetPathSize();
01142                 double realContourSize = sizeInPixel*_onePixelSize;
01143                 manualModel ->SetRealSize(realContourSize);
01144 //------------------------------------------------------------------------------------------------------------
01145 
01146         //int size= kernelManager->GetLstNameThings().size();
01147 
01148                 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
01149                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
01150         }// for i
01151 
01152         //-- Static Contours
01153 
01154 //      fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
01155 //      fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
01156 
01157         lstNameThings           = kernelManager->GetLstNameThingsStatic();
01158         sizeLstNameThings       = lstNameThings.size();
01159         fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
01160 
01161 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
01162         fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
01163 //------------------------------------------------------------------------------------------------------------
01164 
01165         for (i=0 ; i<sizeLstNameThings ; i++)
01166         {
01167                 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
01168                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
01169         }// for i
01170         fclose(pFile);
01171         fclose(pFileData);
01172 }
01173 
01174 
01175 //EED02
01176 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
01177 {
01178         char tmp[255];
01179         int             imageDim[3];
01180         double          imageSpac[3];
01181         vtkImageData    *image          = _images[0];
01182     image->GetDimensions(imageDim);
01183     image->GetSpacing(imageSpac);
01184 
01185     fscanf(pFile,"%s",tmp); // ImageDimensions
01186     fscanf(pFile,"%s",tmp); // X
01187     _tmpReadFileImageDim[0] = atoi(tmp);
01188     fscanf(pFile,"%s",tmp); // Y
01189     _tmpReadFileImageDim[1] = atoi(tmp);
01190     fscanf(pFile,"%s",tmp); // Z
01191     _tmpReadFileImageDim[2] = atoi(tmp);
01192 
01193     fscanf(pFile,"%s",tmp); // ImageSpacing
01194     fscanf(pFile,"%s",tmp); // X
01195     _tmpReadFileImageSpac[0] = atof(tmp);
01196     fscanf(pFile,"%s",tmp); // Y
01197     _tmpReadFileImageSpac[1] = atof(tmp);
01198     fscanf(pFile,"%s",tmp); // Z
01199     _tmpReadFileImageSpac[2] = atof(tmp);
01200 
01201 
01202         if (interactiveOption==true)
01203     {
01204                 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
01205                 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
01206                 {
01207                         wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
01208                         wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
01209                         wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
01210 
01211                         wxString lstOptOperation[2];
01212                         lstOptOperation[0]=_T("By Dimension");
01213                         lstOptOperation[1]=_T("By Spacing");
01214                         wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation,  2, wxRA_SPECIFY_COLS);
01215 
01216                         dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the "))  , 0, wxGROW );
01217                         dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?"))  , 0, wxGROW );
01218                         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
01219                         dialSizer->Add(radioOpts,0,wxGROW);
01220                         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
01221                         dialSizer->Add(buttonsSizer,0,wxGROW);
01222                         dial->SetSizer(dialSizer, true);
01223                         dial->Layout();
01224                         dial->ShowModal();
01225 
01226                         int _tmpReadFileTypeOfTransformation = -1;
01227 //EED                   bool transform = false;
01228 
01229                         if (dial->GetReturnCode() == wxID_OK)
01230                         {
01231                                 _tmpReadFileTypeOfTransformation    = radioOpts->GetSelection();
01232                         }// if wxOK
01233 
01234                 } // if dim spc
01235     } // if interactiveOption
01236 }
01237 
01238 
01239 
01240 
01241 //AD:04-06-09
01242 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
01243 {
01244 
01245         char tmp[255];
01246 
01247         vtkImageData    *image = _images[0];
01248 
01249         int             imageDim[3];
01250         double          imageSpac[3];
01251     image->GetDimensions(imageDim);
01252     image->GetSpacing(imageSpac);
01253 
01254 
01255         fscanf(pFile,"%s",tmp); // NumberOfContours
01256         fscanf(pFile,"%s",tmp); // ##
01257         int numberOfContours = atoi(tmp);
01258 
01259         std::vector<int> instantVector;
01260         int typeContourModel;
01261         manualBaseModel *manModelContour;
01262         int typeView;
01263 
01264 /*
01265         if (compatible==true)
01266         {
01267                 int i;
01268                 for (i=0;i<numberOfContours;i++)
01269                 {
01270                         instantVector.clear();
01271                         fscanf(pFile,"%s",tmp); // Instant
01272 
01273                         fscanf(pFile,"%s",tmp); // 1
01274                         instantVector.push_back( atoi(tmp) );
01275                         fscanf(pFile,"%s",tmp); // 2
01276                         instantVector.push_back( atoi(tmp) );
01277                         fscanf(pFile,"%s",tmp); // 3
01278                         instantVector.push_back( atoi(tmp) );
01279                         fscanf(pFile,"%s",tmp); // 4
01280                         instantVector.push_back( atoi(tmp) );
01281                         fscanf(pFile,"%s",tmp); // 5
01282                         instantVector.push_back( atoi(tmp) );
01283                         fscanf(pFile,"%s",tmp); // 6
01284                         instantVector.push_back( atoi(tmp) );
01285 
01286 
01287                         fscanf(pFile,"%s",tmp); // TypeContourModel
01288                         fscanf(pFile,"%s",tmp); // ##
01289                         typeContourModel = atoi(tmp);
01290 
01291                         manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
01292                         manModelContour->Open(pFile);
01293                         if(pFileData != NULL)
01294                         {
01295                                 manModelContour->OpenData(pFileData);
01296                         }
01297 
01298                         fscanf(pFile,"%s",tmp); // TypeView
01299                         fscanf(pFile,"%s",tmp); // ##
01300                         typeView = atoi(tmp);
01301 
01302                         std::string theName;
01303                         theName = kernelManager->createOutline( manModelContour, instantVector );
01304                         bool addedModel = theName.compare("") != 0;
01305                         if( addedModel )
01306                         {
01307                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
01308                                 _theViewPanel->getSpacing(spc);
01309                                 //Adding the manualContourControler to interface objects structure
01310                                 //Adding the manualViewContour to interface objects structure
01311                                 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
01312                                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
01313                         }
01314 
01315                         if (staticContour) //StaticContours (will appear in all slices)
01316                         {
01317                                 Instant instant(&instantVector);
01318                                 kernelManager->changeContourOfManager( theName , &instant );
01319                         }
01320 
01321                 }// for  numberOfContours
01322         }
01323 
01324         else if (compatible==false)
01325         {
01326 */
01327 
01328                 int i;
01329                 for (i=0;i<numberOfContours;i++)
01330                 {
01331                         instantVector.clear();
01332                         fscanf(pFile,"%s",tmp); // Instant
01333 
01334                         fscanf(pFile,"%s",tmp); // 1
01335                         instantVector.push_back( atoi(tmp) );
01336                         fscanf(pFile,"%s",tmp); // 2
01337                         instantVector.push_back( atoi(tmp) );
01338                         fscanf(pFile,"%s",tmp); // 3
01339                         instantVector.push_back( atoi(tmp) );
01340                         fscanf(pFile,"%s",tmp); // 4
01341                         instantVector.push_back( atoi(tmp) );
01342                         fscanf(pFile,"%s",tmp); // 5
01343                         instantVector.push_back( atoi(tmp) );
01344                         fscanf(pFile,"%s",tmp); // 6
01345                         instantVector.push_back( atoi(tmp) );
01346 
01347                         fscanf(pFile,"%s",tmp); // TypeContourModel
01348                         fscanf(pFile,"%s",tmp); // ##
01349                         typeContourModel = atoi(tmp);
01350 
01351                         manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
01352                         manModelContour->Open(pFile);
01353                         if(pFileData != NULL)
01354                         {
01355                                 manModelContour->OpenData(pFileData);
01356                         }
01357 
01358             if (_tmpReadFileTypeOfTransformation==-1){
01359                 //nothing to do..
01360             } else if (_tmpReadFileTypeOfTransformation==0){
01361                 double transX, transY;
01362                 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
01363                 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
01364                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
01365             } else if (_tmpReadFileTypeOfTransformation==1) {
01366                 double transX, transY;
01367                 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
01368                 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
01369                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
01370             }
01371 
01372                         fscanf(pFile,"%s",tmp); // TypeView
01373                         fscanf(pFile,"%s",tmp); // ##
01374                         typeView = atoi(tmp);
01375 
01376                         std::string theName;
01377                         theName = kernelManager->createOutline( manModelContour, instantVector );
01378                         bool addedModel = theName.compare("") != 0;
01379                         if( addedModel )
01380                         {
01381                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
01382                                 _theViewPanel->getSpacing(spc);
01383                                 //Adding the manualContourControler to interface objects structure
01384                                 //Adding the manualViewContour to interface objects structure
01385                                 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
01386                                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
01387                         }
01388 
01389                         if (staticContour) //StaticContours (will appear in all slices)
01390                         {
01391                                 Instant instant(&instantVector);
01392                                 kernelManager->changeContourOfManager( theName , &instant );
01393                         }
01394                 }// for  numberOfContours
01395 
01396 /*      }    */
01397 
01398 }
01399 
01400 void wxContourMainFrame::RefreshInterface(){
01401         changeInstant();
01402         _theViewPanel->RefreshInterface();
01403         //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
01404         //wxvtk2dbaseview->Refresh();
01405 }
01406 
01407 vtkImageData* wxContourMainFrame::getImageData(){
01408         return _theViewPanel->getImageData();
01409 }
01410 
01411 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
01412 {
01413         //JCP 20-10-08 Undo redo implementation
01414         saveState();
01415         //JCP 20-10-08 Undo redo implementation
01416 
01417         wxBusyCursor wait;
01418         int                                     x                                       = _theViewPanel->GetX();
01419         int                                     y                                       = _theViewPanel->GetY();
01420         int                                     z                                       = _theViewPanel->GetZ();
01421         SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
01422         RefreshInterface();
01423 }
01424 
01425 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
01426 {
01427         int typeofcontour = 1;
01428         //Image Data
01429         vtkImageData    *imagedata      = getImageData();
01430 
01431         //Tipo de pixeles a utilizar internamente en ITK
01432         typedef   float  InternalPixelType;
01433         const     unsigned int    Dimension = 2;
01434         typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
01435 
01436         //Tipo de pixeles de salida 1
01437         typedef unsigned char OutputPixelType;
01438         typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
01439 
01440         //Tipo de pixeles de salida 2
01441         typedef unsigned short OutputPixelType2;
01442         typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
01443 
01444         //DefiniciÛn del thresholder
01445         typedef itk::BinaryThresholdImageFilter<
01446                                                         InternalImageType,
01447                                                         OutputImageType    >    ThresholdingFilterType;
01448 
01449         //DefiniciÛn del primer filtro de conversiÛn de pixeles
01450         typedef itk::CastImageFilter<
01451                                 OutputImageType, OutputImageType2 >  CastFilterType;
01452 
01453         //DefiniciÛn del segundo tipo de conversiÛn de pixeles
01454         typedef itk::CastImageFilter<
01455                                 OutputImageType2, InternalImageType >  CastFilterType2;
01456 
01457         //Tercer tipo de conversiÛn
01458         typedef itk::RescaleIntensityImageFilter<
01459                                                                 InternalImageType,
01460                                                                 OutputImageType >   CastFilterType3;
01461 
01462         //Cuarto tipo de conversiÛn
01463         typedef itk::RescaleIntensityImageFilter<
01464                                                                 OutputImageType,
01465                                                                 OutputImageType >   CastFilterType4;
01466 
01467         ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
01468 
01469         thresholder->SetLowerThreshold( 0.0 );
01470         thresholder->SetUpperThreshold( 128 );
01471 
01472         thresholder->SetOutsideValue(  255  );
01473         thresholder->SetInsideValue(  0 );
01474 
01475         //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
01476         typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
01477         typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
01478 //EED10JUIN2011 typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
01479 
01480         ConnectorType::Pointer connector= ConnectorType::New();
01481         ConnectorType2::Pointer connector2= ConnectorType2::New();
01482 
01483 
01484         CastFilterType::Pointer filter=CastFilterType::New();
01485         CastFilterType2::Pointer filter2=CastFilterType2::New();
01486 
01487         connector->SetInput( imagedata );
01488         filter2->SetInput(connector->GetOutput());
01489 
01490         typedef   itk::CurvatureAnisotropicDiffusionImageFilter<
01491                                                                 InternalImageType,
01492                                                                 InternalImageType >  SmoothingFilterType;
01493 
01494         SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
01495 
01496         typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
01497                                                                 InternalImageType,
01498                                                                 InternalImageType >  GradientFilterType;
01499 
01500         typedef   itk::SigmoidImageFilter<
01501                                                                 InternalImageType,
01502                                                                 InternalImageType >  SigmoidFilterType;
01503 
01504         GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
01505 
01506         SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
01507 
01508         sigmoid->SetOutputMinimum(  0.0  );
01509         sigmoid->SetOutputMaximum(  255.0  );
01510 
01511 
01512         typedef  itk::FastMarchingImageFilter<
01513                                                                 InternalImageType,
01514                                                                 InternalImageType >    FastMarchingFilterType;
01515 
01516 
01517         FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();
01518 
01519         typedef  itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
01520                                         InternalImageType >    GeodesicActiveContourFilterType;
01521         GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
01522                                                                                 GeodesicActiveContourFilterType::New();
01523 
01524         typedef  itk::ZeroCrossingImageFilter<
01525                                                                 InternalImageType,
01526                                                                 InternalImageType >    ZeroCrossingFilterType;
01527         ZeroCrossingFilterType::Pointer zeroCrossing =
01528                                                         ZeroCrossingFilterType::New();
01529 
01530         const double propagationScaling = atof( crea::wx2std(prop).c_str() );
01531 
01532         geodesicActiveContour->SetPropagationScaling( propagationScaling );
01533         geodesicActiveContour->SetCurvatureScaling( 1.0 );
01534         geodesicActiveContour->SetAdvectionScaling( 1.0 );
01535 
01536         geodesicActiveContour->SetMaximumRMSError( 0.02 );
01537         int it=atoi(  crea::wx2std(iter).c_str() );
01538         geodesicActiveContour->SetNumberOfIterations( it );
01539 
01540         smoothing->SetInput( filter2->GetOutput() );
01541         gradientMagnitude->SetInput( smoothing->GetOutput() );
01542         sigmoid->SetInput( gradientMagnitude->GetOutput() );
01543         fastMarching->SetInput( sigmoid->GetOutput() );
01544         geodesicActiveContour->SetInput( fastMarching->GetOutput() );
01545         geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
01546 
01547         zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
01548         //thresholder->SetInput( zeroCrossing->GetOutput() );
01549         thresholder->SetInput( geodesicActiveContour->GetOutput() );
01550         connector2->SetInput( thresholder->GetOutput()  );
01551 
01552 
01553         smoothing->SetTimeStep( 0.125 );
01554         smoothing->SetNumberOfIterations(  5 );
01555         smoothing->SetConductanceParameter( 9.0 );
01556 
01557 
01558         const double sigma = atof(  crea::wx2std(sigm).c_str() );
01559         gradientMagnitude->SetSigma(  sigma  );
01560 
01561         const double alpha =  atof(  crea::wx2std(alf).c_str() );
01562         const double beta  =  atof(  crea::wx2std(bet).c_str() );
01563 
01564         sigmoid->SetAlpha( alpha );
01565         sigmoid->SetBeta(  beta  );
01566 
01567         typedef FastMarchingFilterType::NodeContainer  NodeContainer;
01568         typedef FastMarchingFilterType::NodeType       NodeType;
01569 
01570         NodeContainer::Pointer seeds = NodeContainer::New();
01571 
01572         InternalImageType::IndexType  seedPosition;
01573         seedPosition[0] = x;
01574         seedPosition[1] = y;
01575 
01576         const double initialDistance = atof( crea::wx2std(distanc).c_str() );
01577 
01578         NodeType node;
01579 
01580         const double seedValue = - initialDistance;
01581 
01582         node.SetValue( seedValue );
01583         node.SetIndex( seedPosition );
01584 
01585         seeds->Initialize();
01586         seeds->InsertElement( 0, node );
01587 
01588         fastMarching->SetTrialPoints( seeds );
01589 
01590         fastMarching->SetSpeedConstant( 1.0 );
01591 
01592         fastMarching->SetOutputSize(
01593                         connector->GetOutput()->GetBufferedRegion().GetSize() );
01594 
01595         fastMarching->SetStoppingValue( 800 );
01596         try
01597     {
01598 
01599         connector2->Update();
01600         vtkImageData *idata = connector2->GetOutput();
01601 
01602         vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
01603 
01604         cntVTK->SetInput( idata );
01605 
01606         cntVTK->SetNumberOfContours( 1 );
01607         cntVTK->SetValue( 0, 255 );
01608         cntVTK->Update( );
01609         cntVTK->UpdateInformation();
01610 
01611         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
01612         cpd->SetInput( cntVTK->GetOutput( ) );
01613         cpd->Update( );
01614         cpd->UpdateInformation();
01615 
01616         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
01617         conn->SetExtractionModeToLargestRegion( );
01618         conn->SetInput( cpd->GetOutput( ) );
01619         conn->Update( );
01620         conn->UpdateInformation();
01621 
01622         vtkStripper* vtkstripper = vtkStripper::New( );
01623         vtkstripper->SetInput( conn->GetOutput() );
01624         vtkstripper->Update();
01625         vtkstripper->UpdateInformation();
01626 
01627         vtkPolyData* polyDataResult =  cntVTK->GetOutput();
01628         //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
01629         polyDataResult->Update( );
01630         polyDataResult->UpdateInformation();
01631 
01632         //EED
01633                 /*
01634         ofstream myfile;
01635         myfile.open ("C:/Creatis/example.txt");
01636         myfile << "\n";
01637         polyDataResult->Print(myfile);
01638         myfile << "-------------------------------------\n";
01639         polyDataResult->GetLines()->Print(myfile);
01640         myfile.close();*/
01641 
01642         cntVTK          -> Delete();
01643         cpd                     -> Delete();
01644         conn            -> Delete();
01645 
01646 
01647         //--Calculating control points
01648 
01649         std::vector<double> vecX;
01650         std::vector<double> vecY;
01651         std::vector<double> vecXo;
01652         std::vector<double> vecYo;
01653         std::vector<double>::iterator vecXoi;
01654         std::vector<double>::iterator vecYoi;
01655         std::vector<double> vecZ;
01656 
01657         std::vector<double> vecCtrlPointX;
01658         std::vector<double> vecCtrlPointY;
01659         std::vector<double> vecCtrlPointZ;
01660 
01661 
01662         double *p;
01663         double xAct=0;
01664         double yAct=0;
01665         int ii,size=polyDataResult->GetNumberOfPoints();
01666         ofstream myfile;
01667         myfile.open ("C:/Creatis/example2.txt");
01668 
01669         size=polyDataResult->GetNumberOfPoints();
01670         for (ii=0;ii<size;ii++)
01671         {
01672                 if(ii==0)
01673                 {
01674                         xAct=x;
01675                         yAct=y;
01676                 }
01677                 p       = polyDataResult->GetPoint(ii);
01678                 double x=p[0];
01679                 double y=p[1];
01680                 /*if(fabs(yAct-y)>20)
01681                 {
01682                         if((xAct-x)>1 || (xAct-x)<-1)
01683                         {
01684                         vecX.push_back( p[0] );
01685                         vecY.push_back( p[1] );
01686                         myfile <<p[0]<<","<<p[1]<<"\n";
01687                         std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
01688                 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
01689                 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
01690                         vecZ.push_back( 900 );
01691                         xAct=x;
01692                         yAct=y;
01693                         }
01694                         else
01695                         {
01696                                 vecXo.push_back(p[0]);
01697                                 vecYo.push_back(p[1]);
01698                         }
01699 
01700                 }
01701                 else*/ if(fabs(xAct-x)>11)
01702                 {
01703                         vecXo.push_back(p[0]);
01704                         vecYo.push_back(p[1]);
01705                 }
01706                 else
01707                 {
01708                 vecX.push_back( p[0] );
01709                 myfile <<p[0]<<","<<p[1]<<"\n";
01710                 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
01711                 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
01712                 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
01713                 vecY.push_back( p[1] );
01714                 vecZ.push_back( 900 );
01715                 xAct=x;
01716                 yAct=y;
01717                 }
01718 
01719 
01720         }
01721 
01722         while(!vecXo.empty())
01723         {
01724                 vecX.push_back(vecXo.back());
01725                 //std::cout<<" x Siguiente "<<vecXo.back();
01726                 vecXo.pop_back();
01727                 vecZ.push_back( 900 );
01728         }
01729         while(!vecYo.empty())
01730         {
01731                 vecY.push_back(vecYo.back());
01732                         vecYo.pop_back();
01733         }
01734         myfile.close();
01735 
01736         /*for(int l=0;l<vecX.size();l++)
01737         {
01738                 if(l==0)
01739                 {
01740             vecXo.push_back(p[0]);
01741                         vecYo.push_back(p[1]);
01742                 }
01743                 else
01744                 {
01745                         if(vecXoi[l-1]==)
01746                         {
01747                         }
01748                 }
01749 
01750         }*/
01751 
01752         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
01753 
01754         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
01755 
01756         int method=2;
01757         if (method==0){
01758                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01759         }
01760         else if (method==1){
01761                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01762         }
01763         else if (method==2){
01764                 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
01765                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01766         }
01767         //--Adding contour to the system
01768 
01769         std::vector<int> actualInstantVector;
01770         _instantPanel->getInstant( actualInstantVector );
01771         actualInstantVector[1]=z;
01772 
01773         int j,sizeCtrPt = vecCtrlPointX.size();
01774 
01775         manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
01776         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
01777         if (sizeCtrPt>=3){
01778                 for (j=0 ; j<sizeCtrPt ; j++)
01779                 {
01780                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
01781                 } // for
01782                 std::string theName;
01783                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
01784                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
01785                 bool addedModel = theName.compare("") != 0;
01786                 if( addedModel )
01787                 {
01788                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
01789                         _theViewPanel->getSpacing(spc);
01790                         //Adding the manualContourControler to interface objects structure
01791                         //Adding the manualViewContour to interface objects structure
01792                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
01793                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
01794                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
01795                 }       // if addedModel
01796         } // if sizeCtrPt
01797 
01798 
01799 /*
01800 //EED10JUIN2011
01801                  WriterType::Pointer writer = WriterType::New();
01802          CastFilterType3::Pointer caster = CastFilterType3::New();
01803 
01804                  caster->SetInput( gradientMagnitude->GetOutput() );
01805                  writer->SetInput( caster->GetOutput() );
01806                  writer->SetFileName("Gradient Magnitude.png");
01807                  caster->SetOutputMinimum(   0 );
01808                  caster->SetOutputMaximum( 255 );
01809                  writer->Update();
01810 
01811                  CastFilterType3::Pointer caster2 = CastFilterType3::New();
01812                  WriterType::Pointer writer2 = WriterType::New();
01813 
01814                  caster2->SetInput( sigmoid->GetOutput() );
01815                  writer2->SetInput( caster2->GetOutput() );
01816                  writer2->SetFileName("Sigmoid.png");
01817                  caster2->SetOutputMinimum(   0 );
01818                  caster2->SetOutputMaximum( 255 );
01819                  writer2->Update();
01820 
01821                  CastFilterType3::Pointer caster3 = CastFilterType3::New();
01822                  WriterType::Pointer writer3 = WriterType::New();
01823 
01824                  caster3->SetInput( fastMarching->GetOutput() );
01825                  writer3->SetInput( caster3->GetOutput() );
01826                  writer3->SetFileName("FastMarching.bmp");
01827                  caster3->SetOutputMinimum(   0 );
01828                  caster3->SetOutputMaximum( 255 );
01829                  writer3->Update();
01830 
01831                  CastFilterType3::Pointer caster4 = CastFilterType3::New();
01832                  WriterType::Pointer writer4 = WriterType::New();
01833 
01834                  caster4->SetInput( geodesicActiveContour->GetOutput() );
01835                  writer4->SetInput( caster4->GetOutput() );
01836                  writer4->SetFileName("GeodesicActiveContour.png");
01837                  caster4->SetOutputMinimum(   0 );
01838                  caster4->SetOutputMaximum( 255 );
01839                  writer4->Update();
01840 
01841                  CastFilterType3::Pointer caster5 = CastFilterType3::New();
01842                  WriterType::Pointer writer5 = WriterType::New();
01843 
01844                  caster5->SetInput( zeroCrossing->GetOutput() );
01845                  writer5->SetInput( caster5->GetOutput() );
01846                  writer5->SetFileName("ZeroCrossing.bmp");
01847                  caster5->SetOutputMinimum(   0 );
01848                  caster5->SetOutputMaximum( 255 );
01849                  writer5->Update();
01850 */
01851     }
01852   catch( itk::ExceptionObject & excep )
01853     {
01854     std::cerr << "Exception caught !" << std::endl;
01855     std::cerr << excep << std::endl;
01856     }
01857 }
01858 
01859 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
01860 
01861         //JCP 20-10-08 Undo redo implementation
01862         saveState();
01863         //JCP 20-10-08 Undo redo implementation
01864 
01865         wxBusyCursor wait;
01866         int                                     x                                       = _theViewPanel->GetX();
01867         int                                     y                                       = _theViewPanel->GetY();
01868         int                                     z                                       = _theViewPanel->GetZ();
01869         SegmentationOneSlice( x,y,z,isovalue, sampling, method );
01870         RefreshInterface();
01871 }
01872 
01873 
01874 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
01875 {
01876         int typeofcontour = 1;
01877         //--Extracting Contour
01878         //vtkImageData  *imagedata      = _theViewPanel->getSceneManager()->GetImageData();
01879         vtkImageData    *imagedata      = getImageData();
01880 //              double                  *range          = imagedata->GetScalarRange();
01881 //              double                  thr                     = 1;
01882 
01883         vtkImageReslice *imageReslice = vtkImageReslice::New();
01884 //EED
01885 //              double spc[3];
01886 //              imagedata->GetSpacing(spc);
01887 //              x = x*spc[0];
01888 //              y = y*spc[1];
01889 //              z = z*spc[3];
01890 
01891         imageReslice->SetInput( imagedata );
01892         imageReslice->SetInformationInput(imagedata);
01893         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
01894         imageReslice->SetResliceAxesOrigin(0,0,z);
01895         imageReslice->SetOutputDimensionality(2);
01896         imageReslice->SetInterpolationModeToLinear();
01897 
01898         imagedata = imageReslice->GetOutput();
01899         imagedata->Update();
01900         imagedata->UpdateInformation();
01901 
01902         vtkContourFilter* cntVTK = vtkContourFilter::New( );
01903         cntVTK->SetInput( imagedata );
01904 
01905         cntVTK->SetNumberOfContours( 1 );
01906         //cntVTK->SetValue( 0, vmin );
01907 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
01908         cntVTK->SetValue( 1, isovalue );
01909 //      cntVTK->SetValue( 1, vmax );
01910         cntVTK->Update( );
01911         cntVTK->UpdateInformation();
01912 
01913         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
01914         cpd->SetInput( cntVTK->GetOutput( ) );
01915         cpd->ConvertLinesToPointsOff( );
01916         cpd->Update( );
01917         cpd->UpdateInformation();
01918 
01919         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
01920         conn->SetExtractionModeToClosestPointRegion( );
01921         //conn->SetMaxRecursionDepth( 3000 );
01922 
01923         conn->SetInput( cpd->GetOutput( ) );
01924 
01925         conn->SetClosestPoint( x, y, 0 );
01926         conn->Update( );
01927         conn->UpdateInformation();
01928 
01929         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
01930         cpd2->SetInput( conn->GetOutput( ) );
01931         cpd2->Update();
01932         cpd2->UpdateInformation();
01933 
01934         vtkStripper* vtkstripper = vtkStripper::New( );
01935         vtkstripper->SetInput( cpd2->GetOutput() );
01936         vtkstripper->Update();
01937         vtkstripper->UpdateInformation();
01938 
01939 
01940         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
01941 
01942         polyDataResult->Update( );
01943         polyDataResult->UpdateInformation();
01944 
01945 /* EED
01946 ofstream myfile;
01947 myfile.open ("c:/temp/example.txt");
01948 myfile << "\n";
01949 polyDataResult->Print(myfile);
01950 myfile << "-------------------------------------\n";
01951 polyDataResult->GetLines()->Print(myfile);
01952 myfile.close();
01953 */
01954 
01955         cntVTK          -> Delete();
01956         cpd2            -> Delete();
01957         cpd                     -> Delete();
01958         conn            -> Delete();
01959 
01960 
01961 //--Calculating control points
01962 
01963         std::vector<double> vecX;
01964         std::vector<double> vecY;
01965         std::vector<double> vecZ;
01966 
01967         std::vector<double> vecCtrlPointX;
01968         std::vector<double> vecCtrlPointY;
01969         std::vector<double> vecCtrlPointZ;
01970 
01971 
01972         double *p;
01973         int ii,size=polyDataResult->GetNumberOfPoints();
01974         int id;
01975         for (ii=1;ii<=size;ii++)
01976         {
01977                 id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
01978                 p       = polyDataResult->GetPoint(id);
01979 //              double x=p[0];
01980 //              double y=p[1];
01981                 vecX.push_back( p[0] );
01982                 vecY.push_back( p[1] );
01983                 vecZ.push_back( 900 );
01984 //                      vecZ.push_back( p[2] );
01985         }
01986 
01987 
01988         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
01989         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
01990 
01991 //PROOFS
01992         /*if (methodRadiobox->GetSelection()==0){
01993                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01994         }
01995         if (methodRadiobox->GetSelection()==1){
01996                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01997         }
01998         if (methodRadiobox->GetSelection()==2){
01999                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
02000                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02001         }*/
02002 
02003         if (method==0){
02004                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02005         }
02006         else if (method==1){
02007                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02008         }
02009         else if (method==2){
02010                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
02011                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02012         }
02013 
02014         //--Adding contour to the system
02015 
02016         std::vector<int> actualInstantVector;
02017         _instantPanel->getInstant( actualInstantVector );
02018         actualInstantVector[1]=z;
02019 
02020         int j,sizeCtrPt = vecCtrlPointX.size();
02021         manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
02022         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
02023         if (sizeCtrPt>=3){
02024                 for (j=0 ; j<sizeCtrPt ; j++)
02025                 {
02026                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
02027                 } // for
02028                 std::string theName;
02029                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
02030                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
02031                 bool addedModel = theName.compare("") != 0;
02032                 if( addedModel )
02033                 {
02034                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
02035                         _theViewPanel->getSpacing(spc);
02036                         //Adding the manualContourControler to interface objects structure
02037                         //Adding the manualViewContour to interface objects structure
02038                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
02039                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
02040                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
02041                 }       // if addedModel
02042         } // if sizeCtrPt
02043 }
02044 int wxContourMainFrame::GetImageDataSizeZ(){
02045         return _theViewPanel->GetImageDataSizeZ();
02046 }
02047 
02048 void wxContourMainFrame::GetImageDataRange(double *range){
02049         _theViewPanel->GetImageDataRange(range);
02050 }
02051 
02052 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
02053         //JCP 20-10-08 Undo redo implementation
02054         saveState();
02055         //JCP 20-10-08 Undo redo implementation
02056 
02057         wxBusyCursor wait;
02058         int                                     x                                       = _theViewPanel->GetX();
02059         int                                     y                                       = _theViewPanel->GetY();
02060         int z;
02061         double porcent;
02062         wxString tmpString;
02063         double totalZ = maxZ-minZ+1;
02064         for( z=minZ ; z<=maxZ ; z++ )
02065         {
02066                 porcent = 100.0* (z-minZ)/totalZ;
02067                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
02068                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
02069                 //_staticTextSegmentation->SetLabel(tmpString);
02070                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
02071         }
02072         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
02073         RefreshInterface();
02074 }
02075 
02076 
02077 //Creates a reference line to be used as the axis of the mirroring
02078 void wxContourMainFrame::referenceLine()
02079 {
02080         if (_refLineControl==NULL)
02081         {
02082                 wxBusyCursor wait;
02083                 double spc[3];
02084 
02085                 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
02086                 vtkimagedata->GetSpacing(spc);
02087 
02088                 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
02089 
02090                 _refLineControl = new manualLineControler();
02091                 _refLineModel   = new manualContourModelLine();
02092                 _refLineView = new manualViewLine();
02093                 _refLineView->SetModel( _refLineModel );
02094                 _refLineView->SetWxVtkBaseView( viewer2D );
02095                 _refLineView->SetRange( 2 );
02096                 _refLineView->SetZ( 1200 );
02097 
02098                 _refLineView->SetSpacing(spc);
02099 
02100                 _refLineView->SetColorNormalContour(0, 0, 1);
02101                 _refLineView->SetColorEditContour(0, 0.5, 0.5);
02102                 _refLineView->SetWidthLine(4);
02103 
02104                 _refLineControl->SetModelView( _refLineModel , _refLineView );
02105                 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
02106                 style->AddInteractorStyleMaracas( _refLineControl );
02107                 _refLineModel->SetCloseContour(false);
02108                 _refLineControl->CreateNewManualContour();
02109 
02110 //AD: Inicializar el mirroring con una linea ya pintada
02111         /*
02112                 double z = _refLineControl->GetZ();
02113 
02114                 int imageDim[3];
02115                 image->GetDimensions(imageDim);
02116                 double x = (double) imageDim[0]/2;
02117                 double y1 = (double) (imageDim[1]/2)+15;
02118                 double y2 = (double) (imageDim[1]/2)-15;
02119 
02120                 _refLineControl->AddPoint(x,y1,z);
02121                 _refLineControl->AddPoint(x,y2,z);
02122                 _refLineControl->SetCompleteCreation(true);
02123 
02124                 _refLineModel->AddPoint(x,y1,z);
02125                 _refLineModel->AddPoint(x,y2,z);
02126                 _refLineModel->UpdateSpline();
02127 
02128                 _refLineView->UpdateViewPoint(0);
02129                 _refLineView->UpdateViewPoint(1);
02130         */
02131 
02132                 _refLineControl->SetActive(true);
02133                 _refLineView->RefreshContour();
02134         }
02135 }
02136 
02137 //Hides the referenceLine
02138 void wxContourMainFrame::refLineHide()
02139 {
02140         if (_refLineControl!=NULL)
02141         {
02142                 if (_refLineControl->GetActive())
02143                 {
02144                         _refLineView->RemoveCompleteContourActor();
02145                         _refLineControl->SetEditable(false);
02146                         _refLineControl->SetActive(false);
02147 
02148                         RefreshInterface();
02149                 }
02150         }
02151 }
02152 
02153 //Shows the referenceLine
02154 void wxContourMainFrame::refLineShow()
02155 {
02156         if (_refLineControl!=NULL)
02157         {
02158                 if (_refLineControl->GetActive()==false)
02159                 {
02160                         wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
02161 
02162                         _refLineView->SetModel( _refLineModel );
02163                         _refLineView->SetWxVtkBaseView( viewer2D );
02164                         _refLineView->SetRange( 2 );
02165                         _refLineView->SetZ( 1200 );
02166 
02167                         _refLineControl->SetModelView( _refLineModel , _refLineView );
02168                         vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
02169                         style->AddInteractorStyleMaracas( _refLineControl );
02170                         _refLineControl->CreateNewManualContour();
02171                         _refLineControl->SetActive(true);
02172                         _refLineView->RefreshContour();
02173 
02174                         RefreshInterface();
02175                 }
02176         }
02177 }
02178 
02179 void wxContourMainFrame::refLineChangeWidth(int width)
02180 {
02181         _refLineView->SetWidthLine(width);
02182         _refLineView->RefreshContour();
02183 
02184         RefreshInterface();
02185 }
02186 
02187 
02188 void wxContourMainFrame::onMirror()
02189 {
02190         //AD:02-09
02191         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
02192         std::vector<std::string> filterCurrentSelection;
02193 
02194         std::vector<int> tempVector;
02195         _instantPanel->getInstant( tempVector );
02196     _performingOperation->reset();
02197         _performingOperation->setStartCommand( COPY );
02198         _performingOperation->setStartOperationInstantVector( tempVector );
02199         _performingOperation->setKeyNamesOperationElems( currentSelection );
02200 
02201         char theStartCommand = _performingOperation->getStartCommand();
02202         if (  theStartCommand == COPY )
02203         {
02204                 //JCP 20-10-08 Undo redo implementation
02205                 saveState();
02206                 //JCP 20-10-08 Undo redo implementation
02207                 std::vector<int> tempVector;
02208                 _instantPanel->getInstant( tempVector );
02209                 _performingOperation->setEndOperationInstantVector ( tempVector );
02210                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
02211                 int i,size = elems.size();
02212                 for( i=0; i<size; i++ )
02213                 {
02214                         createMirrorContourOf( elems[i], tempVector, i>0 );
02215                 }
02216         }
02217 
02218         //deleteContour( _refName );
02219         //_refName = "";
02220 }
02221 
02222 
02223 void wxContourMainFrame::showAxis(bool show)
02224 {
02225         _theViewPanel->SetVisibleAxis(show);
02226         _theViewPanel->Refresh();
02227 }
02228 
02229 
02230 void wxContourMainFrame::onRigidPressed(){
02231         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
02232         int elementsSelected = currentSelection.size();
02233 
02234         if ( elementsSelected >= 1 ){
02235                 //JCP 20-10-08 Undo redo implementation
02236                 saveState();
02237                 //JCP 20-10-08 Undo redo implementation
02238 
02239                 std::vector<int> tempVector;
02240                 _instantPanel->getInstant( tempVector );
02241                 Instant instant(&tempVector);
02242 
02243                 int i , size=currentSelection.size();
02244                 for ( i=0 ; i<size ; i++ )
02245                 {
02246                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
02247                 } // i
02248         }
02249 }
02250 
02251 void wxContourMainFrame::onWidthOfContour(double width){
02252 
02253         _theViewPanel->removeSceneContours();
02254         _theViewPanel->SetWidthContour(width);
02255 
02256         //_theViewPanel->getSceneManager()->SetWidthContour( width );
02257 
02258         RefreshInterface();
02259 }
02260 
02261 int wxContourMainFrame::getColorWindow()
02262 {
02263         /*
02264         double range[2];
02265         vtkImageData * img = getImageData();
02266         img->GetScalarRange(range);
02267 
02268         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
02269 
02270         return (int)range[1];
02271         */
02272         return _theViewPanel->getColorWindow();
02273 }
02274 
02275 int wxContourMainFrame::getWindowLevel()
02276 {
02277         /*
02278         double range[2];
02279         vtkImageData * img = getImageData();
02280         img->GetScalarRange(range);
02281 
02282         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
02283 
02284         return (int)range[1];
02285         */
02286         return _theViewPanel->getWindowLevel();
02287 }
02288 
02289 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
02290         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
02291 
02292         RefreshInterface();
02293 }
02294 
02295 void wxContourMainFrame::onInterpolation(bool interpolate){
02296         _theViewPanel->onInterpolation(interpolate);
02297         RefreshInterface();
02298 }
02299 
02300 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
02301         _instantPanel->setConceptValue( name, actual );
02302 }
02303 
02304 
02305 void wxContourMainFrame::resetAppend(){
02306         kernelManager->resetAppend();
02307 
02308 }
02309 
02310 
02311 void wxContourMainFrame::onSpreadAdd(){
02312         std::vector<double> vecX;
02313         std::vector<double> vecY;
02314         std::vector<double> vecZ;
02315         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
02316         std::vector<int> tempVector;
02317         _instantPanel->getInstant( tempVector );
02318         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
02319         interfMainPanel::getInstance()->appendStringSpread(val);
02320 }
02321 
02322 
02323 void wxContourMainFrame::onSpreadAddAll(){
02324 //EED02
02325         std::vector<int> tempVector;
02326         _instantPanel->getInstant( tempVector );
02327         int minZ,maxZ;
02328     minZ        = 0;
02329     maxZ        = interfMainPanel::getInstance()->GetImageDataSizeZ();
02330         int z;
02331         int sizeLstContourThings;
02332         for ( z=minZ ; z<=maxZ ; z++ )
02333         {
02334                 tempVector[1]=z;
02335                 Instant instant(&tempVector);
02336                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
02337                 sizeLstContourThings = lstContourThings.size();
02338                 if (sizeLstContourThings>=1)
02339         {
02340             std::vector<double> vecX;
02341             std::vector<double> vecY;
02342             std::vector<double> vecZ;
02343             ContourThing **contourthing = lstContourThings[0];
02344                         manualBaseModel *cModel                         =  (*contourthing)->getModel();
02345                         int i,size = cModel->GetNumberOfPointsSpline();
02346                         double x,y,z;
02347                         for (i=0; i<size; i++)
02348                         {
02349                                 cModel->GetSpline_i_Point(i, &x, &y, &z);
02350                                 vecX.push_back(x);
02351                                 vecY.push_back(y);
02352                                 vecZ.push_back(z);
02353                         } // for i
02354             std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
02355             interfMainPanel::getInstance()->appendStringSpread(val);
02356         }// if sizeLstContourThings
02357     } // for z
02358 }
02359 
02360 
02361 void wxContourMainFrame::onSpreadGo(int type){
02362         //JCP 20-10-08 Undo redo implementation
02363         saveState();
02364         //JCP 20-10-08 Undo redo implementation
02365         wxBusyCursor wait;
02366         std::vector<double> vecCtrlPointX;
02367         std::vector<double> vecCtrlPointY;
02368         std::vector<double> vecCtrlPointZ;
02369         double  minZ,maxZ;
02370         int z;
02371 
02372         std::vector<int> tempVector;
02373         _instantPanel->getInstant( tempVector );
02374 //              tempVector[1];
02375 
02376         kernelManager->getMaxMinZ(&minZ,&maxZ);
02377 //JSTG_16-07-08_----------------------------------------------------------------
02378         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
02379         kernelManager->CalculeSplinePropagation();
02380 
02381         double          totalZ = maxZ-minZ+1;
02382         double          porcent;
02383         wxString        tmpString;
02384 //--------------------------------------------------------------------
02385         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
02386         {
02387                 porcent = 100.0* (z-minZ)/totalZ;
02388                 int numero = (int)(z-minZ+1)/(int)totalZ;
02389                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
02390 
02391                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
02392 
02393                 int typeofcontour = 1;
02394                 std::string theName;
02395                 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
02396 
02397                 if( manModelContour!=NULL ){
02398                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
02399                         this->_theViewPanel->getSpacing(spc);
02400                         //Adding the manualContourControler to interface objects structure
02401                         //Adding the manualViewContour to interface objects structure
02402                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
02403                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
02404                 } // if addedModel
02405         }
02406         if(z > maxZ){
02407                 porcent = 100.0;
02408                 int numero = (int)(z-minZ+1)/(int)totalZ;
02409                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
02410 
02411                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
02412         }// for z
02413         //RefreshInterface();
02414 }
02415 
02416 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
02417 
02418 }
02419 
02420 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
02421         std::vector<int> tempVector;
02422         _instantPanel->getInstant(tempVector);
02423         //Asignation of slide number should be different ex by name
02424         tempVector[1]=slide;
02425         return kernelManager->getOutlinesNameAtInstant(tempVector);
02426 }
02427 
02428 
02429 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
02430 {
02431         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
02432 }
02433 
02434 
02435 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
02436 {
02437 //EED01Juillet2009      GenerateContourExtractData();
02438 
02439         wxString tempString;
02440         int maxContourGroup     =       0;
02441 
02442         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
02443 
02444         std::vector<manualBaseModel*> lstManConMod;
02445         std::vector<manualBaseModel*> lstManConModTmp;
02446         std::vector<manualBaseModel*> lstManConModExp;
02447         std::vector<double> pLstValue;
02448         std::vector<double> pLstValuePosX;
02449         std::vector<double> pLstValuePosY;
02450         std::vector<double> pLstValuePosZ;
02451 
02452         int             resultSize;
02453         int             resultGrayRangeCount;
02454         double  resultMin;
02455         double  resultMax;
02456         double  resultAverage;
02457         double  resultStandardeviation;
02458 
02459         std::vector<int> tempVector;
02460         _instantPanel->getInstant( tempVector );
02461 
02462 //EED01Juillet2009      vtkImageData *imagedata = _theViewPanel->getImageData();
02463 //      int sizeZ = _theViewPanel->GetImageDataSizeZ();
02464         int z;
02465         int ii,sizeLstContourThings;
02466 
02467 
02468         int minZ,maxZ;
02469         double totalZ;
02470         double porcent;
02471         wxString tmpString;
02472 
02473 
02474         if (selection==0 ) // actual slice
02475         {
02476                 int actualSlice = tempVector[1];
02477                 minZ    = actualSlice;
02478                 maxZ    = actualSlice;
02479         }       else  {  // slice range
02480                 minZ    = minimumZ;
02481                 maxZ    = maximumZ;
02482         }
02483 
02484 
02485         totalZ  = maxZ-minZ+1;
02486 //EED01Juillet2009      _contourextractdata->SetImage( imagedata);
02487 
02488         _contourextractdata->InitVolumeStatistics();
02489 
02490 // For each slice..
02491         for ( z=minZ ; z<=maxZ ; z++ )
02492         {
02493 
02494                 porcent = 100.0* (z-minZ)/totalZ;
02495                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
02496 
02497                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
02498                 //_staticTextInformation->SetLabel(tmpString);
02499 
02500                 //Extraction data from contours of each slice
02501                 _contourextractdata->SetZtoBeAnalys(z);
02502 
02503                 tempVector[1]=z;
02504                 Instant instant(&tempVector);
02505                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
02506                 sizeLstContourThings = lstContourThings.size();
02507 
02508                 lstManConMod.clear();
02509                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
02510                 {
02511                         ContourThing **contourthing = lstContourThings[ii];
02512                         lstManConMod.push_back( (*contourthing)->getModel() );
02513                 }
02514 
02515                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
02516 
02517                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
02518                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
02519                 //_grid->SetRowLabelValue(z, tempString );
02520 //EED004
02521                 int iContourGroup,sizeContourGroup;
02522                 if (typeContourGroup==3) // contour separete
02523                 {
02524                         sizeContourGroup=lstManConModExp.size();
02525                         if ( maxContourGroup<sizeContourGroup )
02526                         {
02527                                 maxContourGroup=sizeContourGroup;
02528                         }
02529                 } else {  // contour AND OR XOR
02530                         sizeContourGroup=1;
02531                         maxContourGroup=1;
02532                 }
02533 
02534                 int tmpIntA;
02535 
02536                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
02537                         lstManConModTmp.clear();
02538 
02539 
02540 
02541                         if (typeContourGroup==3) // contour separete
02542                         {
02543                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
02544                         } else {  // contour AND OR XOR
02545                                 lstManConModTmp = lstManConModExp;
02546                         }
02547 
02548                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
02549                         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
02550 
02551                         pLstValue.clear();
02552                         pLstValuePosX.clear();
02553                         pLstValuePosY.clear();
02554                         pLstValuePosZ.clear();
02555 
02556 
02557                         int numberOfPixels;
02558                         _contourextractdata->GetValuesInsideCrown(  &numberOfPixels,
02559                                                                                                                 &pLstValue,
02560                                                                                                                 &pLstValuePosX,
02561                                                                                                                 &pLstValuePosY,
02562                                                                                                                 &pLstValuePosZ);
02563 
02564                         resultSize=numberOfPixels;
02565                         // Statistics of each slice.
02566                         _contourextractdata->Statistics( &pLstValue,
02567                                                                                         grayRangeMin,
02568                                                                                         grayRangeMax,
02569                                                                                         &resultGrayRangeCount,
02570                                                                                         &resultSize,
02571                                                                                         &resultMin,
02572                                                                                         &resultMax,
02573                                                                                         &resultAverage,
02574                                                                                         &resultStandardeviation);
02575 
02576                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
02577                         {
02578                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
02579                         }
02580 
02581                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
02582 
02583                         tempString.Printf(_T("%d"),numberOfPixels);
02584 
02585                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
02586 
02587                         tempString.Printf(_T("%d"),resultGrayRangeCount);
02588                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
02589 
02590                         tempString.Printf(_T("%f"),resultMin);
02591                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
02592 
02593                         tempString.Printf(_T("%f"),resultMax);
02594                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
02595 
02596                         tempString.Printf(_T("%f"),resultAverage);
02597                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
02598 
02599                         tempString.Printf(_T("%f"),resultStandardeviation);
02600                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
02601 
02602 
02603                 } // for iContourGroup
02604         } // for z
02605 
02606         // Print Volume Statistics
02607 
02608 
02609         int             vol_rCountRange;
02610         int             vol_rsize;
02611         double  vol_minValue;
02612         double  vol_maxValue;
02613         double  vol_average;
02614         double  vol_standardeviation;
02615 
02616         if (selection!=0 ) // actual slice
02617         {
02618 
02619                 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
02620                                                                                                  &vol_minValue, &vol_maxValue,
02621                                                                                                  &vol_average, &vol_standardeviation);
02622 
02623                 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
02624 
02625                 tempString.Printf(_T("%d"),vol_rsize);
02626                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
02627 
02628                 tempString.Printf(_T("%d"),vol_rCountRange);
02629                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
02630 
02631                 tempString.Printf(_T("%f"),vol_minValue);
02632                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
02633 
02634                 tempString.Printf(_T("%f"),vol_maxValue);
02635                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
02636 
02637                 tempString.Printf(_T("%f"),vol_average);
02638                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
02639 
02640                 tempString.Printf(_T("%f"),vol_standardeviation);
02641                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
02642         }
02643         //-----------------------------------------
02644 
02645         int iTitleGroup;
02646         wxString tmpTitleString;
02647         int tmpIntB;
02648         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
02649         {
02650                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
02651                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
02652                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
02653 
02654                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
02655                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
02656                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
02657                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
02658                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
02659                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
02660                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
02661         }// for title
02662         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
02663 }
02664 
02665 //AD: 29-05-09
02666 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
02667         int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
02668 {
02669         if (XYZValues)
02670         {
02671                 SaveValuesXYZ( directory , namefile, typeContourGroup );
02672         }
02673 
02674         if (contourImage)
02675         {
02676                 vtkImageData * mask;
02677                 vtkImageData * value;
02678                 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
02679                 this->SaveImageResult( directory , namefile, mask, value);
02680         }
02681 
02682         if (statistics)
02683         {
02684                 std::ostringstream name;
02685                 name << filename << ".xls";
02686 
02687 
02688                 FILE *pFile=fopen(name.str().c_str(),"w+");
02689 
02690 
02691                 wxString tmpString;
02692                 int i,j,maxX;
02693 
02694 //              int sizeZ = _theViewPanel->GetImageDataSizeZ();
02695 //              int maxY=sizeZ+2;
02696 
02697                 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
02698 
02699                 // -- Title --
02700                 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
02701                 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
02702                 {
02703                                 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
02704                                 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
02705                 }
02706                 fprintf(pFile,"\n\n" );
02707 
02708 
02709 
02710                 if (selection==0 ) // actual slice
02711                 {
02712                         std::vector<int> tempVector;
02713                         _instantPanel->getInstant( tempVector );
02714                         int actualSlice = tempVector[1];
02715                         minZ    = actualSlice;
02716                         maxZ    = actualSlice;
02717                 }
02718 
02719                 // Stadistics...
02720                 for ( j=minZ; j<=maxZ ; j++)
02721                 {
02722                         fprintf(pFile,"%d\t" , j );
02723                         for (i=0 ; i<maxX ; i++){
02724                                 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
02725                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
02726                         } // for i
02727                         fprintf(pFile,"\n"  );
02728                 } // for j
02729 
02730 
02731                 // Total of stadistics.....
02732                 if (selection!=0)
02733                 {
02734                         fprintf(pFile,"\n Total:\t"  );
02735                         for (i=0 ; i<maxX ; i++){
02736                                 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
02737                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
02738                         } // for i
02739                         fprintf(pFile,"\n"  );
02740                 }
02741 
02742                 fclose(pFile);
02743         }
02744 }
02745 
02746 //AD: 29-05-09
02747 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
02748 {
02749         wxBusyCursor wait;
02750 //EED01Juillet2009      GenerateContourExtractData();
02751 
02752         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
02753         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
02754 
02755         std::vector<manualBaseModel*> lstManConMod;
02756         std::vector<manualBaseModel*> lstManConModTmp;
02757         std::vector<manualBaseModel*> lstManConModExp;
02758         std::vector<double> pLstValue;
02759         std::vector<double> pLstValuePosX;
02760         std::vector<double> pLstValuePosY;
02761         std::vector<double> pLstValuePosZ;
02762 
02763         std::vector<int> tempVector;
02764         _instantPanel->getInstant( tempVector );
02765 
02766 //EED01Juillet2009      vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
02767         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
02768         int z;
02769         int ii,sizeLstContourThings;
02770 
02771 
02772         int minZ,maxZ;
02773         double totalZ;
02774         double porcent;
02775         wxString tmpString;
02776         minZ    = 0;// _mbarrange->GetStart();
02777         maxZ    = sizeZ;//_mbarrange->GetEnd();
02778         totalZ  = maxZ-minZ+1;
02779 
02780 //EED01Juillet2009      _contourextractdata->SetImage( imagedata);
02781 
02782 // For each slice..
02783         for ( z=0 ; z<sizeZ ; z++)
02784         {
02785 
02786                 porcent = 100.0* (z-minZ)/totalZ;
02787 
02788                 tmpString.Printf(_T("Saving Values"));
02789                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
02790                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
02791                 //_staticTextInformation->SetLabel(tmpString);
02792 
02793 
02794                 //Extraction data from contours of each slice
02795                 _contourextractdata->SetZtoBeAnalys( z);
02796 
02797                 tempVector[1]=z;
02798                 Instant instant(&tempVector);
02799                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
02800                 sizeLstContourThings = lstContourThings.size();
02801 
02802                 lstManConMod.clear();
02803                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
02804                 {
02805                         ContourThing **contourthing = lstContourThings[ii];
02806                         lstManConMod.push_back( (*contourthing)->getModel() );
02807                 }
02808                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
02809 
02810 
02811 //EED004
02812 
02813                 int iContourGroup,sizeContourGroup;
02814                 if (typeContourGroup==3) // contour separete
02815                 {
02816                         sizeContourGroup=lstManConModExp.size();
02817                 } else {  // contour AND OR XOR
02818                         sizeContourGroup=1;
02819                 }
02820 
02821                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
02822                         lstManConModTmp.clear();
02823                         if (typeContourGroup==3) // contour separete
02824                         {
02825                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
02826                         } else {  // contour AND OR XOR
02827                                 lstManConModTmp = lstManConModExp;
02828                         }
02829 
02830                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
02831 
02832                         pLstValue.clear();
02833                         pLstValuePosX.clear();
02834                         pLstValuePosY.clear();
02835                         pLstValuePosZ.clear();
02836                         int numberOfPixels;
02837                         _contourextractdata->GetValuesInsideCrown(      &numberOfPixels,
02838                                                                                                                 &pLstValue,
02839                                                                                                                 &pLstValuePosX,
02840                                                                                                                 &pLstValuePosY,
02841                                                                                                                 &pLstValuePosZ);
02842 
02843                         std::string temp = directory + "/" + namefile + "-slice";
02844                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
02845                         temp = temp + ".txt";
02846 
02847                         // LG 14/01/09 : using crea
02848                         wxString filename = crea::std2wx(temp);
02849                         /*filename.Printf(_T("%s"),directory.c_str());
02850                         filename.append(_T("\\"));
02851                         filename.append(_T("%s"),namefile.c_str());
02852                         filename.append(_T("-slice"));
02853                         filename.append(_T("%d"),z);
02854                         filename.append(_T("-cont"));
02855                         filename.append(_T("%d"),iContourGroup);
02856                         filename.append(_T(".txt"));*/
02857                         //                      filename.Printf(temp.c_str());
02858 
02859 
02860 
02861                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
02862                         fprintf(pFile,"value \t x \t y \t z\n"  );
02863                         int iLstValue,sizeLstValue=pLstValue.size();
02864                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
02865                         {
02866                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
02867                         }
02868                         fclose(pFile);
02869                 } // for  iContourGroup
02870         } // for z
02871         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
02872         //_staticTextInformation->SetLabel( _T("") );
02873 
02874 }
02875 
02876 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
02877         wxBusyCursor wait;
02878 //EED01Juillet2009      GenerateContourExtractData();
02879 
02880         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
02881         if (typeContourGroup==3)
02882         {
02883                 typeContourGroup=1;
02884         }
02885         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
02886 
02887         std::vector<manualBaseModel*> lstManConMod;
02888         std::vector<manualBaseModel*> lstManConModTmp;
02889         std::vector<manualBaseModel*> lstManConModExp;
02890 
02891         std::vector<int> tempVector;
02892         _instantPanel->getInstant( tempVector );
02893 
02894     vtkImageData *imagedata = _theViewPanel->getImageData();
02895         int ext[6];
02896         imagedata->GetExtent(ext);
02897         int sizeZimage = ext[5]-ext[4]+1;
02898         int z;
02899         int ii,sizeLstContourThings;
02900 
02901 
02902         double totalZ;
02903         double porcent;
02904 
02905         wxString tmpString;
02906 
02907 
02908         if (selection==0 ) // actual slice
02909         {
02910                 int actualSlice = tempVector[1];
02911                 minZ    = actualSlice;
02912                 maxZ    = actualSlice;
02913         }
02914 
02915         totalZ  = maxZ-minZ;
02916 
02917 //EED01Juillet2009      _contourextractdata->SetImage( imagedata);
02918 
02919         // cleanning image before range
02920         for (z=0; z<minZ; z++){
02921                 _contourextractdata->ResetImageResult(z);
02922         }
02923         // cleanning image after range
02924         for (z=maxZ+1; z<sizeZimage; z++){
02925                 _contourextractdata->ResetImageResult(z);
02926         }
02927 
02928 
02929 // For each slice..
02930         for ( z=minZ ; z<=maxZ ; z++)
02931         {
02932 
02933                 porcent = 100.0* (z-minZ)/totalZ;
02934                 tmpString.Printf(_T("Saving Values"));
02935                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
02936                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
02937 
02938                 //Extraction data from contours of each slice
02939                 _contourextractdata->SetZtoBeAnalys( z);
02940 
02941                 tempVector[1]=z;
02942                 Instant instant(&tempVector);
02943                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
02944                 sizeLstContourThings = lstContourThings.size();
02945 
02946                 lstManConMod.clear();
02947                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
02948                 {
02949                         ContourThing **contourthing = lstContourThings[ii];
02950                         lstManConMod.push_back( (*contourthing)->getModel() );
02951                 }
02952                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
02953 
02954 
02955                 int iContourGroup,sizeContourGroup;
02956                 if (typeContourGroup==3) // contour separete
02957                 {
02958                         sizeContourGroup=lstManConModExp.size();
02959                 } else {  // contour AND OR XOR
02960                         sizeContourGroup=1;
02961                 }
02962 
02963                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
02964                         lstManConModTmp.clear();
02965                         if (typeContourGroup==3) // contour separete
02966                         {
02967                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
02968                         } else {  // contour AND OR XOR
02969                                 lstManConModTmp = lstManConModExp;
02970                         }
02971 
02972                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
02973                         _contourextractdata->CalculateImageResult(); // with actual Z
02974 
02975                 } // for  iContourGroup
02976         } // for z
02977 
02978         (*value) = _contourextractdata->GetVtkImageValueResult();
02979         (*mask)  = _contourextractdata->GetVtkImageMaskResult();
02980 
02981 }
02982 
02983 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
02984 {
02985 
02986         double spc[3];
02987         kernelManager->GetSpacing(spc,0);   // returns the spacing of the first image
02988         
02989         std::string temp = directory + "/" + namefile + "-image-Value.mhd";
02990 
02991         wxString filename = crea::std2wx(temp);
02992 
02993 // Image Value
02994         
02995         vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
02996         valueChInfo->SetInput(value);
02997         valueChInfo->SetSpacingScale(spc);      
02998         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
02999         writerValueImage->SetInput( valueChInfo->GetOutput() );
03000         writerValueImage->SetFileName( (const char *)filename.mb_str() );
03001         writerValueImage->SetFileDimensionality( 3 );
03002         writerValueImage->SetCompression(false);
03003         writerValueImage->Write( );
03004 
03005 // Image Mask
03006         temp = directory + "/" + namefile + "-image-Mask.mhd";
03007 
03008         // LG 14/01/09 : using crea
03009         filename = crea::std2wx(temp);
03010         //      filename.Printf(_T(temp.c_str()));
03011 
03012 
03013         vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
03014         maskChInfo->SetInput(mask);
03015         maskChInfo->SetSpacingScale(spc);       
03016         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
03017         writerMaskImage->SetInput( maskChInfo->GetOutput() );
03018         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
03019         writerMaskImage->SetFileDimensionality( 3 );
03020         writerMaskImage->SetCompression(false);
03021         writerMaskImage->Write( );
03022 
03023         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
03024 
03025 }
03026 
03027 
03028 
03029 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
03030         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
03031                 _theViewPanel->setActualVertical( value);
03032         }
03033         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
03034                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
03035         }
03036 
03037         changeInstant();
03038 }
03039 
03040 void wxContourMainFrame::onSnakePressed(){
03041         std::vector<double> vecX;
03042         std::vector<double> vecY;
03043         std::vector<double> vecZ;
03044         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
03045 
03046         if (vecX.size()!=0){
03047                 std::vector<int> tempVector;
03048                 _instantPanel->getInstant( tempVector );
03049                 int i,size=vecZ.size();
03050                 int actualSlice = tempVector[1];
03051                 for ( i=0 ; i<size ; i++ )
03052                 {
03053                         vecZ[i] = actualSlice;
03054                 } // for
03055 
03056                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
03057                 wxPanel* panel = new wxPanel(dialog,-1);
03058                 //              wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
03059          new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
03060                 dialog->ShowModal();
03061         } // if
03062 
03063 }
03064 
03065 void wxContourMainFrame::saveFileWithContoursAutomatique(){
03066         std::string filename = kernelManager->getCurrentFileName();
03067         if(filename.compare("")!=0){
03068                 saveFileWithContours(filename);
03069         }else{
03070                 onSave();
03071         }
03072 }
03073 void wxContourMainFrame::ShowToolsPanel(bool show){
03074         _pannew->Show(show);
03075 }
03076 
03077 
03078 
03079 void wxContourMainFrame::SetContourGroup(int contourGroup)
03080 {
03081         _contourGroup = contourGroup;
03082 }
03083 
03084 
03085 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
03086 {
03087 
03088         if      (_viewMaskImagePanel==NULL)
03089         {
03090                 _contourextractdata = new ContourExtractData(true);
03091                 _contourextractdata->SetImage( _theViewPanel->getImageData() );
03092 //              double range[2];
03093 //              _theViewPanel->getImageData()->GetScalarRange(range);
03094                 //int min = (int)floor (range[0]);
03095                 //int max = (int)ceil (range[1]);
03096                 int min = 254;
03097                 int max = 256;
03098                 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
03099                 _viewMaskImage = new ThresholdImageView();
03100                 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
03101                 _viewMaskImage->SetminMaxValue( min, max);
03102                 _viewMaskImage->SetBaseColor( 0,0,1 );
03103                 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
03104                 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
03105         }
03106         return _viewMaskImagePanel;
03107 }
03108 
03109 
03110 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
03111 {
03112         if      (_viewColorLayerImagePanel==NULL)
03113         {
03114                 double range[2];
03115                 _theViewPanel->getImageData()->GetScalarRange(range);
03116                 int min = (int)floor (range[0]);
03117                 int max = (int)ceil (range[1]);
03118                 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max , 1);
03119                 _viewColorLayerImage = new ColorLayerImageView();
03120 //              _viewColorLayerImage->SetImage( _theViewPanel->getImageData() );
03121                 _viewColorLayerImage->SetImage( NULL );
03122                 _viewColorLayerImagePanel->SetColorLayerImageView( _viewColorLayerImage );
03123                 _viewColorLayerImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
03124         }
03125         return _viewColorLayerImagePanel;
03126 }
03127 
03128 
03129 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
03130 {
03131         if      (_viewThresholdImagePanel==NULL)
03132         {
03133                 double range[2];
03134                 _theViewPanel->getImageData()->GetScalarRange(range);
03135                 int min = (int)floor (range[0]);
03136                 int max = (int)ceil (range[1]);
03137                 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
03138                 _viewThresholdImage = new ThresholdImageView();
03139                 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
03140                 _viewThresholdImage->SetminMaxValue( min, max);
03141                 _viewThresholdImage->SetBaseColor( 1,0,0 );
03142                 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
03143                 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
03144         }
03145         return _viewThresholdImagePanel;
03146 }
03147 
03148 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
03149 int wxContourMainFrame::getType ()
03150 {
03151         int tipo = 0;
03152         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
03153 
03154         if(!currentSelection.empty())
03155         {
03156                 std::string cloneName = currentSelection [0];
03157                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
03158                 tipo = manualModel-> GetTypeModel();
03159         }
03160         return tipo;
03161 }
03162 
03163 double wxContourMainFrame::getContourSizeInPixels()
03164 {
03165         double contourSize = 0;
03166 
03167         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();        if(!currentSelection.empty())
03168         if(!currentSelection.empty())
03169         {
03170                 std::string cloneName = currentSelection [0];
03171 
03172                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
03173                 contourSize = manualModel-> GetPathSize();
03174         }
03175         return contourSize;
03176 }
03177 manualBaseModel * wxContourMainFrame::getContour ()
03178 {
03179         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
03180 
03181         if(!currentSelection.empty())
03182         {
03183                 std::string cloneName = currentSelection [0];
03184                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
03185                 return manualModel;
03186         }
03187         return NULL;
03188 }
03189 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
03190 {
03191         std::string labelAscii(label.ToAscii());
03192         int pos = labelAscii.find(" ");
03193 
03194         int j;
03195 
03196         for (j=0 ; pos != string::npos;j++)
03197         {
03198                 labelAscii.replace( pos, 1, "_" );
03199                 pos= labelAscii.find(" ");
03200         }
03201 
03202         manualModel -> SetLabel(labelAscii);
03203 }
03204 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
03205 {
03206         double sizeInPixel = manualModel ->GetPathSize();
03207         double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
03208         double realContourSize = sizeInPixel*onePixelRealSize;
03209         manualModel ->SetRealSize(realContourSize);
03210 }
03211 
03212 double wxContourMainFrame::onePixelSize( double value)
03213 {
03214         return _onePixelSize = value;
03215 }
03216 
03217 std::string wxContourMainFrame::GetFileLocation()
03218 {
03219         return _fileLocation;
03220 }
03221 
03222 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
03223 {
03224         _fileLocation = newFileLocation;
03225         std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
03226 }
03227 //------------------------------------------------------------------------------------------------------------

Generated on Wed Jun 27 23:28:32 2012 for creaContours_lib by  doxygen 1.5.7.1