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::onSegmentationOneSlice(int isovalue,int sampling,int method){
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 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
933 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
935 int typeofcontour = 1;
936 //--Extracting Contour
937 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
938 vtkImageData *imagedata = getImageData();
939 // double *range = imagedata->GetScalarRange();
942 vtkImageReslice *imageReslice = vtkImageReslice::New();
945 // imagedata->GetSpacing(spc);
950 imageReslice->SetInput( imagedata );
951 imageReslice->SetInformationInput(imagedata);
952 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
953 imageReslice->SetResliceAxesOrigin(0,0,z);
954 imageReslice->SetOutputDimensionality(2);
955 imageReslice->SetInterpolationModeToLinear();
957 imagedata = imageReslice->GetOutput();
959 imagedata->UpdateInformation();
961 vtkContourFilter* cntVTK = vtkContourFilter::New( );
962 cntVTK->SetInput( imagedata );
964 cntVTK->SetNumberOfContours( 1 );
965 //cntVTK->SetValue( 0, vmin );
966 // cntVTK->SetValue( 0, (range[1]*thr/100) );
967 cntVTK->SetValue( 1, isovalue );
968 // cntVTK->SetValue( 1, vmax );
970 cntVTK->UpdateInformation();
972 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
973 cpd->SetInput( cntVTK->GetOutput( ) );
974 cpd->ConvertLinesToPointsOff( );
976 cpd->UpdateInformation();
978 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
979 conn->SetExtractionModeToClosestPointRegion( );
980 //conn->SetMaxRecursionDepth( 3000 );
982 conn->SetInput( cpd->GetOutput( ) );
984 conn->SetClosestPoint( x, y, 0 );
986 conn->UpdateInformation();
988 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
989 cpd2->SetInput( conn->GetOutput( ) );
991 cpd2->UpdateInformation();
993 vtkStripper* vtkstripper = vtkStripper::New( );
994 vtkstripper->SetInput( cpd2->GetOutput() );
995 vtkstripper->Update();
996 vtkstripper->UpdateInformation();
999 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1001 polyDataResult->Update( );
1002 polyDataResult->UpdateInformation();
1006 myfile.open ("c:/temp/example.txt");
1008 polyDataResult->Print(myfile);
1009 myfile << "-------------------------------------\n";
1010 polyDataResult->GetLines()->Print(myfile);
1020 //--Calculating control points
1022 std::vector<double> vecX;
1023 std::vector<double> vecY;
1024 std::vector<double> vecZ;
1026 std::vector<double> vecCtrlPointX;
1027 std::vector<double> vecCtrlPointY;
1028 std::vector<double> vecCtrlPointZ;
1032 int ii,size=polyDataResult->GetNumberOfPoints();
1034 for (ii=1;ii<=size;ii++)
1036 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1037 p = polyDataResult->GetPoint(id);
1040 vecX.push_back( p[0] );
1041 vecY.push_back( p[1] );
1042 vecZ.push_back( -900 );
1043 // vecZ.push_back( p[2] );
1047 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1048 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1051 /*if (methodRadiobox->GetSelection()==0){
1052 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1054 if (methodRadiobox->GetSelection()==1){
1055 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1057 if (methodRadiobox->GetSelection()==2){
1058 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1059 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1063 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1065 else if (method==1){
1066 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1068 else if (method==2){
1069 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1070 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1073 //--Adding contour to the system
1075 std::vector<int> actualInstantVector;
1076 _instantPanel->getInstant( actualInstantVector );
1077 actualInstantVector[1]=z;
1079 int j,sizeCtrPt = vecCtrlPointX.size();
1080 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1081 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1083 for (j=0 ; j<sizeCtrPt ; j++)
1085 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1087 std::string theName;
1088 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1089 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1090 bool addedModel = theName.compare("") != 0;
1093 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1094 _theViewPanel->getSpacing(spc);
1095 //Adding the manualContourControler to interface objects structure
1096 //Adding the manualViewContour to interface objects structure
1097 //_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.
1098 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1099 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1104 int wxContourMainFrame::GetImageDataSizeZ(){
1105 return _theViewPanel->GetImageDataSizeZ();
1108 void wxContourMainFrame::GetImageDataRange(double *range){
1109 _theViewPanel->GetImageDataRange(range);
1112 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1113 //JCP 20-10-08 Undo redo implementation
1115 //JCP 20-10-08 Undo redo implementation
1118 int x = _theViewPanel->GetX();
1119 int y = _theViewPanel->GetY();
1123 double totalZ = maxZ-minZ+1;
1124 for( z=minZ ; z<=maxZ ; z++ )
1126 porcent = 100.0* (z-minZ)/totalZ;
1127 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1128 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1129 //_staticTextSegmentation->SetLabel(tmpString);
1130 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1132 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1137 //Creates a reference line to be used as the axis of the mirroring
1138 void wxContourMainFrame::referenceLine()
1143 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1144 vtkimagedata->GetSpacing(spc);
1146 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1148 _refLineControl = new manualLineControler();
1149 _refLineModel = new manualContourModelLine();
1150 _refLineView = new manualViewLine();
1151 _refLineView->SetModel( _refLineModel );
1152 _refLineView->SetWxVtkBaseView( viewer2D );
1153 _refLineView->SetRange( 2 );
1154 _refLineView->SetZ( 1200 );
1156 _refLineView->SetSpacing(spc);
1158 _refLineView->SetColorNormalContour(0, 0, 1);
1159 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1160 _refLineView->SetWidthLine(4);
1162 _refLineControl->SetModelView( _refLineModel , _refLineView );
1163 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1164 _refLineModel->SetCloseContour(false);
1165 _refLineControl->CreateNewManualContour();
1167 double z = _refLineControl->GetZ();
1169 _refLineModel->AddPoint(50,100,z);
1170 _refLineModel->AddPoint(80,40,z);
1172 _refLineControl->AddPoint(50,100,z);
1173 _refLineControl->AddPoint(80,40,z);
1175 _refLineView->UpdateViewPoint(0);
1176 _refLineView->UpdateViewPoint(1);
1178 _refLineControl->SetCompleteCreation(true);
1179 _refLineControl->SetEditable(true);
1181 _refLineControl->SetActive(true);
1182 _refLineView->RefreshContour();
1185 //Hides the referenceLine
1186 void wxContourMainFrame::refLineHide()
1188 if (_refLineControl!=NULL)
1190 _refLineView->RemoveCompleteContourActor();
1194 //Shows the referenceLine
1195 void wxContourMainFrame::refLineShow()
1197 if (_refLineControl!=NULL)
1199 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1201 _refLineView->SetModel( _refLineModel );
1202 _refLineView->SetWxVtkBaseView( viewer2D );
1203 _refLineView->SetRange( 2 );
1204 _refLineView->SetZ( 1200 );
1206 _refLineControl->SetModelView( _refLineModel , _refLineView );
1207 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1208 _refLineControl->CreateNewManualContour();
1209 //_refLineControl->SetActive(true);
1210 //_refLineControl->SetEditable(true);
1211 _refLineView->RefreshContour();
1215 void wxContourMainFrame::onMirror()
1218 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1219 std::vector<std::string> filterCurrentSelection;
1221 std::vector<int> tempVector;
1222 _instantPanel->getInstant( tempVector );
1223 _performingOperation->reset();
1224 _performingOperation->setStartCommand( COPY );
1225 _performingOperation->setStartOperationInstantVector( tempVector );
1226 _performingOperation->setKeyNamesOperationElems( currentSelection );
1228 char theStartCommand = _performingOperation->getStartCommand();
1229 if ( theStartCommand == COPY )
1231 //JCP 20-10-08 Undo redo implementation
1233 //JCP 20-10-08 Undo redo implementation
1234 std::vector<int> tempVector;
1235 _instantPanel->getInstant( tempVector );
1236 _performingOperation->setEndOperationInstantVector ( tempVector );
1237 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1238 int i,size = elems.size();
1239 for( i=0; i<size; i++ )
1241 createMirrorContourOf( elems[i], tempVector, i>0 );
1245 //deleteContour( _refName );
1249 void wxContourMainFrame::showAxis(bool show){
1250 _theViewPanel->SetVisibleAxis(show);
1251 _theViewPanel->Refresh();
1255 void wxContourMainFrame::onRigidPressed(){
1256 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1257 int elementsSelected = currentSelection.size();
1259 if ( elementsSelected >= 1 ){
1260 //JCP 20-10-08 Undo redo implementation
1262 //JCP 20-10-08 Undo redo implementation
1264 std::vector<int> tempVector;
1265 _instantPanel->getInstant( tempVector );
1266 Instant instant(&tempVector);
1268 int i , size=currentSelection.size();
1269 for ( i=0 ; i<size ; i++ )
1271 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1276 void wxContourMainFrame::onWidthOfContour(double width){
1278 _theViewPanel->removeSceneContours();
1279 _theViewPanel->SetWidthContour(width);
1281 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1285 int wxContourMainFrame::getColorWindow(){
1286 return _theViewPanel->getColorWindow();
1288 int wxContourMainFrame::getWindowLevel(){
1289 return _theViewPanel->getWindowLevel();
1292 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1293 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1299 void wxContourMainFrame::onInterpolation(bool interpolate){
1300 _theViewPanel->onInterpolation(interpolate);
1304 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1305 _instantPanel->setConceptValue( name, actual );
1308 void wxContourMainFrame::resetAppend(){
1309 kernelManager->resetAppend();
1313 void wxContourMainFrame::onSpreadAdd(){
1314 std::vector<double> vecX;
1315 std::vector<double> vecY;
1316 std::vector<double> vecZ;
1317 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1319 std::vector<int> tempVector;
1320 _instantPanel->getInstant( tempVector );
1322 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1324 interfMainPanel::getInstance()->appendStringSpread(val);
1328 void wxContourMainFrame::onSpreadGo(int type){
1330 //JCP 20-10-08 Undo redo implementation
1332 //JCP 20-10-08 Undo redo implementation
1335 std::vector<double> vecCtrlPointX;
1336 std::vector<double> vecCtrlPointY;
1337 std::vector<double> vecCtrlPointZ;
1341 std::vector<int> tempVector;
1342 _instantPanel->getInstant( tempVector );
1345 kernelManager->getMaxMinZ(&minZ,&maxZ);
1346 //JSTG_16-07-08_----------------------------------------------------------------
1347 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1348 kernelManager->CalculeSplinePropagation();
1350 double totalZ = maxZ-minZ+1;
1353 //--------------------------------------------------------------------
1354 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1356 porcent = 100.0* (z-minZ)/totalZ;
1357 int numero = (int)(z-minZ+1)/(int)totalZ;
1358 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1360 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1362 int typeofcontour = 1;
1363 std::string theName;
1364 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1366 if( manModelContour!=NULL ){
1367 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1368 this->_theViewPanel->getSpacing(spc);
1369 //Adding the manualContourControler to interface objects structure
1370 //Adding the manualViewContour to interface objects structure
1371 //_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.
1372 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1377 int numero = (int)(z-minZ+1)/(int)totalZ;
1378 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1380 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1382 //RefreshInterface();
1385 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1389 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1390 std::vector<int> tempVector;
1391 _instantPanel->getInstant(tempVector);
1392 //Asignation of slide number should be different ex by name
1393 tempVector[1]=slide;
1394 return kernelManager->getOutlinesNameAtInstant(tempVector);
1397 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1398 int maxContourGroup = 0;
1400 ContourExtractData *contourextractdata = new ContourExtractData();
1402 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1404 std::vector<manualContourModel*> lstManConMod;
1405 std::vector<manualContourModel*> lstManConModTmp;
1406 std::vector<manualContourModel*> lstManConModExp;
1407 std::vector<double> pLstValue;
1408 std::vector<double> pLstValuePosX;
1409 std::vector<double> pLstValuePosY;
1410 std::vector<double> pLstValuePosZ;
1413 int resultGrayRangeCount;
1416 double resultAverage;
1417 double resultStandardeviation;
1419 std::vector<int> tempVector;
1420 _instantPanel->getInstant( tempVector );
1422 vtkImageData *imagedata = _theViewPanel->getImageData();
1423 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1425 int ii,sizeLstContourThings;
1435 if (selection==0 ) // actual slice
1437 std::vector<int> tempVector;
1438 _instantPanel->getInstant( tempVector );
1439 int actualSlice = tempVector[1];
1443 else if (selection==2 ) // All slices
1448 else if (selection==1 ) // slice range
1455 totalZ = maxZ-minZ+1;
1456 contourextractdata->SetImage( imagedata);
1459 for ( z=minZ ; z<=maxZ ; z++ )
1462 porcent = 100.0* (z-minZ)/totalZ;
1463 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1465 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1466 //_staticTextInformation->SetLabel(tmpString);
1468 //Extraction data from contours of each slice
1469 contourextractdata->SetZtoBeAnalys( z);
1472 Instant instant(&tempVector);
1473 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1474 sizeLstContourThings = lstContourThings.size();
1476 lstManConMod.clear();
1477 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1479 ContourThing **contourthing = lstContourThings[ii];
1480 lstManConMod.push_back( (*contourthing)->getModel() );
1482 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1485 wxString tempString;
1486 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1487 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1488 //_grid->SetRowLabelValue(z, tempString );
1490 int iContourGroup,sizeContourGroup;
1491 if (typeContourGroup==3) // contour separete
1493 sizeContourGroup=lstManConModExp.size();
1494 if ( maxContourGroup<sizeContourGroup )
1496 maxContourGroup=sizeContourGroup;
1498 } else { // contour AND OR XOR
1507 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1508 lstManConModTmp.clear();
1509 if (typeContourGroup==3) // contour separete
1511 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1512 } else { // contour AND OR XOR
1513 lstManConModTmp = lstManConModExp;
1516 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1519 pLstValuePosX.clear();
1520 pLstValuePosY.clear();
1521 pLstValuePosZ.clear();
1522 contourextractdata->GetValuesInsideCrown( &pLstValue,
1526 // Statistics of each slice.
1527 contourextractdata->Statistics( &pLstValue,
1530 &resultGrayRangeCount,
1535 &resultStandardeviation);
1537 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1539 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1542 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1544 tempString.Printf(_T("%d"),resultSize);
1545 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1547 tempString.Printf(_T("%d"),resultGrayRangeCount);
1548 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1550 tempString.Printf(_T("%f"),resultMin);
1551 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1553 tempString.Printf(_T("%f"),resultMax);
1554 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1556 tempString.Printf(_T("%f"),resultAverage);
1557 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1559 tempString.Printf(_T("%f"),resultStandardeviation);
1560 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1563 } // for iContourGroup
1567 wxString tmpTitleString;
1569 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1571 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1572 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1573 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1575 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1576 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1577 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1578 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1579 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1580 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1581 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1584 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1585 delete contourextractdata;
1588 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1589 SaveValuesXYZ( directory , namefile, typeContourGroup );
1590 SaveImageResult( directory , namefile, typeContourGroup);
1593 FILE *pFile=fopen(filename.c_str(),"w+");
1595 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1598 int i,j,maxX,maxY=sizeZ;
1599 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1601 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1602 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1604 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1606 fprintf(pFile,"\n" );
1610 for ( j=0; j<maxY ; j++)
1612 fprintf(pFile,"%d\t" , j );
1613 for (i=0 ; i<maxX ; i++){
1614 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1615 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1617 fprintf(pFile,"\n" );
1623 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1626 ContourExtractData *contourextractdata = new ContourExtractData();
1627 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1628 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1630 std::vector<manualContourModel*> lstManConMod;
1631 std::vector<manualContourModel*> lstManConModTmp;
1632 std::vector<manualContourModel*> lstManConModExp;
1633 std::vector<double> pLstValue;
1634 std::vector<double> pLstValuePosX;
1635 std::vector<double> pLstValuePosY;
1636 std::vector<double> pLstValuePosZ;
1638 std::vector<int> tempVector;
1639 _instantPanel->getInstant( tempVector );
1641 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1642 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1644 int ii,sizeLstContourThings;
1651 minZ = 0;// _mbarrange->GetStart();
1652 maxZ = sizeZ;//_mbarrange->GetEnd();
1653 totalZ = maxZ-minZ+1;
1655 contourextractdata->SetImage( imagedata);
1658 for ( z=0 ; z<sizeZ ; z++)
1661 porcent = 100.0* (z-minZ)/totalZ;
1663 tmpString.Printf(_T("Saving Values"));
1664 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1665 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1666 //_staticTextInformation->SetLabel(tmpString);
1669 //Extraction data from contours of each slice
1670 contourextractdata->SetZtoBeAnalys( z);
1673 Instant instant(&tempVector);
1674 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1675 sizeLstContourThings = lstContourThings.size();
1677 lstManConMod.clear();
1678 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1680 ContourThing **contourthing = lstContourThings[ii];
1681 lstManConMod.push_back( (*contourthing)->getModel() );
1683 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1688 int iContourGroup,sizeContourGroup;
1689 if (typeContourGroup==3) // contour separete
1691 sizeContourGroup=lstManConModExp.size();
1692 } else { // contour AND OR XOR
1696 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1697 lstManConModTmp.clear();
1698 if (typeContourGroup==3) // contour separete
1700 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1701 } else { // contour AND OR XOR
1702 lstManConModTmp = lstManConModExp;
1705 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1708 pLstValuePosX.clear();
1709 pLstValuePosY.clear();
1710 pLstValuePosZ.clear();
1711 contourextractdata->GetValuesInsideCrown( &pLstValue,
1716 std::string temp = directory + "/" + namefile + "-slice";
1717 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1718 temp = temp + ".txt";
1720 // LG 14/01/09 : using crea
1721 wxString filename = crea::std2wx(temp);
1722 /*filename.Printf(_T("%s"),directory.c_str());
1723 filename.append(_T("\\"));
1724 filename.append(_T("%s"),namefile.c_str());
1725 filename.append(_T("-slice"));
1726 filename.append(_T("%d"),z);
1727 filename.append(_T("-cont"));
1728 filename.append(_T("%d"),iContourGroup);
1729 filename.append(_T(".txt"));*/
1730 // filename.Printf(temp.c_str());
1734 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1735 fprintf(pFile,"value \t x \t y \t z\n" );
1736 int iLstValue,sizeLstValue=pLstValue.size();
1737 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1739 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1742 } // for iContourGroup
1744 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1745 //_staticTextInformation->SetLabel( _T("") );
1746 delete contourextractdata;
1749 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1752 ContourExtractData *contourextractdata = new ContourExtractData( true );
1753 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1754 if (typeContourGroup==3)
1758 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1760 std::vector<manualContourModel*> lstManConMod;
1761 std::vector<manualContourModel*> lstManConModTmp;
1762 std::vector<manualContourModel*> lstManConModExp;
1764 std::vector<int> tempVector;
1765 _instantPanel->getInstant( tempVector );
1767 vtkImageData *imagedata = _theViewPanel->getImageData();
1768 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1770 int ii,sizeLstContourThings;
1779 minZ = 0;// _mbarrange->GetStart();
1780 maxZ = sizeZ;//_mbarrange->GetEnd();
1781 totalZ = maxZ-minZ+1;
1783 contourextractdata->SetImage( imagedata);
1786 for ( z=0 ; z<sizeZ ; z++)
1789 porcent = 100.0* (z-minZ)/totalZ;
1790 tmpString.Printf(_T("Saving Values"));
1791 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1792 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1794 //Extraction data from contours of each slice
1795 contourextractdata->SetZtoBeAnalys( z);
1798 Instant instant(&tempVector);
1799 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1800 sizeLstContourThings = lstContourThings.size();
1802 lstManConMod.clear();
1803 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1805 ContourThing **contourthing = lstContourThings[ii];
1806 lstManConMod.push_back( (*contourthing)->getModel() );
1808 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1811 int iContourGroup,sizeContourGroup;
1812 if (typeContourGroup==3) // contour separete
1814 sizeContourGroup=lstManConModExp.size();
1815 } else { // contour AND OR XOR
1819 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1820 lstManConModTmp.clear();
1821 if (typeContourGroup==3) // contour separete
1823 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1824 } else { // contour AND OR XOR
1825 lstManConModTmp = lstManConModExp;
1828 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1831 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1833 // ContourThing **contourthing = lstContourThings[ii];
1834 // lstManConMod.push_back( (*contourthing)->getModel() );
1836 // contourextractdata->SetLstManualContourModel( lstManConMod );
1838 contourextractdata->CalculateImageResult(); // with actual Z
1840 } // for iContourGroup
1843 std::string temp = directory + "/" + namefile + "-Value.mhd";
1845 wxString filename = crea::std2wx(temp);
1847 // filename.Printf(_T(temp.c_str()));
1848 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1849 /*filename.Printf(_T("%s"),directory.c_str());
1850 filename.append(_T("\\"));
1851 filename.append(_T("%s"),namefile.c_str());
1852 filename.append(_T("-Value.mhd"));*/
1855 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1856 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1857 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1858 writerValueImage->SetFileDimensionality( 3 );
1859 writerValueImage->Write( );
1862 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1863 temp = directory + "/" + namefile + "-Mask.mhd";
1865 // LG 14/01/09 : using crea
1866 filename = crea::std2wx(temp);
1867 // filename.Printf(_T(temp.c_str()));
1869 /*filename.Printf(_T("%s"),directory.c_str());
1870 filename.append(_T("\\"));
1871 filename.append(_T("%s"),namefile.c_str());
1872 filename.append(_T("-Mask.mhd"));*/
1874 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1875 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1876 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1877 writerMaskImage->SetFileDimensionality( 3 );
1878 writerMaskImage->Write( );
1880 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1881 delete contourextractdata;
1884 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1885 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1886 _theViewPanel->setActualVertical( value);
1888 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1889 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1895 void wxContourMainFrame::onSnakePressed(){
1896 std::vector<double> vecX;
1897 std::vector<double> vecY;
1898 std::vector<double> vecZ;
1899 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1901 if (vecX.size()!=0){
1902 std::vector<int> tempVector;
1903 _instantPanel->getInstant( tempVector );
1904 int i,size=vecZ.size();
1905 int actualSlice = tempVector[1];
1906 for ( i=0 ; i<size ; i++ )
1908 vecZ[i] = actualSlice;
1911 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1912 wxPanel* panel = new wxPanel(dialog,-1);
1913 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1914 dialog->ShowModal();
1919 void wxContourMainFrame::saveFileWithContoursAutomatique(){
1920 std::string filename = kernelManager->getCurrentFileName();
1921 if(filename.compare("")!=0){
1922 saveFileWithContours(filename);