1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxContourMainFrame.h"
8 //----------------------------------------------------------------------------------------------------------------
10 //----------------------------------------------------------------------------------------------------------------
13 #include "NameWrapper.h"
14 #include "wx/artprov.h"
15 #include "ConceptDataWrap.h"
17 #include <manualContour.h>
18 //#include "ImageSourceThing.h"
19 //#include "wxContour_ActionCommandsID.h"
20 //#include "OutlineModelBuilder.h"
21 //#include "wxContourEventHandler.h"
24 //----------------------------------------------------------------------------------------------------------------
25 // Class implementation
26 //----------------------------------------------------------------------------------------------------------------
27 /** @file wxContourMainFrame.cxx */
29 //------------------------------------------------------------------------------------------------------------
30 // Constructors & Destructors
31 //------------------------------------------------------------------------------------------------------------
33 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
34 char wxContourMainFrame::COPY = 'C';
36 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
37 //: wxPanel(parent, id, title, pos, size, style)
38 //: wxWindow(parent, id, pos, size, style)
39 : wxPanel(parent, id, pos, size, style)
41 m_mgr.SetManagedWindow(this);
42 _creatingContoursActive = false;
44 // _modelManager = NULL;
46 // _buttonsBar = NULL;
48 // _drawToolsPanel = NULL;
49 // _operationsToolsPanel = NULL;
50 //_autoFormsPanel = NULL;
51 // _standardToolsPanel = NULL;
52 // _editionToolsPanel = NULL;
53 // _listViewPanel = NULL;
54 // _sceneManager = NULL;
55 //_actualInstant = NULL;
56 _numberOfVariablesStatistics = 6+1;
58 _refLineControl = NULL;
61 _imageReslicer = NULL;
62 _thresholdTable = NULL;
63 _thresholdMapper = NULL;
64 _thresholdActor = NULL;
65 _actorPresent = false;
67 // set up default notebook style
68 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
69 // m_notebook_theme = 0;
70 //wxContour_ActionCommandsID a;
74 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
75 : wxPanel(parent, id, pos, size, style)
77 m_mgr.SetManagedWindow(this);
78 _creatingContoursActive = false;
82 _refLineControl = NULL;
85 _imageReslicer = NULL;
86 _thresholdTable = NULL;
87 _thresholdMapper = NULL;
88 _thresholdActor = NULL;
89 _actorPresent = false;
91 // set up default notebook style
92 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
94 //wxContour_ActionCommandsID a;
95 _numberOfVariablesStatistics = 7;
103 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
104 _performingOperation = new PerformingOperation();
106 if(images.size() > 0)
108 this->setVectImages(images);
113 void wxContourMainFrame::setVectImages( std::vector<vtkImageData*> images ){
115 #if defined(__GNUC__)
116 std::string str_home(getenv("HOME"));
117 #elif defined(_WIN32)
118 std::string str_home(getenv("USERPROFILE"));
120 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
122 std::vector<std::string> conceptNameVect;
123 std::vector<int> conceptSizeVect;
125 notebook = this->createNotebook();
128 kernelManager = new KernelManagerContour( images , _datadir+"/data/" , strCreaContourDataTmp );
131 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
132 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
134 //-------------------------------------------------------------
135 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
136 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
139 double val = _theViewPanel->getCurrentDeep();
140 _instantPanel->setConceptValue( "Axe Depth", (int)val );
141 //JCP _instantPanel->setConceptValue("time", num de imagenes);
142 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
143 //*******************changeInstant();
144 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
146 this->configurePanels( );
151 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 ){
152 if(instance == NULL){
153 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
158 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
160 return kernelManager->getVectImages();
163 wxContourMainFrame* wxContourMainFrame :: getInstance()
168 void wxContourMainFrame :: resetInstance()
173 wxContourMainFrame :: ~wxContourMainFrame()
177 interfMainPanel::resetInstance();
178 delete kernelManager;
180 //_pannew->Destroy();
186 //El problema al cerrar la aplicacion puede estar asociado
187 //a que wxAUINotebook esta en la aplicacion
188 //principal (wxContourGUIExample)tambien
189 //EED???? delete _theViewPanel;
190 //EED???? delete _instantPanel;
191 //EED???? delete _buttonsBar;
192 //EED???? delete _actualInstant;
193 //EED???? delete _sceneManager;
197 //------------------------------------------------------------------------------------------------------------
198 // Creational and initialization methods using WxAui
199 //------------------------------------------------------------------------------------------------------------
201 wxAuiNotebook * wxContourMainFrame :: createNotebook()
203 wxSize client_size = GetClientSize();
204 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
205 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
210 //------------------------------------------------------------------------------------------------------------
211 // Creational and initialization methods
212 //------------------------------------------------------------------------------------------------------------
213 bool wxContourMainFrame :: configurePanels( )
215 bool configured = _theViewPanel!=NULL;
217 configured &= _theViewPanel!=NULL;
218 if( _theViewPanel!=NULL )
220 notebook->AddPage( _theViewPanel, wxT(" View ") );
227 notebook->AddPage( _instantPanel, wxT("Instant Page") );
231 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
234 SetMinSize(wxSize(300,300));
240 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
242 bool configured = panel!=NULL;
243 configured &= panel!=NULL;
247 notebook->AddPage( panel, wxT(" Viewer "), true );
253 //------------------------------------------------------------------------------------------------------------
254 // Attributes getters and setters
255 //------------------------------------------------------------------------------------------------------------
259 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
261 _instantPanel = theInstantChooserPanel;
264 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
266 // _buttonsBar = theButtonsBar;
269 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
271 // _gridPanel = theGridPanel;
274 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
276 // _drawToolsPanel = theDrawToolsPanel;
279 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
281 // _operationsToolsPanel = theOperationsToolsPanel;
284 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
286 // _autoFormsPanel = theAutoFormsPanel;
289 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
291 // _standardToolsPanel= theStandardToolsPanel;
294 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
296 // _editionToolsPanel = theEditionToolsPanel;
299 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
301 // _listViewPanel = theListViewPanel;
306 void wxContourMainFrame::onCreateContourSpline( ){
308 //JCP 20-10-08 Undo redo implementation
310 //JCP 20-10-08 Undo redo implementation
314 void wxContourMainFrame::onCreateContourRectangle( ){
315 //JCP 20-10-08 Undo redo implementation
317 //JCP 20-10-08 Undo redo implementation
320 void wxContourMainFrame::onCreateContourCircle( ){
321 //JCP 20-10-08 Undo redo implementation
323 //JCP 20-10-08 Undo redo implementation
327 void wxContourMainFrame::onCreateContourLine( ){
328 //JCP 20-10-08 Undo redo implementation
330 //JCP 20-10-08 Undo redo implementation
334 //------------------------------------------------------------------------------------------------------------
336 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
338 //Creating the manualContourModel and including in the model
339 manualContourModel * manModelContour = factoryManualContourModel(panel );
341 std::vector<int> instantVector;
342 _instantPanel->getInstant( instantVector );
343 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
345 /*std::vector<int> instantVector;
346 _instantPanel->getInstant( instantVector );
348 theName= _modelManager->createOutline( manModelContour, instantVector );*/
349 bool addedModel = theName.compare("") != 0;//??
353 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
354 _theViewPanel->getSpacing(spc);
355 //Adding the manualContourControler to interface objects structure
356 //Adding the manualViewContour to interface objects structure
357 //_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.
358 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
361 void wxContourMainFrame :: createContour( int typeContour )
363 //Creating the manualContourModel and including in the model
364 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
367 std::vector<int> instantVector;
368 _instantPanel->getInstant( instantVector );
369 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
371 /*std::vector<int> instantVector;
372 _instantPanel->getInstant( instantVector );
374 theName= _modelManager->createOutline( manModelContour, instantVector );*/
375 bool addedModel = theName.compare("") != 0;//??
378 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
379 _theViewPanel->getSpacing(spc);
380 //Adding the manualContourControler to interface objects structure
381 //Adding the manualViewContour to interface objects structure
382 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
383 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
387 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
389 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
390 manualContourModel *manModelContour=NULL;
391 manModelContour = manModelContourBullEye;
393 int iCrown,sizeCrowns,iSector,sizeSectors;
394 double radioA,radioB,ang,angDelta ;
395 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
396 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
398 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
399 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
400 if (iCrown==sizeCrowns-1)
404 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
408 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
410 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
411 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
412 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
415 } // if _panelBullEyeOptions
417 return manModelContour;
419 void wxContourMainFrame :: saveState(){
421 std::string temp = kernelManager->saveState();
422 saveFileWithContours(temp);
425 void wxContourMainFrame::onDeleteContour(){
426 //JCP 20-10-08 Undo redo implementation
428 //JCP 20-10-08 Undo redo implementation
430 std::vector<std::string> lstKeyNameToBeErase;
431 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
432 deleteContours( lstKeyNameToBeErase );
434 int i,size=_sceneManager->getSelectedObjects().size();
437 std::string keyName = _sceneManager->getSelectedObjects()[i];
438 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
439 if ( ispartofstaticlist>=0 )
441 std::vector<int> tempVector;
442 _instantPanel->getInstant( tempVector );
443 Instant instant(&tempVector);
444 this->_modelManager->ChangeContourOfList(keyName, &instant);
448 std::vector<std::string> lstKeyName;
449 std::vector<std::string> lstKeyNameActualSlice;
450 std::vector<std::string> lstKeyNameToBeErase;
452 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
453 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
454 int k,kSize=lstKeyNameToBeErase.size();
455 int j,jSize=lstKeyNameActualSlice.size();
457 for (k=0;k<kSize; k++)
460 for (j=0;j<jSize; j++)
462 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
469 lstKeyName.push_back( lstKeyNameToBeErase[k] );
473 deleteContours( lstKeyName );
477 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
479 int i,size=keyNamesVector.size();
482 deleteContour( keyNamesVector[i] );
486 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
488 manualContourModel * cModel;
489 manualViewBaseContour * cViewer;
490 manualContourBaseControler * cControler;
492 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
493 cControler = conwrapviewControl->getControler();*/
496 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
497 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
499 if (isedit && ispartofstaticlst)
501 _theViewPanel->removeFromScene(theKeyName);
503 kernelManager->deleteCModel(theKeyName);
504 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
505 //cViewer = conwrapviewControl->getViewer();
506 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
507 //cControler* conwrapviewControl->getControler();
509 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
510 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
511 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
515 // delete cControler;
520 void wxContourMainFrame::onDeleteContoursActSlice(){
521 //JCP 20-10-08 Undo redo implementation
523 //JCP 20-10-08 Undo redo implementation
524 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
526 void wxContourMainFrame::onDeleteAllContours(){
527 //JCP 20-10-08 Undo redo implementation
531 void wxContourMainFrame::deleteAllContours(){
532 //JCP 20-10-08 Undo redo implementation
535 std::vector<int> tempVector;
536 _instantPanel->getInstant( tempVector );
538 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
539 // the values in GetStart and GetEnd will then not be initialize also.
540 // We use instead the values given when initializing the _deletepanel.
542 //int minZ = _mbarrangeDeleteAll->GetStart();
543 //int maxZ = _mbarrangeDeleteAll->GetEnd();
547 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
551 _theViewPanel->getSceneManager()->removeSceneContours( );
552 _theViewPanel->getSceneManager()->removeAllOutlines();
553 kernelManager->removeAllOutlines();
556 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
558 _theViewPanel->getSceneManager()->removeSceneContours( );
559 _modelManager->removeAllOutlines();
560 _theViewPanel->getSceneManager()->removeAllOutlines();
563 for ( z=minZ ; z<=maxZ ; z++)
566 Instant instant(&tempVector);
567 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
569 sizeLstContourThings = lstContourThings.size();
570 for (ii=0 ; ii<sizeLstContourThings ; ii++)
572 ContourThing **contourthing = lstContourThings[ii];
573 deleteContour( (*contourthing)->getName() );
580 void wxContourMainFrame::setConceptValue( std::string name, int value ){
581 _instantPanel->setConceptValue(name, value);
584 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
585 return _instantPanel->getLastConceptData();
587 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
588 return _instantPanel->getIfConceptCheckedAt( name, pos );
591 void wxContourMainFrame::changeInstant()
593 std::vector<int> instantVect;
594 _instantPanel->getInstant( instantVect );
595 // Instant * theInstant = new Instant ( &instantVect );
597 //Setting the actual instant
598 //_actualInstant = theInstant;
600 kernelManager->setInstant(instantVect);
601 //_modelManager->setInstant( _actualInstant );
604 updateInstantOutlines();
605 updateInstantImageData();
610 void wxContourMainFrame :: updateInstantOutlines()
612 _theViewPanel->removeSceneContours();
613 _theViewPanel->addNameWrapperToScene();
615 //for( int i=0; i<size; i++)
617 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
621 int wxContourMainFrame::getNamesWrappingSize(){
622 return kernelManager->getNamesWrappingSize();
624 std::string wxContourMainFrame::getNameWrapping(int i){
625 return kernelManager->getNameWrapping(i);
628 void wxContourMainFrame::updateInstantImageData()
630 std::vector<int> inst;
631 _instantPanel->getInstant(inst);
633 vtkImageData* img = kernelManager->getImageAtInstant(inst);
635 _theViewPanel->changeImage(img);
638 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
639 _theViewPanel->setImageSlice(z);
643 void wxContourMainFrame::updateInstantAxes()
648 void wxContourMainFrame::onChangeDeep(int val){
649 _instantPanel->setConceptValue( "Axe Depth", (int)val );
654 void wxContourMainFrame::onCopy(){
655 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
657 std::vector<int> tempVector;
658 _instantPanel->getInstant( tempVector );
659 _performingOperation->reset();
660 _performingOperation->setStartCommand( COPY );
661 _performingOperation->setStartOperationInstantVector( tempVector );
662 _performingOperation->setKeyNamesOperationElems( currentSelection );
665 void wxContourMainFrame::onPaste(){
668 char theStartCommand = _performingOperation->getStartCommand();
669 if ( theStartCommand == COPY )
671 //JCP 20-10-08 Undo redo implementation
673 //JCP 20-10-08 Undo redo implementation
674 std::vector<int> tempVector;
675 _instantPanel->getInstant( tempVector );
676 _performingOperation->setEndOperationInstantVector ( tempVector );
677 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
678 int i,size = elems.size();
679 for( i=0; i<size; i++ )
681 createCopyContourOf( elems[i], tempVector, i>0 );
685 void wxContourMainFrame::onUndo(){
686 std::string filename;
687 if(kernelManager->onUndoSaveFile(filename)){
688 saveFileWithContours(filename);
690 if(kernelManager->onUndo(filename)){
694 void wxContourMainFrame::onRedo(){
695 std::string filename;
696 if(kernelManager->onRedo(filename)){
701 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
703 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
704 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
705 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
708 ///AD: 03-09 Copy the object and apply the given transformation
709 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
711 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
712 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
714 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
715 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
717 double pnt1X = refPoint1->GetX();
718 double pnt1Y = refPoint1->GetY();
719 // double pnt1Z = refPoint1->GetZ();
720 double pnt2X = refPoint2->GetX();
721 double pnt2Y = refPoint2->GetY();
722 // double pnt2Z = refPoint2->GetZ();
724 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
725 vtkTransform *t = vtkTransform::New();
729 t->Translate(-pnt1X, -pnt1Y, 0);
733 t->Translate(pnt1X, pnt1Y, 0);
736 int i,size=manualModel->GetSizeLstPoints();
739 manualPoint * mp = manualModel->GetManualPoint(i);
745 t->TransformPoint( vecIn, vecOut );
746 mp->SetPointX( vecOut[0] );
747 mp->SetPointY( vecOut[1] );
748 mp->SetPointZ( vecOut[2] );
751 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
754 void wxContourMainFrame ::loadState(std::string filename){
756 FILE *pFile=fopen(filename.c_str(),"r+");
758 fscanf(pFile,"%s",tmp); // --CreaContour--
760 fscanf(pFile,"%s",tmp); // Version
761 fscanf(pFile,"%s",tmp); // 1.0.1
762 std::string version(tmp);
766 openContours(pFile,false);
767 if (version!="1.0.0"){
768 openContours(pFile,true);
773 //_theViewPanel->getSceneManager()->removeSceneContours();
778 void wxContourMainFrame::onLoad(){
780 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
781 if (dialog.ShowModal() == wxID_OK)
783 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
784 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
786 fscanf(pFile,"%s",tmp); // --CreaContour--
788 fscanf(pFile,"%s",tmp); // Version
789 fscanf(pFile,"%s",tmp); // 1.0.1
790 std::string version(tmp);
792 openContours(pFile,false);
793 if (version!="1.0.0"){
794 openContours(pFile,true);
796 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
800 _theViewPanel->getSceneManager()->removeSceneContours();
803 void wxContourMainFrame::onSave(){
804 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
805 if (dialog.ShowModal() == wxID_OK)
807 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
808 kernelManager->setCurrentFileName(fileNameContourROI);
809 saveFileWithContours( fileNameContourROI );
812 void wxContourMainFrame::saveFileWithContours( std::string filename )
815 FILE *pFile=fopen(filename.c_str(),"w+");
816 std::vector< std::string > lstNameThings;
817 int i,sizeLstNameThings;
819 fprintf(pFile,"--CreaContour--\n");
820 fprintf(pFile,"Version %s\n", "1.0.1" );
823 lstNameThings = kernelManager->GetLstNameThings();
824 sizeLstNameThings = lstNameThings.size();
825 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
826 for (i=0 ; i<sizeLstNameThings ; i++)
828 kernelManager->SaveThingName( pFile, lstNameThings[i] );
829 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
832 //-- Contours Statics
833 lstNameThings = kernelManager->GetLstNameThingsStatic();
834 sizeLstNameThings = lstNameThings.size();
835 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
836 for (i=0 ; i<sizeLstNameThings ; i++)
838 kernelManager->SaveThingName( pFile, lstNameThings[i] );
839 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
844 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
846 fscanf(pFile,"%s",tmp); // NumberOfContours
847 fscanf(pFile,"%s",tmp); // ##
848 int numberOfContours = atoi(tmp);
850 std::vector<int> instantVector;
851 int typeContourModel;
852 manualContourModel *manModelContour;
856 for (i=0;i<numberOfContours;i++)
858 instantVector.clear();
859 fscanf(pFile,"%s",tmp); // Instant
861 fscanf(pFile,"%s",tmp); // 1
862 instantVector.push_back( atoi(tmp) );
863 fscanf(pFile,"%s",tmp); // 2
864 instantVector.push_back( atoi(tmp) );
865 fscanf(pFile,"%s",tmp); // 3
866 instantVector.push_back( atoi(tmp) );
867 fscanf(pFile,"%s",tmp); // 4
868 instantVector.push_back( atoi(tmp) );
869 fscanf(pFile,"%s",tmp); // 5
870 instantVector.push_back( atoi(tmp) );
871 fscanf(pFile,"%s",tmp); // 6
872 instantVector.push_back( atoi(tmp) );
875 fscanf(pFile,"%s",tmp); // TypeContourModel
876 fscanf(pFile,"%s",tmp); // ##
877 typeContourModel = atoi(tmp);
879 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
880 manModelContour->Open(pFile);
882 fscanf(pFile,"%s",tmp); // TypeView
883 fscanf(pFile,"%s",tmp); // ##
884 typeView = atoi(tmp);
893 theName = kernelManager->createOutline( manModelContour, instantVector );
894 bool addedModel = theName.compare("") != 0;
897 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
898 _theViewPanel->getSpacing(spc);
899 //Adding the manualContourControler to interface objects structure
900 //Adding the manualViewContour to interface objects structure
901 //_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.
902 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
905 if (staticContour==true)
907 Instant instant(&instantVector);
908 kernelManager->changeContourOfManager( theName , &instant );
911 }// for numberOfContours
915 void wxContourMainFrame::RefreshInterface(){
917 _theViewPanel->RefreshInterface();
918 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
919 //wxvtk2dbaseview->Refresh();
922 vtkImageData* wxContourMainFrame::getImageData(){
923 return _theViewPanel->getImageData();
926 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
928 //JCP 20-10-08 Undo redo implementation
930 //JCP 20-10-08 Undo redo implementation
933 int x = _theViewPanel->GetX();
934 int y = _theViewPanel->GetY();
935 int z = _theViewPanel->GetZ();
936 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
940 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
942 int typeofcontour = 1;
944 vtkImageData *imagedata = getImageData();
946 //Tipo de pixeles a utilizar internamente en ITK
947 typedef float InternalPixelType;
948 const unsigned int Dimension = 2;
949 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
951 //Tipo de pixeles de salida 1
952 typedef unsigned char OutputPixelType;
953 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
955 //Tipo de pixeles de salida 2
956 typedef unsigned short OutputPixelType2;
957 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
959 //DefiniciÛn del thresholder
960 typedef itk::BinaryThresholdImageFilter<
962 OutputImageType > ThresholdingFilterType;
964 //DefiniciÛn del primer filtro de conversiÛn de pixeles
965 typedef itk::CastImageFilter<
966 OutputImageType, OutputImageType2 > CastFilterType;
968 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
969 typedef itk::CastImageFilter<
970 OutputImageType2, InternalImageType > CastFilterType2;
972 //Tercer tipo de conversiÛn
973 typedef itk::RescaleIntensityImageFilter<
975 OutputImageType > CastFilterType3;
977 //Cuarto tipo de conversiÛn
978 typedef itk::RescaleIntensityImageFilter<
980 OutputImageType > CastFilterType4;
982 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
984 thresholder->SetLowerThreshold( 0.0 );
985 thresholder->SetUpperThreshold( 128 );
987 thresholder->SetOutsideValue( 255 );
988 thresholder->SetInsideValue( 0 );
990 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
991 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
992 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
993 typedef itk::ImageFileWriter< OutputImageType > WriterType;
995 ConnectorType::Pointer connector= ConnectorType::New();
996 ConnectorType2::Pointer connector2= ConnectorType2::New();
999 CastFilterType::Pointer filter=CastFilterType::New();
1000 CastFilterType2::Pointer filter2=CastFilterType2::New();
1002 connector->SetInput( imagedata );
1003 filter2->SetInput(connector->GetOutput());
1005 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1007 InternalImageType > SmoothingFilterType;
1009 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1011 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1013 InternalImageType > GradientFilterType;
1015 typedef itk::SigmoidImageFilter<
1017 InternalImageType > SigmoidFilterType;
1019 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1021 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1023 sigmoid->SetOutputMinimum( 0.0 );
1024 sigmoid->SetOutputMaximum( 255.0 );
1027 typedef itk::FastMarchingImageFilter<
1029 InternalImageType > FastMarchingFilterType;
1032 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1034 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1035 InternalImageType > GeodesicActiveContourFilterType;
1036 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1037 GeodesicActiveContourFilterType::New();
1039 typedef itk::ZeroCrossingImageFilter<
1041 InternalImageType > ZeroCrossingFilterType;
1042 ZeroCrossingFilterType::Pointer zeroCrossing =
1043 ZeroCrossingFilterType::New();
1045 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1047 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1048 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1049 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1051 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1052 int it=atoi( crea::wx2std(iter).c_str() );
1053 geodesicActiveContour->SetNumberOfIterations( it );
1055 smoothing->SetInput( filter2->GetOutput() );
1056 gradientMagnitude->SetInput( smoothing->GetOutput() );
1057 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1058 fastMarching->SetInput( sigmoid->GetOutput() );
1059 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1060 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1062 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1063 //thresholder->SetInput( zeroCrossing->GetOutput() );
1064 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1065 connector2->SetInput( thresholder->GetOutput() );
1068 smoothing->SetTimeStep( 0.125 );
1069 smoothing->SetNumberOfIterations( 5 );
1070 smoothing->SetConductanceParameter( 9.0 );
1073 const double sigma = atof( crea::wx2std(sigm).c_str() );
1074 gradientMagnitude->SetSigma( sigma );
1076 const double alpha = atof( crea::wx2std(alf).c_str() );
1077 const double beta = atof( crea::wx2std(bet).c_str() );
1079 sigmoid->SetAlpha( alpha );
1080 sigmoid->SetBeta( beta );
1082 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1083 typedef FastMarchingFilterType::NodeType NodeType;
1085 NodeContainer::Pointer seeds = NodeContainer::New();
1087 InternalImageType::IndexType seedPosition;
1088 seedPosition[0] = x;
1089 seedPosition[1] = y;
1091 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1095 const double seedValue = - initialDistance;
1097 node.SetValue( seedValue );
1098 node.SetIndex( seedPosition );
1100 seeds->Initialize();
1101 seeds->InsertElement( 0, node );
1103 fastMarching->SetTrialPoints( seeds );
1105 fastMarching->SetSpeedConstant( 1.0 );
1107 fastMarching->SetOutputSize(
1108 connector->GetOutput()->GetBufferedRegion().GetSize() );
1110 fastMarching->SetStoppingValue( 800 );
1114 connector2->Update();
1115 vtkImageData *idata = connector2->GetOutput();
1117 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1119 cntVTK->SetInput( idata );
1121 cntVTK->SetNumberOfContours( 1 );
1122 cntVTK->SetValue( 0, 255 );
1124 cntVTK->UpdateInformation();
1126 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1127 cpd->SetInput( cntVTK->GetOutput( ) );
1129 cpd->UpdateInformation();
1131 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1132 conn->SetExtractionModeToLargestRegion( );
1133 conn->SetInput( cpd->GetOutput( ) );
1135 conn->UpdateInformation();
1137 vtkStripper* vtkstripper = vtkStripper::New( );
1138 vtkstripper->SetInput( conn->GetOutput() );
1139 vtkstripper->Update();
1140 vtkstripper->UpdateInformation();
1143 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1144 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1145 polyDataResult->Update( );
1146 polyDataResult->UpdateInformation();
1151 myfile.open ("C:/Creatis/example.txt");
1153 polyDataResult->Print(myfile);
1154 myfile << "-------------------------------------\n";
1155 polyDataResult->GetLines()->Print(myfile);
1163 //--Calculating control points
1165 std::vector<double> vecX;
1166 std::vector<double> vecY;
1167 std::vector<double> vecXo;
1168 std::vector<double> vecYo;
1169 std::vector<double>::iterator vecXoi;
1170 std::vector<double>::iterator vecYoi;
1171 std::vector<double> vecZ;
1173 std::vector<double> vecCtrlPointX;
1174 std::vector<double> vecCtrlPointY;
1175 std::vector<double> vecCtrlPointZ;
1181 int ii,size=polyDataResult->GetNumberOfPoints();
1183 myfile.open ("C:/Creatis/example2.txt");
1185 size=polyDataResult->GetNumberOfPoints();
1186 for (ii=0;ii<size;ii++)
1193 p = polyDataResult->GetPoint(ii);
1196 /*if(fabs(yAct-y)>20)
1198 if((xAct-x)>1 || (xAct-x)<-1)
1200 vecX.push_back( p[0] );
1201 vecY.push_back( p[1] );
1202 myfile <<p[0]<<","<<p[1]<<"\n";
1203 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1204 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1205 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1206 vecZ.push_back( 900 );
1212 vecXo.push_back(p[0]);
1213 vecYo.push_back(p[1]);
1217 else*/ if(fabs(xAct-x)>11)
1219 vecXo.push_back(p[0]);
1220 vecYo.push_back(p[1]);
1224 vecX.push_back( p[0] );
1225 myfile <<p[0]<<","<<p[1]<<"\n";
1226 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1227 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1228 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1229 vecY.push_back( p[1] );
1230 vecZ.push_back( 900 );
1238 while(!vecXo.empty())
1240 vecX.push_back(vecXo.back());
1241 //std::cout<<" x Siguiente "<<vecXo.back();
1243 vecZ.push_back( 900 );
1245 while(!vecYo.empty())
1247 vecY.push_back(vecYo.back());
1252 /*for(int l=0;l<vecX.size();l++)
1256 vecXo.push_back(p[0]);
1257 vecYo.push_back(p[1]);
1268 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1270 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1274 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1276 else if (method==1){
1277 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1279 else if (method==2){
1280 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1281 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1283 //--Adding contour to the system
1285 std::vector<int> actualInstantVector;
1286 _instantPanel->getInstant( actualInstantVector );
1287 actualInstantVector[1]=z;
1289 int j,sizeCtrPt = vecCtrlPointX.size();
1291 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1292 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1294 for (j=0 ; j<sizeCtrPt ; j++)
1296 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1298 std::string theName;
1299 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1300 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1301 bool addedModel = theName.compare("") != 0;
1304 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1305 _theViewPanel->getSpacing(spc);
1306 //Adding the manualContourControler to interface objects structure
1307 //Adding the manualViewContour to interface objects structure
1308 //_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.
1309 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1310 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1316 WriterType::Pointer writer = WriterType::New();
1317 CastFilterType3::Pointer caster = CastFilterType3::New();
1319 caster->SetInput( gradientMagnitude->GetOutput() );
1320 writer->SetInput( caster->GetOutput() );
1321 writer->SetFileName("Gradient Magnitude.png");
1322 caster->SetOutputMinimum( 0 );
1323 caster->SetOutputMaximum( 255 );
1326 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1327 WriterType::Pointer writer2 = WriterType::New();
1329 caster2->SetInput( sigmoid->GetOutput() );
1330 writer2->SetInput( caster2->GetOutput() );
1331 writer2->SetFileName("Sigmoid.png");
1332 caster2->SetOutputMinimum( 0 );
1333 caster2->SetOutputMaximum( 255 );
1336 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1337 WriterType::Pointer writer3 = WriterType::New();
1339 caster3->SetInput( fastMarching->GetOutput() );
1340 writer3->SetInput( caster3->GetOutput() );
1341 writer3->SetFileName("FastMarching.bmp");
1342 caster3->SetOutputMinimum( 0 );
1343 caster3->SetOutputMaximum( 255 );
1346 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1347 WriterType::Pointer writer4 = WriterType::New();
1349 caster4->SetInput( geodesicActiveContour->GetOutput() );
1350 writer4->SetInput( caster4->GetOutput() );
1351 writer4->SetFileName("GeodesicActiveContour.png");
1352 caster4->SetOutputMinimum( 0 );
1353 caster4->SetOutputMaximum( 255 );
1356 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1357 WriterType::Pointer writer5 = WriterType::New();
1359 caster5->SetInput( zeroCrossing->GetOutput() );
1360 writer5->SetInput( caster5->GetOutput() );
1361 writer5->SetFileName("ZeroCrossing.bmp");
1362 caster5->SetOutputMinimum( 0 );
1363 caster5->SetOutputMaximum( 255 );
1366 catch( itk::ExceptionObject & excep )
1368 std::cerr << "Exception caught !" << std::endl;
1369 std::cerr << excep << std::endl;
1373 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1375 //JCP 20-10-08 Undo redo implementation
1377 //JCP 20-10-08 Undo redo implementation
1380 int x = _theViewPanel->GetX();
1381 int y = _theViewPanel->GetY();
1382 int z = _theViewPanel->GetZ();
1383 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1388 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1390 int typeofcontour = 1;
1391 //--Extracting Contour
1392 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1393 vtkImageData *imagedata = getImageData();
1394 // double *range = imagedata->GetScalarRange();
1397 vtkImageReslice *imageReslice = vtkImageReslice::New();
1400 // imagedata->GetSpacing(spc);
1405 imageReslice->SetInput( imagedata );
1406 imageReslice->SetInformationInput(imagedata);
1407 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1408 imageReslice->SetResliceAxesOrigin(0,0,z);
1409 imageReslice->SetOutputDimensionality(2);
1410 imageReslice->SetInterpolationModeToLinear();
1412 imagedata = imageReslice->GetOutput();
1413 imagedata->Update();
1414 imagedata->UpdateInformation();
1416 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1417 cntVTK->SetInput( imagedata );
1419 cntVTK->SetNumberOfContours( 1 );
1420 //cntVTK->SetValue( 0, vmin );
1421 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1422 cntVTK->SetValue( 1, isovalue );
1423 // cntVTK->SetValue( 1, vmax );
1425 cntVTK->UpdateInformation();
1427 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1428 cpd->SetInput( cntVTK->GetOutput( ) );
1429 cpd->ConvertLinesToPointsOff( );
1431 cpd->UpdateInformation();
1433 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1434 conn->SetExtractionModeToClosestPointRegion( );
1435 //conn->SetMaxRecursionDepth( 3000 );
1437 conn->SetInput( cpd->GetOutput( ) );
1439 conn->SetClosestPoint( x, y, 0 );
1441 conn->UpdateInformation();
1443 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1444 cpd2->SetInput( conn->GetOutput( ) );
1446 cpd2->UpdateInformation();
1448 vtkStripper* vtkstripper = vtkStripper::New( );
1449 vtkstripper->SetInput( cpd2->GetOutput() );
1450 vtkstripper->Update();
1451 vtkstripper->UpdateInformation();
1454 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1456 polyDataResult->Update( );
1457 polyDataResult->UpdateInformation();
1461 myfile.open ("c:/temp/example.txt");
1463 polyDataResult->Print(myfile);
1464 myfile << "-------------------------------------\n";
1465 polyDataResult->GetLines()->Print(myfile);
1475 //--Calculating control points
1477 std::vector<double> vecX;
1478 std::vector<double> vecY;
1479 std::vector<double> vecZ;
1481 std::vector<double> vecCtrlPointX;
1482 std::vector<double> vecCtrlPointY;
1483 std::vector<double> vecCtrlPointZ;
1487 int ii,size=polyDataResult->GetNumberOfPoints();
1489 for (ii=1;ii<=size;ii++)
1491 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1492 p = polyDataResult->GetPoint(id);
1495 vecX.push_back( p[0] );
1496 vecY.push_back( p[1] );
1497 vecZ.push_back( 900 );
1498 // vecZ.push_back( p[2] );
1502 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1503 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1506 /*if (methodRadiobox->GetSelection()==0){
1507 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1509 if (methodRadiobox->GetSelection()==1){
1510 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1512 if (methodRadiobox->GetSelection()==2){
1513 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1514 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1518 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1520 else if (method==1){
1521 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1523 else if (method==2){
1524 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1525 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1528 //--Adding contour to the system
1530 std::vector<int> actualInstantVector;
1531 _instantPanel->getInstant( actualInstantVector );
1532 actualInstantVector[1]=z;
1534 int j,sizeCtrPt = vecCtrlPointX.size();
1535 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1536 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1538 for (j=0 ; j<sizeCtrPt ; j++)
1540 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1542 std::string theName;
1543 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1544 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1545 bool addedModel = theName.compare("") != 0;
1548 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1549 _theViewPanel->getSpacing(spc);
1550 //Adding the manualContourControler to interface objects structure
1551 //Adding the manualViewContour to interface objects structure
1552 //_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.
1553 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1554 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1558 int wxContourMainFrame::GetImageDataSizeZ(){
1559 return _theViewPanel->GetImageDataSizeZ();
1562 void wxContourMainFrame::GetImageDataRange(double *range){
1563 _theViewPanel->GetImageDataRange(range);
1566 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1567 //JCP 20-10-08 Undo redo implementation
1569 //JCP 20-10-08 Undo redo implementation
1572 int x = _theViewPanel->GetX();
1573 int y = _theViewPanel->GetY();
1577 double totalZ = maxZ-minZ+1;
1578 for( z=minZ ; z<=maxZ ; z++ )
1580 porcent = 100.0* (z-minZ)/totalZ;
1581 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1582 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1583 //_staticTextSegmentation->SetLabel(tmpString);
1584 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1586 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1591 //Creates a reference line to be used as the axis of the mirroring
1592 void wxContourMainFrame::referenceLine()
1594 if (_refLineControl==NULL)
1599 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1600 vtkimagedata->GetSpacing(spc);
1602 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1604 _refLineControl = new manualLineControler();
1605 _refLineModel = new manualContourModelLine();
1606 _refLineView = new manualViewLine();
1607 _refLineView->SetModel( _refLineModel );
1608 _refLineView->SetWxVtkBaseView( viewer2D );
1609 _refLineView->SetRange( 2 );
1610 _refLineView->SetZ( 1200 );
1612 _refLineView->SetSpacing(spc);
1614 _refLineView->SetColorNormalContour(0, 0, 1);
1615 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1616 _refLineView->SetWidthLine(4);
1618 _refLineControl->SetModelView( _refLineModel , _refLineView );
1619 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1620 _refLineModel->SetCloseContour(false);
1621 _refLineControl->CreateNewManualContour();
1623 //EED?? double z = _refLineControl->GetZ();
1625 _refLineControl->AddPoint(50,100,z);
1626 _refLineControl->AddPoint(80,40,z);
1627 _refLineControl->SetCompleteCreation(true);
1629 _refLineModel->AddPoint(50,100,z);
1630 _refLineModel->AddPoint(80,40,z);
1631 _refLineModel->UpdateSpline();
1633 _refLineView->UpdateViewPoint(0);
1634 _refLineView->UpdateViewPoint(1);
1637 _refLineControl->SetActive(true);
1638 _refLineView->RefreshContour();
1642 //Hides the referenceLine
1643 void wxContourMainFrame::refLineHide()
1645 if (_refLineControl!=NULL)
1647 if (_refLineControl->GetActive())
1649 _refLineView->RemoveCompleteContourActor();
1650 _refLineControl->SetEditable(false);
1651 _refLineControl->SetActive(false);
1658 //Shows the referenceLine
1659 void wxContourMainFrame::refLineShow()
1661 if (_refLineControl!=NULL)
1663 if (_refLineControl->GetActive()==false)
1665 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1667 _refLineView->SetModel( _refLineModel );
1668 _refLineView->SetWxVtkBaseView( viewer2D );
1669 _refLineView->SetRange( 2 );
1670 _refLineView->SetZ( 1200 );
1672 _refLineControl->SetModelView( _refLineModel , _refLineView );
1673 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1674 _refLineControl->CreateNewManualContour();
1675 _refLineControl->SetActive(true);
1676 _refLineView->RefreshContour();
1683 void wxContourMainFrame::refLineChangeWidth(int width)
1685 _refLineView->SetWidthLine(width);
1686 _refLineView->RefreshContour();
1692 void wxContourMainFrame::onMirror()
1695 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1696 std::vector<std::string> filterCurrentSelection;
1698 std::vector<int> tempVector;
1699 _instantPanel->getInstant( tempVector );
1700 _performingOperation->reset();
1701 _performingOperation->setStartCommand( COPY );
1702 _performingOperation->setStartOperationInstantVector( tempVector );
1703 _performingOperation->setKeyNamesOperationElems( currentSelection );
1705 char theStartCommand = _performingOperation->getStartCommand();
1706 if ( theStartCommand == COPY )
1708 //JCP 20-10-08 Undo redo implementation
1710 //JCP 20-10-08 Undo redo implementation
1711 std::vector<int> tempVector;
1712 _instantPanel->getInstant( tempVector );
1713 _performingOperation->setEndOperationInstantVector ( tempVector );
1714 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1715 int i,size = elems.size();
1716 for( i=0; i<size; i++ )
1718 createMirrorContourOf( elems[i], tempVector, i>0 );
1722 //deleteContour( _refName );
1726 void wxContourMainFrame::onThreshold()
1728 int z = _theViewPanel->GetZ();
1731 vtkImageData * img = getImageData();
1732 img->GetScalarRange(range);
1734 int minTot = floor (range[0]);
1735 int maxTot = ceil (range[1]);
1738 _pannew->onThresholdInstantChange(minMax);
1739 int minVal = floor (minMax[0]);
1740 int maxVal = floor (minMax[1]);
1744 if (_imageReslicer==NULL)
1746 _imageReslicer = vtkImageReslice::New();
1747 _imageReslicer->SetInput( img );
1748 _imageReslicer->SetInformationInput(img);
1749 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1750 _imageReslicer->SetOutputDimensionality(2);
1751 _imageReslicer->SetInterpolationModeToLinear();
1754 _imageReslicer->SetResliceAxesOrigin(0,0,z);
1756 img = _imageReslicer->GetOutput();
1758 img->UpdateInformation();
1760 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1762 if (_thresholdTable==NULL)
1765 _thresholdTable = vtkLookupTable::New();
1766 _thresholdTable->SetNumberOfTableValues(maxTot+1);
1767 _thresholdTable->SetTableRange(range);
1768 _thresholdTable->SetAlphaRange(0, 1);
1769 _thresholdTable->SetValueRange(0, 1);
1770 _thresholdTable->SetSaturationRange(0, 0);
1771 _thresholdTable->SetRampToLinear( );
1774 //Assign a fake color for the upper image, and set the white as transparent
1776 for(i = minTot; i <= maxTot; i++)
1778 if( i >= minVal && i <= maxVal )
1780 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1782 else if( i >= minTot && i < minVal )
1784 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1786 else if( i > maxVal && i < maxTot )
1788 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1792 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1795 _thresholdTable->Build( );
1797 if (_thresholdMapper==NULL)
1799 _thresholdMapper = vtkImageMapToColors::New( );
1802 _thresholdMapper->SetLookupTable( _thresholdTable );
1803 _thresholdMapper->SetInput( img );
1805 if (_thresholdActor==NULL)
1807 _thresholdActor = vtkImageActor::New( );
1808 _thresholdActor->SetOpacity( 0.6 );
1809 _thresholdActor->InterpolateOn( );
1810 _thresholdActor->SetPosition( 0,0, 900-1 );
1813 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
1815 baseView->GetRenderer()->AddActor( _thresholdActor );
1816 _actorPresent = true;
1821 _imageReslicer->SetResliceAxesOrigin(0,0,z);
1822 img = _imageReslicer->GetOutput();
1824 img->UpdateInformation();
1826 //Assign a fake color for the upper image, and set the white as transparent
1828 for(i = minTot; i <= maxTot; i++)
1830 if( i >= minVal && i <= maxVal )
1832 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1834 else if( i >= minTot && i < minVal )
1836 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1838 else if( i > maxVal && i < maxTot )
1840 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1844 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1848 _thresholdTable->Build( );
1849 _thresholdMapper->SetLookupTable( _thresholdTable );
1850 _thresholdMapper->SetInput( img );
1851 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
1854 vtkImageViewer2* viewer = vtkImageViewer2::New();
1855 viewer->SetInput( upperImageActor->GetInput() );
1856 viewer->SetColorLevel((range[1]-range[0])/2);
1857 viewer->SetColorWindow(range[1]);
1858 viewer->GetRenderer()->AddActor( upperImageActor );
1861 _theViewPanel->RefreshInterface();
1865 void wxContourMainFrame::onThresholdChange()
1873 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
1875 if (_thresholdActor!=NULL)
1879 _thresholdActor->InterpolateOn( );
1884 _thresholdActor->InterpolateOff( );
1887 _theViewPanel->RefreshInterface();
1891 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
1895 _thresholdActor->SetOpacity(opacity*0.1);
1898 _theViewPanel->RefreshInterface();
1901 void wxContourMainFrame::onThresholdRemove()
1905 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1906 baseView->GetRenderer()->RemoveActor( _thresholdActor );
1907 _actorPresent = false;
1910 _theViewPanel->RefreshInterface();
1913 void wxContourMainFrame::showAxis(bool show)
1915 _theViewPanel->SetVisibleAxis(show);
1916 _theViewPanel->Refresh();
1920 void wxContourMainFrame::onRigidPressed(){
1921 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1922 int elementsSelected = currentSelection.size();
1924 if ( elementsSelected >= 1 ){
1925 //JCP 20-10-08 Undo redo implementation
1927 //JCP 20-10-08 Undo redo implementation
1929 std::vector<int> tempVector;
1930 _instantPanel->getInstant( tempVector );
1931 Instant instant(&tempVector);
1933 int i , size=currentSelection.size();
1934 for ( i=0 ; i<size ; i++ )
1936 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1941 void wxContourMainFrame::onWidthOfContour(double width){
1943 _theViewPanel->removeSceneContours();
1944 _theViewPanel->SetWidthContour(width);
1946 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1950 int wxContourMainFrame::getColorWindow(){
1951 return _theViewPanel->getColorWindow();
1953 int wxContourMainFrame::getWindowLevel(){
1954 return _theViewPanel->getWindowLevel();
1957 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1958 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1963 void wxContourMainFrame::onInterpolation(bool interpolate){
1964 _theViewPanel->onInterpolation(interpolate);
1968 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1969 _instantPanel->setConceptValue( name, actual );
1972 void wxContourMainFrame::resetAppend(){
1973 kernelManager->resetAppend();
1977 void wxContourMainFrame::onSpreadAdd(){
1978 std::vector<double> vecX;
1979 std::vector<double> vecY;
1980 std::vector<double> vecZ;
1981 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1983 std::vector<int> tempVector;
1984 _instantPanel->getInstant( tempVector );
1986 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1988 interfMainPanel::getInstance()->appendStringSpread(val);
1992 void wxContourMainFrame::onSpreadGo(int type){
1994 //JCP 20-10-08 Undo redo implementation
1996 //JCP 20-10-08 Undo redo implementation
1999 std::vector<double> vecCtrlPointX;
2000 std::vector<double> vecCtrlPointY;
2001 std::vector<double> vecCtrlPointZ;
2005 std::vector<int> tempVector;
2006 _instantPanel->getInstant( tempVector );
2009 kernelManager->getMaxMinZ(&minZ,&maxZ);
2010 //JSTG_16-07-08_----------------------------------------------------------------
2011 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2012 kernelManager->CalculeSplinePropagation();
2014 double totalZ = maxZ-minZ+1;
2017 //--------------------------------------------------------------------
2018 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2020 porcent = 100.0* (z-minZ)/totalZ;
2021 int numero = (int)(z-minZ+1)/(int)totalZ;
2022 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2024 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2026 int typeofcontour = 1;
2027 std::string theName;
2028 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2030 if( manModelContour!=NULL ){
2031 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2032 this->_theViewPanel->getSpacing(spc);
2033 //Adding the manualContourControler to interface objects structure
2034 //Adding the manualViewContour to interface objects structure
2035 //_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.
2036 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2041 int numero = (int)(z-minZ+1)/(int)totalZ;
2042 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2044 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2046 //RefreshInterface();
2049 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2053 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2054 std::vector<int> tempVector;
2055 _instantPanel->getInstant(tempVector);
2056 //Asignation of slide number should be different ex by name
2057 tempVector[1]=slide;
2058 return kernelManager->getOutlinesNameAtInstant(tempVector);
2061 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
2062 int maxContourGroup = 0;
2064 ContourExtractData *contourextractdata = new ContourExtractData();
2066 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2068 std::vector<manualContourModel*> lstManConMod;
2069 std::vector<manualContourModel*> lstManConModTmp;
2070 std::vector<manualContourModel*> lstManConModExp;
2071 std::vector<double> pLstValue;
2072 std::vector<double> pLstValuePosX;
2073 std::vector<double> pLstValuePosY;
2074 std::vector<double> pLstValuePosZ;
2077 int resultGrayRangeCount;
2080 double resultAverage;
2081 double resultStandardeviation;
2083 std::vector<int> tempVector;
2084 _instantPanel->getInstant( tempVector );
2086 vtkImageData *imagedata = _theViewPanel->getImageData();
2087 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2089 int ii,sizeLstContourThings;
2099 if (selection==0 ) // actual slice
2101 std::vector<int> tempVector;
2102 _instantPanel->getInstant( tempVector );
2103 int actualSlice = tempVector[1];
2107 else if (selection==2 ) // All slices
2112 else if (selection==1 ) // slice range
2119 totalZ = maxZ-minZ+1;
2120 contourextractdata->SetImage( imagedata);
2123 for ( z=minZ ; z<=maxZ ; z++ )
2126 porcent = 100.0* (z-minZ)/totalZ;
2127 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2129 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2130 //_staticTextInformation->SetLabel(tmpString);
2132 //Extraction data from contours of each slice
2133 contourextractdata->SetZtoBeAnalys( z);
2136 Instant instant(&tempVector);
2137 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2138 sizeLstContourThings = lstContourThings.size();
2140 lstManConMod.clear();
2141 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2143 ContourThing **contourthing = lstContourThings[ii];
2144 lstManConMod.push_back( (*contourthing)->getModel() );
2146 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2149 wxString tempString;
2150 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2151 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2152 //_grid->SetRowLabelValue(z, tempString );
2154 int iContourGroup,sizeContourGroup;
2155 if (typeContourGroup==3) // contour separete
2157 sizeContourGroup=lstManConModExp.size();
2158 if ( maxContourGroup<sizeContourGroup )
2160 maxContourGroup=sizeContourGroup;
2162 } else { // contour AND OR XOR
2171 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2172 lstManConModTmp.clear();
2173 if (typeContourGroup==3) // contour separete
2175 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2176 } else { // contour AND OR XOR
2177 lstManConModTmp = lstManConModExp;
2180 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2183 pLstValuePosX.clear();
2184 pLstValuePosY.clear();
2185 pLstValuePosZ.clear();
2186 contourextractdata->GetValuesInsideCrown( &pLstValue,
2190 // Statistics of each slice.
2191 contourextractdata->Statistics( &pLstValue,
2194 &resultGrayRangeCount,
2199 &resultStandardeviation);
2201 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2203 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2206 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2208 tempString.Printf(_T("%d"),resultSize);
2209 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2211 tempString.Printf(_T("%d"),resultGrayRangeCount);
2212 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2214 tempString.Printf(_T("%f"),resultMin);
2215 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2217 tempString.Printf(_T("%f"),resultMax);
2218 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2220 tempString.Printf(_T("%f"),resultAverage);
2221 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2223 tempString.Printf(_T("%f"),resultStandardeviation);
2224 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2227 } // for iContourGroup
2231 wxString tmpTitleString;
2233 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2235 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2236 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2237 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2239 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2240 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2241 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2242 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2243 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2244 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2245 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2248 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2249 delete contourextractdata;
2252 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2253 SaveValuesXYZ( directory , namefile, typeContourGroup );
2255 vtkImageData* mask, *value;
2256 this->getMaskValue(mask, value, typeContourGroup);
2257 this->SaveImageResult( directory , namefile, mask, value);
2260 FILE *pFile=fopen(filename.c_str(),"w+");
2262 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2265 int i,j,maxX,maxY=sizeZ;
2266 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2268 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2269 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2271 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2272 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2274 fprintf(pFile,"\n" );
2278 for ( j=0; j<maxY ; j++)
2280 fprintf(pFile,"%d\t" , j );
2281 for (i=0 ; i<maxX ; i++){
2282 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2283 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2285 fprintf(pFile,"\n" );
2291 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2294 ContourExtractData *contourextractdata = new ContourExtractData();
2295 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2296 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2298 std::vector<manualContourModel*> lstManConMod;
2299 std::vector<manualContourModel*> lstManConModTmp;
2300 std::vector<manualContourModel*> lstManConModExp;
2301 std::vector<double> pLstValue;
2302 std::vector<double> pLstValuePosX;
2303 std::vector<double> pLstValuePosY;
2304 std::vector<double> pLstValuePosZ;
2306 std::vector<int> tempVector;
2307 _instantPanel->getInstant( tempVector );
2309 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2310 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2312 int ii,sizeLstContourThings;
2319 minZ = 0;// _mbarrange->GetStart();
2320 maxZ = sizeZ;//_mbarrange->GetEnd();
2321 totalZ = maxZ-minZ+1;
2323 contourextractdata->SetImage( imagedata);
2326 for ( z=0 ; z<sizeZ ; z++)
2329 porcent = 100.0* (z-minZ)/totalZ;
2331 tmpString.Printf(_T("Saving Values"));
2332 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2333 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2334 //_staticTextInformation->SetLabel(tmpString);
2337 //Extraction data from contours of each slice
2338 contourextractdata->SetZtoBeAnalys( z);
2341 Instant instant(&tempVector);
2342 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2343 sizeLstContourThings = lstContourThings.size();
2345 lstManConMod.clear();
2346 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2348 ContourThing **contourthing = lstContourThings[ii];
2349 lstManConMod.push_back( (*contourthing)->getModel() );
2351 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2356 int iContourGroup,sizeContourGroup;
2357 if (typeContourGroup==3) // contour separete
2359 sizeContourGroup=lstManConModExp.size();
2360 } else { // contour AND OR XOR
2364 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2365 lstManConModTmp.clear();
2366 if (typeContourGroup==3) // contour separete
2368 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2369 } else { // contour AND OR XOR
2370 lstManConModTmp = lstManConModExp;
2373 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2376 pLstValuePosX.clear();
2377 pLstValuePosY.clear();
2378 pLstValuePosZ.clear();
2379 contourextractdata->GetValuesInsideCrown( &pLstValue,
2384 std::string temp = directory + "/" + namefile + "-slice";
2385 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2386 temp = temp + ".txt";
2388 // LG 14/01/09 : using crea
2389 wxString filename = crea::std2wx(temp);
2390 /*filename.Printf(_T("%s"),directory.c_str());
2391 filename.append(_T("\\"));
2392 filename.append(_T("%s"),namefile.c_str());
2393 filename.append(_T("-slice"));
2394 filename.append(_T("%d"),z);
2395 filename.append(_T("-cont"));
2396 filename.append(_T("%d"),iContourGroup);
2397 filename.append(_T(".txt"));*/
2398 // filename.Printf(temp.c_str());
2402 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2403 fprintf(pFile,"value \t x \t y \t z\n" );
2404 int iLstValue,sizeLstValue=pLstValue.size();
2405 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2407 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2410 } // for iContourGroup
2412 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2413 //_staticTextInformation->SetLabel( _T("") );
2414 delete contourextractdata;
2417 void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){
2419 ContourExtractData *contourextractdata = new ContourExtractData( true );
2420 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2421 if (typeContourGroup==3)
2425 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2427 std::vector<manualContourModel*> lstManConMod;
2428 std::vector<manualContourModel*> lstManConModTmp;
2429 std::vector<manualContourModel*> lstManConModExp;
2431 std::vector<int> tempVector;
2432 _instantPanel->getInstant( tempVector );
2434 vtkImageData *imagedata = _theViewPanel->getImageData();
2435 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2437 int ii,sizeLstContourThings;
2446 minZ = 0;// _mbarrange->GetStart();
2447 maxZ = sizeZ;//_mbarrange->GetEnd();
2448 totalZ = maxZ-minZ+1;
2450 contourextractdata->SetImage( imagedata);
2453 for ( z=0 ; z<sizeZ ; z++)
2456 porcent = 100.0* (z-minZ)/totalZ;
2457 tmpString.Printf(_T("Saving Values"));
2458 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2459 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2461 //Extraction data from contours of each slice
2462 contourextractdata->SetZtoBeAnalys( z);
2465 Instant instant(&tempVector);
2466 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2467 sizeLstContourThings = lstContourThings.size();
2469 lstManConMod.clear();
2470 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2472 ContourThing **contourthing = lstContourThings[ii];
2473 lstManConMod.push_back( (*contourthing)->getModel() );
2475 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2478 int iContourGroup,sizeContourGroup;
2479 if (typeContourGroup==3) // contour separete
2481 sizeContourGroup=lstManConModExp.size();
2482 } else { // contour AND OR XOR
2486 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2487 lstManConModTmp.clear();
2488 if (typeContourGroup==3) // contour separete
2490 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2491 } else { // contour AND OR XOR
2492 lstManConModTmp = lstManConModExp;
2495 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2496 contourextractdata->CalculateImageResult(); // with actual Z
2498 } // for iContourGroup
2501 value = contourextractdata->GetVtkImageValueResult();
2502 mask = contourextractdata->GetVtkImageMaskResult();
2503 delete contourextractdata;
2506 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2509 std::string temp = directory + "/" + namefile + "-Value.mhd";
2511 wxString filename = crea::std2wx(temp);
2513 // filename.Printf(_T(temp.c_str()));
2514 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2515 /*filename.Printf(_T("%s"),directory.c_str());
2516 filename.append(_T("\\"));
2517 filename.append(_T("%s"),namefile.c_str());
2518 filename.append(_T("-Value.mhd"));*/
2521 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2522 writerValueImage->SetInput( value );
2523 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2524 writerValueImage->SetFileDimensionality( 3 );
2525 writerValueImage->Write( );
2528 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2529 temp = directory + "/" + namefile + "-Mask.mhd";
2531 // LG 14/01/09 : using crea
2532 filename = crea::std2wx(temp);
2533 // filename.Printf(_T(temp.c_str()));
2535 /*filename.Printf(_T("%s"),directory.c_str());
2536 filename.append(_T("\\"));
2537 filename.append(_T("%s"),namefile.c_str());
2538 filename.append(_T("-Mask.mhd"));*/
2540 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2541 writerMaskImage->SetInput( mask );
2542 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2543 writerMaskImage->SetFileDimensionality( 3 );
2544 writerMaskImage->Write( );
2546 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2552 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2553 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2554 _theViewPanel->setActualVertical( value);
2556 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2557 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2563 void wxContourMainFrame::onSnakePressed(){
2564 std::vector<double> vecX;
2565 std::vector<double> vecY;
2566 std::vector<double> vecZ;
2567 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2569 if (vecX.size()!=0){
2570 std::vector<int> tempVector;
2571 _instantPanel->getInstant( tempVector );
2572 int i,size=vecZ.size();
2573 int actualSlice = tempVector[1];
2574 for ( i=0 ; i<size ; i++ )
2576 vecZ[i] = actualSlice;
2579 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2580 wxPanel* panel = new wxPanel(dialog,-1);
2581 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2582 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2583 dialog->ShowModal();
2588 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2589 std::string filename = kernelManager->getCurrentFileName();
2590 if(filename.compare("")!=0){
2591 saveFileWithContours(filename);
2596 void wxContourMainFrame::ShowToolsPanel(bool show){
2597 _pannew->Show(show);