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;
62 // set up default notebook style
63 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
64 // m_notebook_theme = 0;
65 //wxContour_ActionCommandsID a;
69 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
70 : wxPanel(parent, id, pos, size, style)
72 m_mgr.SetManagedWindow(this);
73 _creatingContoursActive = false;
77 _refLineControl = NULL;
81 // set up default notebook style
82 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
84 //wxContour_ActionCommandsID a;
85 _numberOfVariablesStatistics = 7;
93 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
94 _performingOperation = new PerformingOperation();
98 this->setVectImages(images);
103 void wxContourMainFrame::setVectImages( std::vector<vtkImageData*> images ){
105 #if defined(__GNUC__)
106 std::string str_home(getenv("HOME"));
107 #elif defined(_WIN32)
108 std::string str_home(getenv("USERPROFILE"));
110 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
112 std::vector<std::string> conceptNameVect;
113 std::vector<int> conceptSizeVect;
115 wxAuiNotebook * notebook = this->createNotebook();
118 kernelManager = new KernelManagerContour( images , _datadir+"/data/" , strCreaContourDataTmp );
121 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
122 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
124 //-------------------------------------------------------------
125 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
126 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
129 double val = _theViewPanel->getCurrentDeep();
130 _instantPanel->setConceptValue( "Axe Depth", (int)val );
131 //JCP _instantPanel->setConceptValue("time", num de imagenes);
132 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
133 //*******************changeInstant();
134 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
136 this->configurePanels( notebook );
141 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 ){
142 if(instance == NULL){
143 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
148 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
150 return kernelManager->getVectImages();
153 wxContourMainFrame* wxContourMainFrame :: getInstance()
158 void wxContourMainFrame :: resetInstance()
164 wxContourMainFrame :: ~wxContourMainFrame()
168 interfMainPanel::resetInstance();
169 //_pannew->Destroy();
175 //El problema al cerrar la aplicacion puede estar asociado
176 //a que wxAUINotebook esta en la aplicacion
177 //principal (wxContourGUIExample)tambien
178 //EED???? delete _theViewPanel;
179 //EED???? delete _instantPanel;
180 //EED???? delete _buttonsBar;
181 //EED???? delete _actualInstant;
182 //EED???? delete _sceneManager;
186 //------------------------------------------------------------------------------------------------------------
187 // Creational and initialization methods using WxAui
188 //------------------------------------------------------------------------------------------------------------
190 wxAuiNotebook * wxContourMainFrame :: createNotebook()
192 wxSize client_size = GetClientSize();
193 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
194 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
199 //------------------------------------------------------------------------------------------------------------
200 // Creational and initialization methods
201 //------------------------------------------------------------------------------------------------------------
202 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
204 bool configured = _theViewPanel!=NULL;
206 configured &= _theViewPanel!=NULL;
207 if( _theViewPanel!=NULL )
209 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
216 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
220 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
222 /* configured &= _buttonsBar!=NULL;
223 if( _buttonsBar!=NULL )
225 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
226 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
228 LeftDockable( ).RightDockable( false ).CloseButton(false));
233 SetMinSize(wxSize(300,300));
238 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
243 //------------------------------------------------------------------------------------------------------------
244 // Attributes getters and setters
245 //------------------------------------------------------------------------------------------------------------
249 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
251 _instantPanel = theInstantChooserPanel;
254 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
256 // _buttonsBar = theButtonsBar;
259 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
261 // _gridPanel = theGridPanel;
264 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
266 // _drawToolsPanel = theDrawToolsPanel;
269 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
271 // _operationsToolsPanel = theOperationsToolsPanel;
274 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
276 // _autoFormsPanel = theAutoFormsPanel;
279 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
281 // _standardToolsPanel= theStandardToolsPanel;
284 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
286 // _editionToolsPanel = theEditionToolsPanel;
289 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
291 // _listViewPanel = theListViewPanel;
296 void wxContourMainFrame::onCreateContourSpline( ){
298 //JCP 20-10-08 Undo redo implementation
300 //JCP 20-10-08 Undo redo implementation
304 void wxContourMainFrame::onCreateContourRectangle( ){
305 //JCP 20-10-08 Undo redo implementation
307 //JCP 20-10-08 Undo redo implementation
310 void wxContourMainFrame::onCreateContourCircle( ){
311 //JCP 20-10-08 Undo redo implementation
313 //JCP 20-10-08 Undo redo implementation
317 void wxContourMainFrame::onCreateContourLine( ){
318 //JCP 20-10-08 Undo redo implementation
320 //JCP 20-10-08 Undo redo implementation
324 //------------------------------------------------------------------------------------------------------------
326 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
328 //Creating the manualContourModel and including in the model
329 manualContourModel * manModelContour = factoryManualContourModel(panel );
331 std::vector<int> instantVector;
332 _instantPanel->getInstant( instantVector );
333 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
335 /*std::vector<int> instantVector;
336 _instantPanel->getInstant( instantVector );
338 theName= _modelManager->createOutline( manModelContour, instantVector );*/
339 bool addedModel = theName.compare("") != 0;//??
343 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
344 _theViewPanel->getSpacing(spc);
345 //Adding the manualContourControler to interface objects structure
346 //Adding the manualViewContour to interface objects structure
347 //_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.
348 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
351 void wxContourMainFrame :: createContour( int typeContour )
353 //Creating the manualContourModel and including in the model
354 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
357 std::vector<int> instantVector;
358 _instantPanel->getInstant( instantVector );
359 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
361 /*std::vector<int> instantVector;
362 _instantPanel->getInstant( instantVector );
364 theName= _modelManager->createOutline( manModelContour, instantVector );*/
365 bool addedModel = theName.compare("") != 0;//??
368 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
369 _theViewPanel->getSpacing(spc);
370 //Adding the manualContourControler to interface objects structure
371 //Adding the manualViewContour to interface objects structure
372 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
373 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
377 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
379 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
380 manualContourModel *manModelContour=NULL;
381 manModelContour = manModelContourBullEye;
383 int iCrown,sizeCrowns,iSector,sizeSectors;
384 double radioA,radioB,ang,angDelta ;
385 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
386 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
388 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
389 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
390 if (iCrown==sizeCrowns-1)
394 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
398 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
400 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
401 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
402 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
405 } // if _panelBullEyeOptions
407 return manModelContour;
409 void wxContourMainFrame :: saveState(){
411 std::string temp = kernelManager->saveState();
412 saveFileWithContours(temp);
415 void wxContourMainFrame::onDeleteContour(){
416 //JCP 20-10-08 Undo redo implementation
418 //JCP 20-10-08 Undo redo implementation
420 std::vector<std::string> lstKeyNameToBeErase;
421 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
422 deleteContours( lstKeyNameToBeErase );
424 int i,size=_sceneManager->getSelectedObjects().size();
427 std::string keyName = _sceneManager->getSelectedObjects()[i];
428 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
429 if ( ispartofstaticlist>=0 )
431 std::vector<int> tempVector;
432 _instantPanel->getInstant( tempVector );
433 Instant instant(&tempVector);
434 this->_modelManager->ChangeContourOfList(keyName, &instant);
438 std::vector<std::string> lstKeyName;
439 std::vector<std::string> lstKeyNameActualSlice;
440 std::vector<std::string> lstKeyNameToBeErase;
442 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
443 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
444 int k,kSize=lstKeyNameToBeErase.size();
445 int j,jSize=lstKeyNameActualSlice.size();
447 for (k=0;k<kSize; k++)
450 for (j=0;j<jSize; j++)
452 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
459 lstKeyName.push_back( lstKeyNameToBeErase[k] );
463 deleteContours( lstKeyName );
467 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
469 int i,size=keyNamesVector.size();
472 deleteContour( keyNamesVector[i] );
476 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
478 manualContourModel * cModel;
479 manualViewBaseContour * cViewer;
480 manualContourBaseControler * cControler;
482 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
483 cControler = conwrapviewControl->getControler();*/
486 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
487 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
489 if (isedit && ispartofstaticlst)
491 _theViewPanel->removeFromScene(theKeyName);
493 kernelManager->deleteCModel(theKeyName);
494 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
495 //cViewer = conwrapviewControl->getViewer();
496 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
497 //cControler* conwrapviewControl->getControler();
499 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
500 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
501 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
505 // delete cControler;
510 void wxContourMainFrame::onDeleteContoursActSlice(){
511 //JCP 20-10-08 Undo redo implementation
513 //JCP 20-10-08 Undo redo implementation
514 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
516 void wxContourMainFrame::onDeleteAllContours(){
517 //JCP 20-10-08 Undo redo implementation
521 void wxContourMainFrame::deleteAllContours(){
522 //JCP 20-10-08 Undo redo implementation
525 std::vector<int> tempVector;
526 _instantPanel->getInstant( tempVector );
528 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
529 // the values in GetStart and GetEnd will then not be initialize also.
530 // We use instead the values given when initializing the _deletepanel.
532 //int minZ = _mbarrangeDeleteAll->GetStart();
533 //int maxZ = _mbarrangeDeleteAll->GetEnd();
537 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
541 _theViewPanel->getSceneManager()->removeSceneContours( );
542 _theViewPanel->getSceneManager()->removeAllOutlines();
543 kernelManager->removeAllOutlines();
546 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
548 _theViewPanel->getSceneManager()->removeSceneContours( );
549 _modelManager->removeAllOutlines();
550 _theViewPanel->getSceneManager()->removeAllOutlines();
553 for ( z=minZ ; z<=maxZ ; z++)
556 Instant instant(&tempVector);
557 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
559 sizeLstContourThings = lstContourThings.size();
560 for (ii=0 ; ii<sizeLstContourThings ; ii++)
562 ContourThing **contourthing = lstContourThings[ii];
563 deleteContour( (*contourthing)->getName() );
570 void wxContourMainFrame::setConceptValue( std::string name, int value ){
571 _instantPanel->setConceptValue(name, value);
574 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
575 return _instantPanel->getLastConceptData();
577 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
578 return _instantPanel->getIfConceptCheckedAt( name, pos );
581 void wxContourMainFrame::changeInstant()
583 std::vector<int> instantVect;
584 _instantPanel->getInstant( instantVect );
585 // Instant * theInstant = new Instant ( &instantVect );
587 //Setting the actual instant
588 //_actualInstant = theInstant;
590 kernelManager->setInstant(instantVect);
591 //_modelManager->setInstant( _actualInstant );
593 updateInstantOutlines();
594 updateInstantImageData();
599 void wxContourMainFrame :: updateInstantOutlines(){
601 _theViewPanel->removeSceneContours();
602 _theViewPanel->addNameWrapperToScene();
604 //for( int i=0; i<size; i++)
606 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
610 int wxContourMainFrame::getNamesWrappingSize(){
611 return kernelManager->getNamesWrappingSize();
613 std::string wxContourMainFrame::getNameWrapping(int i){
614 return kernelManager->getNameWrapping(i);
617 void wxContourMainFrame::updateInstantImageData(){
618 std::vector<int> inst;
619 _instantPanel->getInstant(inst);
621 vtkImageData* img = kernelManager->getImageAtInstant(inst);
623 _theViewPanel->changeImage(img);
626 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
627 _theViewPanel->setImageSlice(z);
631 void wxContourMainFrame::updateInstantAxes(){
634 void wxContourMainFrame::onChangeDeep(int val){
635 _instantPanel->setConceptValue( "Axe Depth", (int)val );
640 void wxContourMainFrame::onCopy(){
641 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
643 std::vector<int> tempVector;
644 _instantPanel->getInstant( tempVector );
645 _performingOperation->reset();
646 _performingOperation->setStartCommand( COPY );
647 _performingOperation->setStartOperationInstantVector( tempVector );
648 _performingOperation->setKeyNamesOperationElems( currentSelection );
651 void wxContourMainFrame::onPaste(){
654 char theStartCommand = _performingOperation->getStartCommand();
655 if ( theStartCommand == COPY )
657 //JCP 20-10-08 Undo redo implementation
659 //JCP 20-10-08 Undo redo implementation
660 std::vector<int> tempVector;
661 _instantPanel->getInstant( tempVector );
662 _performingOperation->setEndOperationInstantVector ( tempVector );
663 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
664 int i,size = elems.size();
665 for( i=0; i<size; i++ )
667 createCopyContourOf( elems[i], tempVector, i>0 );
671 void wxContourMainFrame::onUndo(){
672 std::string filename;
673 if(kernelManager->onUndoSaveFile(filename)){
674 saveFileWithContours(filename);
676 if(kernelManager->onUndo(filename)){
680 void wxContourMainFrame::onRedo(){
681 std::string filename;
682 if(kernelManager->onRedo(filename)){
687 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
689 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
690 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
691 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
694 ///AD: 03-09 Copy the object and apply the given transformation
695 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
697 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
698 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
700 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
701 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
703 double pnt1X = refPoint1->GetX();
704 double pnt1Y = refPoint1->GetY();
705 // double pnt1Z = refPoint1->GetZ();
706 double pnt2X = refPoint2->GetX();
707 double pnt2Y = refPoint2->GetY();
708 // double pnt2Z = refPoint2->GetZ();
710 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
711 vtkTransform *t = vtkTransform::New();
715 t->Translate(-pnt1X, -pnt1Y, 0);
719 t->Translate(pnt1X, pnt1Y, 0);
722 int i,size=manualModel->GetSizeLstPoints();
725 manualPoint * mp = manualModel->GetManualPoint(i);
731 t->TransformPoint( vecIn, vecOut );
732 mp->SetPointX( vecOut[0] );
733 mp->SetPointY( vecOut[1] );
734 mp->SetPointZ( vecOut[2] );
737 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
740 void wxContourMainFrame ::loadState(std::string filename){
742 FILE *pFile=fopen(filename.c_str(),"r+");
744 fscanf(pFile,"%s",tmp); // --CreaContour--
746 fscanf(pFile,"%s",tmp); // Version
747 fscanf(pFile,"%s",tmp); // 1.0.1
748 std::string version(tmp);
752 openContours(pFile,false);
753 if (version!="1.0.0"){
754 openContours(pFile,true);
759 //_theViewPanel->getSceneManager()->removeSceneContours();
764 void wxContourMainFrame::onLoad(){
766 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
767 if (dialog.ShowModal() == wxID_OK)
769 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
770 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
772 fscanf(pFile,"%s",tmp); // --CreaContour--
774 fscanf(pFile,"%s",tmp); // Version
775 fscanf(pFile,"%s",tmp); // 1.0.1
776 std::string version(tmp);
778 openContours(pFile,false);
779 if (version!="1.0.0"){
780 openContours(pFile,true);
782 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
786 _theViewPanel->getSceneManager()->removeSceneContours();
789 void wxContourMainFrame::onSave(){
790 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
791 if (dialog.ShowModal() == wxID_OK)
793 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
794 kernelManager->setCurrentFileName(fileNameContourROI);
795 saveFileWithContours( fileNameContourROI );
798 void wxContourMainFrame::saveFileWithContours( std::string filename ){
800 FILE *pFile=fopen(filename.c_str(),"w+");
801 std::vector< std::string > lstNameThings;
802 int i,sizeLstNameThings;
804 fprintf(pFile,"--CreaContour--\n");
805 fprintf(pFile,"Version %s\n", "1.0.1" );
808 lstNameThings = kernelManager->GetLstNameThings();
809 sizeLstNameThings = lstNameThings.size();
810 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
811 for (i=0 ; i<sizeLstNameThings ; i++)
813 kernelManager->SaveThingName( pFile, lstNameThings[i] );
814 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
817 //-- Contours Statics
818 lstNameThings = kernelManager->GetLstNameThingsStatic();
819 sizeLstNameThings = lstNameThings.size();
820 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
821 for (i=0 ; i<sizeLstNameThings ; i++)
823 kernelManager->SaveThingName( pFile, lstNameThings[i] );
824 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
829 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
831 fscanf(pFile,"%s",tmp); // NumberOfContours
832 fscanf(pFile,"%s",tmp); // ##
833 int numberOfContours = atoi(tmp);
835 std::vector<int> instantVector;
836 int typeContourModel;
837 manualContourModel *manModelContour;
841 for (i=0;i<numberOfContours;i++)
843 instantVector.clear();
844 fscanf(pFile,"%s",tmp); // Instant
846 fscanf(pFile,"%s",tmp); // 1
847 instantVector.push_back( atoi(tmp) );
848 fscanf(pFile,"%s",tmp); // 2
849 instantVector.push_back( atoi(tmp) );
850 fscanf(pFile,"%s",tmp); // 3
851 instantVector.push_back( atoi(tmp) );
852 fscanf(pFile,"%s",tmp); // 4
853 instantVector.push_back( atoi(tmp) );
854 fscanf(pFile,"%s",tmp); // 5
855 instantVector.push_back( atoi(tmp) );
856 fscanf(pFile,"%s",tmp); // 6
857 instantVector.push_back( atoi(tmp) );
860 fscanf(pFile,"%s",tmp); // TypeContourModel
861 fscanf(pFile,"%s",tmp); // ##
862 typeContourModel = atoi(tmp);
864 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
865 manModelContour->Open(pFile);
867 fscanf(pFile,"%s",tmp); // TypeView
868 fscanf(pFile,"%s",tmp); // ##
869 typeView = atoi(tmp);
878 theName = kernelManager->createOutline( manModelContour, instantVector );
879 bool addedModel = theName.compare("") != 0;
882 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
883 _theViewPanel->getSpacing(spc);
884 //Adding the manualContourControler to interface objects structure
885 //Adding the manualViewContour to interface objects structure
886 //_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.
887 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
890 if (staticContour==true)
892 Instant instant(&instantVector);
893 kernelManager->changeContourOfManager( theName , &instant );
896 }// for numberOfContours
900 void wxContourMainFrame::RefreshInterface(){
902 _theViewPanel->RefreshInterface();
903 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
904 //wxvtk2dbaseview->Refresh();
907 vtkImageData* wxContourMainFrame::getImageData(){
908 return _theViewPanel->getImageData();
911 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
913 //JCP 20-10-08 Undo redo implementation
915 //JCP 20-10-08 Undo redo implementation
918 int x = _theViewPanel->GetX();
919 int y = _theViewPanel->GetY();
920 int z = _theViewPanel->GetZ();
921 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
925 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
928 int typeofcontour = 1;
930 vtkImageData *imagedata = getImageData();
932 //Tipo de pixeles a utilizar internamente en ITK
933 typedef float InternalPixelType;
934 const unsigned int Dimension = 2;
935 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
937 //Tipo de pixeles de salida 1
938 typedef unsigned char OutputPixelType;
939 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
941 //Tipo de pixeles de salida 2
942 typedef unsigned short OutputPixelType2;
943 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
945 //Definición del thresholder
946 typedef itk::BinaryThresholdImageFilter<
948 OutputImageType > ThresholdingFilterType;
950 //Definición del primer filtro de conversión de pixeles
951 typedef itk::CastImageFilter<
952 OutputImageType, OutputImageType2 > CastFilterType;
954 //Definición del segundo tipo de conversión de pixeles
955 typedef itk::CastImageFilter<
956 OutputImageType2, InternalImageType > CastFilterType2;
958 //Tercer tipo de conversión
959 typedef itk::RescaleIntensityImageFilter<
961 OutputImageType > CastFilterType3;
963 //Cuarto tipo de conversión
964 typedef itk::RescaleIntensityImageFilter<
966 OutputImageType > CastFilterType4;
968 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
970 thresholder->SetLowerThreshold( 0.0 );
971 thresholder->SetUpperThreshold( 128 );
973 thresholder->SetOutsideValue( 255 );
974 thresholder->SetInsideValue( 0 );
976 //Definción de conexiónes entre VTK e ITK y el writer
977 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
978 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
979 typedef itk::ImageFileWriter< OutputImageType > WriterType;
981 ConnectorType::Pointer connector= ConnectorType::New();
982 ConnectorType2::Pointer connector2= ConnectorType2::New();
985 CastFilterType::Pointer filter=CastFilterType::New();
986 CastFilterType2::Pointer filter2=CastFilterType2::New();
988 connector->SetInput( imagedata );
989 filter2->SetInput(connector->GetOutput());
991 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
993 InternalImageType > SmoothingFilterType;
995 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
997 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
999 InternalImageType > GradientFilterType;
1001 typedef itk::SigmoidImageFilter<
1003 InternalImageType > SigmoidFilterType;
1005 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1007 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1009 sigmoid->SetOutputMinimum( 0.0 );
1010 sigmoid->SetOutputMaximum( 255.0 );
1013 typedef itk::FastMarchingImageFilter<
1015 InternalImageType > FastMarchingFilterType;
1018 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1020 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1021 InternalImageType > GeodesicActiveContourFilterType;
1022 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1023 GeodesicActiveContourFilterType::New();
1025 typedef itk::ZeroCrossingImageFilter<
1027 InternalImageType > ZeroCrossingFilterType;
1028 ZeroCrossingFilterType::Pointer zeroCrossing =
1029 ZeroCrossingFilterType::New();
1031 const double propagationScaling = atof( prop );
1033 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1034 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1035 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1037 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1038 int it=atoi( iter );
1039 geodesicActiveContour->SetNumberOfIterations( it );
1041 smoothing->SetInput( filter2->GetOutput() );
1042 gradientMagnitude->SetInput( smoothing->GetOutput() );
1043 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1044 fastMarching->SetInput( sigmoid->GetOutput() );
1045 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1046 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1048 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1049 //thresholder->SetInput( zeroCrossing->GetOutput() );
1050 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1051 connector2->SetInput( thresholder->GetOutput() );
1054 smoothing->SetTimeStep( 0.125 );
1055 smoothing->SetNumberOfIterations( 5 );
1056 smoothing->SetConductanceParameter( 9.0 );
1059 const double sigma = atof( sigm );
1060 gradientMagnitude->SetSigma( sigma );
1062 const double alpha = atof( alf );
1063 const double beta = atof( bet );
1065 sigmoid->SetAlpha( alpha );
1066 sigmoid->SetBeta( beta );
1068 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1069 typedef FastMarchingFilterType::NodeType NodeType;
1071 NodeContainer::Pointer seeds = NodeContainer::New();
1073 InternalImageType::IndexType seedPosition;
1074 seedPosition[0] = x;
1075 seedPosition[1] = y;
1077 const double initialDistance = atof( distanc );
1081 const double seedValue = - initialDistance;
1083 node.SetValue( seedValue );
1084 node.SetIndex( seedPosition );
1086 seeds->Initialize();
1087 seeds->InsertElement( 0, node );
1089 fastMarching->SetTrialPoints( seeds );
1091 fastMarching->SetSpeedConstant( 1.0 );
1093 fastMarching->SetOutputSize(
1094 connector->GetOutput()->GetBufferedRegion().GetSize() );
1096 fastMarching->SetStoppingValue( 800 );
1100 connector2->Update();
1101 vtkImageData *idata = connector2->GetOutput();
1103 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1105 cntVTK->SetInput( idata );
1107 cntVTK->SetNumberOfContours( 1 );
1108 cntVTK->SetValue( 0, 255 );
1110 cntVTK->UpdateInformation();
1112 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1113 cpd->SetInput( cntVTK->GetOutput( ) );
1115 cpd->UpdateInformation();
1117 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1118 conn->SetExtractionModeToLargestRegion( );
1119 conn->SetInput( cpd->GetOutput( ) );
1121 conn->UpdateInformation();
1123 vtkStripper* vtkstripper = vtkStripper::New( );
1124 vtkstripper->SetInput( conn->GetOutput() );
1125 vtkstripper->Update();
1126 vtkstripper->UpdateInformation();
1129 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1130 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1131 polyDataResult->Update( );
1132 polyDataResult->UpdateInformation();
1137 myfile.open ("C:/Creatis/example.txt");
1139 polyDataResult->Print(myfile);
1140 myfile << "-------------------------------------\n";
1141 polyDataResult->GetLines()->Print(myfile);
1149 //--Calculating control points
1151 std::vector<double> vecX;
1152 std::vector<double> vecY;
1153 std::vector<double> vecXo;
1154 std::vector<double> vecYo;
1155 std::vector<double>::iterator vecXoi;
1156 std::vector<double>::iterator vecYoi;
1157 std::vector<double> vecZ;
1159 std::vector<double> vecCtrlPointX;
1160 std::vector<double> vecCtrlPointY;
1161 std::vector<double> vecCtrlPointZ;
1167 int ii,size=polyDataResult->GetNumberOfPoints();
1169 myfile.open ("C:/Creatis/example2.txt");
1171 size=polyDataResult->GetNumberOfPoints();
1172 for (ii=0;ii<size;ii++)
1179 p = polyDataResult->GetPoint(ii);
1182 /*if(fabs(yAct-y)>20)
1184 if((xAct-x)>1 || (xAct-x)<-1)
1186 vecX.push_back( p[0] );
1187 vecY.push_back( p[1] );
1188 myfile <<p[0]<<","<<p[1]<<"\n";
1189 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1190 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1191 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1192 vecZ.push_back( -900 );
1198 vecXo.push_back(p[0]);
1199 vecYo.push_back(p[1]);
1203 else*/ if(fabs(xAct-x)>11)
1205 vecXo.push_back(p[0]);
1206 vecYo.push_back(p[1]);
1210 vecX.push_back( p[0] );
1211 myfile <<p[0]<<","<<p[1]<<"\n";
1212 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1213 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1214 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1215 vecY.push_back( p[1] );
1216 vecZ.push_back( -900 );
1224 while(!vecXo.empty())
1226 vecX.push_back(vecXo.back());
1227 std::cout<<" x Siguiente "<<vecXo.back();
1229 vecZ.push_back( -900 );
1231 while(!vecYo.empty())
1233 vecY.push_back(vecYo.back());
1238 /*for(int l=0;l<vecX.size();l++)
1242 vecXo.push_back(p[0]);
1243 vecYo.push_back(p[1]);
1254 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1256 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1260 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1262 else if (method==1){
1263 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1265 else if (method==2){
1266 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1267 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1269 //--Adding contour to the system
1271 std::vector<int> actualInstantVector;
1272 _instantPanel->getInstant( actualInstantVector );
1273 actualInstantVector[1]=z;
1275 int j,sizeCtrPt = vecCtrlPointX.size();
1277 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1278 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1280 for (j=0 ; j<sizeCtrPt ; j++)
1282 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1284 std::string theName;
1285 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1286 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1287 bool addedModel = theName.compare("") != 0;
1290 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1291 _theViewPanel->getSpacing(spc);
1292 //Adding the manualContourControler to interface objects structure
1293 //Adding the manualViewContour to interface objects structure
1294 //_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.
1295 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1296 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1302 WriterType::Pointer writer = WriterType::New();
1303 CastFilterType3::Pointer caster = CastFilterType3::New();
1305 caster->SetInput( gradientMagnitude->GetOutput() );
1306 writer->SetInput( caster->GetOutput() );
1307 writer->SetFileName("Gradient Magnitude.png");
1308 caster->SetOutputMinimum( 0 );
1309 caster->SetOutputMaximum( 255 );
1312 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1313 WriterType::Pointer writer2 = WriterType::New();
1315 caster2->SetInput( sigmoid->GetOutput() );
1316 writer2->SetInput( caster2->GetOutput() );
1317 writer2->SetFileName("Sigmoid.png");
1318 caster2->SetOutputMinimum( 0 );
1319 caster2->SetOutputMaximum( 255 );
1322 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1323 WriterType::Pointer writer3 = WriterType::New();
1325 caster3->SetInput( fastMarching->GetOutput() );
1326 writer3->SetInput( caster3->GetOutput() );
1327 writer3->SetFileName("FastMarching.bmp");
1328 caster3->SetOutputMinimum( 0 );
1329 caster3->SetOutputMaximum( 255 );
1332 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1333 WriterType::Pointer writer4 = WriterType::New();
1335 caster4->SetInput( geodesicActiveContour->GetOutput() );
1336 writer4->SetInput( caster4->GetOutput() );
1337 writer4->SetFileName("GeodesicActiveContour.png");
1338 caster4->SetOutputMinimum( 0 );
1339 caster4->SetOutputMaximum( 255 );
1342 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1343 WriterType::Pointer writer5 = WriterType::New();
1345 caster5->SetInput( zeroCrossing->GetOutput() );
1346 writer5->SetInput( caster5->GetOutput() );
1347 writer5->SetFileName("ZeroCrossing.bmp");
1348 caster5->SetOutputMinimum( 0 );
1349 caster5->SetOutputMaximum( 255 );
1352 catch( itk::ExceptionObject & excep )
1354 std::cerr << "Exception caught !" << std::endl;
1355 std::cerr << excep << std::endl;
1359 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1361 //JCP 20-10-08 Undo redo implementation
1363 //JCP 20-10-08 Undo redo implementation
1366 int x = _theViewPanel->GetX();
1367 int y = _theViewPanel->GetY();
1368 int z = _theViewPanel->GetZ();
1369 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1374 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1376 int typeofcontour = 1;
1377 //--Extracting Contour
1378 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1379 vtkImageData *imagedata = getImageData();
1380 // double *range = imagedata->GetScalarRange();
1383 vtkImageReslice *imageReslice = vtkImageReslice::New();
1386 // imagedata->GetSpacing(spc);
1391 imageReslice->SetInput( imagedata );
1392 imageReslice->SetInformationInput(imagedata);
1393 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1394 imageReslice->SetResliceAxesOrigin(0,0,z);
1395 imageReslice->SetOutputDimensionality(2);
1396 imageReslice->SetInterpolationModeToLinear();
1398 imagedata = imageReslice->GetOutput();
1399 imagedata->Update();
1400 imagedata->UpdateInformation();
1402 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1403 cntVTK->SetInput( imagedata );
1405 cntVTK->SetNumberOfContours( 1 );
1406 //cntVTK->SetValue( 0, vmin );
1407 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1408 cntVTK->SetValue( 1, isovalue );
1409 // cntVTK->SetValue( 1, vmax );
1411 cntVTK->UpdateInformation();
1413 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1414 cpd->SetInput( cntVTK->GetOutput( ) );
1415 cpd->ConvertLinesToPointsOff( );
1417 cpd->UpdateInformation();
1419 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1420 conn->SetExtractionModeToClosestPointRegion( );
1421 //conn->SetMaxRecursionDepth( 3000 );
1423 conn->SetInput( cpd->GetOutput( ) );
1425 conn->SetClosestPoint( x, y, 0 );
1427 conn->UpdateInformation();
1429 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1430 cpd2->SetInput( conn->GetOutput( ) );
1432 cpd2->UpdateInformation();
1434 vtkStripper* vtkstripper = vtkStripper::New( );
1435 vtkstripper->SetInput( cpd2->GetOutput() );
1436 vtkstripper->Update();
1437 vtkstripper->UpdateInformation();
1440 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1442 polyDataResult->Update( );
1443 polyDataResult->UpdateInformation();
1447 myfile.open ("c:/temp/example.txt");
1449 polyDataResult->Print(myfile);
1450 myfile << "-------------------------------------\n";
1451 polyDataResult->GetLines()->Print(myfile);
1461 //--Calculating control points
1463 std::vector<double> vecX;
1464 std::vector<double> vecY;
1465 std::vector<double> vecZ;
1467 std::vector<double> vecCtrlPointX;
1468 std::vector<double> vecCtrlPointY;
1469 std::vector<double> vecCtrlPointZ;
1473 int ii,size=polyDataResult->GetNumberOfPoints();
1475 for (ii=1;ii<=size;ii++)
1477 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1478 p = polyDataResult->GetPoint(id);
1481 vecX.push_back( p[0] );
1482 vecY.push_back( p[1] );
1483 vecZ.push_back( -900 );
1484 // vecZ.push_back( p[2] );
1488 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1489 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1492 /*if (methodRadiobox->GetSelection()==0){
1493 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1495 if (methodRadiobox->GetSelection()==1){
1496 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1498 if (methodRadiobox->GetSelection()==2){
1499 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1500 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1504 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1506 else if (method==1){
1507 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1509 else if (method==2){
1510 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1511 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1514 //--Adding contour to the system
1516 std::vector<int> actualInstantVector;
1517 _instantPanel->getInstant( actualInstantVector );
1518 actualInstantVector[1]=z;
1520 int j,sizeCtrPt = vecCtrlPointX.size();
1521 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1522 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1524 for (j=0 ; j<sizeCtrPt ; j++)
1526 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1528 std::string theName;
1529 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1530 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1531 bool addedModel = theName.compare("") != 0;
1534 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1535 _theViewPanel->getSpacing(spc);
1536 //Adding the manualContourControler to interface objects structure
1537 //Adding the manualViewContour to interface objects structure
1538 //_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.
1539 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1540 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1544 int wxContourMainFrame::GetImageDataSizeZ(){
1545 return _theViewPanel->GetImageDataSizeZ();
1548 void wxContourMainFrame::GetImageDataRange(double *range){
1549 _theViewPanel->GetImageDataRange(range);
1552 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1553 //JCP 20-10-08 Undo redo implementation
1555 //JCP 20-10-08 Undo redo implementation
1558 int x = _theViewPanel->GetX();
1559 int y = _theViewPanel->GetY();
1563 double totalZ = maxZ-minZ+1;
1564 for( z=minZ ; z<=maxZ ; z++ )
1566 porcent = 100.0* (z-minZ)/totalZ;
1567 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1568 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1569 //_staticTextSegmentation->SetLabel(tmpString);
1570 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1572 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1577 //Creates a reference line to be used as the axis of the mirroring
1578 void wxContourMainFrame::referenceLine()
1583 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1584 vtkimagedata->GetSpacing(spc);
1586 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1588 _refLineControl = new manualLineControler();
1589 _refLineModel = new manualContourModelLine();
1590 _refLineView = new manualViewLine();
1591 _refLineView->SetModel( _refLineModel );
1592 _refLineView->SetWxVtkBaseView( viewer2D );
1593 _refLineView->SetRange( 2 );
1594 _refLineView->SetZ( 1200 );
1596 _refLineView->SetSpacing(spc);
1598 _refLineView->SetColorNormalContour(0, 0, 1);
1599 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1600 _refLineView->SetWidthLine(4);
1602 _refLineControl->SetModelView( _refLineModel , _refLineView );
1603 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1604 _refLineModel->SetCloseContour(false);
1605 _refLineControl->CreateNewManualContour();
1607 double z = _refLineControl->GetZ();
1609 _refLineControl->AddPoint(50,100,z);
1610 _refLineControl->AddPoint(80,40,z);
1611 _refLineControl->SetCompleteCreation(true);
1613 _refLineModel->AddPoint(50,100,z);
1614 _refLineModel->AddPoint(80,40,z);
1615 _refLineModel->UpdateSpline();
1617 _refLineView->UpdateViewPoint(0);
1618 _refLineView->UpdateViewPoint(1);
1621 _refLineControl->SetActive(true);
1622 _refLineView->RefreshContour();
1625 //Hides the referenceLine
1626 void wxContourMainFrame::refLineHide()
1628 if (_refLineControl!=NULL)
1630 _refLineView->RemoveCompleteContourActor();
1631 _refLineControl->SetEditable(false);
1632 _refLineControl->SetActive(false);
1636 //Shows the referenceLine
1637 void wxContourMainFrame::refLineShow()
1639 if (_refLineControl!=NULL)
1641 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1643 _refLineView->SetModel( _refLineModel );
1644 _refLineView->SetWxVtkBaseView( viewer2D );
1645 _refLineView->SetRange( 2 );
1646 _refLineView->SetZ( 1200 );
1648 _refLineControl->SetModelView( _refLineModel , _refLineView );
1649 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1650 _refLineControl->CreateNewManualContour();
1651 _refLineControl->SetActive(true);
1652 _refLineView->RefreshContour();
1656 void wxContourMainFrame::refLineChangeWidth(int width)
1658 _refLineView->SetWidthLine(width);
1659 _refLineView->RefreshContour();
1665 void wxContourMainFrame::onMirror()
1668 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1669 std::vector<std::string> filterCurrentSelection;
1671 std::vector<int> tempVector;
1672 _instantPanel->getInstant( tempVector );
1673 _performingOperation->reset();
1674 _performingOperation->setStartCommand( COPY );
1675 _performingOperation->setStartOperationInstantVector( tempVector );
1676 _performingOperation->setKeyNamesOperationElems( currentSelection );
1678 char theStartCommand = _performingOperation->getStartCommand();
1679 if ( theStartCommand == COPY )
1681 //JCP 20-10-08 Undo redo implementation
1683 //JCP 20-10-08 Undo redo implementation
1684 std::vector<int> tempVector;
1685 _instantPanel->getInstant( tempVector );
1686 _performingOperation->setEndOperationInstantVector ( tempVector );
1687 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1688 int i,size = elems.size();
1689 for( i=0; i<size; i++ )
1691 createMirrorContourOf( elems[i], tempVector, i>0 );
1695 //deleteContour( _refName );
1699 void wxContourMainFrame::onThreshold(int minVal, int maxVal)
1702 vtkImageData * img = _theViewPanel->getImageData();
1705 img->GetScalarRange(range);
1707 //vtkImageData * fakeImage = new vtkImageData();
1710 vtkLookupTable *lookup = vtkLookupTable::New();
1711 lookup->SetNumberOfTableValues(range[1]);
1712 lookup->SetTableRange(range);
1713 lookup->SetAlphaRange(0, 1);
1714 lookup->SetValueRange(0, 1);
1715 lookup->SetSaturationRange(0, 0);
1716 lookup->SetRampToLinear( );
1719 //Assign a fake color for the upper image, and set the white as transparent
1720 for(int i = range[0]; i < range[1]; i++)
1722 if( i >= minVal && i <= maxVal )
1724 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1726 else if( i >= range[0] && i < minVal )
1728 lookup->SetTableValue(i, 0.0, 0.0, 0.0, 0); //transparent
1730 else if( i > maxVal && i < range[1] )
1732 lookup->SetTableValue(i, 0.0, 0.0, 0.0, 0); //transparent
1738 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
1739 mapperImage->SetInput( img );
1740 mapperImage->SetLookupTable( lookup );
1742 vtkImageActor * upperImageActor = vtkImageActor::New( );
1743 upperImageActor->SetInput( mapperImage->GetOutput() );
1744 upperImageActor->SetOpacity( 1 );
1746 //viewer->SetInput( myImage ); viewer->GetRenderer()->AddActor( myActor );ACTOR!!!
1748 //baseImageActor = vtkImageActor::New( );
1749 //baseImageActor->SetInput( mBox->bbGetInputImage1() );
1754 void wxContourMainFrame::showAxis(bool show)
1756 _theViewPanel->SetVisibleAxis(show);
1757 _theViewPanel->Refresh();
1761 void wxContourMainFrame::onRigidPressed(){
1762 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1763 int elementsSelected = currentSelection.size();
1765 if ( elementsSelected >= 1 ){
1766 //JCP 20-10-08 Undo redo implementation
1768 //JCP 20-10-08 Undo redo implementation
1770 std::vector<int> tempVector;
1771 _instantPanel->getInstant( tempVector );
1772 Instant instant(&tempVector);
1774 int i , size=currentSelection.size();
1775 for ( i=0 ; i<size ; i++ )
1777 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1782 void wxContourMainFrame::onWidthOfContour(double width){
1784 _theViewPanel->removeSceneContours();
1785 _theViewPanel->SetWidthContour(width);
1787 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1791 int wxContourMainFrame::getColorWindow(){
1792 return _theViewPanel->getColorWindow();
1794 int wxContourMainFrame::getWindowLevel(){
1795 return _theViewPanel->getWindowLevel();
1798 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1799 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1805 void wxContourMainFrame::onInterpolation(bool interpolate){
1806 _theViewPanel->onInterpolation(interpolate);
1810 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1811 _instantPanel->setConceptValue( name, actual );
1814 void wxContourMainFrame::resetAppend(){
1815 kernelManager->resetAppend();
1819 void wxContourMainFrame::onSpreadAdd(){
1820 std::vector<double> vecX;
1821 std::vector<double> vecY;
1822 std::vector<double> vecZ;
1823 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1825 std::vector<int> tempVector;
1826 _instantPanel->getInstant( tempVector );
1828 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1830 interfMainPanel::getInstance()->appendStringSpread(val);
1834 void wxContourMainFrame::onSpreadGo(int type){
1836 //JCP 20-10-08 Undo redo implementation
1838 //JCP 20-10-08 Undo redo implementation
1841 std::vector<double> vecCtrlPointX;
1842 std::vector<double> vecCtrlPointY;
1843 std::vector<double> vecCtrlPointZ;
1847 std::vector<int> tempVector;
1848 _instantPanel->getInstant( tempVector );
1851 kernelManager->getMaxMinZ(&minZ,&maxZ);
1852 //JSTG_16-07-08_----------------------------------------------------------------
1853 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1854 kernelManager->CalculeSplinePropagation();
1856 double totalZ = maxZ-minZ+1;
1859 //--------------------------------------------------------------------
1860 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1862 porcent = 100.0* (z-minZ)/totalZ;
1863 int numero = (int)(z-minZ+1)/(int)totalZ;
1864 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1866 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1868 int typeofcontour = 1;
1869 std::string theName;
1870 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1872 if( manModelContour!=NULL ){
1873 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1874 this->_theViewPanel->getSpacing(spc);
1875 //Adding the manualContourControler to interface objects structure
1876 //Adding the manualViewContour to interface objects structure
1877 //_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.
1878 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1883 int numero = (int)(z-minZ+1)/(int)totalZ;
1884 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1886 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1888 //RefreshInterface();
1891 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1895 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1896 std::vector<int> tempVector;
1897 _instantPanel->getInstant(tempVector);
1898 //Asignation of slide number should be different ex by name
1899 tempVector[1]=slide;
1900 return kernelManager->getOutlinesNameAtInstant(tempVector);
1903 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1904 int maxContourGroup = 0;
1906 ContourExtractData *contourextractdata = new ContourExtractData();
1908 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1910 std::vector<manualContourModel*> lstManConMod;
1911 std::vector<manualContourModel*> lstManConModTmp;
1912 std::vector<manualContourModel*> lstManConModExp;
1913 std::vector<double> pLstValue;
1914 std::vector<double> pLstValuePosX;
1915 std::vector<double> pLstValuePosY;
1916 std::vector<double> pLstValuePosZ;
1919 int resultGrayRangeCount;
1922 double resultAverage;
1923 double resultStandardeviation;
1925 std::vector<int> tempVector;
1926 _instantPanel->getInstant( tempVector );
1928 vtkImageData *imagedata = _theViewPanel->getImageData();
1929 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1931 int ii,sizeLstContourThings;
1941 if (selection==0 ) // actual slice
1943 std::vector<int> tempVector;
1944 _instantPanel->getInstant( tempVector );
1945 int actualSlice = tempVector[1];
1949 else if (selection==2 ) // All slices
1954 else if (selection==1 ) // slice range
1961 totalZ = maxZ-minZ+1;
1962 contourextractdata->SetImage( imagedata);
1965 for ( z=minZ ; z<=maxZ ; z++ )
1968 porcent = 100.0* (z-minZ)/totalZ;
1969 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1971 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1972 //_staticTextInformation->SetLabel(tmpString);
1974 //Extraction data from contours of each slice
1975 contourextractdata->SetZtoBeAnalys( z);
1978 Instant instant(&tempVector);
1979 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1980 sizeLstContourThings = lstContourThings.size();
1982 lstManConMod.clear();
1983 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1985 ContourThing **contourthing = lstContourThings[ii];
1986 lstManConMod.push_back( (*contourthing)->getModel() );
1988 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1991 wxString tempString;
1992 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1993 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1994 //_grid->SetRowLabelValue(z, tempString );
1996 int iContourGroup,sizeContourGroup;
1997 if (typeContourGroup==3) // contour separete
1999 sizeContourGroup=lstManConModExp.size();
2000 if ( maxContourGroup<sizeContourGroup )
2002 maxContourGroup=sizeContourGroup;
2004 } else { // contour AND OR XOR
2013 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2014 lstManConModTmp.clear();
2015 if (typeContourGroup==3) // contour separete
2017 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2018 } else { // contour AND OR XOR
2019 lstManConModTmp = lstManConModExp;
2022 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2025 pLstValuePosX.clear();
2026 pLstValuePosY.clear();
2027 pLstValuePosZ.clear();
2028 contourextractdata->GetValuesInsideCrown( &pLstValue,
2032 // Statistics of each slice.
2033 contourextractdata->Statistics( &pLstValue,
2036 &resultGrayRangeCount,
2041 &resultStandardeviation);
2043 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2045 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2048 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2050 tempString.Printf(_T("%d"),resultSize);
2051 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2053 tempString.Printf(_T("%d"),resultGrayRangeCount);
2054 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2056 tempString.Printf(_T("%f"),resultMin);
2057 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2059 tempString.Printf(_T("%f"),resultMax);
2060 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2062 tempString.Printf(_T("%f"),resultAverage);
2063 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2065 tempString.Printf(_T("%f"),resultStandardeviation);
2066 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2069 } // for iContourGroup
2073 wxString tmpTitleString;
2075 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2077 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2078 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2079 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2081 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2082 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2083 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2084 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2085 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2086 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2087 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2090 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2091 delete contourextractdata;
2094 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2095 SaveValuesXYZ( directory , namefile, typeContourGroup );
2097 vtkImageData* mask, *value;
2098 this->getMaskValue(mask, value, typeContourGroup);
2099 this->SaveImageResult( directory , namefile, mask, value);
2102 FILE *pFile=fopen(filename.c_str(),"w+");
2104 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2107 int i,j,maxX,maxY=sizeZ;
2108 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2110 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2111 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2113 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2114 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2116 fprintf(pFile,"\n" );
2120 for ( j=0; j<maxY ; j++)
2122 fprintf(pFile,"%d\t" , j );
2123 for (i=0 ; i<maxX ; i++){
2124 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2125 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2127 fprintf(pFile,"\n" );
2133 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2136 ContourExtractData *contourextractdata = new ContourExtractData();
2137 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2138 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2140 std::vector<manualContourModel*> lstManConMod;
2141 std::vector<manualContourModel*> lstManConModTmp;
2142 std::vector<manualContourModel*> lstManConModExp;
2143 std::vector<double> pLstValue;
2144 std::vector<double> pLstValuePosX;
2145 std::vector<double> pLstValuePosY;
2146 std::vector<double> pLstValuePosZ;
2148 std::vector<int> tempVector;
2149 _instantPanel->getInstant( tempVector );
2151 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2152 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2154 int ii,sizeLstContourThings;
2161 minZ = 0;// _mbarrange->GetStart();
2162 maxZ = sizeZ;//_mbarrange->GetEnd();
2163 totalZ = maxZ-minZ+1;
2165 contourextractdata->SetImage( imagedata);
2168 for ( z=0 ; z<sizeZ ; z++)
2171 porcent = 100.0* (z-minZ)/totalZ;
2173 tmpString.Printf(_T("Saving Values"));
2174 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2175 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2176 //_staticTextInformation->SetLabel(tmpString);
2179 //Extraction data from contours of each slice
2180 contourextractdata->SetZtoBeAnalys( z);
2183 Instant instant(&tempVector);
2184 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2185 sizeLstContourThings = lstContourThings.size();
2187 lstManConMod.clear();
2188 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2190 ContourThing **contourthing = lstContourThings[ii];
2191 lstManConMod.push_back( (*contourthing)->getModel() );
2193 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2198 int iContourGroup,sizeContourGroup;
2199 if (typeContourGroup==3) // contour separete
2201 sizeContourGroup=lstManConModExp.size();
2202 } else { // contour AND OR XOR
2206 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2207 lstManConModTmp.clear();
2208 if (typeContourGroup==3) // contour separete
2210 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2211 } else { // contour AND OR XOR
2212 lstManConModTmp = lstManConModExp;
2215 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2218 pLstValuePosX.clear();
2219 pLstValuePosY.clear();
2220 pLstValuePosZ.clear();
2221 contourextractdata->GetValuesInsideCrown( &pLstValue,
2226 std::string temp = directory + "/" + namefile + "-slice";
2227 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2228 temp = temp + ".txt";
2230 // LG 14/01/09 : using crea
2231 wxString filename = crea::std2wx(temp);
2232 /*filename.Printf(_T("%s"),directory.c_str());
2233 filename.append(_T("\\"));
2234 filename.append(_T("%s"),namefile.c_str());
2235 filename.append(_T("-slice"));
2236 filename.append(_T("%d"),z);
2237 filename.append(_T("-cont"));
2238 filename.append(_T("%d"),iContourGroup);
2239 filename.append(_T(".txt"));*/
2240 // filename.Printf(temp.c_str());
2244 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2245 fprintf(pFile,"value \t x \t y \t z\n" );
2246 int iLstValue,sizeLstValue=pLstValue.size();
2247 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2249 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2252 } // for iContourGroup
2254 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2255 //_staticTextInformation->SetLabel( _T("") );
2256 delete contourextractdata;
2259 void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){
2261 ContourExtractData *contourextractdata = new ContourExtractData( true );
2262 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2263 if (typeContourGroup==3)
2267 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2269 std::vector<manualContourModel*> lstManConMod;
2270 std::vector<manualContourModel*> lstManConModTmp;
2271 std::vector<manualContourModel*> lstManConModExp;
2273 std::vector<int> tempVector;
2274 _instantPanel->getInstant( tempVector );
2276 vtkImageData *imagedata = _theViewPanel->getImageData();
2277 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2279 int ii,sizeLstContourThings;
2288 minZ = 0;// _mbarrange->GetStart();
2289 maxZ = sizeZ;//_mbarrange->GetEnd();
2290 totalZ = maxZ-minZ+1;
2292 contourextractdata->SetImage( imagedata);
2295 for ( z=0 ; z<sizeZ ; z++)
2298 porcent = 100.0* (z-minZ)/totalZ;
2299 tmpString.Printf(_T("Saving Values"));
2300 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2301 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2303 //Extraction data from contours of each slice
2304 contourextractdata->SetZtoBeAnalys( z);
2307 Instant instant(&tempVector);
2308 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2309 sizeLstContourThings = lstContourThings.size();
2311 lstManConMod.clear();
2312 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2314 ContourThing **contourthing = lstContourThings[ii];
2315 lstManConMod.push_back( (*contourthing)->getModel() );
2317 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2320 int iContourGroup,sizeContourGroup;
2321 if (typeContourGroup==3) // contour separete
2323 sizeContourGroup=lstManConModExp.size();
2324 } else { // contour AND OR XOR
2328 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2329 lstManConModTmp.clear();
2330 if (typeContourGroup==3) // contour separete
2332 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2333 } else { // contour AND OR XOR
2334 lstManConModTmp = lstManConModExp;
2337 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2338 contourextractdata->CalculateImageResult(); // with actual Z
2340 } // for iContourGroup
2343 value = contourextractdata->GetVtkImageValueResult();
2344 mask = contourextractdata->GetVtkImageMaskResult();
2345 delete contourextractdata;
2348 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2351 std::string temp = directory + "/" + namefile + "-Value.mhd";
2353 wxString filename = crea::std2wx(temp);
2355 // filename.Printf(_T(temp.c_str()));
2356 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2357 /*filename.Printf(_T("%s"),directory.c_str());
2358 filename.append(_T("\\"));
2359 filename.append(_T("%s"),namefile.c_str());
2360 filename.append(_T("-Value.mhd"));*/
2363 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2364 writerValueImage->SetInput( value );
2365 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2366 writerValueImage->SetFileDimensionality( 3 );
2367 writerValueImage->Write( );
2370 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2371 temp = directory + "/" + namefile + "-Mask.mhd";
2373 // LG 14/01/09 : using crea
2374 filename = crea::std2wx(temp);
2375 // filename.Printf(_T(temp.c_str()));
2377 /*filename.Printf(_T("%s"),directory.c_str());
2378 filename.append(_T("\\"));
2379 filename.append(_T("%s"),namefile.c_str());
2380 filename.append(_T("-Mask.mhd"));*/
2382 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2383 writerMaskImage->SetInput( mask );
2384 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2385 writerMaskImage->SetFileDimensionality( 3 );
2386 writerMaskImage->Write( );
2388 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2394 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2395 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2396 _theViewPanel->setActualVertical( value);
2398 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2399 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2405 void wxContourMainFrame::onSnakePressed(){
2406 std::vector<double> vecX;
2407 std::vector<double> vecY;
2408 std::vector<double> vecZ;
2409 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2411 if (vecX.size()!=0){
2412 std::vector<int> tempVector;
2413 _instantPanel->getInstant( tempVector );
2414 int i,size=vecZ.size();
2415 int actualSlice = tempVector[1];
2416 for ( i=0 ; i<size ; i++ )
2418 vecZ[i] = actualSlice;
2421 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2422 wxPanel* panel = new wxPanel(dialog,-1);
2423 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2424 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2425 dialog->ShowModal();
2430 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2431 std::string filename = kernelManager->getCurrentFileName();
2432 if(filename.compare("")!=0){
2433 saveFileWithContours(filename);