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 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( );
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( )
204 bool configured = _theViewPanel!=NULL;
206 configured &= _theViewPanel!=NULL;
207 if( _theViewPanel!=NULL )
209 notebook->AddPage( _theViewPanel, wxT(" View ") );
216 notebook->AddPage( _instantPanel, wxT("Instant Page") );
220 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
223 SetMinSize(wxSize(300,300));
229 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
231 bool configured = panel!=NULL;
232 configured &= panel!=NULL;
236 notebook->AddPage( panel, wxT(" Viewer "), true );
242 //------------------------------------------------------------------------------------------------------------
243 // Attributes getters and setters
244 //------------------------------------------------------------------------------------------------------------
248 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
250 _instantPanel = theInstantChooserPanel;
253 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
255 // _buttonsBar = theButtonsBar;
258 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
260 // _gridPanel = theGridPanel;
263 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
265 // _drawToolsPanel = theDrawToolsPanel;
268 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
270 // _operationsToolsPanel = theOperationsToolsPanel;
273 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
275 // _autoFormsPanel = theAutoFormsPanel;
278 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
280 // _standardToolsPanel= theStandardToolsPanel;
283 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
285 // _editionToolsPanel = theEditionToolsPanel;
288 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
290 // _listViewPanel = theListViewPanel;
295 void wxContourMainFrame::onCreateContourSpline( ){
297 //JCP 20-10-08 Undo redo implementation
299 //JCP 20-10-08 Undo redo implementation
303 void wxContourMainFrame::onCreateContourRectangle( ){
304 //JCP 20-10-08 Undo redo implementation
306 //JCP 20-10-08 Undo redo implementation
309 void wxContourMainFrame::onCreateContourCircle( ){
310 //JCP 20-10-08 Undo redo implementation
312 //JCP 20-10-08 Undo redo implementation
316 void wxContourMainFrame::onCreateContourLine( ){
317 //JCP 20-10-08 Undo redo implementation
319 //JCP 20-10-08 Undo redo implementation
323 //------------------------------------------------------------------------------------------------------------
325 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
327 //Creating the manualContourModel and including in the model
328 manualContourModel * manModelContour = factoryManualContourModel(panel );
330 std::vector<int> instantVector;
331 _instantPanel->getInstant( instantVector );
332 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
334 /*std::vector<int> instantVector;
335 _instantPanel->getInstant( instantVector );
337 theName= _modelManager->createOutline( manModelContour, instantVector );*/
338 bool addedModel = theName.compare("") != 0;//??
342 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
343 _theViewPanel->getSpacing(spc);
344 //Adding the manualContourControler to interface objects structure
345 //Adding the manualViewContour to interface objects structure
346 //_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.
347 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
350 void wxContourMainFrame :: createContour( int typeContour )
352 //Creating the manualContourModel and including in the model
353 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
356 std::vector<int> instantVector;
357 _instantPanel->getInstant( instantVector );
358 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
360 /*std::vector<int> instantVector;
361 _instantPanel->getInstant( instantVector );
363 theName= _modelManager->createOutline( manModelContour, instantVector );*/
364 bool addedModel = theName.compare("") != 0;//??
367 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
368 _theViewPanel->getSpacing(spc);
369 //Adding the manualContourControler to interface objects structure
370 //Adding the manualViewContour to interface objects structure
371 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
372 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
376 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
378 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
379 manualContourModel *manModelContour=NULL;
380 manModelContour = manModelContourBullEye;
382 int iCrown,sizeCrowns,iSector,sizeSectors;
383 double radioA,radioB,ang,angDelta ;
384 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
385 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
387 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
388 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
389 if (iCrown==sizeCrowns-1)
393 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
397 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
399 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
400 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
401 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
404 } // if _panelBullEyeOptions
406 return manModelContour;
408 void wxContourMainFrame :: saveState(){
410 std::string temp = kernelManager->saveState();
411 saveFileWithContours(temp);
414 void wxContourMainFrame::onDeleteContour(){
415 //JCP 20-10-08 Undo redo implementation
417 //JCP 20-10-08 Undo redo implementation
419 std::vector<std::string> lstKeyNameToBeErase;
420 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
421 deleteContours( lstKeyNameToBeErase );
423 int i,size=_sceneManager->getSelectedObjects().size();
426 std::string keyName = _sceneManager->getSelectedObjects()[i];
427 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
428 if ( ispartofstaticlist>=0 )
430 std::vector<int> tempVector;
431 _instantPanel->getInstant( tempVector );
432 Instant instant(&tempVector);
433 this->_modelManager->ChangeContourOfList(keyName, &instant);
437 std::vector<std::string> lstKeyName;
438 std::vector<std::string> lstKeyNameActualSlice;
439 std::vector<std::string> lstKeyNameToBeErase;
441 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
442 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
443 int k,kSize=lstKeyNameToBeErase.size();
444 int j,jSize=lstKeyNameActualSlice.size();
446 for (k=0;k<kSize; k++)
449 for (j=0;j<jSize; j++)
451 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
458 lstKeyName.push_back( lstKeyNameToBeErase[k] );
462 deleteContours( lstKeyName );
466 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
468 int i,size=keyNamesVector.size();
471 deleteContour( keyNamesVector[i] );
475 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
477 manualContourModel * cModel;
478 manualViewBaseContour * cViewer;
479 manualContourBaseControler * cControler;
481 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
482 cControler = conwrapviewControl->getControler();*/
485 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
486 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
488 if (isedit && ispartofstaticlst)
490 _theViewPanel->removeFromScene(theKeyName);
492 kernelManager->deleteCModel(theKeyName);
493 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
494 //cViewer = conwrapviewControl->getViewer();
495 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
496 //cControler* conwrapviewControl->getControler();
498 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
499 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
500 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
504 // delete cControler;
509 void wxContourMainFrame::onDeleteContoursActSlice(){
510 //JCP 20-10-08 Undo redo implementation
512 //JCP 20-10-08 Undo redo implementation
513 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
515 void wxContourMainFrame::onDeleteAllContours(){
516 //JCP 20-10-08 Undo redo implementation
520 void wxContourMainFrame::deleteAllContours(){
521 //JCP 20-10-08 Undo redo implementation
524 std::vector<int> tempVector;
525 _instantPanel->getInstant( tempVector );
527 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
528 // the values in GetStart and GetEnd will then not be initialize also.
529 // We use instead the values given when initializing the _deletepanel.
531 //int minZ = _mbarrangeDeleteAll->GetStart();
532 //int maxZ = _mbarrangeDeleteAll->GetEnd();
536 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
540 _theViewPanel->getSceneManager()->removeSceneContours( );
541 _theViewPanel->getSceneManager()->removeAllOutlines();
542 kernelManager->removeAllOutlines();
545 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
547 _theViewPanel->getSceneManager()->removeSceneContours( );
548 _modelManager->removeAllOutlines();
549 _theViewPanel->getSceneManager()->removeAllOutlines();
552 for ( z=minZ ; z<=maxZ ; z++)
555 Instant instant(&tempVector);
556 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
558 sizeLstContourThings = lstContourThings.size();
559 for (ii=0 ; ii<sizeLstContourThings ; ii++)
561 ContourThing **contourthing = lstContourThings[ii];
562 deleteContour( (*contourthing)->getName() );
569 void wxContourMainFrame::setConceptValue( std::string name, int value ){
570 _instantPanel->setConceptValue(name, value);
573 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
574 return _instantPanel->getLastConceptData();
576 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
577 return _instantPanel->getIfConceptCheckedAt( name, pos );
580 void wxContourMainFrame::changeInstant()
582 std::vector<int> instantVect;
583 _instantPanel->getInstant( instantVect );
584 // Instant * theInstant = new Instant ( &instantVect );
586 //Setting the actual instant
587 //_actualInstant = theInstant;
589 kernelManager->setInstant(instantVect);
590 //_modelManager->setInstant( _actualInstant );
592 updateInstantOutlines();
593 updateInstantImageData();
598 void wxContourMainFrame :: updateInstantOutlines(){
600 _theViewPanel->removeSceneContours();
601 _theViewPanel->addNameWrapperToScene();
603 //for( int i=0; i<size; i++)
605 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
609 int wxContourMainFrame::getNamesWrappingSize(){
610 return kernelManager->getNamesWrappingSize();
612 std::string wxContourMainFrame::getNameWrapping(int i){
613 return kernelManager->getNameWrapping(i);
616 void wxContourMainFrame::updateInstantImageData(){
617 std::vector<int> inst;
618 _instantPanel->getInstant(inst);
620 vtkImageData* img = kernelManager->getImageAtInstant(inst);
622 _theViewPanel->changeImage(img);
625 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
626 _theViewPanel->setImageSlice(z);
630 void wxContourMainFrame::updateInstantAxes(){
633 void wxContourMainFrame::onChangeDeep(int val){
634 _instantPanel->setConceptValue( "Axe Depth", (int)val );
639 void wxContourMainFrame::onCopy(){
640 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
642 std::vector<int> tempVector;
643 _instantPanel->getInstant( tempVector );
644 _performingOperation->reset();
645 _performingOperation->setStartCommand( COPY );
646 _performingOperation->setStartOperationInstantVector( tempVector );
647 _performingOperation->setKeyNamesOperationElems( currentSelection );
650 void wxContourMainFrame::onPaste(){
653 char theStartCommand = _performingOperation->getStartCommand();
654 if ( theStartCommand == COPY )
656 //JCP 20-10-08 Undo redo implementation
658 //JCP 20-10-08 Undo redo implementation
659 std::vector<int> tempVector;
660 _instantPanel->getInstant( tempVector );
661 _performingOperation->setEndOperationInstantVector ( tempVector );
662 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
663 int i,size = elems.size();
664 for( i=0; i<size; i++ )
666 createCopyContourOf( elems[i], tempVector, i>0 );
670 void wxContourMainFrame::onUndo(){
671 std::string filename;
672 if(kernelManager->onUndoSaveFile(filename)){
673 saveFileWithContours(filename);
675 if(kernelManager->onUndo(filename)){
679 void wxContourMainFrame::onRedo(){
680 std::string filename;
681 if(kernelManager->onRedo(filename)){
686 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
688 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
689 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
690 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
693 ///AD: 03-09 Copy the object and apply the given transformation
694 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
696 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
697 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
699 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
700 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
702 double pnt1X = refPoint1->GetX();
703 double pnt1Y = refPoint1->GetY();
704 // double pnt1Z = refPoint1->GetZ();
705 double pnt2X = refPoint2->GetX();
706 double pnt2Y = refPoint2->GetY();
707 // double pnt2Z = refPoint2->GetZ();
709 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
710 vtkTransform *t = vtkTransform::New();
714 t->Translate(-pnt1X, -pnt1Y, 0);
718 t->Translate(pnt1X, pnt1Y, 0);
721 int i,size=manualModel->GetSizeLstPoints();
724 manualPoint * mp = manualModel->GetManualPoint(i);
730 t->TransformPoint( vecIn, vecOut );
731 mp->SetPointX( vecOut[0] );
732 mp->SetPointY( vecOut[1] );
733 mp->SetPointZ( vecOut[2] );
736 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
739 void wxContourMainFrame ::loadState(std::string filename){
741 FILE *pFile=fopen(filename.c_str(),"r+");
743 fscanf(pFile,"%s",tmp); // --CreaContour--
745 fscanf(pFile,"%s",tmp); // Version
746 fscanf(pFile,"%s",tmp); // 1.0.1
747 std::string version(tmp);
751 openContours(pFile,false);
752 if (version!="1.0.0"){
753 openContours(pFile,true);
758 //_theViewPanel->getSceneManager()->removeSceneContours();
763 void wxContourMainFrame::onLoad(){
765 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
766 if (dialog.ShowModal() == wxID_OK)
768 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
769 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
771 fscanf(pFile,"%s",tmp); // --CreaContour--
773 fscanf(pFile,"%s",tmp); // Version
774 fscanf(pFile,"%s",tmp); // 1.0.1
775 std::string version(tmp);
777 openContours(pFile,false);
778 if (version!="1.0.0"){
779 openContours(pFile,true);
781 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
785 _theViewPanel->getSceneManager()->removeSceneContours();
788 void wxContourMainFrame::onSave(){
789 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
790 if (dialog.ShowModal() == wxID_OK)
792 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
793 kernelManager->setCurrentFileName(fileNameContourROI);
794 saveFileWithContours( fileNameContourROI );
797 void wxContourMainFrame::saveFileWithContours( std::string filename ){
799 FILE *pFile=fopen(filename.c_str(),"w+");
800 std::vector< std::string > lstNameThings;
801 int i,sizeLstNameThings;
803 fprintf(pFile,"--CreaContour--\n");
804 fprintf(pFile,"Version %s\n", "1.0.1" );
807 lstNameThings = kernelManager->GetLstNameThings();
808 sizeLstNameThings = lstNameThings.size();
809 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
810 for (i=0 ; i<sizeLstNameThings ; i++)
812 kernelManager->SaveThingName( pFile, lstNameThings[i] );
813 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
816 //-- Contours Statics
817 lstNameThings = kernelManager->GetLstNameThingsStatic();
818 sizeLstNameThings = lstNameThings.size();
819 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
820 for (i=0 ; i<sizeLstNameThings ; i++)
822 kernelManager->SaveThingName( pFile, lstNameThings[i] );
823 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
828 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
830 fscanf(pFile,"%s",tmp); // NumberOfContours
831 fscanf(pFile,"%s",tmp); // ##
832 int numberOfContours = atoi(tmp);
834 std::vector<int> instantVector;
835 int typeContourModel;
836 manualContourModel *manModelContour;
840 for (i=0;i<numberOfContours;i++)
842 instantVector.clear();
843 fscanf(pFile,"%s",tmp); // Instant
845 fscanf(pFile,"%s",tmp); // 1
846 instantVector.push_back( atoi(tmp) );
847 fscanf(pFile,"%s",tmp); // 2
848 instantVector.push_back( atoi(tmp) );
849 fscanf(pFile,"%s",tmp); // 3
850 instantVector.push_back( atoi(tmp) );
851 fscanf(pFile,"%s",tmp); // 4
852 instantVector.push_back( atoi(tmp) );
853 fscanf(pFile,"%s",tmp); // 5
854 instantVector.push_back( atoi(tmp) );
855 fscanf(pFile,"%s",tmp); // 6
856 instantVector.push_back( atoi(tmp) );
859 fscanf(pFile,"%s",tmp); // TypeContourModel
860 fscanf(pFile,"%s",tmp); // ##
861 typeContourModel = atoi(tmp);
863 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
864 manModelContour->Open(pFile);
866 fscanf(pFile,"%s",tmp); // TypeView
867 fscanf(pFile,"%s",tmp); // ##
868 typeView = atoi(tmp);
877 theName = kernelManager->createOutline( manModelContour, instantVector );
878 bool addedModel = theName.compare("") != 0;
881 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
882 _theViewPanel->getSpacing(spc);
883 //Adding the manualContourControler to interface objects structure
884 //Adding the manualViewContour to interface objects structure
885 //_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.
886 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
889 if (staticContour==true)
891 Instant instant(&instantVector);
892 kernelManager->changeContourOfManager( theName , &instant );
895 }// for numberOfContours
899 void wxContourMainFrame::RefreshInterface(){
901 _theViewPanel->RefreshInterface();
902 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
903 //wxvtk2dbaseview->Refresh();
906 vtkImageData* wxContourMainFrame::getImageData(){
907 return _theViewPanel->getImageData();
910 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
912 //JCP 20-10-08 Undo redo implementation
914 //JCP 20-10-08 Undo redo implementation
917 int x = _theViewPanel->GetX();
918 int y = _theViewPanel->GetY();
919 int z = _theViewPanel->GetZ();
920 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
924 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
927 int typeofcontour = 1;
929 vtkImageData *imagedata = getImageData();
931 //Tipo de pixeles a utilizar internamente en ITK
932 typedef float InternalPixelType;
933 const unsigned int Dimension = 2;
934 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
936 //Tipo de pixeles de salida 1
937 typedef unsigned char OutputPixelType;
938 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
940 //Tipo de pixeles de salida 2
941 typedef unsigned short OutputPixelType2;
942 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
944 //Definición del thresholder
945 typedef itk::BinaryThresholdImageFilter<
947 OutputImageType > ThresholdingFilterType;
949 //Definición del primer filtro de conversión de pixeles
950 typedef itk::CastImageFilter<
951 OutputImageType, OutputImageType2 > CastFilterType;
953 //Definición del segundo tipo de conversión de pixeles
954 typedef itk::CastImageFilter<
955 OutputImageType2, InternalImageType > CastFilterType2;
957 //Tercer tipo de conversión
958 typedef itk::RescaleIntensityImageFilter<
960 OutputImageType > CastFilterType3;
962 //Cuarto tipo de conversión
963 typedef itk::RescaleIntensityImageFilter<
965 OutputImageType > CastFilterType4;
967 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
969 thresholder->SetLowerThreshold( 0.0 );
970 thresholder->SetUpperThreshold( 128 );
972 thresholder->SetOutsideValue( 255 );
973 thresholder->SetInsideValue( 0 );
975 //Definción de conexiónes entre VTK e ITK y el writer
976 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
977 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
978 typedef itk::ImageFileWriter< OutputImageType > WriterType;
980 ConnectorType::Pointer connector= ConnectorType::New();
981 ConnectorType2::Pointer connector2= ConnectorType2::New();
984 CastFilterType::Pointer filter=CastFilterType::New();
985 CastFilterType2::Pointer filter2=CastFilterType2::New();
987 connector->SetInput( imagedata );
988 filter2->SetInput(connector->GetOutput());
990 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
992 InternalImageType > SmoothingFilterType;
994 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
996 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
998 InternalImageType > GradientFilterType;
1000 typedef itk::SigmoidImageFilter<
1002 InternalImageType > SigmoidFilterType;
1004 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1006 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1008 sigmoid->SetOutputMinimum( 0.0 );
1009 sigmoid->SetOutputMaximum( 255.0 );
1012 typedef itk::FastMarchingImageFilter<
1014 InternalImageType > FastMarchingFilterType;
1017 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1019 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1020 InternalImageType > GeodesicActiveContourFilterType;
1021 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1022 GeodesicActiveContourFilterType::New();
1024 typedef itk::ZeroCrossingImageFilter<
1026 InternalImageType > ZeroCrossingFilterType;
1027 ZeroCrossingFilterType::Pointer zeroCrossing =
1028 ZeroCrossingFilterType::New();
1030 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1032 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1033 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1034 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1036 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1037 int it=atoi( crea::wx2std(iter).c_str() );
1038 geodesicActiveContour->SetNumberOfIterations( it );
1040 smoothing->SetInput( filter2->GetOutput() );
1041 gradientMagnitude->SetInput( smoothing->GetOutput() );
1042 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1043 fastMarching->SetInput( sigmoid->GetOutput() );
1044 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1045 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1047 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1048 //thresholder->SetInput( zeroCrossing->GetOutput() );
1049 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1050 connector2->SetInput( thresholder->GetOutput() );
1053 smoothing->SetTimeStep( 0.125 );
1054 smoothing->SetNumberOfIterations( 5 );
1055 smoothing->SetConductanceParameter( 9.0 );
1058 const double sigma = atof( crea::wx2std(sigm).c_str() );
1059 gradientMagnitude->SetSigma( sigma );
1061 const double alpha = atof( crea::wx2std(alf).c_str() );
1062 const double beta = atof( crea::wx2std(bet).c_str() );
1064 sigmoid->SetAlpha( alpha );
1065 sigmoid->SetBeta( beta );
1067 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1068 typedef FastMarchingFilterType::NodeType NodeType;
1070 NodeContainer::Pointer seeds = NodeContainer::New();
1072 InternalImageType::IndexType seedPosition;
1073 seedPosition[0] = x;
1074 seedPosition[1] = y;
1076 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1080 const double seedValue = - initialDistance;
1082 node.SetValue( seedValue );
1083 node.SetIndex( seedPosition );
1085 seeds->Initialize();
1086 seeds->InsertElement( 0, node );
1088 fastMarching->SetTrialPoints( seeds );
1090 fastMarching->SetSpeedConstant( 1.0 );
1092 fastMarching->SetOutputSize(
1093 connector->GetOutput()->GetBufferedRegion().GetSize() );
1095 fastMarching->SetStoppingValue( 800 );
1099 connector2->Update();
1100 vtkImageData *idata = connector2->GetOutput();
1102 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1104 cntVTK->SetInput( idata );
1106 cntVTK->SetNumberOfContours( 1 );
1107 cntVTK->SetValue( 0, 255 );
1109 cntVTK->UpdateInformation();
1111 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1112 cpd->SetInput( cntVTK->GetOutput( ) );
1114 cpd->UpdateInformation();
1116 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1117 conn->SetExtractionModeToLargestRegion( );
1118 conn->SetInput( cpd->GetOutput( ) );
1120 conn->UpdateInformation();
1122 vtkStripper* vtkstripper = vtkStripper::New( );
1123 vtkstripper->SetInput( conn->GetOutput() );
1124 vtkstripper->Update();
1125 vtkstripper->UpdateInformation();
1128 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1129 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1130 polyDataResult->Update( );
1131 polyDataResult->UpdateInformation();
1136 myfile.open ("C:/Creatis/example.txt");
1138 polyDataResult->Print(myfile);
1139 myfile << "-------------------------------------\n";
1140 polyDataResult->GetLines()->Print(myfile);
1148 //--Calculating control points
1150 std::vector<double> vecX;
1151 std::vector<double> vecY;
1152 std::vector<double> vecXo;
1153 std::vector<double> vecYo;
1154 std::vector<double>::iterator vecXoi;
1155 std::vector<double>::iterator vecYoi;
1156 std::vector<double> vecZ;
1158 std::vector<double> vecCtrlPointX;
1159 std::vector<double> vecCtrlPointY;
1160 std::vector<double> vecCtrlPointZ;
1166 int ii,size=polyDataResult->GetNumberOfPoints();
1168 myfile.open ("C:/Creatis/example2.txt");
1170 size=polyDataResult->GetNumberOfPoints();
1171 for (ii=0;ii<size;ii++)
1178 p = polyDataResult->GetPoint(ii);
1181 /*if(fabs(yAct-y)>20)
1183 if((xAct-x)>1 || (xAct-x)<-1)
1185 vecX.push_back( p[0] );
1186 vecY.push_back( p[1] );
1187 myfile <<p[0]<<","<<p[1]<<"\n";
1188 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1189 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1190 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1191 vecZ.push_back( -900 );
1197 vecXo.push_back(p[0]);
1198 vecYo.push_back(p[1]);
1202 else*/ if(fabs(xAct-x)>11)
1204 vecXo.push_back(p[0]);
1205 vecYo.push_back(p[1]);
1209 vecX.push_back( p[0] );
1210 myfile <<p[0]<<","<<p[1]<<"\n";
1211 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1212 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1213 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1214 vecY.push_back( p[1] );
1215 vecZ.push_back( -900 );
1223 while(!vecXo.empty())
1225 vecX.push_back(vecXo.back());
1226 std::cout<<" x Siguiente "<<vecXo.back();
1228 vecZ.push_back( -900 );
1230 while(!vecYo.empty())
1232 vecY.push_back(vecYo.back());
1237 /*for(int l=0;l<vecX.size();l++)
1241 vecXo.push_back(p[0]);
1242 vecYo.push_back(p[1]);
1253 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1255 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1259 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1261 else if (method==1){
1262 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1264 else if (method==2){
1265 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1266 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1268 //--Adding contour to the system
1270 std::vector<int> actualInstantVector;
1271 _instantPanel->getInstant( actualInstantVector );
1272 actualInstantVector[1]=z;
1274 int j,sizeCtrPt = vecCtrlPointX.size();
1276 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1277 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1279 for (j=0 ; j<sizeCtrPt ; j++)
1281 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1283 std::string theName;
1284 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1285 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1286 bool addedModel = theName.compare("") != 0;
1289 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1290 _theViewPanel->getSpacing(spc);
1291 //Adding the manualContourControler to interface objects structure
1292 //Adding the manualViewContour to interface objects structure
1293 //_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.
1294 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1295 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1301 WriterType::Pointer writer = WriterType::New();
1302 CastFilterType3::Pointer caster = CastFilterType3::New();
1304 caster->SetInput( gradientMagnitude->GetOutput() );
1305 writer->SetInput( caster->GetOutput() );
1306 writer->SetFileName("Gradient Magnitude.png");
1307 caster->SetOutputMinimum( 0 );
1308 caster->SetOutputMaximum( 255 );
1311 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1312 WriterType::Pointer writer2 = WriterType::New();
1314 caster2->SetInput( sigmoid->GetOutput() );
1315 writer2->SetInput( caster2->GetOutput() );
1316 writer2->SetFileName("Sigmoid.png");
1317 caster2->SetOutputMinimum( 0 );
1318 caster2->SetOutputMaximum( 255 );
1321 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1322 WriterType::Pointer writer3 = WriterType::New();
1324 caster3->SetInput( fastMarching->GetOutput() );
1325 writer3->SetInput( caster3->GetOutput() );
1326 writer3->SetFileName("FastMarching.bmp");
1327 caster3->SetOutputMinimum( 0 );
1328 caster3->SetOutputMaximum( 255 );
1331 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1332 WriterType::Pointer writer4 = WriterType::New();
1334 caster4->SetInput( geodesicActiveContour->GetOutput() );
1335 writer4->SetInput( caster4->GetOutput() );
1336 writer4->SetFileName("GeodesicActiveContour.png");
1337 caster4->SetOutputMinimum( 0 );
1338 caster4->SetOutputMaximum( 255 );
1341 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1342 WriterType::Pointer writer5 = WriterType::New();
1344 caster5->SetInput( zeroCrossing->GetOutput() );
1345 writer5->SetInput( caster5->GetOutput() );
1346 writer5->SetFileName("ZeroCrossing.bmp");
1347 caster5->SetOutputMinimum( 0 );
1348 caster5->SetOutputMaximum( 255 );
1351 catch( itk::ExceptionObject & excep )
1353 std::cerr << "Exception caught !" << std::endl;
1354 std::cerr << excep << std::endl;
1358 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1360 //JCP 20-10-08 Undo redo implementation
1362 //JCP 20-10-08 Undo redo implementation
1365 int x = _theViewPanel->GetX();
1366 int y = _theViewPanel->GetY();
1367 int z = _theViewPanel->GetZ();
1368 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1373 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1375 int typeofcontour = 1;
1376 //--Extracting Contour
1377 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1378 vtkImageData *imagedata = getImageData();
1379 // double *range = imagedata->GetScalarRange();
1382 vtkImageReslice *imageReslice = vtkImageReslice::New();
1385 // imagedata->GetSpacing(spc);
1390 imageReslice->SetInput( imagedata );
1391 imageReslice->SetInformationInput(imagedata);
1392 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1393 imageReslice->SetResliceAxesOrigin(0,0,z);
1394 imageReslice->SetOutputDimensionality(2);
1395 imageReslice->SetInterpolationModeToLinear();
1397 imagedata = imageReslice->GetOutput();
1398 imagedata->Update();
1399 imagedata->UpdateInformation();
1401 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1402 cntVTK->SetInput( imagedata );
1404 cntVTK->SetNumberOfContours( 1 );
1405 //cntVTK->SetValue( 0, vmin );
1406 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1407 cntVTK->SetValue( 1, isovalue );
1408 // cntVTK->SetValue( 1, vmax );
1410 cntVTK->UpdateInformation();
1412 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1413 cpd->SetInput( cntVTK->GetOutput( ) );
1414 cpd->ConvertLinesToPointsOff( );
1416 cpd->UpdateInformation();
1418 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1419 conn->SetExtractionModeToClosestPointRegion( );
1420 //conn->SetMaxRecursionDepth( 3000 );
1422 conn->SetInput( cpd->GetOutput( ) );
1424 conn->SetClosestPoint( x, y, 0 );
1426 conn->UpdateInformation();
1428 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1429 cpd2->SetInput( conn->GetOutput( ) );
1431 cpd2->UpdateInformation();
1433 vtkStripper* vtkstripper = vtkStripper::New( );
1434 vtkstripper->SetInput( cpd2->GetOutput() );
1435 vtkstripper->Update();
1436 vtkstripper->UpdateInformation();
1439 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1441 polyDataResult->Update( );
1442 polyDataResult->UpdateInformation();
1446 myfile.open ("c:/temp/example.txt");
1448 polyDataResult->Print(myfile);
1449 myfile << "-------------------------------------\n";
1450 polyDataResult->GetLines()->Print(myfile);
1460 //--Calculating control points
1462 std::vector<double> vecX;
1463 std::vector<double> vecY;
1464 std::vector<double> vecZ;
1466 std::vector<double> vecCtrlPointX;
1467 std::vector<double> vecCtrlPointY;
1468 std::vector<double> vecCtrlPointZ;
1472 int ii,size=polyDataResult->GetNumberOfPoints();
1474 for (ii=1;ii<=size;ii++)
1476 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1477 p = polyDataResult->GetPoint(id);
1480 vecX.push_back( p[0] );
1481 vecY.push_back( p[1] );
1482 vecZ.push_back( -900 );
1483 // vecZ.push_back( p[2] );
1487 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1488 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1491 /*if (methodRadiobox->GetSelection()==0){
1492 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1494 if (methodRadiobox->GetSelection()==1){
1495 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1497 if (methodRadiobox->GetSelection()==2){
1498 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1499 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1503 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1505 else if (method==1){
1506 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1508 else if (method==2){
1509 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1510 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1513 //--Adding contour to the system
1515 std::vector<int> actualInstantVector;
1516 _instantPanel->getInstant( actualInstantVector );
1517 actualInstantVector[1]=z;
1519 int j,sizeCtrPt = vecCtrlPointX.size();
1520 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1521 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1523 for (j=0 ; j<sizeCtrPt ; j++)
1525 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1527 std::string theName;
1528 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1529 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1530 bool addedModel = theName.compare("") != 0;
1533 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1534 _theViewPanel->getSpacing(spc);
1535 //Adding the manualContourControler to interface objects structure
1536 //Adding the manualViewContour to interface objects structure
1537 //_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.
1538 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1539 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1543 int wxContourMainFrame::GetImageDataSizeZ(){
1544 return _theViewPanel->GetImageDataSizeZ();
1547 void wxContourMainFrame::GetImageDataRange(double *range){
1548 _theViewPanel->GetImageDataRange(range);
1551 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1552 //JCP 20-10-08 Undo redo implementation
1554 //JCP 20-10-08 Undo redo implementation
1557 int x = _theViewPanel->GetX();
1558 int y = _theViewPanel->GetY();
1562 double totalZ = maxZ-minZ+1;
1563 for( z=minZ ; z<=maxZ ; z++ )
1565 porcent = 100.0* (z-minZ)/totalZ;
1566 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1567 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1568 //_staticTextSegmentation->SetLabel(tmpString);
1569 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1571 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1576 //Creates a reference line to be used as the axis of the mirroring
1577 void wxContourMainFrame::referenceLine()
1582 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1583 vtkimagedata->GetSpacing(spc);
1585 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1587 _refLineControl = new manualLineControler();
1588 _refLineModel = new manualContourModelLine();
1589 _refLineView = new manualViewLine();
1590 _refLineView->SetModel( _refLineModel );
1591 _refLineView->SetWxVtkBaseView( viewer2D );
1592 _refLineView->SetRange( 2 );
1593 _refLineView->SetZ( 1200 );
1595 _refLineView->SetSpacing(spc);
1597 _refLineView->SetColorNormalContour(0, 0, 1);
1598 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1599 _refLineView->SetWidthLine(4);
1601 _refLineControl->SetModelView( _refLineModel , _refLineView );
1602 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1603 _refLineModel->SetCloseContour(false);
1604 _refLineControl->CreateNewManualContour();
1606 double z = _refLineControl->GetZ();
1608 _refLineControl->AddPoint(50,100,z);
1609 _refLineControl->AddPoint(80,40,z);
1610 _refLineControl->SetCompleteCreation(true);
1612 _refLineModel->AddPoint(50,100,z);
1613 _refLineModel->AddPoint(80,40,z);
1614 _refLineModel->UpdateSpline();
1616 _refLineView->UpdateViewPoint(0);
1617 _refLineView->UpdateViewPoint(1);
1620 _refLineControl->SetActive(true);
1621 _refLineView->RefreshContour();
1624 //Hides the referenceLine
1625 void wxContourMainFrame::refLineHide()
1627 if (_refLineControl!=NULL)
1629 _refLineView->RemoveCompleteContourActor();
1630 _refLineControl->SetEditable(false);
1631 _refLineControl->SetActive(false);
1635 //Shows the referenceLine
1636 void wxContourMainFrame::refLineShow()
1638 if (_refLineControl!=NULL)
1640 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1642 _refLineView->SetModel( _refLineModel );
1643 _refLineView->SetWxVtkBaseView( viewer2D );
1644 _refLineView->SetRange( 2 );
1645 _refLineView->SetZ( 1200 );
1647 _refLineControl->SetModelView( _refLineModel , _refLineView );
1648 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1649 _refLineControl->CreateNewManualContour();
1650 _refLineControl->SetActive(true);
1651 _refLineView->RefreshContour();
1655 void wxContourMainFrame::refLineChangeWidth(int width)
1657 _refLineView->SetWidthLine(width);
1658 _refLineView->RefreshContour();
1664 void wxContourMainFrame::onMirror()
1667 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1668 std::vector<std::string> filterCurrentSelection;
1670 std::vector<int> tempVector;
1671 _instantPanel->getInstant( tempVector );
1672 _performingOperation->reset();
1673 _performingOperation->setStartCommand( COPY );
1674 _performingOperation->setStartOperationInstantVector( tempVector );
1675 _performingOperation->setKeyNamesOperationElems( currentSelection );
1677 char theStartCommand = _performingOperation->getStartCommand();
1678 if ( theStartCommand == COPY )
1680 //JCP 20-10-08 Undo redo implementation
1682 //JCP 20-10-08 Undo redo implementation
1683 std::vector<int> tempVector;
1684 _instantPanel->getInstant( tempVector );
1685 _performingOperation->setEndOperationInstantVector ( tempVector );
1686 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1687 int i,size = elems.size();
1688 for( i=0; i<size; i++ )
1690 createMirrorContourOf( elems[i], tempVector, i>0 );
1694 //deleteContour( _refName );
1698 void wxContourMainFrame::onThreshold(int minVal, int maxVal)
1701 vtkImageData * img = _theViewPanel->getImageData();
1704 img->GetScalarRange(range);
1706 //vtkImageData * fakeImage = new vtkImageData();
1709 vtkLookupTable *lookup = vtkLookupTable::New();
1710 lookup->SetNumberOfTableValues(range[1]+1);
1711 lookup->SetTableRange(range);
1712 lookup->SetAlphaRange(0, 1);
1713 lookup->SetValueRange(0, 1);
1714 lookup->SetSaturationRange(0, 0);
1715 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->SetLookupTable( lookup );
1740 mapperImage->SetInput( img );
1741 //mapperImage->SetOutputFormatToRGBA( );
1743 vtkImageActor * upperImageActor = vtkImageActor::New( );
1744 upperImageActor->SetInput( mapperImage->GetOutput() );
1745 upperImageActor->SetOpacity( 1 );
1747 vtkImageViewer2* viewer = vtkImageViewer2::New();
1748 viewer->SetInput( upperImageActor->GetInput() );
1749 viewer->SetColorLevel((range[1]-range[0])/2);
1750 viewer->SetColorWindow(range[1]);
1751 viewer->GetRenderer()->AddActor( upperImageActor );
1758 void wxContourMainFrame::showAxis(bool show)
1760 _theViewPanel->SetVisibleAxis(show);
1761 _theViewPanel->Refresh();
1765 void wxContourMainFrame::onRigidPressed(){
1766 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1767 int elementsSelected = currentSelection.size();
1769 if ( elementsSelected >= 1 ){
1770 //JCP 20-10-08 Undo redo implementation
1772 //JCP 20-10-08 Undo redo implementation
1774 std::vector<int> tempVector;
1775 _instantPanel->getInstant( tempVector );
1776 Instant instant(&tempVector);
1778 int i , size=currentSelection.size();
1779 for ( i=0 ; i<size ; i++ )
1781 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1786 void wxContourMainFrame::onWidthOfContour(double width){
1788 _theViewPanel->removeSceneContours();
1789 _theViewPanel->SetWidthContour(width);
1791 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1795 int wxContourMainFrame::getColorWindow(){
1796 return _theViewPanel->getColorWindow();
1798 int wxContourMainFrame::getWindowLevel(){
1799 return _theViewPanel->getWindowLevel();
1802 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1803 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1809 void wxContourMainFrame::onInterpolation(bool interpolate){
1810 _theViewPanel->onInterpolation(interpolate);
1814 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1815 _instantPanel->setConceptValue( name, actual );
1818 void wxContourMainFrame::resetAppend(){
1819 kernelManager->resetAppend();
1823 void wxContourMainFrame::onSpreadAdd(){
1824 std::vector<double> vecX;
1825 std::vector<double> vecY;
1826 std::vector<double> vecZ;
1827 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1829 std::vector<int> tempVector;
1830 _instantPanel->getInstant( tempVector );
1832 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1834 interfMainPanel::getInstance()->appendStringSpread(val);
1838 void wxContourMainFrame::onSpreadGo(int type){
1840 //JCP 20-10-08 Undo redo implementation
1842 //JCP 20-10-08 Undo redo implementation
1845 std::vector<double> vecCtrlPointX;
1846 std::vector<double> vecCtrlPointY;
1847 std::vector<double> vecCtrlPointZ;
1851 std::vector<int> tempVector;
1852 _instantPanel->getInstant( tempVector );
1855 kernelManager->getMaxMinZ(&minZ,&maxZ);
1856 //JSTG_16-07-08_----------------------------------------------------------------
1857 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1858 kernelManager->CalculeSplinePropagation();
1860 double totalZ = maxZ-minZ+1;
1863 //--------------------------------------------------------------------
1864 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1866 porcent = 100.0* (z-minZ)/totalZ;
1867 int numero = (int)(z-minZ+1)/(int)totalZ;
1868 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1870 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1872 int typeofcontour = 1;
1873 std::string theName;
1874 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1876 if( manModelContour!=NULL ){
1877 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1878 this->_theViewPanel->getSpacing(spc);
1879 //Adding the manualContourControler to interface objects structure
1880 //Adding the manualViewContour to interface objects structure
1881 //_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.
1882 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1887 int numero = (int)(z-minZ+1)/(int)totalZ;
1888 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1890 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1892 //RefreshInterface();
1895 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1899 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1900 std::vector<int> tempVector;
1901 _instantPanel->getInstant(tempVector);
1902 //Asignation of slide number should be different ex by name
1903 tempVector[1]=slide;
1904 return kernelManager->getOutlinesNameAtInstant(tempVector);
1907 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1908 int maxContourGroup = 0;
1910 ContourExtractData *contourextractdata = new ContourExtractData();
1912 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1914 std::vector<manualContourModel*> lstManConMod;
1915 std::vector<manualContourModel*> lstManConModTmp;
1916 std::vector<manualContourModel*> lstManConModExp;
1917 std::vector<double> pLstValue;
1918 std::vector<double> pLstValuePosX;
1919 std::vector<double> pLstValuePosY;
1920 std::vector<double> pLstValuePosZ;
1923 int resultGrayRangeCount;
1926 double resultAverage;
1927 double resultStandardeviation;
1929 std::vector<int> tempVector;
1930 _instantPanel->getInstant( tempVector );
1932 vtkImageData *imagedata = _theViewPanel->getImageData();
1933 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1935 int ii,sizeLstContourThings;
1945 if (selection==0 ) // actual slice
1947 std::vector<int> tempVector;
1948 _instantPanel->getInstant( tempVector );
1949 int actualSlice = tempVector[1];
1953 else if (selection==2 ) // All slices
1958 else if (selection==1 ) // slice range
1965 totalZ = maxZ-minZ+1;
1966 contourextractdata->SetImage( imagedata);
1969 for ( z=minZ ; z<=maxZ ; z++ )
1972 porcent = 100.0* (z-minZ)/totalZ;
1973 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1975 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1976 //_staticTextInformation->SetLabel(tmpString);
1978 //Extraction data from contours of each slice
1979 contourextractdata->SetZtoBeAnalys( z);
1982 Instant instant(&tempVector);
1983 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1984 sizeLstContourThings = lstContourThings.size();
1986 lstManConMod.clear();
1987 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1989 ContourThing **contourthing = lstContourThings[ii];
1990 lstManConMod.push_back( (*contourthing)->getModel() );
1992 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1995 wxString tempString;
1996 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1997 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1998 //_grid->SetRowLabelValue(z, tempString );
2000 int iContourGroup,sizeContourGroup;
2001 if (typeContourGroup==3) // contour separete
2003 sizeContourGroup=lstManConModExp.size();
2004 if ( maxContourGroup<sizeContourGroup )
2006 maxContourGroup=sizeContourGroup;
2008 } else { // contour AND OR XOR
2017 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2018 lstManConModTmp.clear();
2019 if (typeContourGroup==3) // contour separete
2021 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2022 } else { // contour AND OR XOR
2023 lstManConModTmp = lstManConModExp;
2026 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2029 pLstValuePosX.clear();
2030 pLstValuePosY.clear();
2031 pLstValuePosZ.clear();
2032 contourextractdata->GetValuesInsideCrown( &pLstValue,
2036 // Statistics of each slice.
2037 contourextractdata->Statistics( &pLstValue,
2040 &resultGrayRangeCount,
2045 &resultStandardeviation);
2047 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2049 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2052 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2054 tempString.Printf(_T("%d"),resultSize);
2055 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2057 tempString.Printf(_T("%d"),resultGrayRangeCount);
2058 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2060 tempString.Printf(_T("%f"),resultMin);
2061 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2063 tempString.Printf(_T("%f"),resultMax);
2064 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2066 tempString.Printf(_T("%f"),resultAverage);
2067 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2069 tempString.Printf(_T("%f"),resultStandardeviation);
2070 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2073 } // for iContourGroup
2077 wxString tmpTitleString;
2079 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2081 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2082 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2083 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2085 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2086 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2087 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2088 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2089 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2090 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2091 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2094 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2095 delete contourextractdata;
2098 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2099 SaveValuesXYZ( directory , namefile, typeContourGroup );
2101 vtkImageData* mask, *value;
2102 this->getMaskValue(mask, value, typeContourGroup);
2103 this->SaveImageResult( directory , namefile, mask, value);
2106 FILE *pFile=fopen(filename.c_str(),"w+");
2108 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2111 int i,j,maxX,maxY=sizeZ;
2112 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2114 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2115 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2117 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2118 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2120 fprintf(pFile,"\n" );
2124 for ( j=0; j<maxY ; j++)
2126 fprintf(pFile,"%d\t" , j );
2127 for (i=0 ; i<maxX ; i++){
2128 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2129 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2131 fprintf(pFile,"\n" );
2137 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2140 ContourExtractData *contourextractdata = new ContourExtractData();
2141 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2142 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2144 std::vector<manualContourModel*> lstManConMod;
2145 std::vector<manualContourModel*> lstManConModTmp;
2146 std::vector<manualContourModel*> lstManConModExp;
2147 std::vector<double> pLstValue;
2148 std::vector<double> pLstValuePosX;
2149 std::vector<double> pLstValuePosY;
2150 std::vector<double> pLstValuePosZ;
2152 std::vector<int> tempVector;
2153 _instantPanel->getInstant( tempVector );
2155 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2156 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2158 int ii,sizeLstContourThings;
2165 minZ = 0;// _mbarrange->GetStart();
2166 maxZ = sizeZ;//_mbarrange->GetEnd();
2167 totalZ = maxZ-minZ+1;
2169 contourextractdata->SetImage( imagedata);
2172 for ( z=0 ; z<sizeZ ; z++)
2175 porcent = 100.0* (z-minZ)/totalZ;
2177 tmpString.Printf(_T("Saving Values"));
2178 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2179 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2180 //_staticTextInformation->SetLabel(tmpString);
2183 //Extraction data from contours of each slice
2184 contourextractdata->SetZtoBeAnalys( z);
2187 Instant instant(&tempVector);
2188 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2189 sizeLstContourThings = lstContourThings.size();
2191 lstManConMod.clear();
2192 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2194 ContourThing **contourthing = lstContourThings[ii];
2195 lstManConMod.push_back( (*contourthing)->getModel() );
2197 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2202 int iContourGroup,sizeContourGroup;
2203 if (typeContourGroup==3) // contour separete
2205 sizeContourGroup=lstManConModExp.size();
2206 } else { // contour AND OR XOR
2210 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2211 lstManConModTmp.clear();
2212 if (typeContourGroup==3) // contour separete
2214 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2215 } else { // contour AND OR XOR
2216 lstManConModTmp = lstManConModExp;
2219 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2222 pLstValuePosX.clear();
2223 pLstValuePosY.clear();
2224 pLstValuePosZ.clear();
2225 contourextractdata->GetValuesInsideCrown( &pLstValue,
2230 std::string temp = directory + "/" + namefile + "-slice";
2231 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2232 temp = temp + ".txt";
2234 // LG 14/01/09 : using crea
2235 wxString filename = crea::std2wx(temp);
2236 /*filename.Printf(_T("%s"),directory.c_str());
2237 filename.append(_T("\\"));
2238 filename.append(_T("%s"),namefile.c_str());
2239 filename.append(_T("-slice"));
2240 filename.append(_T("%d"),z);
2241 filename.append(_T("-cont"));
2242 filename.append(_T("%d"),iContourGroup);
2243 filename.append(_T(".txt"));*/
2244 // filename.Printf(temp.c_str());
2248 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2249 fprintf(pFile,"value \t x \t y \t z\n" );
2250 int iLstValue,sizeLstValue=pLstValue.size();
2251 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2253 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2256 } // for iContourGroup
2258 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2259 //_staticTextInformation->SetLabel( _T("") );
2260 delete contourextractdata;
2263 void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){
2265 ContourExtractData *contourextractdata = new ContourExtractData( true );
2266 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2267 if (typeContourGroup==3)
2271 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2273 std::vector<manualContourModel*> lstManConMod;
2274 std::vector<manualContourModel*> lstManConModTmp;
2275 std::vector<manualContourModel*> lstManConModExp;
2277 std::vector<int> tempVector;
2278 _instantPanel->getInstant( tempVector );
2280 vtkImageData *imagedata = _theViewPanel->getImageData();
2281 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2283 int ii,sizeLstContourThings;
2292 minZ = 0;// _mbarrange->GetStart();
2293 maxZ = sizeZ;//_mbarrange->GetEnd();
2294 totalZ = maxZ-minZ+1;
2296 contourextractdata->SetImage( imagedata);
2299 for ( z=0 ; z<sizeZ ; z++)
2302 porcent = 100.0* (z-minZ)/totalZ;
2303 tmpString.Printf(_T("Saving Values"));
2304 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2305 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2307 //Extraction data from contours of each slice
2308 contourextractdata->SetZtoBeAnalys( z);
2311 Instant instant(&tempVector);
2312 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2313 sizeLstContourThings = lstContourThings.size();
2315 lstManConMod.clear();
2316 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2318 ContourThing **contourthing = lstContourThings[ii];
2319 lstManConMod.push_back( (*contourthing)->getModel() );
2321 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2324 int iContourGroup,sizeContourGroup;
2325 if (typeContourGroup==3) // contour separete
2327 sizeContourGroup=lstManConModExp.size();
2328 } else { // contour AND OR XOR
2332 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2333 lstManConModTmp.clear();
2334 if (typeContourGroup==3) // contour separete
2336 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2337 } else { // contour AND OR XOR
2338 lstManConModTmp = lstManConModExp;
2341 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2342 contourextractdata->CalculateImageResult(); // with actual Z
2344 } // for iContourGroup
2347 value = contourextractdata->GetVtkImageValueResult();
2348 mask = contourextractdata->GetVtkImageMaskResult();
2349 delete contourextractdata;
2352 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2355 std::string temp = directory + "/" + namefile + "-Value.mhd";
2357 wxString filename = crea::std2wx(temp);
2359 // filename.Printf(_T(temp.c_str()));
2360 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2361 /*filename.Printf(_T("%s"),directory.c_str());
2362 filename.append(_T("\\"));
2363 filename.append(_T("%s"),namefile.c_str());
2364 filename.append(_T("-Value.mhd"));*/
2367 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2368 writerValueImage->SetInput( value );
2369 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2370 writerValueImage->SetFileDimensionality( 3 );
2371 writerValueImage->Write( );
2374 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2375 temp = directory + "/" + namefile + "-Mask.mhd";
2377 // LG 14/01/09 : using crea
2378 filename = crea::std2wx(temp);
2379 // filename.Printf(_T(temp.c_str()));
2381 /*filename.Printf(_T("%s"),directory.c_str());
2382 filename.append(_T("\\"));
2383 filename.append(_T("%s"),namefile.c_str());
2384 filename.append(_T("-Mask.mhd"));*/
2386 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2387 writerMaskImage->SetInput( mask );
2388 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2389 writerMaskImage->SetFileDimensionality( 3 );
2390 writerMaskImage->Write( );
2392 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2398 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2399 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2400 _theViewPanel->setActualVertical( value);
2402 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2403 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2409 void wxContourMainFrame::onSnakePressed(){
2410 std::vector<double> vecX;
2411 std::vector<double> vecY;
2412 std::vector<double> vecZ;
2413 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2415 if (vecX.size()!=0){
2416 std::vector<int> tempVector;
2417 _instantPanel->getInstant( tempVector );
2418 int i,size=vecZ.size();
2419 int actualSlice = tempVector[1];
2420 for ( i=0 ; i<size ; i++ )
2422 vecZ[i] = actualSlice;
2425 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2426 wxPanel* panel = new wxPanel(dialog,-1);
2427 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2428 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2429 dialog->ShowModal();
2434 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2435 std::string filename = kernelManager->getCurrentFileName();
2436 if(filename.compare("")!=0){
2437 saveFileWithContours(filename);