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