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));
228 //------------------------------------------------------------------------------------------------------------
229 // Attributes getters and setters
230 //------------------------------------------------------------------------------------------------------------
234 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
236 _instantPanel = theInstantChooserPanel;
239 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
241 // _buttonsBar = theButtonsBar;
244 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
246 // _gridPanel = theGridPanel;
249 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
251 // _drawToolsPanel = theDrawToolsPanel;
254 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
256 // _operationsToolsPanel = theOperationsToolsPanel;
259 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
261 // _autoFormsPanel = theAutoFormsPanel;
264 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
266 // _standardToolsPanel= theStandardToolsPanel;
269 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
271 // _editionToolsPanel = theEditionToolsPanel;
274 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
276 // _listViewPanel = theListViewPanel;
281 void wxContourMainFrame::onCreateContourSpline( ){
283 //JCP 20-10-08 Undo redo implementation
285 //JCP 20-10-08 Undo redo implementation
289 void wxContourMainFrame::onCreateContourRectangle( ){
290 //JCP 20-10-08 Undo redo implementation
292 //JCP 20-10-08 Undo redo implementation
295 void wxContourMainFrame::onCreateContourCircle( ){
296 //JCP 20-10-08 Undo redo implementation
298 //JCP 20-10-08 Undo redo implementation
302 void wxContourMainFrame::onCreateContourLine( ){
303 //JCP 20-10-08 Undo redo implementation
305 //JCP 20-10-08 Undo redo implementation
309 //------------------------------------------------------------------------------------------------------------
311 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
313 //Creating the manualContourModel and including in the model
314 manualContourModel * manModelContour = factoryManualContourModel(panel );
316 std::vector<int> instantVector;
317 _instantPanel->getInstant( instantVector );
318 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
320 /*std::vector<int> instantVector;
321 _instantPanel->getInstant( instantVector );
323 theName= _modelManager->createOutline( manModelContour, instantVector );*/
324 bool addedModel = theName.compare("") != 0;//??
328 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
329 _theViewPanel->getSpacing(spc);
330 //Adding the manualContourControler to interface objects structure
331 //Adding the manualViewContour to interface objects structure
332 //_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.
333 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
336 void wxContourMainFrame :: createContour( int typeContour )
338 //Creating the manualContourModel and including in the model
339 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
342 std::vector<int> instantVector;
343 _instantPanel->getInstant( instantVector );
344 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
346 /*std::vector<int> instantVector;
347 _instantPanel->getInstant( instantVector );
349 theName= _modelManager->createOutline( manModelContour, instantVector );*/
350 bool addedModel = theName.compare("") != 0;//??
353 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
354 _theViewPanel->getSpacing(spc);
355 //Adding the manualContourControler to interface objects structure
356 //Adding the manualViewContour to interface objects structure
357 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
358 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
362 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
364 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
365 manualContourModel *manModelContour=NULL;
366 manModelContour = manModelContourBullEye;
368 int iCrown,sizeCrowns,iSector,sizeSectors;
369 double radioA,radioB,ang,angDelta ;
370 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
371 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
373 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
374 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
375 if (iCrown==sizeCrowns-1)
379 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
383 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
385 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
386 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
387 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
390 } // if _panelBullEyeOptions
392 return manModelContour;
394 void wxContourMainFrame :: saveState(){
396 std::string temp = kernelManager->saveState();
397 saveFileWithContours(temp);
400 void wxContourMainFrame::onDeleteContour(){
401 //JCP 20-10-08 Undo redo implementation
403 //JCP 20-10-08 Undo redo implementation
405 std::vector<std::string> lstKeyNameToBeErase;
406 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
407 deleteContours( lstKeyNameToBeErase );
409 int i,size=_sceneManager->getSelectedObjects().size();
412 std::string keyName = _sceneManager->getSelectedObjects()[i];
413 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
414 if ( ispartofstaticlist>=0 )
416 std::vector<int> tempVector;
417 _instantPanel->getInstant( tempVector );
418 Instant instant(&tempVector);
419 this->_modelManager->ChangeContourOfList(keyName, &instant);
423 std::vector<std::string> lstKeyName;
424 std::vector<std::string> lstKeyNameActualSlice;
425 std::vector<std::string> lstKeyNameToBeErase;
427 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
428 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
429 int k,kSize=lstKeyNameToBeErase.size();
430 int j,jSize=lstKeyNameActualSlice.size();
432 for (k=0;k<kSize; k++)
435 for (j=0;j<jSize; j++)
437 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
444 lstKeyName.push_back( lstKeyNameToBeErase[k] );
448 deleteContours( lstKeyName );
452 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
454 int i,size=keyNamesVector.size();
457 deleteContour( keyNamesVector[i] );
461 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
463 manualContourModel * cModel;
464 manualViewBaseContour * cViewer;
465 manualContourBaseControler * cControler;
467 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
468 cControler = conwrapviewControl->getControler();*/
471 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
472 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
474 if (isedit && ispartofstaticlst)
476 _theViewPanel->removeFromScene(theKeyName);
478 kernelManager->deleteCModel(theKeyName);
479 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
480 //cViewer = conwrapviewControl->getViewer();
481 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
482 //cControler* conwrapviewControl->getControler();
484 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
485 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
486 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
490 // delete cControler;
495 void wxContourMainFrame::onDeleteContoursActSlice(){
496 //JCP 20-10-08 Undo redo implementation
498 //JCP 20-10-08 Undo redo implementation
499 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
501 void wxContourMainFrame::onDeleteAllContours(){
502 //JCP 20-10-08 Undo redo implementation
506 void wxContourMainFrame::deleteAllContours(){
507 //JCP 20-10-08 Undo redo implementation
510 std::vector<int> tempVector;
511 _instantPanel->getInstant( tempVector );
513 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
514 // the values in GetStart and GetEnd will then not be initialize also.
515 // We use instead the values given when initializing the _deletepanel.
517 //int minZ = _mbarrangeDeleteAll->GetStart();
518 //int maxZ = _mbarrangeDeleteAll->GetEnd();
522 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
526 _theViewPanel->getSceneManager()->removeSceneContours( );
527 _theViewPanel->getSceneManager()->removeAllOutlines();
528 kernelManager->removeAllOutlines();
531 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
533 _theViewPanel->getSceneManager()->removeSceneContours( );
534 _modelManager->removeAllOutlines();
535 _theViewPanel->getSceneManager()->removeAllOutlines();
538 for ( z=minZ ; z<=maxZ ; z++)
541 Instant instant(&tempVector);
542 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
544 sizeLstContourThings = lstContourThings.size();
545 for (ii=0 ; ii<sizeLstContourThings ; ii++)
547 ContourThing **contourthing = lstContourThings[ii];
548 deleteContour( (*contourthing)->getName() );
555 void wxContourMainFrame::setConceptValue( std::string name, int value ){
556 _instantPanel->setConceptValue(name, value);
559 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
560 return _instantPanel->getLastConceptData();
562 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
563 return _instantPanel->getIfConceptCheckedAt( name, pos );
566 void wxContourMainFrame::changeInstant()
568 std::vector<int> instantVect;
569 _instantPanel->getInstant( instantVect );
570 // Instant * theInstant = new Instant ( &instantVect );
572 //Setting the actual instant
573 //_actualInstant = theInstant;
575 kernelManager->setInstant(instantVect);
576 //_modelManager->setInstant( _actualInstant );
578 updateInstantOutlines();
579 updateInstantImageData();
584 void wxContourMainFrame :: updateInstantOutlines(){
586 _theViewPanel->removeSceneContours();
587 _theViewPanel->addNameWrapperToScene();
589 //for( int i=0; i<size; i++)
591 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
595 int wxContourMainFrame::getNamesWrappingSize(){
596 return kernelManager->getNamesWrappingSize();
598 std::string wxContourMainFrame::getNameWrapping(int i){
599 return kernelManager->getNameWrapping(i);
602 void wxContourMainFrame::updateInstantImageData(){
603 std::vector<int> inst;
604 _instantPanel->getInstant(inst);
606 vtkImageData* img = kernelManager->getImageAtInstant(inst);
608 _theViewPanel->changeImage(img);
611 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
612 _theViewPanel->setImageSlice(z);
616 void wxContourMainFrame::updateInstantAxes(){
619 void wxContourMainFrame::onChangeDeep(int val){
620 _instantPanel->setConceptValue( "Axe Depth", (int)val );
625 void wxContourMainFrame::onCopy(){
626 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
628 std::vector<int> tempVector;
629 _instantPanel->getInstant( tempVector );
630 _performingOperation->reset();
631 _performingOperation->setStartCommand( COPY );
632 _performingOperation->setStartOperationInstantVector( tempVector );
633 _performingOperation->setKeyNamesOperationElems( currentSelection );
636 void wxContourMainFrame::onPaste(){
639 char theStartCommand = _performingOperation->getStartCommand();
640 if ( theStartCommand == COPY )
642 //JCP 20-10-08 Undo redo implementation
644 //JCP 20-10-08 Undo redo implementation
645 std::vector<int> tempVector;
646 _instantPanel->getInstant( tempVector );
647 _performingOperation->setEndOperationInstantVector ( tempVector );
648 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
649 int i,size = elems.size();
650 for( i=0; i<size; i++ )
652 createCopyContourOf( elems[i], tempVector, i>0 );
656 void wxContourMainFrame::onUndo(){
657 std::string filename;
658 if(kernelManager->onUndoSaveFile(filename)){
659 saveFileWithContours(filename);
661 if(kernelManager->onUndo(filename)){
665 void wxContourMainFrame::onRedo(){
666 std::string filename;
667 if(kernelManager->onRedo(filename)){
672 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
674 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
675 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
676 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
679 ///AD: 03-09 Copy the object and apply the given transformation
680 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
682 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
683 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
685 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
686 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
688 double pnt1X = refPoint1->GetX();
689 double pnt1Y = refPoint1->GetY();
690 // double pnt1Z = refPoint1->GetZ();
691 double pnt2X = refPoint2->GetX();
692 double pnt2Y = refPoint2->GetY();
693 // double pnt2Z = refPoint2->GetZ();
695 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
696 vtkTransform *t = vtkTransform::New();
700 t->Translate(-pnt1X, -pnt1Y, 0);
704 t->Translate(pnt1X, pnt1Y, 0);
707 int i,size=manualModel->GetSizeLstPoints();
710 manualPoint * mp = manualModel->GetManualPoint(i);
716 t->TransformPoint( vecIn, vecOut );
717 mp->SetPointX( vecOut[0] );
718 mp->SetPointY( vecOut[1] );
719 mp->SetPointZ( vecOut[2] );
722 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
725 void wxContourMainFrame ::loadState(std::string filename){
727 FILE *pFile=fopen(filename.c_str(),"r+");
729 fscanf(pFile,"%s",tmp); // --CreaContour--
731 fscanf(pFile,"%s",tmp); // Version
732 fscanf(pFile,"%s",tmp); // 1.0.1
733 std::string version(tmp);
737 openContours(pFile,false);
738 if (version!="1.0.0"){
739 openContours(pFile,true);
744 //_theViewPanel->getSceneManager()->removeSceneContours();
749 void wxContourMainFrame::onLoad(){
751 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
752 if (dialog.ShowModal() == wxID_OK)
754 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
755 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
757 fscanf(pFile,"%s",tmp); // --CreaContour--
759 fscanf(pFile,"%s",tmp); // Version
760 fscanf(pFile,"%s",tmp); // 1.0.1
761 std::string version(tmp);
763 openContours(pFile,false);
764 if (version!="1.0.0"){
765 openContours(pFile,true);
767 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
771 _theViewPanel->getSceneManager()->removeSceneContours();
774 void wxContourMainFrame::onSave(){
775 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
776 if (dialog.ShowModal() == wxID_OK)
778 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
779 kernelManager->setCurrentFileName(fileNameContourROI);
780 saveFileWithContours( fileNameContourROI );
783 void wxContourMainFrame::saveFileWithContours( std::string filename ){
785 FILE *pFile=fopen(filename.c_str(),"w+");
786 std::vector< std::string > lstNameThings;
787 int i,sizeLstNameThings;
789 fprintf(pFile,"--CreaContour--\n");
790 fprintf(pFile,"Version %s\n", "1.0.1" );
793 lstNameThings = kernelManager->GetLstNameThings();
794 sizeLstNameThings = lstNameThings.size();
795 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
796 for (i=0 ; i<sizeLstNameThings ; i++)
798 kernelManager->SaveThingName( pFile, lstNameThings[i] );
799 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
802 //-- Contours Statics
803 lstNameThings = kernelManager->GetLstNameThingsStatic();
804 sizeLstNameThings = lstNameThings.size();
805 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
806 for (i=0 ; i<sizeLstNameThings ; i++)
808 kernelManager->SaveThingName( pFile, lstNameThings[i] );
809 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
814 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
816 fscanf(pFile,"%s",tmp); // NumberOfContours
817 fscanf(pFile,"%s",tmp); // ##
818 int numberOfContours = atoi(tmp);
820 std::vector<int> instantVector;
821 int typeContourModel;
822 manualContourModel *manModelContour;
826 for (i=0;i<numberOfContours;i++)
828 instantVector.clear();
829 fscanf(pFile,"%s",tmp); // Instant
831 fscanf(pFile,"%s",tmp); // 1
832 instantVector.push_back( atoi(tmp) );
833 fscanf(pFile,"%s",tmp); // 2
834 instantVector.push_back( atoi(tmp) );
835 fscanf(pFile,"%s",tmp); // 3
836 instantVector.push_back( atoi(tmp) );
837 fscanf(pFile,"%s",tmp); // 4
838 instantVector.push_back( atoi(tmp) );
839 fscanf(pFile,"%s",tmp); // 5
840 instantVector.push_back( atoi(tmp) );
841 fscanf(pFile,"%s",tmp); // 6
842 instantVector.push_back( atoi(tmp) );
845 fscanf(pFile,"%s",tmp); // TypeContourModel
846 fscanf(pFile,"%s",tmp); // ##
847 typeContourModel = atoi(tmp);
849 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
850 manModelContour->Open(pFile);
852 fscanf(pFile,"%s",tmp); // TypeView
853 fscanf(pFile,"%s",tmp); // ##
854 typeView = atoi(tmp);
863 theName = kernelManager->createOutline( manModelContour, instantVector );
864 bool addedModel = theName.compare("") != 0;
867 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
868 _theViewPanel->getSpacing(spc);
869 //Adding the manualContourControler to interface objects structure
870 //Adding the manualViewContour to interface objects structure
871 //_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.
872 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
875 if (staticContour==true)
877 Instant instant(&instantVector);
878 kernelManager->changeContourOfManager( theName , &instant );
881 }// for numberOfContours
885 void wxContourMainFrame::RefreshInterface(){
887 _theViewPanel->RefreshInterface();
888 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
889 //wxvtk2dbaseview->Refresh();
892 vtkImageData* wxContourMainFrame::getImageData(){
893 return _theViewPanel->getImageData();
896 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
898 //JCP 20-10-08 Undo redo implementation
900 //JCP 20-10-08 Undo redo implementation
903 int x = _theViewPanel->GetX();
904 int y = _theViewPanel->GetY();
905 int z = _theViewPanel->GetZ();
906 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
910 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
913 int typeofcontour = 1;
915 vtkImageData *imagedata = getImageData();
917 //Tipo de pixeles a utilizar internamente en ITK
918 typedef float InternalPixelType;
919 const unsigned int Dimension = 2;
920 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
922 //Tipo de pixeles de salida 1
923 typedef unsigned char OutputPixelType;
924 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
926 //Tipo de pixeles de salida 2
927 typedef unsigned short OutputPixelType2;
928 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
930 //Definición del thresholder
931 typedef itk::BinaryThresholdImageFilter<
933 OutputImageType > ThresholdingFilterType;
935 //Definición del primer filtro de conversión de pixeles
936 typedef itk::CastImageFilter<
937 OutputImageType, OutputImageType2 > CastFilterType;
939 //Definición del segundo tipo de conversión de pixeles
940 typedef itk::CastImageFilter<
941 OutputImageType2, InternalImageType > CastFilterType2;
943 //Tercer tipo de conversión
944 typedef itk::RescaleIntensityImageFilter<
946 OutputImageType > CastFilterType3;
948 //Cuarto tipo de conversión
949 typedef itk::RescaleIntensityImageFilter<
951 OutputImageType > CastFilterType4;
953 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
955 thresholder->SetLowerThreshold( 0.0 );
956 thresholder->SetUpperThreshold( 128 );
958 thresholder->SetOutsideValue( 255 );
959 thresholder->SetInsideValue( 0 );
961 //Definción de conexiónes entre VTK e ITK y el writer
962 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
963 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
964 typedef itk::ImageFileWriter< OutputImageType > WriterType;
966 ConnectorType::Pointer connector= ConnectorType::New();
967 ConnectorType2::Pointer connector2= ConnectorType2::New();
970 CastFilterType::Pointer filter=CastFilterType::New();
971 CastFilterType2::Pointer filter2=CastFilterType2::New();
973 connector->SetInput( imagedata );
974 filter2->SetInput(connector->GetOutput());
976 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
978 InternalImageType > SmoothingFilterType;
980 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
982 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
984 InternalImageType > GradientFilterType;
986 typedef itk::SigmoidImageFilter<
988 InternalImageType > SigmoidFilterType;
990 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
992 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
994 sigmoid->SetOutputMinimum( 0.0 );
995 sigmoid->SetOutputMaximum( 255.0 );
998 typedef itk::FastMarchingImageFilter<
1000 InternalImageType > FastMarchingFilterType;
1003 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1005 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1006 InternalImageType > GeodesicActiveContourFilterType;
1007 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1008 GeodesicActiveContourFilterType::New();
1010 typedef itk::ZeroCrossingImageFilter<
1012 InternalImageType > ZeroCrossingFilterType;
1013 ZeroCrossingFilterType::Pointer zeroCrossing =
1014 ZeroCrossingFilterType::New();
1016 const double propagationScaling = atof( prop );
1018 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1019 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1020 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1022 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1023 int it=atoi( iter );
1024 geodesicActiveContour->SetNumberOfIterations( it );
1026 smoothing->SetInput( filter2->GetOutput() );
1027 gradientMagnitude->SetInput( smoothing->GetOutput() );
1028 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1029 fastMarching->SetInput( sigmoid->GetOutput() );
1030 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1031 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1033 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1034 //thresholder->SetInput( zeroCrossing->GetOutput() );
1035 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1036 connector2->SetInput( thresholder->GetOutput() );
1039 smoothing->SetTimeStep( 0.125 );
1040 smoothing->SetNumberOfIterations( 5 );
1041 smoothing->SetConductanceParameter( 9.0 );
1044 const double sigma = atof( sigm );
1045 gradientMagnitude->SetSigma( sigma );
1047 const double alpha = atof( alf );
1048 const double beta = atof( bet );
1050 sigmoid->SetAlpha( alpha );
1051 sigmoid->SetBeta( beta );
1053 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1054 typedef FastMarchingFilterType::NodeType NodeType;
1056 NodeContainer::Pointer seeds = NodeContainer::New();
1058 InternalImageType::IndexType seedPosition;
1059 seedPosition[0] = x;
1060 seedPosition[1] = y;
1062 const double initialDistance = atof( distanc );
1066 const double seedValue = - initialDistance;
1068 node.SetValue( seedValue );
1069 node.SetIndex( seedPosition );
1071 seeds->Initialize();
1072 seeds->InsertElement( 0, node );
1074 fastMarching->SetTrialPoints( seeds );
1076 fastMarching->SetSpeedConstant( 1.0 );
1078 fastMarching->SetOutputSize(
1079 connector->GetOutput()->GetBufferedRegion().GetSize() );
1081 fastMarching->SetStoppingValue( 800 );
1085 connector2->Update();
1086 vtkImageData *idata = connector2->GetOutput();
1088 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1090 cntVTK->SetInput( idata );
1092 cntVTK->SetNumberOfContours( 1 );
1093 cntVTK->SetValue( 0, 255 );
1095 cntVTK->UpdateInformation();
1097 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1098 cpd->SetInput( cntVTK->GetOutput( ) );
1100 cpd->UpdateInformation();
1102 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1103 conn->SetExtractionModeToLargestRegion( );
1104 conn->SetInput( cpd->GetOutput( ) );
1106 conn->UpdateInformation();
1108 vtkStripper* vtkstripper = vtkStripper::New( );
1109 vtkstripper->SetInput( conn->GetOutput() );
1110 vtkstripper->Update();
1111 vtkstripper->UpdateInformation();
1114 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1115 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1116 polyDataResult->Update( );
1117 polyDataResult->UpdateInformation();
1122 myfile.open ("C:/Creatis/example.txt");
1124 polyDataResult->Print(myfile);
1125 myfile << "-------------------------------------\n";
1126 polyDataResult->GetLines()->Print(myfile);
1134 //--Calculating control points
1136 std::vector<double> vecX;
1137 std::vector<double> vecY;
1138 std::vector<double> vecXo;
1139 std::vector<double> vecYo;
1140 std::vector<double>::iterator vecXoi;
1141 std::vector<double>::iterator vecYoi;
1142 std::vector<double> vecZ;
1144 std::vector<double> vecCtrlPointX;
1145 std::vector<double> vecCtrlPointY;
1146 std::vector<double> vecCtrlPointZ;
1152 int ii,size=polyDataResult->GetNumberOfPoints();
1154 myfile.open ("C:/Creatis/example2.txt");
1156 size=polyDataResult->GetNumberOfPoints();
1157 for (ii=0;ii<size;ii++)
1164 p = polyDataResult->GetPoint(ii);
1167 /*if(fabs(yAct-y)>20)
1169 if((xAct-x)>1 || (xAct-x)<-1)
1171 vecX.push_back( p[0] );
1172 vecY.push_back( p[1] );
1173 myfile <<p[0]<<","<<p[1]<<"\n";
1174 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1175 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1176 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1177 vecZ.push_back( -900 );
1183 vecXo.push_back(p[0]);
1184 vecYo.push_back(p[1]);
1188 else*/ if(fabs(xAct-x)>11)
1190 vecXo.push_back(p[0]);
1191 vecYo.push_back(p[1]);
1195 vecX.push_back( p[0] );
1196 myfile <<p[0]<<","<<p[1]<<"\n";
1197 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1198 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1199 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1200 vecY.push_back( p[1] );
1201 vecZ.push_back( -900 );
1209 while(!vecXo.empty())
1211 vecX.push_back(vecXo.back());
1212 std::cout<<" x Siguiente "<<vecXo.back();
1214 vecZ.push_back( -900 );
1216 while(!vecYo.empty())
1218 vecY.push_back(vecYo.back());
1223 /*for(int l=0;l<vecX.size();l++)
1227 vecXo.push_back(p[0]);
1228 vecYo.push_back(p[1]);
1239 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1241 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1245 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1247 else if (method==1){
1248 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1250 else if (method==2){
1251 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1252 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1254 //--Adding contour to the system
1256 std::vector<int> actualInstantVector;
1257 _instantPanel->getInstant( actualInstantVector );
1258 actualInstantVector[1]=z;
1260 int j,sizeCtrPt = vecCtrlPointX.size();
1262 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1263 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1265 for (j=0 ; j<sizeCtrPt ; j++)
1267 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1269 std::string theName;
1270 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1271 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1272 bool addedModel = theName.compare("") != 0;
1275 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1276 _theViewPanel->getSpacing(spc);
1277 //Adding the manualContourControler to interface objects structure
1278 //Adding the manualViewContour to interface objects structure
1279 //_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.
1280 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1281 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1287 WriterType::Pointer writer = WriterType::New();
1288 CastFilterType3::Pointer caster = CastFilterType3::New();
1290 caster->SetInput( gradientMagnitude->GetOutput() );
1291 writer->SetInput( caster->GetOutput() );
1292 writer->SetFileName("Gradient Magnitude.png");
1293 caster->SetOutputMinimum( 0 );
1294 caster->SetOutputMaximum( 255 );
1297 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1298 WriterType::Pointer writer2 = WriterType::New();
1300 caster2->SetInput( sigmoid->GetOutput() );
1301 writer2->SetInput( caster2->GetOutput() );
1302 writer2->SetFileName("Sigmoid.png");
1303 caster2->SetOutputMinimum( 0 );
1304 caster2->SetOutputMaximum( 255 );
1307 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1308 WriterType::Pointer writer3 = WriterType::New();
1310 caster3->SetInput( fastMarching->GetOutput() );
1311 writer3->SetInput( caster3->GetOutput() );
1312 writer3->SetFileName("FastMarching.bmp");
1313 caster3->SetOutputMinimum( 0 );
1314 caster3->SetOutputMaximum( 255 );
1317 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1318 WriterType::Pointer writer4 = WriterType::New();
1320 caster4->SetInput( geodesicActiveContour->GetOutput() );
1321 writer4->SetInput( caster4->GetOutput() );
1322 writer4->SetFileName("GeodesicActiveContour.png");
1323 caster4->SetOutputMinimum( 0 );
1324 caster4->SetOutputMaximum( 255 );
1327 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1328 WriterType::Pointer writer5 = WriterType::New();
1330 caster5->SetInput( zeroCrossing->GetOutput() );
1331 writer5->SetInput( caster5->GetOutput() );
1332 writer5->SetFileName("ZeroCrossing.bmp");
1333 caster5->SetOutputMinimum( 0 );
1334 caster5->SetOutputMaximum( 255 );
1337 catch( itk::ExceptionObject & excep )
1339 std::cerr << "Exception caught !" << std::endl;
1340 std::cerr << excep << std::endl;
1344 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1346 //JCP 20-10-08 Undo redo implementation
1348 //JCP 20-10-08 Undo redo implementation
1351 int x = _theViewPanel->GetX();
1352 int y = _theViewPanel->GetY();
1353 int z = _theViewPanel->GetZ();
1354 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1359 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1361 int typeofcontour = 1;
1362 //--Extracting Contour
1363 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1364 vtkImageData *imagedata = getImageData();
1365 // double *range = imagedata->GetScalarRange();
1368 vtkImageReslice *imageReslice = vtkImageReslice::New();
1371 // imagedata->GetSpacing(spc);
1376 imageReslice->SetInput( imagedata );
1377 imageReslice->SetInformationInput(imagedata);
1378 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1379 imageReslice->SetResliceAxesOrigin(0,0,z);
1380 imageReslice->SetOutputDimensionality(2);
1381 imageReslice->SetInterpolationModeToLinear();
1383 imagedata = imageReslice->GetOutput();
1384 imagedata->Update();
1385 imagedata->UpdateInformation();
1387 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1388 cntVTK->SetInput( imagedata );
1390 cntVTK->SetNumberOfContours( 1 );
1391 //cntVTK->SetValue( 0, vmin );
1392 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1393 cntVTK->SetValue( 1, isovalue );
1394 // cntVTK->SetValue( 1, vmax );
1396 cntVTK->UpdateInformation();
1398 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1399 cpd->SetInput( cntVTK->GetOutput( ) );
1400 cpd->ConvertLinesToPointsOff( );
1402 cpd->UpdateInformation();
1404 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1405 conn->SetExtractionModeToClosestPointRegion( );
1406 //conn->SetMaxRecursionDepth( 3000 );
1408 conn->SetInput( cpd->GetOutput( ) );
1410 conn->SetClosestPoint( x, y, 0 );
1412 conn->UpdateInformation();
1414 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1415 cpd2->SetInput( conn->GetOutput( ) );
1417 cpd2->UpdateInformation();
1419 vtkStripper* vtkstripper = vtkStripper::New( );
1420 vtkstripper->SetInput( cpd2->GetOutput() );
1421 vtkstripper->Update();
1422 vtkstripper->UpdateInformation();
1425 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1427 polyDataResult->Update( );
1428 polyDataResult->UpdateInformation();
1432 myfile.open ("c:/temp/example.txt");
1434 polyDataResult->Print(myfile);
1435 myfile << "-------------------------------------\n";
1436 polyDataResult->GetLines()->Print(myfile);
1446 //--Calculating control points
1448 std::vector<double> vecX;
1449 std::vector<double> vecY;
1450 std::vector<double> vecZ;
1452 std::vector<double> vecCtrlPointX;
1453 std::vector<double> vecCtrlPointY;
1454 std::vector<double> vecCtrlPointZ;
1458 int ii,size=polyDataResult->GetNumberOfPoints();
1460 for (ii=1;ii<=size;ii++)
1462 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1463 p = polyDataResult->GetPoint(id);
1466 vecX.push_back( p[0] );
1467 vecY.push_back( p[1] );
1468 vecZ.push_back( -900 );
1469 // vecZ.push_back( p[2] );
1473 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1474 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1477 /*if (methodRadiobox->GetSelection()==0){
1478 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1480 if (methodRadiobox->GetSelection()==1){
1481 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1483 if (methodRadiobox->GetSelection()==2){
1484 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1485 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1489 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1491 else if (method==1){
1492 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1494 else if (method==2){
1495 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1496 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1499 //--Adding contour to the system
1501 std::vector<int> actualInstantVector;
1502 _instantPanel->getInstant( actualInstantVector );
1503 actualInstantVector[1]=z;
1505 int j,sizeCtrPt = vecCtrlPointX.size();
1506 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1507 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1509 for (j=0 ; j<sizeCtrPt ; j++)
1511 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1513 std::string theName;
1514 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1515 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1516 bool addedModel = theName.compare("") != 0;
1519 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1520 _theViewPanel->getSpacing(spc);
1521 //Adding the manualContourControler to interface objects structure
1522 //Adding the manualViewContour to interface objects structure
1523 //_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.
1524 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1525 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1529 int wxContourMainFrame::GetImageDataSizeZ(){
1530 return _theViewPanel->GetImageDataSizeZ();
1533 void wxContourMainFrame::GetImageDataRange(double *range){
1534 _theViewPanel->GetImageDataRange(range);
1537 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1538 //JCP 20-10-08 Undo redo implementation
1540 //JCP 20-10-08 Undo redo implementation
1543 int x = _theViewPanel->GetX();
1544 int y = _theViewPanel->GetY();
1548 double totalZ = maxZ-minZ+1;
1549 for( z=minZ ; z<=maxZ ; z++ )
1551 porcent = 100.0* (z-minZ)/totalZ;
1552 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1553 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1554 //_staticTextSegmentation->SetLabel(tmpString);
1555 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1557 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1562 //Creates a reference line to be used as the axis of the mirroring
1563 void wxContourMainFrame::referenceLine()
1568 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1569 vtkimagedata->GetSpacing(spc);
1571 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1573 _refLineControl = new manualLineControler();
1574 _refLineModel = new manualContourModelLine();
1575 _refLineView = new manualViewLine();
1576 _refLineView->SetModel( _refLineModel );
1577 _refLineView->SetWxVtkBaseView( viewer2D );
1578 _refLineView->SetRange( 2 );
1579 _refLineView->SetZ( 1200 );
1581 _refLineView->SetSpacing(spc);
1583 _refLineView->SetColorNormalContour(0, 0, 1);
1584 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1585 _refLineView->SetWidthLine(4);
1587 _refLineControl->SetModelView( _refLineModel , _refLineView );
1588 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1589 _refLineModel->SetCloseContour(false);
1590 _refLineControl->CreateNewManualContour();
1592 double z = _refLineControl->GetZ();
1594 _refLineControl->AddPoint(50,100,z);
1595 _refLineControl->AddPoint(80,40,z);
1596 _refLineControl->SetCompleteCreation(true);
1598 _refLineModel->AddPoint(50,100,z);
1599 _refLineModel->AddPoint(80,40,z);
1600 _refLineModel->UpdateSpline();
1602 _refLineView->UpdateViewPoint(0);
1603 _refLineView->UpdateViewPoint(1);
1606 _refLineControl->SetActive(true);
1607 _refLineView->RefreshContour();
1610 //Hides the referenceLine
1611 void wxContourMainFrame::refLineHide()
1613 if (_refLineControl!=NULL)
1615 _refLineView->RemoveCompleteContourActor();
1616 _refLineControl->SetEditable(false);
1617 _refLineControl->SetActive(false);
1621 //Shows the referenceLine
1622 void wxContourMainFrame::refLineShow()
1624 if (_refLineControl!=NULL)
1626 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1628 _refLineView->SetModel( _refLineModel );
1629 _refLineView->SetWxVtkBaseView( viewer2D );
1630 _refLineView->SetRange( 2 );
1631 _refLineView->SetZ( 1200 );
1633 _refLineControl->SetModelView( _refLineModel , _refLineView );
1634 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1635 _refLineControl->CreateNewManualContour();
1636 _refLineControl->SetActive(true);
1637 _refLineView->RefreshContour();
1641 void wxContourMainFrame::refLineChangeWidth(int width)
1643 _refLineView->SetWidthLine(width);
1644 _refLineView->RefreshContour();
1650 void wxContourMainFrame::onMirror()
1653 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1654 std::vector<std::string> filterCurrentSelection;
1656 std::vector<int> tempVector;
1657 _instantPanel->getInstant( tempVector );
1658 _performingOperation->reset();
1659 _performingOperation->setStartCommand( COPY );
1660 _performingOperation->setStartOperationInstantVector( tempVector );
1661 _performingOperation->setKeyNamesOperationElems( currentSelection );
1663 char theStartCommand = _performingOperation->getStartCommand();
1664 if ( theStartCommand == COPY )
1666 //JCP 20-10-08 Undo redo implementation
1668 //JCP 20-10-08 Undo redo implementation
1669 std::vector<int> tempVector;
1670 _instantPanel->getInstant( tempVector );
1671 _performingOperation->setEndOperationInstantVector ( tempVector );
1672 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1673 int i,size = elems.size();
1674 for( i=0; i<size; i++ )
1676 createMirrorContourOf( elems[i], tempVector, i>0 );
1680 //deleteContour( _refName );
1684 void wxContourMainFrame::onThreshold(int minVal, int maxVal)
1687 vtkImageData * img = _theViewPanel->getImageData();
1690 img->GetScalarRange(range);
1692 //vtkImageData * fakeImage = new vtkImageData();
1695 vtkLookupTable *lookup = vtkLookupTable::New();
1696 lookup->SetNumberOfTableValues(range[1]+1);
1697 lookup->SetTableRange(range);
1698 lookup->SetAlphaRange(0, 1);
1699 lookup->SetValueRange(0, 1);
1700 lookup->SetSaturationRange(0, 0);
1701 lookup->SetRampToLinear( );
1705 //Assign a fake color for the upper image, and set the white as transparent
1706 for(int i = range[0]; i < range[1]; i++)
1708 //std::cout<<"Int equal: " << i << std::endl;
1710 if( i >= minVal && i <= maxVal )
1712 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1714 else if( i >= range[0] && i < minVal )
1716 lookup->SetTableValue(i, 0.0, 0.0, 0.0, 0); //transparent
1718 else if( i > maxVal && i < range[1] )
1720 lookup->SetTableValue(i, 0.0, 0.0, 0.0, 0); //transparent
1726 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
1727 mapperImage->SetLookupTable( lookup );
1728 mapperImage->SetInput( img );
1729 //mapperImage->SetOutputFormatToRGBA( );
1731 vtkImageActor * upperImageActor = vtkImageActor::New( );
1732 upperImageActor->SetInput( mapperImage->GetOutput() );
1733 upperImageActor->SetOpacity( 1 );
1735 vtkImageViewer2* viewer = vtkImageViewer2::New();
1736 viewer->SetInput( upperImageActor->GetInput() );
1737 viewer->SetColorLevel((range[1]-range[0])/2);
1738 viewer->SetColorWindow(range[1]);
1739 viewer->GetRenderer()->AddActor( upperImageActor );
1742 //wxThresholdPanel * panel = new wxThresholdPanel( viewer, notebook );
1744 //onThresholdPanel(panel);
1748 //baseImageActor = vtkImageActor::New( );
1749 //baseImageActor->SetInput( mBox->bbGetInputImage1() );
1753 bool wxContourMainFrame::onThresholdPanel(wxPanel* panel)
1755 bool configured = panel!=NULL;
1756 configured &= panel!=NULL;
1760 notebook->AddPage( panel, wxT(" Threshold "), true );
1766 void wxContourMainFrame::showAxis(bool show)
1768 _theViewPanel->SetVisibleAxis(show);
1769 _theViewPanel->Refresh();
1773 void wxContourMainFrame::onRigidPressed(){
1774 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1775 int elementsSelected = currentSelection.size();
1777 if ( elementsSelected >= 1 ){
1778 //JCP 20-10-08 Undo redo implementation
1780 //JCP 20-10-08 Undo redo implementation
1782 std::vector<int> tempVector;
1783 _instantPanel->getInstant( tempVector );
1784 Instant instant(&tempVector);
1786 int i , size=currentSelection.size();
1787 for ( i=0 ; i<size ; i++ )
1789 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1794 void wxContourMainFrame::onWidthOfContour(double width){
1796 _theViewPanel->removeSceneContours();
1797 _theViewPanel->SetWidthContour(width);
1799 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1803 int wxContourMainFrame::getColorWindow(){
1804 return _theViewPanel->getColorWindow();
1806 int wxContourMainFrame::getWindowLevel(){
1807 return _theViewPanel->getWindowLevel();
1810 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1811 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1817 void wxContourMainFrame::onInterpolation(bool interpolate){
1818 _theViewPanel->onInterpolation(interpolate);
1822 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1823 _instantPanel->setConceptValue( name, actual );
1826 void wxContourMainFrame::resetAppend(){
1827 kernelManager->resetAppend();
1831 void wxContourMainFrame::onSpreadAdd(){
1832 std::vector<double> vecX;
1833 std::vector<double> vecY;
1834 std::vector<double> vecZ;
1835 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1837 std::vector<int> tempVector;
1838 _instantPanel->getInstant( tempVector );
1840 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1842 interfMainPanel::getInstance()->appendStringSpread(val);
1846 void wxContourMainFrame::onSpreadGo(int type){
1848 //JCP 20-10-08 Undo redo implementation
1850 //JCP 20-10-08 Undo redo implementation
1853 std::vector<double> vecCtrlPointX;
1854 std::vector<double> vecCtrlPointY;
1855 std::vector<double> vecCtrlPointZ;
1859 std::vector<int> tempVector;
1860 _instantPanel->getInstant( tempVector );
1863 kernelManager->getMaxMinZ(&minZ,&maxZ);
1864 //JSTG_16-07-08_----------------------------------------------------------------
1865 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1866 kernelManager->CalculeSplinePropagation();
1868 double totalZ = maxZ-minZ+1;
1871 //--------------------------------------------------------------------
1872 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1874 porcent = 100.0* (z-minZ)/totalZ;
1875 int numero = (int)(z-minZ+1)/(int)totalZ;
1876 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1878 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1880 int typeofcontour = 1;
1881 std::string theName;
1882 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1884 if( manModelContour!=NULL ){
1885 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1886 this->_theViewPanel->getSpacing(spc);
1887 //Adding the manualContourControler to interface objects structure
1888 //Adding the manualViewContour to interface objects structure
1889 //_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.
1890 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1895 int numero = (int)(z-minZ+1)/(int)totalZ;
1896 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1898 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1900 //RefreshInterface();
1903 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1907 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1908 std::vector<int> tempVector;
1909 _instantPanel->getInstant(tempVector);
1910 //Asignation of slide number should be different ex by name
1911 tempVector[1]=slide;
1912 return kernelManager->getOutlinesNameAtInstant(tempVector);
1915 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1916 int maxContourGroup = 0;
1918 ContourExtractData *contourextractdata = new ContourExtractData();
1920 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1922 std::vector<manualContourModel*> lstManConMod;
1923 std::vector<manualContourModel*> lstManConModTmp;
1924 std::vector<manualContourModel*> lstManConModExp;
1925 std::vector<double> pLstValue;
1926 std::vector<double> pLstValuePosX;
1927 std::vector<double> pLstValuePosY;
1928 std::vector<double> pLstValuePosZ;
1931 int resultGrayRangeCount;
1934 double resultAverage;
1935 double resultStandardeviation;
1937 std::vector<int> tempVector;
1938 _instantPanel->getInstant( tempVector );
1940 vtkImageData *imagedata = _theViewPanel->getImageData();
1941 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1943 int ii,sizeLstContourThings;
1953 if (selection==0 ) // actual slice
1955 std::vector<int> tempVector;
1956 _instantPanel->getInstant( tempVector );
1957 int actualSlice = tempVector[1];
1961 else if (selection==2 ) // All slices
1966 else if (selection==1 ) // slice range
1973 totalZ = maxZ-minZ+1;
1974 contourextractdata->SetImage( imagedata);
1977 for ( z=minZ ; z<=maxZ ; z++ )
1980 porcent = 100.0* (z-minZ)/totalZ;
1981 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1983 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1984 //_staticTextInformation->SetLabel(tmpString);
1986 //Extraction data from contours of each slice
1987 contourextractdata->SetZtoBeAnalys( z);
1990 Instant instant(&tempVector);
1991 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1992 sizeLstContourThings = lstContourThings.size();
1994 lstManConMod.clear();
1995 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1997 ContourThing **contourthing = lstContourThings[ii];
1998 lstManConMod.push_back( (*contourthing)->getModel() );
2000 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2003 wxString tempString;
2004 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2005 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2006 //_grid->SetRowLabelValue(z, tempString );
2008 int iContourGroup,sizeContourGroup;
2009 if (typeContourGroup==3) // contour separete
2011 sizeContourGroup=lstManConModExp.size();
2012 if ( maxContourGroup<sizeContourGroup )
2014 maxContourGroup=sizeContourGroup;
2016 } else { // contour AND OR XOR
2025 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2026 lstManConModTmp.clear();
2027 if (typeContourGroup==3) // contour separete
2029 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2030 } else { // contour AND OR XOR
2031 lstManConModTmp = lstManConModExp;
2034 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2037 pLstValuePosX.clear();
2038 pLstValuePosY.clear();
2039 pLstValuePosZ.clear();
2040 contourextractdata->GetValuesInsideCrown( &pLstValue,
2044 // Statistics of each slice.
2045 contourextractdata->Statistics( &pLstValue,
2048 &resultGrayRangeCount,
2053 &resultStandardeviation);
2055 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2057 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2060 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2062 tempString.Printf(_T("%d"),resultSize);
2063 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2065 tempString.Printf(_T("%d"),resultGrayRangeCount);
2066 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2068 tempString.Printf(_T("%f"),resultMin);
2069 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2071 tempString.Printf(_T("%f"),resultMax);
2072 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2074 tempString.Printf(_T("%f"),resultAverage);
2075 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2077 tempString.Printf(_T("%f"),resultStandardeviation);
2078 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2081 } // for iContourGroup
2085 wxString tmpTitleString;
2087 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2089 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2090 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2091 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2093 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2094 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2095 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2096 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2097 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2098 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2099 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2102 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2103 delete contourextractdata;
2106 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2107 SaveValuesXYZ( directory , namefile, typeContourGroup );
2109 vtkImageData* mask, *value;
2110 this->getMaskValue(mask, value, typeContourGroup);
2111 this->SaveImageResult( directory , namefile, mask, value);
2114 FILE *pFile=fopen(filename.c_str(),"w+");
2116 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2119 int i,j,maxX,maxY=sizeZ;
2120 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2122 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2123 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2125 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2126 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2128 fprintf(pFile,"\n" );
2132 for ( j=0; j<maxY ; j++)
2134 fprintf(pFile,"%d\t" , j );
2135 for (i=0 ; i<maxX ; i++){
2136 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2137 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2139 fprintf(pFile,"\n" );
2145 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2148 ContourExtractData *contourextractdata = new ContourExtractData();
2149 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2150 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2152 std::vector<manualContourModel*> lstManConMod;
2153 std::vector<manualContourModel*> lstManConModTmp;
2154 std::vector<manualContourModel*> lstManConModExp;
2155 std::vector<double> pLstValue;
2156 std::vector<double> pLstValuePosX;
2157 std::vector<double> pLstValuePosY;
2158 std::vector<double> pLstValuePosZ;
2160 std::vector<int> tempVector;
2161 _instantPanel->getInstant( tempVector );
2163 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2164 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2166 int ii,sizeLstContourThings;
2173 minZ = 0;// _mbarrange->GetStart();
2174 maxZ = sizeZ;//_mbarrange->GetEnd();
2175 totalZ = maxZ-minZ+1;
2177 contourextractdata->SetImage( imagedata);
2180 for ( z=0 ; z<sizeZ ; z++)
2183 porcent = 100.0* (z-minZ)/totalZ;
2185 tmpString.Printf(_T("Saving Values"));
2186 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2187 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2188 //_staticTextInformation->SetLabel(tmpString);
2191 //Extraction data from contours of each slice
2192 contourextractdata->SetZtoBeAnalys( z);
2195 Instant instant(&tempVector);
2196 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2197 sizeLstContourThings = lstContourThings.size();
2199 lstManConMod.clear();
2200 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2202 ContourThing **contourthing = lstContourThings[ii];
2203 lstManConMod.push_back( (*contourthing)->getModel() );
2205 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2210 int iContourGroup,sizeContourGroup;
2211 if (typeContourGroup==3) // contour separete
2213 sizeContourGroup=lstManConModExp.size();
2214 } else { // contour AND OR XOR
2218 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2219 lstManConModTmp.clear();
2220 if (typeContourGroup==3) // contour separete
2222 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2223 } else { // contour AND OR XOR
2224 lstManConModTmp = lstManConModExp;
2227 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2230 pLstValuePosX.clear();
2231 pLstValuePosY.clear();
2232 pLstValuePosZ.clear();
2233 contourextractdata->GetValuesInsideCrown( &pLstValue,
2238 std::string temp = directory + "/" + namefile + "-slice";
2239 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2240 temp = temp + ".txt";
2242 // LG 14/01/09 : using crea
2243 wxString filename = crea::std2wx(temp);
2244 /*filename.Printf(_T("%s"),directory.c_str());
2245 filename.append(_T("\\"));
2246 filename.append(_T("%s"),namefile.c_str());
2247 filename.append(_T("-slice"));
2248 filename.append(_T("%d"),z);
2249 filename.append(_T("-cont"));
2250 filename.append(_T("%d"),iContourGroup);
2251 filename.append(_T(".txt"));*/
2252 // filename.Printf(temp.c_str());
2256 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2257 fprintf(pFile,"value \t x \t y \t z\n" );
2258 int iLstValue,sizeLstValue=pLstValue.size();
2259 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2261 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2264 } // for iContourGroup
2266 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2267 //_staticTextInformation->SetLabel( _T("") );
2268 delete contourextractdata;
2271 void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){
2273 ContourExtractData *contourextractdata = new ContourExtractData( true );
2274 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2275 if (typeContourGroup==3)
2279 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2281 std::vector<manualContourModel*> lstManConMod;
2282 std::vector<manualContourModel*> lstManConModTmp;
2283 std::vector<manualContourModel*> lstManConModExp;
2285 std::vector<int> tempVector;
2286 _instantPanel->getInstant( tempVector );
2288 vtkImageData *imagedata = _theViewPanel->getImageData();
2289 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2291 int ii,sizeLstContourThings;
2300 minZ = 0;// _mbarrange->GetStart();
2301 maxZ = sizeZ;//_mbarrange->GetEnd();
2302 totalZ = maxZ-minZ+1;
2304 contourextractdata->SetImage( imagedata);
2307 for ( z=0 ; z<sizeZ ; z++)
2310 porcent = 100.0* (z-minZ)/totalZ;
2311 tmpString.Printf(_T("Saving Values"));
2312 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2313 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2315 //Extraction data from contours of each slice
2316 contourextractdata->SetZtoBeAnalys( z);
2319 Instant instant(&tempVector);
2320 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2321 sizeLstContourThings = lstContourThings.size();
2323 lstManConMod.clear();
2324 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2326 ContourThing **contourthing = lstContourThings[ii];
2327 lstManConMod.push_back( (*contourthing)->getModel() );
2329 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2332 int iContourGroup,sizeContourGroup;
2333 if (typeContourGroup==3) // contour separete
2335 sizeContourGroup=lstManConModExp.size();
2336 } else { // contour AND OR XOR
2340 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2341 lstManConModTmp.clear();
2342 if (typeContourGroup==3) // contour separete
2344 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2345 } else { // contour AND OR XOR
2346 lstManConModTmp = lstManConModExp;
2349 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2350 contourextractdata->CalculateImageResult(); // with actual Z
2352 } // for iContourGroup
2355 value = contourextractdata->GetVtkImageValueResult();
2356 mask = contourextractdata->GetVtkImageMaskResult();
2357 delete contourextractdata;
2360 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2363 std::string temp = directory + "/" + namefile + "-Value.mhd";
2365 wxString filename = crea::std2wx(temp);
2367 // filename.Printf(_T(temp.c_str()));
2368 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2369 /*filename.Printf(_T("%s"),directory.c_str());
2370 filename.append(_T("\\"));
2371 filename.append(_T("%s"),namefile.c_str());
2372 filename.append(_T("-Value.mhd"));*/
2375 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2376 writerValueImage->SetInput( value );
2377 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2378 writerValueImage->SetFileDimensionality( 3 );
2379 writerValueImage->Write( );
2382 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2383 temp = directory + "/" + namefile + "-Mask.mhd";
2385 // LG 14/01/09 : using crea
2386 filename = crea::std2wx(temp);
2387 // filename.Printf(_T(temp.c_str()));
2389 /*filename.Printf(_T("%s"),directory.c_str());
2390 filename.append(_T("\\"));
2391 filename.append(_T("%s"),namefile.c_str());
2392 filename.append(_T("-Mask.mhd"));*/
2394 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2395 writerMaskImage->SetInput( mask );
2396 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2397 writerMaskImage->SetFileDimensionality( 3 );
2398 writerMaskImage->Write( );
2400 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2406 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2407 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2408 _theViewPanel->setActualVertical( value);
2410 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2411 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2417 void wxContourMainFrame::onSnakePressed(){
2418 std::vector<double> vecX;
2419 std::vector<double> vecY;
2420 std::vector<double> vecZ;
2421 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2423 if (vecX.size()!=0){
2424 std::vector<int> tempVector;
2425 _instantPanel->getInstant( tempVector );
2426 int i,size=vecZ.size();
2427 int actualSlice = tempVector[1];
2428 for ( i=0 ; i<size ; i++ )
2430 vecZ[i] = actualSlice;
2433 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2434 wxPanel* panel = new wxPanel(dialog,-1);
2435 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2436 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2437 dialog->ShowModal();
2442 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2443 std::string filename = kernelManager->getCurrentFileName();
2444 if(filename.compare("")!=0){
2445 saveFileWithContours(filename);