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;
75 // _modelManager = NULL;
77 // _buttonsBar = NULL;
79 // _drawToolsPanel = NULL;
80 // _operationsToolsPanel = NULL;
81 // _autoFormsPanel = NULL;
82 // _standardToolsPanel = NULL;
83 // _editionToolsPanel = NULL;
84 // _listViewPanel = NULL;
85 // _sceneManager = NULL;
86 // _actualInstant = NULL;
88 _refLineControl = NULL;
92 // set up default notebook style
93 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
95 //wxContour_ActionCommandsID a;
96 _numberOfVariablesStatistics = 6+1;
99 _performingOperation = new PerformingOperation();
105 kernelManager = new KernelManagerContour(images,datadir+"/data/");
106 //kernelManager->setVectImages(images);
107 //kernelManager->initializeEnvironment();
109 //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
111 //-------------------------------------------------------------
113 /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600));
116 //Creating the evtHandler of the panels
117 //wxContourEventHandler * eventHandler = new wxContourEventHandler();
119 //Creating the window that will show the panels
121 //Getting the parent for the panels ( using aui )
122 wxAuiNotebook * notebook = this->createNotebook();
125 //wxInstantChooserPanel * instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
127 std::vector<std::string> conceptNameVect;
128 std::vector<int> conceptSizeVect;
132 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
133 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
137 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
138 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
141 double val = _theViewPanel->getCurrentDeep();
142 _instantPanel->setConceptValue( "Axe Depth", (int)val );
143 //JCP _instantPanel->setConceptValue("time", num de imagenes);
144 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
145 //*******************changeInstant();
146 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
148 //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
149 //eventHandler->setViewPanel( _theViewPanel );
150 //_theViewPanel->initializeScenceManager();
151 //eventHandler->setInstantChooserPanel( _instantPanel );
153 //bool successConfiuration = eventHandler->configureEventsHandling();
155 //successConfiuration &= this->configurePanels( notebook );
156 this->configurePanels( notebook );
158 interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
166 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 ){
167 if(instance == NULL){
168 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
173 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
174 return kernelManager->getVectImages();
176 wxContourMainFrame* wxContourMainFrame :: getInstance(){
181 wxContourMainFrame :: ~wxContourMainFrame()
184 //El problema al cerrar la aplicacion puede estar asociado
185 //a que wxAUINotebook esta en la aplicacion
186 //principal (wxContourGUIExample)tambien
187 //EED???? delete _theViewPanel;
188 //EED???? delete _instantPanel;
189 //EED???? delete _buttonsBar;
190 //EED???? delete _actualInstant;
191 //EED???? delete _sceneManager;
195 //------------------------------------------------------------------------------------------------------------
196 // Creational and initialization methods using WxAui
197 //------------------------------------------------------------------------------------------------------------
199 wxAuiNotebook * wxContourMainFrame :: createNotebook()
201 wxSize client_size = GetClientSize();
202 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
203 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
208 //------------------------------------------------------------------------------------------------------------
209 // Creational and initialization methods
210 //------------------------------------------------------------------------------------------------------------
211 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
213 bool configured = _theViewPanel!=NULL;
215 configured &= _theViewPanel!=NULL;
216 if( _theViewPanel!=NULL )
218 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
225 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
229 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
231 /* configured &= _buttonsBar!=NULL;
232 if( _buttonsBar!=NULL )
234 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
235 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
237 LeftDockable( ).RightDockable( false ).CloseButton(false));
242 SetMinSize(wxSize(300,300));
247 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
252 //------------------------------------------------------------------------------------------------------------
253 // Attributes getters and setters
254 //------------------------------------------------------------------------------------------------------------
258 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
260 _instantPanel = theInstantChooserPanel;
263 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
265 // _buttonsBar = theButtonsBar;
268 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
270 // _gridPanel = theGridPanel;
273 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
275 // _drawToolsPanel = theDrawToolsPanel;
278 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
280 // _operationsToolsPanel = theOperationsToolsPanel;
283 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
285 // _autoFormsPanel = theAutoFormsPanel;
288 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
290 // _standardToolsPanel= theStandardToolsPanel;
293 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
295 // _editionToolsPanel = theEditionToolsPanel;
298 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
300 // _listViewPanel = theListViewPanel;
305 void wxContourMainFrame::onCreateContourSpline( ){
307 //JCP 20-10-08 Undo redo implementation
309 //JCP 20-10-08 Undo redo implementation
313 void wxContourMainFrame::onCreateContourRectangle( ){
314 //JCP 20-10-08 Undo redo implementation
316 //JCP 20-10-08 Undo redo implementation
319 void wxContourMainFrame::onCreateContourCircle( ){
320 //JCP 20-10-08 Undo redo implementation
322 //JCP 20-10-08 Undo redo implementation
326 void wxContourMainFrame::onCreateContourLine( ){
327 //JCP 20-10-08 Undo redo implementation
329 //JCP 20-10-08 Undo redo implementation
333 //------------------------------------------------------------------------------------------------------------
335 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
337 //Creating the manualContourModel and including in the model
338 manualContourModel * manModelContour = factoryManualContourModel(panel );
340 std::vector<int> instantVector;
341 _instantPanel->getInstant( instantVector );
342 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
344 /*std::vector<int> instantVector;
345 _instantPanel->getInstant( instantVector );
347 theName= _modelManager->createOutline( manModelContour, instantVector );*/
348 bool addedModel = theName.compare("") != 0;//??
352 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
353 _theViewPanel->getSpacing(spc);
354 //Adding the manualContourControler to interface objects structure
355 //Adding the manualViewContour to interface objects structure
356 //_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.
357 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
360 void wxContourMainFrame :: createContour( int typeContour )
362 //Creating the manualContourModel and including in the model
363 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
366 std::vector<int> instantVector;
367 _instantPanel->getInstant( instantVector );
368 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
370 /*std::vector<int> instantVector;
371 _instantPanel->getInstant( instantVector );
373 theName= _modelManager->createOutline( manModelContour, instantVector );*/
374 bool addedModel = theName.compare("") != 0;//??
377 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
378 _theViewPanel->getSpacing(spc);
379 //Adding the manualContourControler to interface objects structure
380 //Adding the manualViewContour to interface objects structure
381 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
382 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
386 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
388 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
389 manualContourModel *manModelContour=NULL;
390 manModelContour = manModelContourBullEye;
392 int iCrown,sizeCrowns,iSector,sizeSectors;
393 double radioA,radioB,ang,angDelta ;
394 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
395 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
397 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
398 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
399 if (iCrown==sizeCrowns-1)
403 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
407 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
409 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
410 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
411 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
414 } // if _panelBullEyeOptions
416 return manModelContour;
418 void wxContourMainFrame :: saveState(){
420 std::string temp = kernelManager->saveState();
421 saveFileWithContours(temp);
424 void wxContourMainFrame::onDeleteContour(){
425 //JCP 20-10-08 Undo redo implementation
427 //JCP 20-10-08 Undo redo implementation
429 std::vector<std::string> lstKeyNameToBeErase;
430 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
431 deleteContours( lstKeyNameToBeErase );
433 int i,size=_sceneManager->getSelectedObjects().size();
436 std::string keyName = _sceneManager->getSelectedObjects()[i];
437 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
438 if ( ispartofstaticlist>=0 )
440 std::vector<int> tempVector;
441 _instantPanel->getInstant( tempVector );
442 Instant instant(&tempVector);
443 this->_modelManager->ChangeContourOfList(keyName, &instant);
447 std::vector<std::string> lstKeyName;
448 std::vector<std::string> lstKeyNameActualSlice;
449 std::vector<std::string> lstKeyNameToBeErase;
451 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
452 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
453 int k,kSize=lstKeyNameToBeErase.size();
454 int j,jSize=lstKeyNameActualSlice.size();
456 for (k=0;k<kSize; k++)
459 for (j=0;j<jSize; j++)
461 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
468 lstKeyName.push_back( lstKeyNameToBeErase[k] );
472 deleteContours( lstKeyName );
476 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
478 int i,size=keyNamesVector.size();
481 deleteContour( keyNamesVector[i] );
485 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
487 manualContourModel * cModel;
488 manualViewBaseContour * cViewer;
489 manualContourBaseControler * cControler;
491 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
492 cControler = conwrapviewControl->getControler();*/
495 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
496 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
498 if (isedit && ispartofstaticlst)
500 _theViewPanel->removeFromScene(theKeyName);
502 kernelManager->deleteCModel(theKeyName);
503 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
504 //cViewer = conwrapviewControl->getViewer();
505 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
506 //cControler* conwrapviewControl->getControler();
508 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
509 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
510 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
514 // delete cControler;
519 void wxContourMainFrame::onDeleteContoursActSlice(){
520 //JCP 20-10-08 Undo redo implementation
522 //JCP 20-10-08 Undo redo implementation
523 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
525 void wxContourMainFrame::onDeleteAllContours(){
526 //JCP 20-10-08 Undo redo implementation
530 void wxContourMainFrame::deleteAllContours(){
531 //JCP 20-10-08 Undo redo implementation
534 std::vector<int> tempVector;
535 _instantPanel->getInstant( tempVector );
537 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
538 // the values in GetStart and GetEnd will then not be initialize also.
539 // We use instead the values given when initializing the _deletepanel.
541 //int minZ = _mbarrangeDeleteAll->GetStart();
542 //int maxZ = _mbarrangeDeleteAll->GetEnd();
546 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
550 _theViewPanel->getSceneManager()->removeSceneContours( );
551 _theViewPanel->getSceneManager()->removeAllOutlines();
552 kernelManager->removeAllOutlines();
555 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
557 _theViewPanel->getSceneManager()->removeSceneContours( );
558 _modelManager->removeAllOutlines();
559 _theViewPanel->getSceneManager()->removeAllOutlines();
562 for ( z=minZ ; z<=maxZ ; z++)
565 Instant instant(&tempVector);
566 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
568 sizeLstContourThings = lstContourThings.size();
569 for (ii=0 ; ii<sizeLstContourThings ; ii++)
571 ContourThing **contourthing = lstContourThings[ii];
572 deleteContour( (*contourthing)->getName() );
579 void wxContourMainFrame::setConceptValue( std::string name, int value ){
580 _instantPanel->setConceptValue(name, value);
583 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
584 return _instantPanel->getLastConceptData();
586 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
587 return _instantPanel->getIfConceptCheckedAt( name, pos );
590 void wxContourMainFrame::changeInstant(){
591 std::vector<int> instantVect;
592 _instantPanel->getInstant( instantVect );
593 // Instant * theInstant = new Instant ( &instantVect );
595 //Setting the actual instant
596 //_actualInstant = theInstant;
598 kernelManager->setInstant(instantVect);
599 //_modelManager->setInstant( _actualInstant );
601 updateInstantOutlines();
602 updateInstantImageData();
607 void wxContourMainFrame :: updateInstantOutlines(){
609 _theViewPanel->removeSceneContours();
610 _theViewPanel->addNameWrapperToScene();
612 //for( int i=0; i<size; i++)
614 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
618 int wxContourMainFrame::getNamesWrappingSize(){
619 return kernelManager->getNamesWrappingSize();
621 std::string wxContourMainFrame::getNameWrapping(int i){
622 return kernelManager->getNameWrapping(i);
625 void wxContourMainFrame::updateInstantImageData(){
626 std::vector<int> inst;
627 _instantPanel->getInstant(inst);
629 vtkImageData* img = kernelManager->getImageAtInstant(inst);
631 _theViewPanel->changeImage(img);
634 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
635 _theViewPanel->setImageSlice(z);
638 void wxContourMainFrame::updateInstantAxes(){
641 void wxContourMainFrame::onChangeDeep(int val){
642 _instantPanel->setConceptValue( "Axe Depth", (int)val );
647 void wxContourMainFrame::onCopy(){
648 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
650 std::vector<int> tempVector;
651 _instantPanel->getInstant( tempVector );
652 _performingOperation->reset();
653 _performingOperation->setStartCommand( COPY );
654 _performingOperation->setStartOperationInstantVector( tempVector );
655 _performingOperation->setKeyNamesOperationElems( currentSelection );
658 void wxContourMainFrame::onPaste(){
661 char theStartCommand = _performingOperation->getStartCommand();
662 if ( theStartCommand == COPY )
664 //JCP 20-10-08 Undo redo implementation
666 //JCP 20-10-08 Undo redo implementation
667 std::vector<int> tempVector;
668 _instantPanel->getInstant( tempVector );
669 _performingOperation->setEndOperationInstantVector ( tempVector );
670 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
671 int i,size = elems.size();
672 for( i=0; i<size; i++ )
674 createCopyContourOf( elems[i], tempVector, i>0 );
678 void wxContourMainFrame::onUndo(){
679 std::string filename;
680 if(kernelManager->onUndoSaveFile(filename)){
681 saveFileWithContours(filename);
683 if(kernelManager->onUndo(filename)){
687 void wxContourMainFrame::onRedo(){
688 std::string filename;
689 if(kernelManager->onRedo(filename)){
694 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
696 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
697 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
698 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
701 ///AD: 03-09 Copy the object and apply the given transformation
702 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
704 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
705 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
707 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
708 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
710 double pnt1X = refPoint1->GetX();
711 double pnt1Y = refPoint1->GetY();
712 double pnt1Z = refPoint1->GetZ();
713 double pnt2X = refPoint2->GetX();
714 double pnt2Y = refPoint2->GetY();
715 double pnt2Z = refPoint2->GetZ();
717 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
718 vtkTransform *t = vtkTransform::New();
722 t->Translate(-pnt1X, -pnt1Y, 0);
726 t->Translate(pnt1X, pnt1Y, 0);
729 int i,size=manualModel->GetSizeLstPoints();
732 manualPoint * mp = manualModel->GetManualPoint(i);
738 t->TransformPoint( vecIn, vecOut );
739 mp->SetPointX( vecOut[0] );
740 mp->SetPointY( vecOut[1] );
741 mp->SetPointZ( vecOut[2] );
744 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
747 void wxContourMainFrame ::loadState(std::string filename){
749 FILE *pFile=fopen(filename.c_str(),"r+");
751 fscanf(pFile,"%s",tmp); // --CreaContour--
753 fscanf(pFile,"%s",tmp); // Version
754 fscanf(pFile,"%s",tmp); // 1.0.1
755 std::string version(tmp);
759 openContours(pFile,false);
760 if (version!="1.0.0"){
761 openContours(pFile,true);
766 //_theViewPanel->getSceneManager()->removeSceneContours();
771 void wxContourMainFrame::onLoad(){
773 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
774 if (dialog.ShowModal() == wxID_OK)
776 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
777 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
779 fscanf(pFile,"%s",tmp); // --CreaContour--
781 fscanf(pFile,"%s",tmp); // Version
782 fscanf(pFile,"%s",tmp); // 1.0.1
783 std::string version(tmp);
785 openContours(pFile,false);
786 if (version!="1.0.0"){
787 openContours(pFile,true);
789 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
793 _theViewPanel->getSceneManager()->removeSceneContours();
796 void wxContourMainFrame::onSave(){
797 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
798 if (dialog.ShowModal() == wxID_OK)
800 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
801 kernelManager->setCurrentFileName(fileNameContourROI);
802 saveFileWithContours( fileNameContourROI );
805 void wxContourMainFrame::saveFileWithContours( std::string filename ){
807 FILE *pFile=fopen(filename.c_str(),"w+");
808 std::vector< std::string > lstNameThings;
809 int i,sizeLstNameThings;
811 fprintf(pFile,"--CreaContour--\n");
812 fprintf(pFile,"Version %s\n", "1.0.1" );
815 lstNameThings = kernelManager->GetLstNameThings();
816 sizeLstNameThings = lstNameThings.size();
817 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
818 for (i=0 ; i<sizeLstNameThings ; i++)
820 kernelManager->SaveThingName( pFile, lstNameThings[i] );
821 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
824 //-- Contours Statics
825 lstNameThings = kernelManager->GetLstNameThingsStatic();
826 sizeLstNameThings = lstNameThings.size();
827 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
828 for (i=0 ; i<sizeLstNameThings ; i++)
830 kernelManager->SaveThingName( pFile, lstNameThings[i] );
831 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
836 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
838 fscanf(pFile,"%s",tmp); // NumberOfContours
839 fscanf(pFile,"%s",tmp); // ##
840 int numberOfContours = atoi(tmp);
842 std::vector<int> instantVector;
843 int typeContourModel;
844 manualContourModel *manModelContour;
848 for (i=0;i<numberOfContours;i++)
850 instantVector.clear();
851 fscanf(pFile,"%s",tmp); // Instant
853 fscanf(pFile,"%s",tmp); // 1
854 instantVector.push_back( atoi(tmp) );
855 fscanf(pFile,"%s",tmp); // 2
856 instantVector.push_back( atoi(tmp) );
857 fscanf(pFile,"%s",tmp); // 3
858 instantVector.push_back( atoi(tmp) );
859 fscanf(pFile,"%s",tmp); // 4
860 instantVector.push_back( atoi(tmp) );
861 fscanf(pFile,"%s",tmp); // 5
862 instantVector.push_back( atoi(tmp) );
863 fscanf(pFile,"%s",tmp); // 6
864 instantVector.push_back( atoi(tmp) );
867 fscanf(pFile,"%s",tmp); // TypeContourModel
868 fscanf(pFile,"%s",tmp); // ##
869 typeContourModel = atoi(tmp);
871 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
872 manModelContour->Open(pFile);
874 fscanf(pFile,"%s",tmp); // TypeView
875 fscanf(pFile,"%s",tmp); // ##
876 typeView = atoi(tmp);
885 theName = kernelManager->createOutline( manModelContour, instantVector );
886 bool addedModel = theName.compare("") != 0;
889 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
890 _theViewPanel->getSpacing(spc);
891 //Adding the manualContourControler to interface objects structure
892 //Adding the manualViewContour to interface objects structure
893 //_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.
894 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
897 if (staticContour==true)
899 Instant instant(&instantVector);
900 kernelManager->changeContourOfManager( theName , &instant );
903 }// for numberOfContours
907 void wxContourMainFrame::RefreshInterface(){
909 _theViewPanel->RefreshInterface();
910 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
911 //wxvtk2dbaseview->Refresh();
914 vtkImageData* wxContourMainFrame::getImageData(){
915 return _theViewPanel->getImageData();
918 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
920 //JCP 20-10-08 Undo redo implementation
922 //JCP 20-10-08 Undo redo implementation
925 int x = _theViewPanel->GetX();
926 int y = _theViewPanel->GetY();
927 int z = _theViewPanel->GetZ();
928 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
932 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
935 int typeofcontour = 1;
937 vtkImageData *imagedata = getImageData();
939 //Tipo de pixeles a utilizar internamente en ITK
940 typedef float InternalPixelType;
941 const unsigned int Dimension = 2;
942 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
944 //Tipo de pixeles de salida 1
945 typedef unsigned char OutputPixelType;
946 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
948 //Tipo de pixeles de salida 2
949 typedef unsigned short OutputPixelType2;
950 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
952 //Definición del thresholder
953 typedef itk::BinaryThresholdImageFilter<
955 OutputImageType > ThresholdingFilterType;
957 //Definición del primer filtro de conversión de pixeles
958 typedef itk::CastImageFilter<
959 OutputImageType, OutputImageType2 > CastFilterType;
961 //Definición del segundo tipo de conversión de pixeles
962 typedef itk::CastImageFilter<
963 OutputImageType2, InternalImageType > CastFilterType2;
965 //Tercer tipo de conversión
966 typedef itk::RescaleIntensityImageFilter<
968 OutputImageType > CastFilterType3;
970 //Cuarto tipo de conversión
971 typedef itk::RescaleIntensityImageFilter<
973 OutputImageType > CastFilterType4;
975 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
977 thresholder->SetLowerThreshold( 0.0 );
978 thresholder->SetUpperThreshold( 128 );
980 thresholder->SetOutsideValue( 255 );
981 thresholder->SetInsideValue( 0 );
983 //Definción de conexiónes entre VTK e ITK y el writer
984 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
985 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
986 typedef itk::ImageFileWriter< OutputImageType > WriterType;
988 ConnectorType::Pointer connector= ConnectorType::New();
989 ConnectorType2::Pointer connector2= ConnectorType2::New();
992 CastFilterType::Pointer filter=CastFilterType::New();
993 CastFilterType2::Pointer filter2=CastFilterType2::New();
995 connector->SetInput( imagedata );
996 filter2->SetInput(connector->GetOutput());
998 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1000 InternalImageType > SmoothingFilterType;
1002 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1004 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1006 InternalImageType > GradientFilterType;
1008 typedef itk::SigmoidImageFilter<
1010 InternalImageType > SigmoidFilterType;
1012 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1014 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1016 sigmoid->SetOutputMinimum( 0.0 );
1017 sigmoid->SetOutputMaximum( 255.0 );
1020 typedef itk::FastMarchingImageFilter<
1022 InternalImageType > FastMarchingFilterType;
1025 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1027 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1028 InternalImageType > GeodesicActiveContourFilterType;
1029 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1030 GeodesicActiveContourFilterType::New();
1032 typedef itk::ZeroCrossingImageFilter<
1034 InternalImageType > ZeroCrossingFilterType;
1035 ZeroCrossingFilterType::Pointer zeroCrossing =
1036 ZeroCrossingFilterType::New();
1038 const double propagationScaling = atof( prop );
1040 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1041 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1042 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1044 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1045 int it=atoi( iter );
1046 geodesicActiveContour->SetNumberOfIterations( it );
1048 smoothing->SetInput( filter2->GetOutput() );
1049 gradientMagnitude->SetInput( smoothing->GetOutput() );
1050 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1051 fastMarching->SetInput( sigmoid->GetOutput() );
1052 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1053 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1055 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1056 //thresholder->SetInput( zeroCrossing->GetOutput() );
1057 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1058 connector2->SetInput( thresholder->GetOutput() );
1061 smoothing->SetTimeStep( 0.125 );
1062 smoothing->SetNumberOfIterations( 5 );
1063 smoothing->SetConductanceParameter( 9.0 );
1066 const double sigma = atof( sigm );
1067 gradientMagnitude->SetSigma( sigma );
1069 const double alpha = atof( alf );
1070 const double beta = atof( bet );
1072 sigmoid->SetAlpha( alpha );
1073 sigmoid->SetBeta( beta );
1075 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1076 typedef FastMarchingFilterType::NodeType NodeType;
1078 NodeContainer::Pointer seeds = NodeContainer::New();
1080 InternalImageType::IndexType seedPosition;
1081 seedPosition[0] = x;
1082 seedPosition[1] = y;
1084 const double initialDistance = atof( distanc );
1088 const double seedValue = - initialDistance;
1090 node.SetValue( seedValue );
1091 node.SetIndex( seedPosition );
1093 seeds->Initialize();
1094 seeds->InsertElement( 0, node );
1096 fastMarching->SetTrialPoints( seeds );
1098 fastMarching->SetSpeedConstant( 1.0 );
1100 fastMarching->SetOutputSize(
1101 connector->GetOutput()->GetBufferedRegion().GetSize() );
1103 fastMarching->SetStoppingValue( 800 );
1107 connector2->Update();
1108 vtkImageData *idata = connector2->GetOutput();
1110 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1112 cntVTK->SetInput( idata );
1114 cntVTK->SetNumberOfContours( 1 );
1115 cntVTK->SetValue( 0, 255 );
1117 cntVTK->UpdateInformation();
1119 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1120 cpd->SetInput( cntVTK->GetOutput( ) );
1122 cpd->UpdateInformation();
1124 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1125 conn->SetExtractionModeToLargestRegion( );
1126 conn->SetInput( cpd->GetOutput( ) );
1128 conn->UpdateInformation();
1130 vtkStripper* vtkstripper = vtkStripper::New( );
1131 vtkstripper->SetInput( conn->GetOutput() );
1132 vtkstripper->Update();
1133 vtkstripper->UpdateInformation();
1136 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1137 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1138 polyDataResult->Update( );
1139 polyDataResult->UpdateInformation();
1144 myfile.open ("C:/Creatis/example.txt");
1146 polyDataResult->Print(myfile);
1147 myfile << "-------------------------------------\n";
1148 polyDataResult->GetLines()->Print(myfile);
1156 //--Calculating control points
1158 std::vector<double> vecX;
1159 std::vector<double> vecY;
1160 std::vector<double> vecXo;
1161 std::vector<double> vecYo;
1162 std::vector<double>::iterator vecXoi;
1163 std::vector<double>::iterator vecYoi;
1164 std::vector<double> vecZ;
1166 std::vector<double> vecCtrlPointX;
1167 std::vector<double> vecCtrlPointY;
1168 std::vector<double> vecCtrlPointZ;
1174 int ii,size=polyDataResult->GetNumberOfPoints();
1176 myfile.open ("C:/Creatis/example2.txt");
1178 size=polyDataResult->GetNumberOfPoints();
1179 for (ii=0;ii<size;ii++)
1186 p = polyDataResult->GetPoint(ii);
1189 /*if(fabs(yAct-y)>20)
1191 if((xAct-x)>1 || (xAct-x)<-1)
1193 vecX.push_back( p[0] );
1194 vecY.push_back( p[1] );
1195 myfile <<p[0]<<","<<p[1]<<"\n";
1196 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1197 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1198 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1199 vecZ.push_back( -900 );
1205 vecXo.push_back(p[0]);
1206 vecYo.push_back(p[1]);
1210 else*/ if(fabs(xAct-x)>11)
1212 vecXo.push_back(p[0]);
1213 vecYo.push_back(p[1]);
1217 vecX.push_back( p[0] );
1218 myfile <<p[0]<<","<<p[1]<<"\n";
1219 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1220 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1221 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1222 vecY.push_back( p[1] );
1223 vecZ.push_back( -900 );
1231 while(!vecXo.empty())
1233 vecX.push_back(vecXo.back());
1234 std::cout<<" x Siguiente "<<vecXo.back();
1236 vecZ.push_back( -900 );
1238 while(!vecYo.empty())
1240 vecY.push_back(vecYo.back());
1245 /*for(int l=0;l<vecX.size();l++)
1249 vecXo.push_back(p[0]);
1250 vecYo.push_back(p[1]);
1261 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1263 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1267 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1269 else if (method==1){
1270 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1272 else if (method==2){
1273 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1274 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1276 //--Adding contour to the system
1278 std::vector<int> actualInstantVector;
1279 _instantPanel->getInstant( actualInstantVector );
1280 actualInstantVector[1]=z;
1282 int j,sizeCtrPt = vecCtrlPointX.size();
1284 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1285 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1287 for (j=0 ; j<sizeCtrPt ; j++)
1289 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1291 std::string theName;
1292 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1293 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1294 bool addedModel = theName.compare("") != 0;
1297 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1298 _theViewPanel->getSpacing(spc);
1299 //Adding the manualContourControler to interface objects structure
1300 //Adding the manualViewContour to interface objects structure
1301 //_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.
1302 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1303 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1309 WriterType::Pointer writer = WriterType::New();
1310 CastFilterType3::Pointer caster = CastFilterType3::New();
1312 caster->SetInput( gradientMagnitude->GetOutput() );
1313 writer->SetInput( caster->GetOutput() );
1314 writer->SetFileName("Gradient Magnitude.png");
1315 caster->SetOutputMinimum( 0 );
1316 caster->SetOutputMaximum( 255 );
1319 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1320 WriterType::Pointer writer2 = WriterType::New();
1322 caster2->SetInput( sigmoid->GetOutput() );
1323 writer2->SetInput( caster2->GetOutput() );
1324 writer2->SetFileName("Sigmoid.png");
1325 caster2->SetOutputMinimum( 0 );
1326 caster2->SetOutputMaximum( 255 );
1329 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1330 WriterType::Pointer writer3 = WriterType::New();
1332 caster3->SetInput( fastMarching->GetOutput() );
1333 writer3->SetInput( caster3->GetOutput() );
1334 writer3->SetFileName("FastMarching.bmp");
1335 caster3->SetOutputMinimum( 0 );
1336 caster3->SetOutputMaximum( 255 );
1339 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1340 WriterType::Pointer writer4 = WriterType::New();
1342 caster4->SetInput( geodesicActiveContour->GetOutput() );
1343 writer4->SetInput( caster4->GetOutput() );
1344 writer4->SetFileName("GeodesicActiveContour.png");
1345 caster4->SetOutputMinimum( 0 );
1346 caster4->SetOutputMaximum( 255 );
1349 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1350 WriterType::Pointer writer5 = WriterType::New();
1352 caster5->SetInput( zeroCrossing->GetOutput() );
1353 writer5->SetInput( caster5->GetOutput() );
1354 writer5->SetFileName("ZeroCrossing.bmp");
1355 caster5->SetOutputMinimum( 0 );
1356 caster5->SetOutputMaximum( 255 );
1359 catch( itk::ExceptionObject & excep )
1361 std::cerr << "Exception caught !" << std::endl;
1362 std::cerr << excep << std::endl;
1366 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1368 //JCP 20-10-08 Undo redo implementation
1370 //JCP 20-10-08 Undo redo implementation
1373 int x = _theViewPanel->GetX();
1374 int y = _theViewPanel->GetY();
1375 int z = _theViewPanel->GetZ();
1376 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1381 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1383 int typeofcontour = 1;
1384 //--Extracting Contour
1385 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1386 vtkImageData *imagedata = getImageData();
1387 // double *range = imagedata->GetScalarRange();
1390 vtkImageReslice *imageReslice = vtkImageReslice::New();
1393 // imagedata->GetSpacing(spc);
1398 imageReslice->SetInput( imagedata );
1399 imageReslice->SetInformationInput(imagedata);
1400 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1401 imageReslice->SetResliceAxesOrigin(0,0,z);
1402 imageReslice->SetOutputDimensionality(2);
1403 imageReslice->SetInterpolationModeToLinear();
1405 imagedata = imageReslice->GetOutput();
1406 imagedata->Update();
1407 imagedata->UpdateInformation();
1409 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1410 cntVTK->SetInput( imagedata );
1412 cntVTK->SetNumberOfContours( 1 );
1413 //cntVTK->SetValue( 0, vmin );
1414 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1415 cntVTK->SetValue( 1, isovalue );
1416 // cntVTK->SetValue( 1, vmax );
1418 cntVTK->UpdateInformation();
1420 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1421 cpd->SetInput( cntVTK->GetOutput( ) );
1422 cpd->ConvertLinesToPointsOff( );
1424 cpd->UpdateInformation();
1426 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1427 conn->SetExtractionModeToClosestPointRegion( );
1428 //conn->SetMaxRecursionDepth( 3000 );
1430 conn->SetInput( cpd->GetOutput( ) );
1432 conn->SetClosestPoint( x, y, 0 );
1434 conn->UpdateInformation();
1436 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1437 cpd2->SetInput( conn->GetOutput( ) );
1439 cpd2->UpdateInformation();
1441 vtkStripper* vtkstripper = vtkStripper::New( );
1442 vtkstripper->SetInput( cpd2->GetOutput() );
1443 vtkstripper->Update();
1444 vtkstripper->UpdateInformation();
1447 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1449 polyDataResult->Update( );
1450 polyDataResult->UpdateInformation();
1454 myfile.open ("c:/temp/example.txt");
1456 polyDataResult->Print(myfile);
1457 myfile << "-------------------------------------\n";
1458 polyDataResult->GetLines()->Print(myfile);
1468 //--Calculating control points
1470 std::vector<double> vecX;
1471 std::vector<double> vecY;
1472 std::vector<double> vecZ;
1474 std::vector<double> vecCtrlPointX;
1475 std::vector<double> vecCtrlPointY;
1476 std::vector<double> vecCtrlPointZ;
1480 int ii,size=polyDataResult->GetNumberOfPoints();
1482 for (ii=1;ii<=size;ii++)
1484 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1485 p = polyDataResult->GetPoint(id);
1488 vecX.push_back( p[0] );
1489 vecY.push_back( p[1] );
1490 vecZ.push_back( -900 );
1491 // vecZ.push_back( p[2] );
1495 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1496 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1499 /*if (methodRadiobox->GetSelection()==0){
1500 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1502 if (methodRadiobox->GetSelection()==1){
1503 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1505 if (methodRadiobox->GetSelection()==2){
1506 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1507 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1511 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1513 else if (method==1){
1514 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1516 else if (method==2){
1517 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1518 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1521 //--Adding contour to the system
1523 std::vector<int> actualInstantVector;
1524 _instantPanel->getInstant( actualInstantVector );
1525 actualInstantVector[1]=z;
1527 int j,sizeCtrPt = vecCtrlPointX.size();
1528 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1529 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1531 for (j=0 ; j<sizeCtrPt ; j++)
1533 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1535 std::string theName;
1536 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1537 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1538 bool addedModel = theName.compare("") != 0;
1541 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1542 _theViewPanel->getSpacing(spc);
1543 //Adding the manualContourControler to interface objects structure
1544 //Adding the manualViewContour to interface objects structure
1545 //_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.
1546 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1547 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1552 int wxContourMainFrame::GetImageDataSizeZ(){
1553 return _theViewPanel->GetImageDataSizeZ();
1556 void wxContourMainFrame::GetImageDataRange(double *range){
1557 _theViewPanel->GetImageDataRange(range);
1560 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1561 //JCP 20-10-08 Undo redo implementation
1563 //JCP 20-10-08 Undo redo implementation
1566 int x = _theViewPanel->GetX();
1567 int y = _theViewPanel->GetY();
1571 double totalZ = maxZ-minZ+1;
1572 for( z=minZ ; z<=maxZ ; z++ )
1574 porcent = 100.0* (z-minZ)/totalZ;
1575 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1576 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1577 //_staticTextSegmentation->SetLabel(tmpString);
1578 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1580 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1585 //Creates a reference line to be used as the axis of the mirroring
1586 void wxContourMainFrame::referenceLine()
1591 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1592 vtkimagedata->GetSpacing(spc);
1594 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1596 _refLineControl = new manualLineControler();
1597 _refLineModel = new manualContourModelLine();
1598 _refLineView = new manualViewLine();
1599 _refLineView->SetModel( _refLineModel );
1600 _refLineView->SetWxVtkBaseView( viewer2D );
1601 _refLineView->SetRange( 2 );
1602 _refLineView->SetZ( 1200 );
1604 _refLineView->SetSpacing(spc);
1606 _refLineView->SetColorNormalContour(0, 0, 1);
1607 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1608 _refLineView->SetWidthLine(4);
1610 _refLineControl->SetModelView( _refLineModel , _refLineView );
1611 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1612 _refLineModel->SetCloseContour(false);
1613 _refLineControl->CreateNewManualContour();
1615 double z = _refLineControl->GetZ();
1617 _refLineModel->AddPoint(50,100,z);
1618 _refLineModel->AddPoint(80,40,z);
1620 _refLineControl->AddPoint(50,100,z);
1621 _refLineControl->AddPoint(80,40,z);
1623 _refLineView->UpdateViewPoint(0);
1624 _refLineView->UpdateViewPoint(1);
1626 _refLineControl->SetCompleteCreation(true);
1627 _refLineControl->SetEditable(true);
1629 _refLineControl->SetActive(true);
1630 _refLineView->RefreshContour();
1633 //Hides the referenceLine
1634 void wxContourMainFrame::refLineHide()
1636 if (_refLineControl!=NULL)
1638 _refLineView->RemoveCompleteContourActor();
1642 //Shows the referenceLine
1643 void wxContourMainFrame::refLineShow()
1645 if (_refLineControl!=NULL)
1647 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1649 _refLineView->SetModel( _refLineModel );
1650 _refLineView->SetWxVtkBaseView( viewer2D );
1651 _refLineView->SetRange( 2 );
1652 _refLineView->SetZ( 1200 );
1654 _refLineControl->SetModelView( _refLineModel , _refLineView );
1655 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1656 _refLineControl->CreateNewManualContour();
1657 //_refLineControl->SetActive(true);
1658 //_refLineControl->SetEditable(true);
1659 _refLineView->RefreshContour();
1663 void wxContourMainFrame::onMirror()
1666 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1667 std::vector<std::string> filterCurrentSelection;
1669 std::vector<int> tempVector;
1670 _instantPanel->getInstant( tempVector );
1671 _performingOperation->reset();
1672 _performingOperation->setStartCommand( COPY );
1673 _performingOperation->setStartOperationInstantVector( tempVector );
1674 _performingOperation->setKeyNamesOperationElems( currentSelection );
1676 char theStartCommand = _performingOperation->getStartCommand();
1677 if ( theStartCommand == COPY )
1679 //JCP 20-10-08 Undo redo implementation
1681 //JCP 20-10-08 Undo redo implementation
1682 std::vector<int> tempVector;
1683 _instantPanel->getInstant( tempVector );
1684 _performingOperation->setEndOperationInstantVector ( tempVector );
1685 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1686 int i,size = elems.size();
1687 for( i=0; i<size; i++ )
1689 createMirrorContourOf( elems[i], tempVector, i>0 );
1693 //deleteContour( _refName );
1697 void wxContourMainFrame::showAxis(bool show){
1698 _theViewPanel->SetVisibleAxis(show);
1699 _theViewPanel->Refresh();
1703 void wxContourMainFrame::onRigidPressed(){
1704 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1705 int elementsSelected = currentSelection.size();
1707 if ( elementsSelected >= 1 ){
1708 //JCP 20-10-08 Undo redo implementation
1710 //JCP 20-10-08 Undo redo implementation
1712 std::vector<int> tempVector;
1713 _instantPanel->getInstant( tempVector );
1714 Instant instant(&tempVector);
1716 int i , size=currentSelection.size();
1717 for ( i=0 ; i<size ; i++ )
1719 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1724 void wxContourMainFrame::onWidthOfContour(double width){
1726 _theViewPanel->removeSceneContours();
1727 _theViewPanel->SetWidthContour(width);
1729 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1733 int wxContourMainFrame::getColorWindow(){
1734 return _theViewPanel->getColorWindow();
1736 int wxContourMainFrame::getWindowLevel(){
1737 return _theViewPanel->getWindowLevel();
1740 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1741 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1747 void wxContourMainFrame::onInterpolation(bool interpolate){
1748 _theViewPanel->onInterpolation(interpolate);
1752 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1753 _instantPanel->setConceptValue( name, actual );
1756 void wxContourMainFrame::resetAppend(){
1757 kernelManager->resetAppend();
1761 void wxContourMainFrame::onSpreadAdd(){
1762 std::vector<double> vecX;
1763 std::vector<double> vecY;
1764 std::vector<double> vecZ;
1765 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1767 std::vector<int> tempVector;
1768 _instantPanel->getInstant( tempVector );
1770 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1772 interfMainPanel::getInstance()->appendStringSpread(val);
1776 void wxContourMainFrame::onSpreadGo(int type){
1778 //JCP 20-10-08 Undo redo implementation
1780 //JCP 20-10-08 Undo redo implementation
1783 std::vector<double> vecCtrlPointX;
1784 std::vector<double> vecCtrlPointY;
1785 std::vector<double> vecCtrlPointZ;
1789 std::vector<int> tempVector;
1790 _instantPanel->getInstant( tempVector );
1793 kernelManager->getMaxMinZ(&minZ,&maxZ);
1794 //JSTG_16-07-08_----------------------------------------------------------------
1795 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1796 kernelManager->CalculeSplinePropagation();
1798 double totalZ = maxZ-minZ+1;
1801 //--------------------------------------------------------------------
1802 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1804 porcent = 100.0* (z-minZ)/totalZ;
1805 int numero = (int)(z-minZ+1)/(int)totalZ;
1806 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1808 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1810 int typeofcontour = 1;
1811 std::string theName;
1812 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1814 if( manModelContour!=NULL ){
1815 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1816 this->_theViewPanel->getSpacing(spc);
1817 //Adding the manualContourControler to interface objects structure
1818 //Adding the manualViewContour to interface objects structure
1819 //_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.
1820 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1825 int numero = (int)(z-minZ+1)/(int)totalZ;
1826 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1828 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1830 //RefreshInterface();
1833 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1837 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1838 std::vector<int> tempVector;
1839 _instantPanel->getInstant(tempVector);
1840 //Asignation of slide number should be different ex by name
1841 tempVector[1]=slide;
1842 return kernelManager->getOutlinesNameAtInstant(tempVector);
1845 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1846 int maxContourGroup = 0;
1848 ContourExtractData *contourextractdata = new ContourExtractData();
1850 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1852 std::vector<manualContourModel*> lstManConMod;
1853 std::vector<manualContourModel*> lstManConModTmp;
1854 std::vector<manualContourModel*> lstManConModExp;
1855 std::vector<double> pLstValue;
1856 std::vector<double> pLstValuePosX;
1857 std::vector<double> pLstValuePosY;
1858 std::vector<double> pLstValuePosZ;
1861 int resultGrayRangeCount;
1864 double resultAverage;
1865 double resultStandardeviation;
1867 std::vector<int> tempVector;
1868 _instantPanel->getInstant( tempVector );
1870 vtkImageData *imagedata = _theViewPanel->getImageData();
1871 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1873 int ii,sizeLstContourThings;
1883 if (selection==0 ) // actual slice
1885 std::vector<int> tempVector;
1886 _instantPanel->getInstant( tempVector );
1887 int actualSlice = tempVector[1];
1891 else if (selection==2 ) // All slices
1896 else if (selection==1 ) // slice range
1903 totalZ = maxZ-minZ+1;
1904 contourextractdata->SetImage( imagedata);
1907 for ( z=minZ ; z<=maxZ ; z++ )
1910 porcent = 100.0* (z-minZ)/totalZ;
1911 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1913 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1914 //_staticTextInformation->SetLabel(tmpString);
1916 //Extraction data from contours of each slice
1917 contourextractdata->SetZtoBeAnalys( z);
1920 Instant instant(&tempVector);
1921 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1922 sizeLstContourThings = lstContourThings.size();
1924 lstManConMod.clear();
1925 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1927 ContourThing **contourthing = lstContourThings[ii];
1928 lstManConMod.push_back( (*contourthing)->getModel() );
1930 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1933 wxString tempString;
1934 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1935 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1936 //_grid->SetRowLabelValue(z, tempString );
1938 int iContourGroup,sizeContourGroup;
1939 if (typeContourGroup==3) // contour separete
1941 sizeContourGroup=lstManConModExp.size();
1942 if ( maxContourGroup<sizeContourGroup )
1944 maxContourGroup=sizeContourGroup;
1946 } else { // contour AND OR XOR
1955 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1956 lstManConModTmp.clear();
1957 if (typeContourGroup==3) // contour separete
1959 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1960 } else { // contour AND OR XOR
1961 lstManConModTmp = lstManConModExp;
1964 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1967 pLstValuePosX.clear();
1968 pLstValuePosY.clear();
1969 pLstValuePosZ.clear();
1970 contourextractdata->GetValuesInsideCrown( &pLstValue,
1974 // Statistics of each slice.
1975 contourextractdata->Statistics( &pLstValue,
1978 &resultGrayRangeCount,
1983 &resultStandardeviation);
1985 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1987 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1990 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1992 tempString.Printf(_T("%d"),resultSize);
1993 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1995 tempString.Printf(_T("%d"),resultGrayRangeCount);
1996 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1998 tempString.Printf(_T("%f"),resultMin);
1999 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2001 tempString.Printf(_T("%f"),resultMax);
2002 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2004 tempString.Printf(_T("%f"),resultAverage);
2005 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2007 tempString.Printf(_T("%f"),resultStandardeviation);
2008 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2011 } // for iContourGroup
2015 wxString tmpTitleString;
2017 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2019 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2020 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2021 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2023 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2024 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2025 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2026 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2027 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2028 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2029 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2032 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2033 delete contourextractdata;
2036 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2037 SaveValuesXYZ( directory , namefile, typeContourGroup );
2038 SaveImageResult( directory , namefile, typeContourGroup);
2041 FILE *pFile=fopen(filename.c_str(),"w+");
2043 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2046 int i,j,maxX,maxY=sizeZ;
2047 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2049 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2050 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2052 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2054 fprintf(pFile,"\n" );
2058 for ( j=0; j<maxY ; j++)
2060 fprintf(pFile,"%d\t" , j );
2061 for (i=0 ; i<maxX ; i++){
2062 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2063 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2065 fprintf(pFile,"\n" );
2071 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2074 ContourExtractData *contourextractdata = new ContourExtractData();
2075 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2076 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2078 std::vector<manualContourModel*> lstManConMod;
2079 std::vector<manualContourModel*> lstManConModTmp;
2080 std::vector<manualContourModel*> lstManConModExp;
2081 std::vector<double> pLstValue;
2082 std::vector<double> pLstValuePosX;
2083 std::vector<double> pLstValuePosY;
2084 std::vector<double> pLstValuePosZ;
2086 std::vector<int> tempVector;
2087 _instantPanel->getInstant( tempVector );
2089 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2090 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2092 int ii,sizeLstContourThings;
2099 minZ = 0;// _mbarrange->GetStart();
2100 maxZ = sizeZ;//_mbarrange->GetEnd();
2101 totalZ = maxZ-minZ+1;
2103 contourextractdata->SetImage( imagedata);
2106 for ( z=0 ; z<sizeZ ; z++)
2109 porcent = 100.0* (z-minZ)/totalZ;
2111 tmpString.Printf(_T("Saving Values"));
2112 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2113 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2114 //_staticTextInformation->SetLabel(tmpString);
2117 //Extraction data from contours of each slice
2118 contourextractdata->SetZtoBeAnalys( z);
2121 Instant instant(&tempVector);
2122 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2123 sizeLstContourThings = lstContourThings.size();
2125 lstManConMod.clear();
2126 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2128 ContourThing **contourthing = lstContourThings[ii];
2129 lstManConMod.push_back( (*contourthing)->getModel() );
2131 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2136 int iContourGroup,sizeContourGroup;
2137 if (typeContourGroup==3) // contour separete
2139 sizeContourGroup=lstManConModExp.size();
2140 } else { // contour AND OR XOR
2144 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2145 lstManConModTmp.clear();
2146 if (typeContourGroup==3) // contour separete
2148 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2149 } else { // contour AND OR XOR
2150 lstManConModTmp = lstManConModExp;
2153 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2156 pLstValuePosX.clear();
2157 pLstValuePosY.clear();
2158 pLstValuePosZ.clear();
2159 contourextractdata->GetValuesInsideCrown( &pLstValue,
2164 std::string temp = directory + "/" + namefile + "-slice";
2165 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2166 temp = temp + ".txt";
2168 // LG 14/01/09 : using crea
2169 wxString filename = crea::std2wx(temp);
2170 /*filename.Printf(_T("%s"),directory.c_str());
2171 filename.append(_T("\\"));
2172 filename.append(_T("%s"),namefile.c_str());
2173 filename.append(_T("-slice"));
2174 filename.append(_T("%d"),z);
2175 filename.append(_T("-cont"));
2176 filename.append(_T("%d"),iContourGroup);
2177 filename.append(_T(".txt"));*/
2178 // filename.Printf(temp.c_str());
2182 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2183 fprintf(pFile,"value \t x \t y \t z\n" );
2184 int iLstValue,sizeLstValue=pLstValue.size();
2185 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2187 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2190 } // for iContourGroup
2192 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2193 //_staticTextInformation->SetLabel( _T("") );
2194 delete contourextractdata;
2197 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
2200 ContourExtractData *contourextractdata = new ContourExtractData( true );
2201 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2202 if (typeContourGroup==3)
2206 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2208 std::vector<manualContourModel*> lstManConMod;
2209 std::vector<manualContourModel*> lstManConModTmp;
2210 std::vector<manualContourModel*> lstManConModExp;
2212 std::vector<int> tempVector;
2213 _instantPanel->getInstant( tempVector );
2215 vtkImageData *imagedata = _theViewPanel->getImageData();
2216 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2218 int ii,sizeLstContourThings;
2227 minZ = 0;// _mbarrange->GetStart();
2228 maxZ = sizeZ;//_mbarrange->GetEnd();
2229 totalZ = maxZ-minZ+1;
2231 contourextractdata->SetImage( imagedata);
2234 for ( z=0 ; z<sizeZ ; z++)
2237 porcent = 100.0* (z-minZ)/totalZ;
2238 tmpString.Printf(_T("Saving Values"));
2239 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2240 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2242 //Extraction data from contours of each slice
2243 contourextractdata->SetZtoBeAnalys( z);
2246 Instant instant(&tempVector);
2247 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2248 sizeLstContourThings = lstContourThings.size();
2250 lstManConMod.clear();
2251 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2253 ContourThing **contourthing = lstContourThings[ii];
2254 lstManConMod.push_back( (*contourthing)->getModel() );
2256 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2259 int iContourGroup,sizeContourGroup;
2260 if (typeContourGroup==3) // contour separete
2262 sizeContourGroup=lstManConModExp.size();
2263 } else { // contour AND OR XOR
2267 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2268 lstManConModTmp.clear();
2269 if (typeContourGroup==3) // contour separete
2271 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2272 } else { // contour AND OR XOR
2273 lstManConModTmp = lstManConModExp;
2276 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2279 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
2281 // ContourThing **contourthing = lstContourThings[ii];
2282 // lstManConMod.push_back( (*contourthing)->getModel() );
2284 // contourextractdata->SetLstManualContourModel( lstManConMod );
2286 contourextractdata->CalculateImageResult(); // with actual Z
2288 } // for iContourGroup
2291 std::string temp = directory + "/" + namefile + "-Value.mhd";
2293 wxString filename = crea::std2wx(temp);
2295 // filename.Printf(_T(temp.c_str()));
2296 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2297 /*filename.Printf(_T("%s"),directory.c_str());
2298 filename.append(_T("\\"));
2299 filename.append(_T("%s"),namefile.c_str());
2300 filename.append(_T("-Value.mhd"));*/
2303 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2304 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
2305 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2306 writerValueImage->SetFileDimensionality( 3 );
2307 writerValueImage->Write( );
2310 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2311 temp = directory + "/" + namefile + "-Mask.mhd";
2313 // LG 14/01/09 : using crea
2314 filename = crea::std2wx(temp);
2315 // filename.Printf(_T(temp.c_str()));
2317 /*filename.Printf(_T("%s"),directory.c_str());
2318 filename.append(_T("\\"));
2319 filename.append(_T("%s"),namefile.c_str());
2320 filename.append(_T("-Mask.mhd"));*/
2322 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2323 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
2324 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2325 writerMaskImage->SetFileDimensionality( 3 );
2326 writerMaskImage->Write( );
2328 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2329 delete contourextractdata;
2332 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2333 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2334 _theViewPanel->setActualVertical( value);
2336 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2337 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2343 void wxContourMainFrame::onSnakePressed(){
2344 std::vector<double> vecX;
2345 std::vector<double> vecY;
2346 std::vector<double> vecZ;
2347 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2349 if (vecX.size()!=0){
2350 std::vector<int> tempVector;
2351 _instantPanel->getInstant( tempVector );
2352 int i,size=vecZ.size();
2353 int actualSlice = tempVector[1];
2354 for ( i=0 ; i<size ; i++ )
2356 vecZ[i] = actualSlice;
2359 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2360 wxPanel* panel = new wxPanel(dialog,-1);
2361 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2362 dialog->ShowModal();
2367 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2368 std::string filename = kernelManager->getCurrentFileName();
2369 if(filename.compare("")!=0){
2370 saveFileWithContours(filename);