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 interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
94 _performingOperation = new PerformingOperation();
98 if(images.size() > 0){
99 this->setVectImages(images);
104 void wxContourMainFrame::setVectImages( std::vector<vtkImageData*> images ){
106 #if defined(__GNUC__)
107 std::string str_home(getenv("HOME"));
108 #elif defined(_WIN32)
109 std::string str_home(getenv("USERPROFILE"));
111 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
113 std::vector<std::string> conceptNameVect;
114 std::vector<int> conceptSizeVect;
116 wxAuiNotebook * notebook = this->createNotebook();
119 kernelManager = new KernelManagerContour( images , _datadir+"/data/" , strCreaContourDataTmp );
122 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
123 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
125 //-------------------------------------------------------------
126 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
127 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
130 double val = _theViewPanel->getCurrentDeep();
131 _instantPanel->setConceptValue( "Axe Depth", (int)val );
132 //JCP _instantPanel->setConceptValue("time", num de imagenes);
133 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
134 //*******************changeInstant();
135 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
137 this->configurePanels( notebook );
142 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 ){
143 if(instance == NULL){
144 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
149 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
150 return kernelManager->getVectImages();
152 wxContourMainFrame* wxContourMainFrame :: getInstance(){
157 wxContourMainFrame :: ~wxContourMainFrame()
160 //El problema al cerrar la aplicacion puede estar asociado
161 //a que wxAUINotebook esta en la aplicacion
162 //principal (wxContourGUIExample)tambien
163 //EED???? delete _theViewPanel;
164 //EED???? delete _instantPanel;
165 //EED???? delete _buttonsBar;
166 //EED???? delete _actualInstant;
167 //EED???? delete _sceneManager;
171 //------------------------------------------------------------------------------------------------------------
172 // Creational and initialization methods using WxAui
173 //------------------------------------------------------------------------------------------------------------
175 wxAuiNotebook * wxContourMainFrame :: createNotebook()
177 wxSize client_size = GetClientSize();
178 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
179 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
184 //------------------------------------------------------------------------------------------------------------
185 // Creational and initialization methods
186 //------------------------------------------------------------------------------------------------------------
187 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
189 bool configured = _theViewPanel!=NULL;
191 configured &= _theViewPanel!=NULL;
192 if( _theViewPanel!=NULL )
194 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
201 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
205 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
207 /* configured &= _buttonsBar!=NULL;
208 if( _buttonsBar!=NULL )
210 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
211 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
213 LeftDockable( ).RightDockable( false ).CloseButton(false));
218 SetMinSize(wxSize(300,300));
223 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
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(){
567 std::vector<int> instantVect;
568 _instantPanel->getInstant( instantVect );
569 // Instant * theInstant = new Instant ( &instantVect );
571 //Setting the actual instant
572 //_actualInstant = theInstant;
574 kernelManager->setInstant(instantVect);
575 //_modelManager->setInstant( _actualInstant );
577 updateInstantOutlines();
578 updateInstantImageData();
583 void wxContourMainFrame :: updateInstantOutlines(){
585 _theViewPanel->removeSceneContours();
586 _theViewPanel->addNameWrapperToScene();
588 //for( int i=0; i<size; i++)
590 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
594 int wxContourMainFrame::getNamesWrappingSize(){
595 return kernelManager->getNamesWrappingSize();
597 std::string wxContourMainFrame::getNameWrapping(int i){
598 return kernelManager->getNameWrapping(i);
601 void wxContourMainFrame::updateInstantImageData(){
602 std::vector<int> inst;
603 _instantPanel->getInstant(inst);
605 vtkImageData* img = kernelManager->getImageAtInstant(inst);
607 _theViewPanel->changeImage(img);
610 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
611 _theViewPanel->setImageSlice(z);
614 void wxContourMainFrame::updateInstantAxes(){
617 void wxContourMainFrame::onChangeDeep(int val){
618 _instantPanel->setConceptValue( "Axe Depth", (int)val );
623 void wxContourMainFrame::onCopy(){
624 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
626 std::vector<int> tempVector;
627 _instantPanel->getInstant( tempVector );
628 _performingOperation->reset();
629 _performingOperation->setStartCommand( COPY );
630 _performingOperation->setStartOperationInstantVector( tempVector );
631 _performingOperation->setKeyNamesOperationElems( currentSelection );
634 void wxContourMainFrame::onPaste(){
637 char theStartCommand = _performingOperation->getStartCommand();
638 if ( theStartCommand == COPY )
640 //JCP 20-10-08 Undo redo implementation
642 //JCP 20-10-08 Undo redo implementation
643 std::vector<int> tempVector;
644 _instantPanel->getInstant( tempVector );
645 _performingOperation->setEndOperationInstantVector ( tempVector );
646 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
647 int i,size = elems.size();
648 for( i=0; i<size; i++ )
650 createCopyContourOf( elems[i], tempVector, i>0 );
654 void wxContourMainFrame::onUndo(){
655 std::string filename;
656 if(kernelManager->onUndoSaveFile(filename)){
657 saveFileWithContours(filename);
659 if(kernelManager->onUndo(filename)){
663 void wxContourMainFrame::onRedo(){
664 std::string filename;
665 if(kernelManager->onRedo(filename)){
670 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
672 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
673 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
674 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
677 ///AD: 03-09 Copy the object and apply the given transformation
678 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
680 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
681 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
683 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
684 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
686 double pnt1X = refPoint1->GetX();
687 double pnt1Y = refPoint1->GetY();
688 // double pnt1Z = refPoint1->GetZ();
689 double pnt2X = refPoint2->GetX();
690 double pnt2Y = refPoint2->GetY();
691 // double pnt2Z = refPoint2->GetZ();
693 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
694 vtkTransform *t = vtkTransform::New();
698 t->Translate(-pnt1X, -pnt1Y, 0);
702 t->Translate(pnt1X, pnt1Y, 0);
705 int i,size=manualModel->GetSizeLstPoints();
708 manualPoint * mp = manualModel->GetManualPoint(i);
714 t->TransformPoint( vecIn, vecOut );
715 mp->SetPointX( vecOut[0] );
716 mp->SetPointY( vecOut[1] );
717 mp->SetPointZ( vecOut[2] );
720 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
723 void wxContourMainFrame ::loadState(std::string filename){
725 FILE *pFile=fopen(filename.c_str(),"r+");
727 fscanf(pFile,"%s",tmp); // --CreaContour--
729 fscanf(pFile,"%s",tmp); // Version
730 fscanf(pFile,"%s",tmp); // 1.0.1
731 std::string version(tmp);
735 openContours(pFile,false);
736 if (version!="1.0.0"){
737 openContours(pFile,true);
742 //_theViewPanel->getSceneManager()->removeSceneContours();
747 void wxContourMainFrame::onLoad(){
749 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
750 if (dialog.ShowModal() == wxID_OK)
752 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
753 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
755 fscanf(pFile,"%s",tmp); // --CreaContour--
757 fscanf(pFile,"%s",tmp); // Version
758 fscanf(pFile,"%s",tmp); // 1.0.1
759 std::string version(tmp);
761 openContours(pFile,false);
762 if (version!="1.0.0"){
763 openContours(pFile,true);
765 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
769 _theViewPanel->getSceneManager()->removeSceneContours();
772 void wxContourMainFrame::onSave(){
773 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
774 if (dialog.ShowModal() == wxID_OK)
776 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
777 kernelManager->setCurrentFileName(fileNameContourROI);
778 saveFileWithContours( fileNameContourROI );
781 void wxContourMainFrame::saveFileWithContours( std::string filename ){
783 FILE *pFile=fopen(filename.c_str(),"w+");
784 std::vector< std::string > lstNameThings;
785 int i,sizeLstNameThings;
787 fprintf(pFile,"--CreaContour--\n");
788 fprintf(pFile,"Version %s\n", "1.0.1" );
791 lstNameThings = kernelManager->GetLstNameThings();
792 sizeLstNameThings = lstNameThings.size();
793 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
794 for (i=0 ; i<sizeLstNameThings ; i++)
796 kernelManager->SaveThingName( pFile, lstNameThings[i] );
797 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
800 //-- Contours Statics
801 lstNameThings = kernelManager->GetLstNameThingsStatic();
802 sizeLstNameThings = lstNameThings.size();
803 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
804 for (i=0 ; i<sizeLstNameThings ; i++)
806 kernelManager->SaveThingName( pFile, lstNameThings[i] );
807 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
812 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
814 fscanf(pFile,"%s",tmp); // NumberOfContours
815 fscanf(pFile,"%s",tmp); // ##
816 int numberOfContours = atoi(tmp);
818 std::vector<int> instantVector;
819 int typeContourModel;
820 manualContourModel *manModelContour;
824 for (i=0;i<numberOfContours;i++)
826 instantVector.clear();
827 fscanf(pFile,"%s",tmp); // Instant
829 fscanf(pFile,"%s",tmp); // 1
830 instantVector.push_back( atoi(tmp) );
831 fscanf(pFile,"%s",tmp); // 2
832 instantVector.push_back( atoi(tmp) );
833 fscanf(pFile,"%s",tmp); // 3
834 instantVector.push_back( atoi(tmp) );
835 fscanf(pFile,"%s",tmp); // 4
836 instantVector.push_back( atoi(tmp) );
837 fscanf(pFile,"%s",tmp); // 5
838 instantVector.push_back( atoi(tmp) );
839 fscanf(pFile,"%s",tmp); // 6
840 instantVector.push_back( atoi(tmp) );
843 fscanf(pFile,"%s",tmp); // TypeContourModel
844 fscanf(pFile,"%s",tmp); // ##
845 typeContourModel = atoi(tmp);
847 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
848 manModelContour->Open(pFile);
850 fscanf(pFile,"%s",tmp); // TypeView
851 fscanf(pFile,"%s",tmp); // ##
852 typeView = atoi(tmp);
861 theName = kernelManager->createOutline( manModelContour, instantVector );
862 bool addedModel = theName.compare("") != 0;
865 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
866 _theViewPanel->getSpacing(spc);
867 //Adding the manualContourControler to interface objects structure
868 //Adding the manualViewContour to interface objects structure
869 //_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.
870 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
873 if (staticContour==true)
875 Instant instant(&instantVector);
876 kernelManager->changeContourOfManager( theName , &instant );
879 }// for numberOfContours
883 void wxContourMainFrame::RefreshInterface(){
885 _theViewPanel->RefreshInterface();
886 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
887 //wxvtk2dbaseview->Refresh();
890 vtkImageData* wxContourMainFrame::getImageData(){
891 return _theViewPanel->getImageData();
894 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
896 //JCP 20-10-08 Undo redo implementation
898 //JCP 20-10-08 Undo redo implementation
901 int x = _theViewPanel->GetX();
902 int y = _theViewPanel->GetY();
903 int z = _theViewPanel->GetZ();
904 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
908 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
911 int typeofcontour = 1;
913 vtkImageData *imagedata = getImageData();
915 //Tipo de pixeles a utilizar internamente en ITK
916 typedef float InternalPixelType;
917 const unsigned int Dimension = 2;
918 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
920 //Tipo de pixeles de salida 1
921 typedef unsigned char OutputPixelType;
922 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
924 //Tipo de pixeles de salida 2
925 typedef unsigned short OutputPixelType2;
926 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
928 //Definición del thresholder
929 typedef itk::BinaryThresholdImageFilter<
931 OutputImageType > ThresholdingFilterType;
933 //Definición del primer filtro de conversión de pixeles
934 typedef itk::CastImageFilter<
935 OutputImageType, OutputImageType2 > CastFilterType;
937 //Definición del segundo tipo de conversión de pixeles
938 typedef itk::CastImageFilter<
939 OutputImageType2, InternalImageType > CastFilterType2;
941 //Tercer tipo de conversión
942 typedef itk::RescaleIntensityImageFilter<
944 OutputImageType > CastFilterType3;
946 //Cuarto tipo de conversión
947 typedef itk::RescaleIntensityImageFilter<
949 OutputImageType > CastFilterType4;
951 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
953 thresholder->SetLowerThreshold( 0.0 );
954 thresholder->SetUpperThreshold( 128 );
956 thresholder->SetOutsideValue( 255 );
957 thresholder->SetInsideValue( 0 );
959 //Definción de conexiónes entre VTK e ITK y el writer
960 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
961 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
962 typedef itk::ImageFileWriter< OutputImageType > WriterType;
964 ConnectorType::Pointer connector= ConnectorType::New();
965 ConnectorType2::Pointer connector2= ConnectorType2::New();
968 CastFilterType::Pointer filter=CastFilterType::New();
969 CastFilterType2::Pointer filter2=CastFilterType2::New();
971 connector->SetInput( imagedata );
972 filter2->SetInput(connector->GetOutput());
974 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
976 InternalImageType > SmoothingFilterType;
978 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
980 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
982 InternalImageType > GradientFilterType;
984 typedef itk::SigmoidImageFilter<
986 InternalImageType > SigmoidFilterType;
988 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
990 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
992 sigmoid->SetOutputMinimum( 0.0 );
993 sigmoid->SetOutputMaximum( 255.0 );
996 typedef itk::FastMarchingImageFilter<
998 InternalImageType > FastMarchingFilterType;
1001 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1003 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1004 InternalImageType > GeodesicActiveContourFilterType;
1005 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1006 GeodesicActiveContourFilterType::New();
1008 typedef itk::ZeroCrossingImageFilter<
1010 InternalImageType > ZeroCrossingFilterType;
1011 ZeroCrossingFilterType::Pointer zeroCrossing =
1012 ZeroCrossingFilterType::New();
1014 const double propagationScaling = atof( prop );
1016 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1017 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1018 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1020 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1021 int it=atoi( iter );
1022 geodesicActiveContour->SetNumberOfIterations( it );
1024 smoothing->SetInput( filter2->GetOutput() );
1025 gradientMagnitude->SetInput( smoothing->GetOutput() );
1026 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1027 fastMarching->SetInput( sigmoid->GetOutput() );
1028 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1029 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1031 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1032 //thresholder->SetInput( zeroCrossing->GetOutput() );
1033 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1034 connector2->SetInput( thresholder->GetOutput() );
1037 smoothing->SetTimeStep( 0.125 );
1038 smoothing->SetNumberOfIterations( 5 );
1039 smoothing->SetConductanceParameter( 9.0 );
1042 const double sigma = atof( sigm );
1043 gradientMagnitude->SetSigma( sigma );
1045 const double alpha = atof( alf );
1046 const double beta = atof( bet );
1048 sigmoid->SetAlpha( alpha );
1049 sigmoid->SetBeta( beta );
1051 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1052 typedef FastMarchingFilterType::NodeType NodeType;
1054 NodeContainer::Pointer seeds = NodeContainer::New();
1056 InternalImageType::IndexType seedPosition;
1057 seedPosition[0] = x;
1058 seedPosition[1] = y;
1060 const double initialDistance = atof( distanc );
1064 const double seedValue = - initialDistance;
1066 node.SetValue( seedValue );
1067 node.SetIndex( seedPosition );
1069 seeds->Initialize();
1070 seeds->InsertElement( 0, node );
1072 fastMarching->SetTrialPoints( seeds );
1074 fastMarching->SetSpeedConstant( 1.0 );
1076 fastMarching->SetOutputSize(
1077 connector->GetOutput()->GetBufferedRegion().GetSize() );
1079 fastMarching->SetStoppingValue( 800 );
1083 connector2->Update();
1084 vtkImageData *idata = connector2->GetOutput();
1086 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1088 cntVTK->SetInput( idata );
1090 cntVTK->SetNumberOfContours( 1 );
1091 cntVTK->SetValue( 0, 255 );
1093 cntVTK->UpdateInformation();
1095 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1096 cpd->SetInput( cntVTK->GetOutput( ) );
1098 cpd->UpdateInformation();
1100 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1101 conn->SetExtractionModeToLargestRegion( );
1102 conn->SetInput( cpd->GetOutput( ) );
1104 conn->UpdateInformation();
1106 vtkStripper* vtkstripper = vtkStripper::New( );
1107 vtkstripper->SetInput( conn->GetOutput() );
1108 vtkstripper->Update();
1109 vtkstripper->UpdateInformation();
1112 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1113 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1114 polyDataResult->Update( );
1115 polyDataResult->UpdateInformation();
1120 myfile.open ("C:/Creatis/example.txt");
1122 polyDataResult->Print(myfile);
1123 myfile << "-------------------------------------\n";
1124 polyDataResult->GetLines()->Print(myfile);
1132 //--Calculating control points
1134 std::vector<double> vecX;
1135 std::vector<double> vecY;
1136 std::vector<double> vecXo;
1137 std::vector<double> vecYo;
1138 std::vector<double>::iterator vecXoi;
1139 std::vector<double>::iterator vecYoi;
1140 std::vector<double> vecZ;
1142 std::vector<double> vecCtrlPointX;
1143 std::vector<double> vecCtrlPointY;
1144 std::vector<double> vecCtrlPointZ;
1150 int ii,size=polyDataResult->GetNumberOfPoints();
1152 myfile.open ("C:/Creatis/example2.txt");
1154 size=polyDataResult->GetNumberOfPoints();
1155 for (ii=0;ii<size;ii++)
1162 p = polyDataResult->GetPoint(ii);
1165 /*if(fabs(yAct-y)>20)
1167 if((xAct-x)>1 || (xAct-x)<-1)
1169 vecX.push_back( p[0] );
1170 vecY.push_back( p[1] );
1171 myfile <<p[0]<<","<<p[1]<<"\n";
1172 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1173 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1174 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1175 vecZ.push_back( -900 );
1181 vecXo.push_back(p[0]);
1182 vecYo.push_back(p[1]);
1186 else*/ if(fabs(xAct-x)>11)
1188 vecXo.push_back(p[0]);
1189 vecYo.push_back(p[1]);
1193 vecX.push_back( p[0] );
1194 myfile <<p[0]<<","<<p[1]<<"\n";
1195 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1196 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1197 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1198 vecY.push_back( p[1] );
1199 vecZ.push_back( -900 );
1207 while(!vecXo.empty())
1209 vecX.push_back(vecXo.back());
1210 std::cout<<" x Siguiente "<<vecXo.back();
1212 vecZ.push_back( -900 );
1214 while(!vecYo.empty())
1216 vecY.push_back(vecYo.back());
1221 /*for(int l=0;l<vecX.size();l++)
1225 vecXo.push_back(p[0]);
1226 vecYo.push_back(p[1]);
1237 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1239 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1243 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1245 else if (method==1){
1246 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1248 else if (method==2){
1249 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1250 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1252 //--Adding contour to the system
1254 std::vector<int> actualInstantVector;
1255 _instantPanel->getInstant( actualInstantVector );
1256 actualInstantVector[1]=z;
1258 int j,sizeCtrPt = vecCtrlPointX.size();
1260 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1261 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1263 for (j=0 ; j<sizeCtrPt ; j++)
1265 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1267 std::string theName;
1268 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1269 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1270 bool addedModel = theName.compare("") != 0;
1273 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1274 _theViewPanel->getSpacing(spc);
1275 //Adding the manualContourControler to interface objects structure
1276 //Adding the manualViewContour to interface objects structure
1277 //_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.
1278 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1279 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1285 WriterType::Pointer writer = WriterType::New();
1286 CastFilterType3::Pointer caster = CastFilterType3::New();
1288 caster->SetInput( gradientMagnitude->GetOutput() );
1289 writer->SetInput( caster->GetOutput() );
1290 writer->SetFileName("Gradient Magnitude.png");
1291 caster->SetOutputMinimum( 0 );
1292 caster->SetOutputMaximum( 255 );
1295 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1296 WriterType::Pointer writer2 = WriterType::New();
1298 caster2->SetInput( sigmoid->GetOutput() );
1299 writer2->SetInput( caster2->GetOutput() );
1300 writer2->SetFileName("Sigmoid.png");
1301 caster2->SetOutputMinimum( 0 );
1302 caster2->SetOutputMaximum( 255 );
1305 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1306 WriterType::Pointer writer3 = WriterType::New();
1308 caster3->SetInput( fastMarching->GetOutput() );
1309 writer3->SetInput( caster3->GetOutput() );
1310 writer3->SetFileName("FastMarching.bmp");
1311 caster3->SetOutputMinimum( 0 );
1312 caster3->SetOutputMaximum( 255 );
1315 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1316 WriterType::Pointer writer4 = WriterType::New();
1318 caster4->SetInput( geodesicActiveContour->GetOutput() );
1319 writer4->SetInput( caster4->GetOutput() );
1320 writer4->SetFileName("GeodesicActiveContour.png");
1321 caster4->SetOutputMinimum( 0 );
1322 caster4->SetOutputMaximum( 255 );
1325 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1326 WriterType::Pointer writer5 = WriterType::New();
1328 caster5->SetInput( zeroCrossing->GetOutput() );
1329 writer5->SetInput( caster5->GetOutput() );
1330 writer5->SetFileName("ZeroCrossing.bmp");
1331 caster5->SetOutputMinimum( 0 );
1332 caster5->SetOutputMaximum( 255 );
1335 catch( itk::ExceptionObject & excep )
1337 std::cerr << "Exception caught !" << std::endl;
1338 std::cerr << excep << std::endl;
1342 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1344 //JCP 20-10-08 Undo redo implementation
1346 //JCP 20-10-08 Undo redo implementation
1349 int x = _theViewPanel->GetX();
1350 int y = _theViewPanel->GetY();
1351 int z = _theViewPanel->GetZ();
1352 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1357 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1359 int typeofcontour = 1;
1360 //--Extracting Contour
1361 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1362 vtkImageData *imagedata = getImageData();
1363 // double *range = imagedata->GetScalarRange();
1366 vtkImageReslice *imageReslice = vtkImageReslice::New();
1369 // imagedata->GetSpacing(spc);
1374 imageReslice->SetInput( imagedata );
1375 imageReslice->SetInformationInput(imagedata);
1376 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1377 imageReslice->SetResliceAxesOrigin(0,0,z);
1378 imageReslice->SetOutputDimensionality(2);
1379 imageReslice->SetInterpolationModeToLinear();
1381 imagedata = imageReslice->GetOutput();
1382 imagedata->Update();
1383 imagedata->UpdateInformation();
1385 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1386 cntVTK->SetInput( imagedata );
1388 cntVTK->SetNumberOfContours( 1 );
1389 //cntVTK->SetValue( 0, vmin );
1390 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1391 cntVTK->SetValue( 1, isovalue );
1392 // cntVTK->SetValue( 1, vmax );
1394 cntVTK->UpdateInformation();
1396 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1397 cpd->SetInput( cntVTK->GetOutput( ) );
1398 cpd->ConvertLinesToPointsOff( );
1400 cpd->UpdateInformation();
1402 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1403 conn->SetExtractionModeToClosestPointRegion( );
1404 //conn->SetMaxRecursionDepth( 3000 );
1406 conn->SetInput( cpd->GetOutput( ) );
1408 conn->SetClosestPoint( x, y, 0 );
1410 conn->UpdateInformation();
1412 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1413 cpd2->SetInput( conn->GetOutput( ) );
1415 cpd2->UpdateInformation();
1417 vtkStripper* vtkstripper = vtkStripper::New( );
1418 vtkstripper->SetInput( cpd2->GetOutput() );
1419 vtkstripper->Update();
1420 vtkstripper->UpdateInformation();
1423 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1425 polyDataResult->Update( );
1426 polyDataResult->UpdateInformation();
1430 myfile.open ("c:/temp/example.txt");
1432 polyDataResult->Print(myfile);
1433 myfile << "-------------------------------------\n";
1434 polyDataResult->GetLines()->Print(myfile);
1444 //--Calculating control points
1446 std::vector<double> vecX;
1447 std::vector<double> vecY;
1448 std::vector<double> vecZ;
1450 std::vector<double> vecCtrlPointX;
1451 std::vector<double> vecCtrlPointY;
1452 std::vector<double> vecCtrlPointZ;
1456 int ii,size=polyDataResult->GetNumberOfPoints();
1458 for (ii=1;ii<=size;ii++)
1460 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1461 p = polyDataResult->GetPoint(id);
1464 vecX.push_back( p[0] );
1465 vecY.push_back( p[1] );
1466 vecZ.push_back( -900 );
1467 // vecZ.push_back( p[2] );
1471 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1472 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1475 /*if (methodRadiobox->GetSelection()==0){
1476 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1478 if (methodRadiobox->GetSelection()==1){
1479 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1481 if (methodRadiobox->GetSelection()==2){
1482 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1483 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1487 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1489 else if (method==1){
1490 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1492 else if (method==2){
1493 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1494 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1497 //--Adding contour to the system
1499 std::vector<int> actualInstantVector;
1500 _instantPanel->getInstant( actualInstantVector );
1501 actualInstantVector[1]=z;
1503 int j,sizeCtrPt = vecCtrlPointX.size();
1504 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1505 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1507 for (j=0 ; j<sizeCtrPt ; j++)
1509 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1511 std::string theName;
1512 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1513 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1514 bool addedModel = theName.compare("") != 0;
1517 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1518 _theViewPanel->getSpacing(spc);
1519 //Adding the manualContourControler to interface objects structure
1520 //Adding the manualViewContour to interface objects structure
1521 //_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.
1522 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1523 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1528 int wxContourMainFrame::GetImageDataSizeZ(){
1529 return _theViewPanel->GetImageDataSizeZ();
1532 void wxContourMainFrame::GetImageDataRange(double *range){
1533 _theViewPanel->GetImageDataRange(range);
1536 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1537 //JCP 20-10-08 Undo redo implementation
1539 //JCP 20-10-08 Undo redo implementation
1542 int x = _theViewPanel->GetX();
1543 int y = _theViewPanel->GetY();
1547 double totalZ = maxZ-minZ+1;
1548 for( z=minZ ; z<=maxZ ; z++ )
1550 porcent = 100.0* (z-minZ)/totalZ;
1551 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1552 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1553 //_staticTextSegmentation->SetLabel(tmpString);
1554 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1556 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1561 //Creates a reference line to be used as the axis of the mirroring
1562 void wxContourMainFrame::referenceLine()
1567 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1568 vtkimagedata->GetSpacing(spc);
1570 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1572 _refLineControl = new manualLineControler();
1573 _refLineModel = new manualContourModelLine();
1574 _refLineView = new manualViewLine();
1575 _refLineView->SetModel( _refLineModel );
1576 _refLineView->SetWxVtkBaseView( viewer2D );
1577 _refLineView->SetRange( 2 );
1578 _refLineView->SetZ( 1200 );
1580 _refLineView->SetSpacing(spc);
1582 _refLineView->SetColorNormalContour(0, 0, 1);
1583 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1584 _refLineView->SetWidthLine(4);
1586 _refLineControl->SetModelView( _refLineModel , _refLineView );
1587 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1588 _refLineModel->SetCloseContour(false);
1589 _refLineControl->CreateNewManualContour();
1591 double z = _refLineControl->GetZ();
1593 _refLineControl->AddPoint(50,100,z);
1594 _refLineControl->AddPoint(80,40,z);
1595 _refLineControl->SetCompleteCreation(true);
1597 _refLineModel->AddPoint(50,100,z);
1598 _refLineModel->AddPoint(80,40,z);
1599 _refLineModel->UpdateSpline();
1601 _refLineView->UpdateViewPoint(0);
1602 _refLineView->UpdateViewPoint(1);
1605 _refLineControl->SetActive(true);
1606 _refLineView->RefreshContour();
1609 //Hides the referenceLine
1610 void wxContourMainFrame::refLineHide()
1612 if (_refLineControl!=NULL)
1614 _refLineView->RemoveCompleteContourActor();
1615 _refLineControl->SetEditable(false);
1616 _refLineControl->SetActive(false);
1620 //Shows the referenceLine
1621 void wxContourMainFrame::refLineShow()
1623 if (_refLineControl!=NULL)
1625 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1627 _refLineView->SetModel( _refLineModel );
1628 _refLineView->SetWxVtkBaseView( viewer2D );
1629 _refLineView->SetRange( 2 );
1630 _refLineView->SetZ( 1200 );
1632 _refLineControl->SetModelView( _refLineModel , _refLineView );
1633 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1634 _refLineControl->CreateNewManualContour();
1635 _refLineControl->SetActive(true);
1636 _refLineView->RefreshContour();
1640 void wxContourMainFrame::onMirror()
1643 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1644 std::vector<std::string> filterCurrentSelection;
1646 std::vector<int> tempVector;
1647 _instantPanel->getInstant( tempVector );
1648 _performingOperation->reset();
1649 _performingOperation->setStartCommand( COPY );
1650 _performingOperation->setStartOperationInstantVector( tempVector );
1651 _performingOperation->setKeyNamesOperationElems( currentSelection );
1653 char theStartCommand = _performingOperation->getStartCommand();
1654 if ( theStartCommand == COPY )
1656 //JCP 20-10-08 Undo redo implementation
1658 //JCP 20-10-08 Undo redo implementation
1659 std::vector<int> tempVector;
1660 _instantPanel->getInstant( tempVector );
1661 _performingOperation->setEndOperationInstantVector ( tempVector );
1662 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1663 int i,size = elems.size();
1664 for( i=0; i<size; i++ )
1666 createMirrorContourOf( elems[i], tempVector, i>0 );
1670 //deleteContour( _refName );
1674 void wxContourMainFrame::showAxis(bool show){
1675 _theViewPanel->SetVisibleAxis(show);
1676 _theViewPanel->Refresh();
1680 void wxContourMainFrame::onRigidPressed(){
1681 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1682 int elementsSelected = currentSelection.size();
1684 if ( elementsSelected >= 1 ){
1685 //JCP 20-10-08 Undo redo implementation
1687 //JCP 20-10-08 Undo redo implementation
1689 std::vector<int> tempVector;
1690 _instantPanel->getInstant( tempVector );
1691 Instant instant(&tempVector);
1693 int i , size=currentSelection.size();
1694 for ( i=0 ; i<size ; i++ )
1696 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1701 void wxContourMainFrame::onWidthOfContour(double width){
1703 _theViewPanel->removeSceneContours();
1704 _theViewPanel->SetWidthContour(width);
1706 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1710 int wxContourMainFrame::getColorWindow(){
1711 return _theViewPanel->getColorWindow();
1713 int wxContourMainFrame::getWindowLevel(){
1714 return _theViewPanel->getWindowLevel();
1717 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1718 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1724 void wxContourMainFrame::onInterpolation(bool interpolate){
1725 _theViewPanel->onInterpolation(interpolate);
1729 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1730 _instantPanel->setConceptValue( name, actual );
1733 void wxContourMainFrame::resetAppend(){
1734 kernelManager->resetAppend();
1738 void wxContourMainFrame::onSpreadAdd(){
1739 std::vector<double> vecX;
1740 std::vector<double> vecY;
1741 std::vector<double> vecZ;
1742 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1744 std::vector<int> tempVector;
1745 _instantPanel->getInstant( tempVector );
1747 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1749 interfMainPanel::getInstance()->appendStringSpread(val);
1753 void wxContourMainFrame::onSpreadGo(int type){
1755 //JCP 20-10-08 Undo redo implementation
1757 //JCP 20-10-08 Undo redo implementation
1760 std::vector<double> vecCtrlPointX;
1761 std::vector<double> vecCtrlPointY;
1762 std::vector<double> vecCtrlPointZ;
1766 std::vector<int> tempVector;
1767 _instantPanel->getInstant( tempVector );
1770 kernelManager->getMaxMinZ(&minZ,&maxZ);
1771 //JSTG_16-07-08_----------------------------------------------------------------
1772 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1773 kernelManager->CalculeSplinePropagation();
1775 double totalZ = maxZ-minZ+1;
1778 //--------------------------------------------------------------------
1779 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1781 porcent = 100.0* (z-minZ)/totalZ;
1782 int numero = (int)(z-minZ+1)/(int)totalZ;
1783 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1785 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1787 int typeofcontour = 1;
1788 std::string theName;
1789 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1791 if( manModelContour!=NULL ){
1792 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1793 this->_theViewPanel->getSpacing(spc);
1794 //Adding the manualContourControler to interface objects structure
1795 //Adding the manualViewContour to interface objects structure
1796 //_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.
1797 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1802 int numero = (int)(z-minZ+1)/(int)totalZ;
1803 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1805 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1807 //RefreshInterface();
1810 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1814 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1815 std::vector<int> tempVector;
1816 _instantPanel->getInstant(tempVector);
1817 //Asignation of slide number should be different ex by name
1818 tempVector[1]=slide;
1819 return kernelManager->getOutlinesNameAtInstant(tempVector);
1822 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1823 int maxContourGroup = 0;
1825 ContourExtractData *contourextractdata = new ContourExtractData();
1827 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1829 std::vector<manualContourModel*> lstManConMod;
1830 std::vector<manualContourModel*> lstManConModTmp;
1831 std::vector<manualContourModel*> lstManConModExp;
1832 std::vector<double> pLstValue;
1833 std::vector<double> pLstValuePosX;
1834 std::vector<double> pLstValuePosY;
1835 std::vector<double> pLstValuePosZ;
1838 int resultGrayRangeCount;
1841 double resultAverage;
1842 double resultStandardeviation;
1844 std::vector<int> tempVector;
1845 _instantPanel->getInstant( tempVector );
1847 vtkImageData *imagedata = _theViewPanel->getImageData();
1848 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1850 int ii,sizeLstContourThings;
1860 if (selection==0 ) // actual slice
1862 std::vector<int> tempVector;
1863 _instantPanel->getInstant( tempVector );
1864 int actualSlice = tempVector[1];
1868 else if (selection==2 ) // All slices
1873 else if (selection==1 ) // slice range
1880 totalZ = maxZ-minZ+1;
1881 contourextractdata->SetImage( imagedata);
1884 for ( z=minZ ; z<=maxZ ; z++ )
1887 porcent = 100.0* (z-minZ)/totalZ;
1888 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1890 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1891 //_staticTextInformation->SetLabel(tmpString);
1893 //Extraction data from contours of each slice
1894 contourextractdata->SetZtoBeAnalys( z);
1897 Instant instant(&tempVector);
1898 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1899 sizeLstContourThings = lstContourThings.size();
1901 lstManConMod.clear();
1902 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1904 ContourThing **contourthing = lstContourThings[ii];
1905 lstManConMod.push_back( (*contourthing)->getModel() );
1907 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1910 wxString tempString;
1911 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1912 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1913 //_grid->SetRowLabelValue(z, tempString );
1915 int iContourGroup,sizeContourGroup;
1916 if (typeContourGroup==3) // contour separete
1918 sizeContourGroup=lstManConModExp.size();
1919 if ( maxContourGroup<sizeContourGroup )
1921 maxContourGroup=sizeContourGroup;
1923 } else { // contour AND OR XOR
1932 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1933 lstManConModTmp.clear();
1934 if (typeContourGroup==3) // contour separete
1936 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1937 } else { // contour AND OR XOR
1938 lstManConModTmp = lstManConModExp;
1941 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1944 pLstValuePosX.clear();
1945 pLstValuePosY.clear();
1946 pLstValuePosZ.clear();
1947 contourextractdata->GetValuesInsideCrown( &pLstValue,
1951 // Statistics of each slice.
1952 contourextractdata->Statistics( &pLstValue,
1955 &resultGrayRangeCount,
1960 &resultStandardeviation);
1962 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1964 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1967 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1969 tempString.Printf(_T("%d"),resultSize);
1970 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1972 tempString.Printf(_T("%d"),resultGrayRangeCount);
1973 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1975 tempString.Printf(_T("%f"),resultMin);
1976 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1978 tempString.Printf(_T("%f"),resultMax);
1979 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1981 tempString.Printf(_T("%f"),resultAverage);
1982 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1984 tempString.Printf(_T("%f"),resultStandardeviation);
1985 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1988 } // for iContourGroup
1992 wxString tmpTitleString;
1994 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1996 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1997 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1998 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2000 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2001 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2002 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2003 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2004 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2005 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2006 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2009 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2010 delete contourextractdata;
2013 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2014 SaveValuesXYZ( directory , namefile, typeContourGroup );
2015 SaveImageResult( directory , namefile, typeContourGroup);
2018 FILE *pFile=fopen(filename.c_str(),"w+");
2020 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2023 int i,j,maxX,maxY=sizeZ;
2024 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2026 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2027 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2029 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2030 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2032 fprintf(pFile,"\n" );
2036 for ( j=0; j<maxY ; j++)
2038 fprintf(pFile,"%d\t" , j );
2039 for (i=0 ; i<maxX ; i++){
2040 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2041 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2043 fprintf(pFile,"\n" );
2049 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2052 ContourExtractData *contourextractdata = new ContourExtractData();
2053 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2054 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2056 std::vector<manualContourModel*> lstManConMod;
2057 std::vector<manualContourModel*> lstManConModTmp;
2058 std::vector<manualContourModel*> lstManConModExp;
2059 std::vector<double> pLstValue;
2060 std::vector<double> pLstValuePosX;
2061 std::vector<double> pLstValuePosY;
2062 std::vector<double> pLstValuePosZ;
2064 std::vector<int> tempVector;
2065 _instantPanel->getInstant( tempVector );
2067 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2068 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2070 int ii,sizeLstContourThings;
2077 minZ = 0;// _mbarrange->GetStart();
2078 maxZ = sizeZ;//_mbarrange->GetEnd();
2079 totalZ = maxZ-minZ+1;
2081 contourextractdata->SetImage( imagedata);
2084 for ( z=0 ; z<sizeZ ; z++)
2087 porcent = 100.0* (z-minZ)/totalZ;
2089 tmpString.Printf(_T("Saving Values"));
2090 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2091 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2092 //_staticTextInformation->SetLabel(tmpString);
2095 //Extraction data from contours of each slice
2096 contourextractdata->SetZtoBeAnalys( z);
2099 Instant instant(&tempVector);
2100 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2101 sizeLstContourThings = lstContourThings.size();
2103 lstManConMod.clear();
2104 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2106 ContourThing **contourthing = lstContourThings[ii];
2107 lstManConMod.push_back( (*contourthing)->getModel() );
2109 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2114 int iContourGroup,sizeContourGroup;
2115 if (typeContourGroup==3) // contour separete
2117 sizeContourGroup=lstManConModExp.size();
2118 } else { // contour AND OR XOR
2122 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2123 lstManConModTmp.clear();
2124 if (typeContourGroup==3) // contour separete
2126 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2127 } else { // contour AND OR XOR
2128 lstManConModTmp = lstManConModExp;
2131 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2134 pLstValuePosX.clear();
2135 pLstValuePosY.clear();
2136 pLstValuePosZ.clear();
2137 contourextractdata->GetValuesInsideCrown( &pLstValue,
2142 std::string temp = directory + "/" + namefile + "-slice";
2143 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2144 temp = temp + ".txt";
2146 // LG 14/01/09 : using crea
2147 wxString filename = crea::std2wx(temp);
2148 /*filename.Printf(_T("%s"),directory.c_str());
2149 filename.append(_T("\\"));
2150 filename.append(_T("%s"),namefile.c_str());
2151 filename.append(_T("-slice"));
2152 filename.append(_T("%d"),z);
2153 filename.append(_T("-cont"));
2154 filename.append(_T("%d"),iContourGroup);
2155 filename.append(_T(".txt"));*/
2156 // filename.Printf(temp.c_str());
2160 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2161 fprintf(pFile,"value \t x \t y \t z\n" );
2162 int iLstValue,sizeLstValue=pLstValue.size();
2163 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2165 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2168 } // for iContourGroup
2170 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2171 //_staticTextInformation->SetLabel( _T("") );
2172 delete contourextractdata;
2175 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
2178 ContourExtractData *contourextractdata = new ContourExtractData( true );
2179 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2180 if (typeContourGroup==3)
2184 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2186 std::vector<manualContourModel*> lstManConMod;
2187 std::vector<manualContourModel*> lstManConModTmp;
2188 std::vector<manualContourModel*> lstManConModExp;
2190 std::vector<int> tempVector;
2191 _instantPanel->getInstant( tempVector );
2193 vtkImageData *imagedata = _theViewPanel->getImageData();
2194 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2196 int ii,sizeLstContourThings;
2205 minZ = 0;// _mbarrange->GetStart();
2206 maxZ = sizeZ;//_mbarrange->GetEnd();
2207 totalZ = maxZ-minZ+1;
2209 contourextractdata->SetImage( imagedata);
2212 for ( z=0 ; z<sizeZ ; z++)
2215 porcent = 100.0* (z-minZ)/totalZ;
2216 tmpString.Printf(_T("Saving Values"));
2217 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2218 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2220 //Extraction data from contours of each slice
2221 contourextractdata->SetZtoBeAnalys( z);
2224 Instant instant(&tempVector);
2225 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2226 sizeLstContourThings = lstContourThings.size();
2228 lstManConMod.clear();
2229 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2231 ContourThing **contourthing = lstContourThings[ii];
2232 lstManConMod.push_back( (*contourthing)->getModel() );
2234 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2237 int iContourGroup,sizeContourGroup;
2238 if (typeContourGroup==3) // contour separete
2240 sizeContourGroup=lstManConModExp.size();
2241 } else { // contour AND OR XOR
2245 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2246 lstManConModTmp.clear();
2247 if (typeContourGroup==3) // contour separete
2249 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2250 } else { // contour AND OR XOR
2251 lstManConModTmp = lstManConModExp;
2254 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2257 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
2259 // ContourThing **contourthing = lstContourThings[ii];
2260 // lstManConMod.push_back( (*contourthing)->getModel() );
2262 // contourextractdata->SetLstManualContourModel( lstManConMod );
2264 contourextractdata->CalculateImageResult(); // with actual Z
2266 } // for iContourGroup
2269 std::string temp = directory + "/" + namefile + "-Value.mhd";
2271 wxString filename = crea::std2wx(temp);
2273 // filename.Printf(_T(temp.c_str()));
2274 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2275 /*filename.Printf(_T("%s"),directory.c_str());
2276 filename.append(_T("\\"));
2277 filename.append(_T("%s"),namefile.c_str());
2278 filename.append(_T("-Value.mhd"));*/
2281 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2282 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
2283 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2284 writerValueImage->SetFileDimensionality( 3 );
2285 writerValueImage->Write( );
2288 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2289 temp = directory + "/" + namefile + "-Mask.mhd";
2291 // LG 14/01/09 : using crea
2292 filename = crea::std2wx(temp);
2293 // filename.Printf(_T(temp.c_str()));
2295 /*filename.Printf(_T("%s"),directory.c_str());
2296 filename.append(_T("\\"));
2297 filename.append(_T("%s"),namefile.c_str());
2298 filename.append(_T("-Mask.mhd"));*/
2300 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2301 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
2302 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2303 writerMaskImage->SetFileDimensionality( 3 );
2304 writerMaskImage->Write( );
2306 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2307 delete contourextractdata;
2310 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2311 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2312 _theViewPanel->setActualVertical( value);
2314 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2315 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2321 void wxContourMainFrame::onSnakePressed(){
2322 std::vector<double> vecX;
2323 std::vector<double> vecY;
2324 std::vector<double> vecZ;
2325 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2327 if (vecX.size()!=0){
2328 std::vector<int> tempVector;
2329 _instantPanel->getInstant( tempVector );
2330 int i,size=vecZ.size();
2331 int actualSlice = tempVector[1];
2332 for ( i=0 ; i<size ; i++ )
2334 vecZ[i] = actualSlice;
2337 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2338 wxPanel* panel = new wxPanel(dialog,-1);
2339 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2340 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2341 dialog->ShowModal();
2346 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2347 std::string filename = kernelManager->getCurrentFileName();
2348 if(filename.compare("")!=0){
2349 saveFileWithContours(filename);