1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxContourMainFrame.h"
8 //----------------------------------------------------------------------------------------------------------------
10 //----------------------------------------------------------------------------------------------------------------
13 #include "NameWrapper.h"
14 #include "wx/artprov.h"
15 #include "ConceptDataWrap.h"
17 #include <manualContour.h>
18 //#include "ImageSourceThing.h"
19 //#include "wxContour_ActionCommandsID.h"
20 //#include "OutlineModelBuilder.h"
21 //#include "wxContourEventHandler.h"
24 //----------------------------------------------------------------------------------------------------------------
25 // Class implementation
26 //----------------------------------------------------------------------------------------------------------------
27 /** @file wxContourMainFrame.cxx */
29 //------------------------------------------------------------------------------------------------------------
30 // Constructors & Destructors
31 //------------------------------------------------------------------------------------------------------------
33 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
34 char wxContourMainFrame::COPY = 'C';
36 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
37 //: wxPanel(parent, id, title, pos, size, style)
38 //: wxWindow(parent, id, pos, size, style)
39 : wxPanel(parent, id, pos, size, style)
41 m_mgr.SetManagedWindow(this);
42 _creatingContoursActive = false;
44 // _modelManager = NULL;
46 // _buttonsBar = NULL;
48 // _drawToolsPanel = NULL;
49 // _operationsToolsPanel = NULL;
50 //_autoFormsPanel = NULL;
51 // _standardToolsPanel = NULL;
52 // _editionToolsPanel = NULL;
53 // _listViewPanel = NULL;
54 // _sceneManager = NULL;
55 //_actualInstant = NULL;
56 _numberOfVariablesStatistics = 6+1;
58 _refLineControl = NULL;
61 _thresholdActor = NULL;
62 _actorPresent = false;
64 // set up default notebook style
65 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
66 // m_notebook_theme = 0;
67 //wxContour_ActionCommandsID a;
71 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
72 : wxPanel(parent, id, pos, size, style)
74 m_mgr.SetManagedWindow(this);
75 _creatingContoursActive = false;
79 _refLineControl = NULL;
82 _thresholdActor = NULL;
83 _actorPresent = false;
85 // set up default notebook style
86 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 //wxContour_ActionCommandsID a;
89 _numberOfVariablesStatistics = 7;
97 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
98 _performingOperation = new PerformingOperation();
100 if(images.size() > 0)
102 this->setVectImages(images);
107 void wxContourMainFrame::setVectImages( std::vector<vtkImageData*> images ){
109 #if defined(__GNUC__)
110 std::string str_home(getenv("HOME"));
111 #elif defined(_WIN32)
112 std::string str_home(getenv("USERPROFILE"));
114 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
116 std::vector<std::string> conceptNameVect;
117 std::vector<int> conceptSizeVect;
119 notebook = this->createNotebook();
122 kernelManager = new KernelManagerContour( images , _datadir+"/data/" , strCreaContourDataTmp );
125 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
126 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
128 //-------------------------------------------------------------
129 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
130 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
133 double val = _theViewPanel->getCurrentDeep();
134 _instantPanel->setConceptValue( "Axe Depth", (int)val );
135 //JCP _instantPanel->setConceptValue("time", num de imagenes);
136 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
137 //*******************changeInstant();
138 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
140 this->configurePanels( );
145 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 ){
146 if(instance == NULL){
147 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
152 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
154 return kernelManager->getVectImages();
157 wxContourMainFrame* wxContourMainFrame :: getInstance()
162 void wxContourMainFrame :: resetInstance()
167 wxContourMainFrame :: ~wxContourMainFrame()
171 interfMainPanel::resetInstance();
172 delete kernelManager;
174 //_pannew->Destroy();
180 //El problema al cerrar la aplicacion puede estar asociado
181 //a que wxAUINotebook esta en la aplicacion
182 //principal (wxContourGUIExample)tambien
183 //EED???? delete _theViewPanel;
184 //EED???? delete _instantPanel;
185 //EED???? delete _buttonsBar;
186 //EED???? delete _actualInstant;
187 //EED???? delete _sceneManager;
191 //------------------------------------------------------------------------------------------------------------
192 // Creational and initialization methods using WxAui
193 //------------------------------------------------------------------------------------------------------------
195 wxAuiNotebook * wxContourMainFrame :: createNotebook()
197 wxSize client_size = GetClientSize();
198 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
199 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
204 //------------------------------------------------------------------------------------------------------------
205 // Creational and initialization methods
206 //------------------------------------------------------------------------------------------------------------
207 bool wxContourMainFrame :: configurePanels( )
209 bool configured = _theViewPanel!=NULL;
211 configured &= _theViewPanel!=NULL;
212 if( _theViewPanel!=NULL )
214 notebook->AddPage( _theViewPanel, wxT(" View ") );
221 notebook->AddPage( _instantPanel, wxT("Instant Page") );
225 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
228 SetMinSize(wxSize(300,300));
234 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
236 bool configured = panel!=NULL;
237 configured &= panel!=NULL;
241 notebook->AddPage( panel, wxT(" Viewer "), true );
247 //------------------------------------------------------------------------------------------------------------
248 // Attributes getters and setters
249 //------------------------------------------------------------------------------------------------------------
253 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
255 _instantPanel = theInstantChooserPanel;
258 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
260 // _buttonsBar = theButtonsBar;
263 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
265 // _gridPanel = theGridPanel;
268 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
270 // _drawToolsPanel = theDrawToolsPanel;
273 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
275 // _operationsToolsPanel = theOperationsToolsPanel;
278 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
280 // _autoFormsPanel = theAutoFormsPanel;
283 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
285 // _standardToolsPanel= theStandardToolsPanel;
288 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
290 // _editionToolsPanel = theEditionToolsPanel;
293 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
295 // _listViewPanel = theListViewPanel;
300 void wxContourMainFrame::onCreateContourSpline( ){
302 //JCP 20-10-08 Undo redo implementation
304 //JCP 20-10-08 Undo redo implementation
308 void wxContourMainFrame::onCreateContourRectangle( ){
309 //JCP 20-10-08 Undo redo implementation
311 //JCP 20-10-08 Undo redo implementation
314 void wxContourMainFrame::onCreateContourCircle( ){
315 //JCP 20-10-08 Undo redo implementation
317 //JCP 20-10-08 Undo redo implementation
321 void wxContourMainFrame::onCreateContourLine( ){
322 //JCP 20-10-08 Undo redo implementation
324 //JCP 20-10-08 Undo redo implementation
328 //------------------------------------------------------------------------------------------------------------
330 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
332 //Creating the manualContourModel and including in the model
333 manualContourModel * manModelContour = factoryManualContourModel(panel );
335 std::vector<int> instantVector;
336 _instantPanel->getInstant( instantVector );
337 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
339 /*std::vector<int> instantVector;
340 _instantPanel->getInstant( instantVector );
342 theName= _modelManager->createOutline( manModelContour, instantVector );*/
343 bool addedModel = theName.compare("") != 0;//??
347 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
348 _theViewPanel->getSpacing(spc);
349 //Adding the manualContourControler to interface objects structure
350 //Adding the manualViewContour to interface objects structure
351 //_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.
352 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
355 void wxContourMainFrame :: createContour( int typeContour )
357 //Creating the manualContourModel and including in the model
358 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
361 std::vector<int> instantVector;
362 _instantPanel->getInstant( instantVector );
363 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
365 /*std::vector<int> instantVector;
366 _instantPanel->getInstant( instantVector );
368 theName= _modelManager->createOutline( manModelContour, instantVector );*/
369 bool addedModel = theName.compare("") != 0;//??
372 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
373 _theViewPanel->getSpacing(spc);
374 //Adding the manualContourControler to interface objects structure
375 //Adding the manualViewContour to interface objects structure
376 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
377 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
381 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
383 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
384 manualContourModel *manModelContour=NULL;
385 manModelContour = manModelContourBullEye;
387 int iCrown,sizeCrowns,iSector,sizeSectors;
388 double radioA,radioB,ang,angDelta ;
389 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
390 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
392 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
393 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
394 if (iCrown==sizeCrowns-1)
398 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
402 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
404 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
405 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
406 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
409 } // if _panelBullEyeOptions
411 return manModelContour;
413 void wxContourMainFrame :: saveState(){
415 std::string temp = kernelManager->saveState();
416 saveFileWithContours(temp);
419 void wxContourMainFrame::onDeleteContour(){
420 //JCP 20-10-08 Undo redo implementation
422 //JCP 20-10-08 Undo redo implementation
424 std::vector<std::string> lstKeyNameToBeErase;
425 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
426 deleteContours( lstKeyNameToBeErase );
428 int i,size=_sceneManager->getSelectedObjects().size();
431 std::string keyName = _sceneManager->getSelectedObjects()[i];
432 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
433 if ( ispartofstaticlist>=0 )
435 std::vector<int> tempVector;
436 _instantPanel->getInstant( tempVector );
437 Instant instant(&tempVector);
438 this->_modelManager->ChangeContourOfList(keyName, &instant);
442 std::vector<std::string> lstKeyName;
443 std::vector<std::string> lstKeyNameActualSlice;
444 std::vector<std::string> lstKeyNameToBeErase;
446 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
447 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
448 int k,kSize=lstKeyNameToBeErase.size();
449 int j,jSize=lstKeyNameActualSlice.size();
451 for (k=0;k<kSize; k++)
454 for (j=0;j<jSize; j++)
456 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
463 lstKeyName.push_back( lstKeyNameToBeErase[k] );
467 deleteContours( lstKeyName );
471 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
473 int i,size=keyNamesVector.size();
476 deleteContour( keyNamesVector[i] );
480 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
482 manualContourModel * cModel;
483 manualViewBaseContour * cViewer;
484 manualContourBaseControler * cControler;
486 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
487 cControler = conwrapviewControl->getControler();*/
490 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
491 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
493 if (isedit && ispartofstaticlst)
495 _theViewPanel->removeFromScene(theKeyName);
497 kernelManager->deleteCModel(theKeyName);
498 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
499 //cViewer = conwrapviewControl->getViewer();
500 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
501 //cControler* conwrapviewControl->getControler();
503 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
504 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
505 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
509 // delete cControler;
514 void wxContourMainFrame::onDeleteContoursActSlice(){
515 //JCP 20-10-08 Undo redo implementation
517 //JCP 20-10-08 Undo redo implementation
518 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
520 void wxContourMainFrame::onDeleteAllContours(){
521 //JCP 20-10-08 Undo redo implementation
525 void wxContourMainFrame::deleteAllContours(){
526 //JCP 20-10-08 Undo redo implementation
529 std::vector<int> tempVector;
530 _instantPanel->getInstant( tempVector );
532 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
533 // the values in GetStart and GetEnd will then not be initialize also.
534 // We use instead the values given when initializing the _deletepanel.
536 //int minZ = _mbarrangeDeleteAll->GetStart();
537 //int maxZ = _mbarrangeDeleteAll->GetEnd();
541 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
545 _theViewPanel->getSceneManager()->removeSceneContours( );
546 _theViewPanel->getSceneManager()->removeAllOutlines();
547 kernelManager->removeAllOutlines();
550 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
552 _theViewPanel->getSceneManager()->removeSceneContours( );
553 _modelManager->removeAllOutlines();
554 _theViewPanel->getSceneManager()->removeAllOutlines();
557 for ( z=minZ ; z<=maxZ ; z++)
560 Instant instant(&tempVector);
561 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
563 sizeLstContourThings = lstContourThings.size();
564 for (ii=0 ; ii<sizeLstContourThings ; ii++)
566 ContourThing **contourthing = lstContourThings[ii];
567 deleteContour( (*contourthing)->getName() );
574 void wxContourMainFrame::setConceptValue( std::string name, int value ){
575 _instantPanel->setConceptValue(name, value);
578 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
579 return _instantPanel->getLastConceptData();
581 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
582 return _instantPanel->getIfConceptCheckedAt( name, pos );
585 void wxContourMainFrame::changeInstant()
587 std::vector<int> instantVect;
588 _instantPanel->getInstant( instantVect );
589 // Instant * theInstant = new Instant ( &instantVect );
591 //Setting the actual instant
592 //_actualInstant = theInstant;
594 kernelManager->setInstant(instantVect);
595 //_modelManager->setInstant( _actualInstant );
598 updateInstantOutlines();
599 updateInstantImageData();
604 void wxContourMainFrame :: updateInstantOutlines()
606 _theViewPanel->removeSceneContours();
607 _theViewPanel->addNameWrapperToScene();
609 //for( int i=0; i<size; i++)
611 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
615 int wxContourMainFrame::getNamesWrappingSize(){
616 return kernelManager->getNamesWrappingSize();
618 std::string wxContourMainFrame::getNameWrapping(int i){
619 return kernelManager->getNameWrapping(i);
622 void wxContourMainFrame::updateInstantImageData()
624 std::vector<int> inst;
625 _instantPanel->getInstant(inst);
627 vtkImageData* img = kernelManager->getImageAtInstant(inst);
629 _theViewPanel->changeImage(img);
632 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
633 _theViewPanel->setImageSlice(z);
637 void wxContourMainFrame::updateInstantAxes()
641 void wxContourMainFrame :: updateActor()
646 _pannew->onThresholdInstantChange(minMax);
648 int z = _theViewPanel->GetZ();
650 vtkImageData * img = getImageData();
651 vtkImageReslice *imageReslice = vtkImageReslice::New();
653 imageReslice->SetInput( img );
654 imageReslice->SetInformationInput(img);
655 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
656 imageReslice->SetResliceAxesOrigin(0,0,z);
657 imageReslice->SetOutputDimensionality(2);
658 imageReslice->SetInterpolationModeToLinear();
660 img = imageReslice->GetOutput();
662 img->UpdateInformation();
664 //EED??? wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
667 img->GetScalarRange(range);
669 int min = floor (range[0]);
670 int max = ceil (range[1]);
673 vtkLookupTable *lookup = vtkLookupTable::New();
674 lookup->SetNumberOfTableValues(max+1);
675 lookup->SetTableRange(range);
676 lookup->SetAlphaRange(0, 1);
677 lookup->SetValueRange(0, 1);
678 lookup->SetSaturationRange(0, 0);
679 lookup->SetRampToLinear( );
681 //Assign a fake color for the upper image, and set the white as transparent
683 int minVal = minMax[0];
684 int maxVal = minMax[1];
686 for(i = min; i <= max; i++)
688 if( i >= minVal && i <= maxVal )
690 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
692 else if( i >= min && i < minVal )
694 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
696 else if( i > maxVal && i < max )
698 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
702 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
708 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
709 mapperImage->SetLookupTable( lookup );
710 mapperImage->SetInput( img );
711 //mapperImage->SetOutputFormatToRGBA( );
713 _thresholdActor->SetInput( mapperImage->GetOutput() );
714 printf("EED wxContourMainFrame::updateActor %d \n" , z);
715 _thresholdActor->SetPosition( 0,0, 900-1 );
719 void wxContourMainFrame::onChangeDeep(int val){
720 _instantPanel->setConceptValue( "Axe Depth", (int)val );
725 void wxContourMainFrame::onCopy(){
726 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
728 std::vector<int> tempVector;
729 _instantPanel->getInstant( tempVector );
730 _performingOperation->reset();
731 _performingOperation->setStartCommand( COPY );
732 _performingOperation->setStartOperationInstantVector( tempVector );
733 _performingOperation->setKeyNamesOperationElems( currentSelection );
736 void wxContourMainFrame::onPaste(){
739 char theStartCommand = _performingOperation->getStartCommand();
740 if ( theStartCommand == COPY )
742 //JCP 20-10-08 Undo redo implementation
744 //JCP 20-10-08 Undo redo implementation
745 std::vector<int> tempVector;
746 _instantPanel->getInstant( tempVector );
747 _performingOperation->setEndOperationInstantVector ( tempVector );
748 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
749 int i,size = elems.size();
750 for( i=0; i<size; i++ )
752 createCopyContourOf( elems[i], tempVector, i>0 );
756 void wxContourMainFrame::onUndo(){
757 std::string filename;
758 if(kernelManager->onUndoSaveFile(filename)){
759 saveFileWithContours(filename);
761 if(kernelManager->onUndo(filename)){
765 void wxContourMainFrame::onRedo(){
766 std::string filename;
767 if(kernelManager->onRedo(filename)){
772 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
774 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
775 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
776 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
779 ///AD: 03-09 Copy the object and apply the given transformation
780 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
782 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
783 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
785 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
786 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
788 double pnt1X = refPoint1->GetX();
789 double pnt1Y = refPoint1->GetY();
790 // double pnt1Z = refPoint1->GetZ();
791 double pnt2X = refPoint2->GetX();
792 double pnt2Y = refPoint2->GetY();
793 // double pnt2Z = refPoint2->GetZ();
795 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
796 vtkTransform *t = vtkTransform::New();
800 t->Translate(-pnt1X, -pnt1Y, 0);
804 t->Translate(pnt1X, pnt1Y, 0);
807 int i,size=manualModel->GetSizeLstPoints();
810 manualPoint * mp = manualModel->GetManualPoint(i);
816 t->TransformPoint( vecIn, vecOut );
817 mp->SetPointX( vecOut[0] );
818 mp->SetPointY( vecOut[1] );
819 mp->SetPointZ( vecOut[2] );
822 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
825 void wxContourMainFrame ::loadState(std::string filename){
827 FILE *pFile=fopen(filename.c_str(),"r+");
829 fscanf(pFile,"%s",tmp); // --CreaContour--
831 fscanf(pFile,"%s",tmp); // Version
832 fscanf(pFile,"%s",tmp); // 1.0.1
833 std::string version(tmp);
837 openContours(pFile,false);
838 if (version!="1.0.0"){
839 openContours(pFile,true);
844 //_theViewPanel->getSceneManager()->removeSceneContours();
849 void wxContourMainFrame::onLoad(){
851 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
852 if (dialog.ShowModal() == wxID_OK)
854 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
855 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
857 fscanf(pFile,"%s",tmp); // --CreaContour--
859 fscanf(pFile,"%s",tmp); // Version
860 fscanf(pFile,"%s",tmp); // 1.0.1
861 std::string version(tmp);
863 openContours(pFile,false);
864 if (version!="1.0.0"){
865 openContours(pFile,true);
867 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
871 _theViewPanel->getSceneManager()->removeSceneContours();
874 void wxContourMainFrame::onSave(){
875 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
876 if (dialog.ShowModal() == wxID_OK)
878 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
879 kernelManager->setCurrentFileName(fileNameContourROI);
880 saveFileWithContours( fileNameContourROI );
883 void wxContourMainFrame::saveFileWithContours( std::string filename ){
885 FILE *pFile=fopen(filename.c_str(),"w+");
886 std::vector< std::string > lstNameThings;
887 int i,sizeLstNameThings;
889 fprintf(pFile,"--CreaContour--\n");
890 fprintf(pFile,"Version %s\n", "1.0.1" );
893 lstNameThings = kernelManager->GetLstNameThings();
894 sizeLstNameThings = lstNameThings.size();
895 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
896 for (i=0 ; i<sizeLstNameThings ; i++)
898 kernelManager->SaveThingName( pFile, lstNameThings[i] );
899 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
902 //-- Contours Statics
903 lstNameThings = kernelManager->GetLstNameThingsStatic();
904 sizeLstNameThings = lstNameThings.size();
905 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
906 for (i=0 ; i<sizeLstNameThings ; i++)
908 kernelManager->SaveThingName( pFile, lstNameThings[i] );
909 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
914 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
916 fscanf(pFile,"%s",tmp); // NumberOfContours
917 fscanf(pFile,"%s",tmp); // ##
918 int numberOfContours = atoi(tmp);
920 std::vector<int> instantVector;
921 int typeContourModel;
922 manualContourModel *manModelContour;
926 for (i=0;i<numberOfContours;i++)
928 instantVector.clear();
929 fscanf(pFile,"%s",tmp); // Instant
931 fscanf(pFile,"%s",tmp); // 1
932 instantVector.push_back( atoi(tmp) );
933 fscanf(pFile,"%s",tmp); // 2
934 instantVector.push_back( atoi(tmp) );
935 fscanf(pFile,"%s",tmp); // 3
936 instantVector.push_back( atoi(tmp) );
937 fscanf(pFile,"%s",tmp); // 4
938 instantVector.push_back( atoi(tmp) );
939 fscanf(pFile,"%s",tmp); // 5
940 instantVector.push_back( atoi(tmp) );
941 fscanf(pFile,"%s",tmp); // 6
942 instantVector.push_back( atoi(tmp) );
945 fscanf(pFile,"%s",tmp); // TypeContourModel
946 fscanf(pFile,"%s",tmp); // ##
947 typeContourModel = atoi(tmp);
949 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
950 manModelContour->Open(pFile);
952 fscanf(pFile,"%s",tmp); // TypeView
953 fscanf(pFile,"%s",tmp); // ##
954 typeView = atoi(tmp);
963 theName = kernelManager->createOutline( manModelContour, instantVector );
964 bool addedModel = theName.compare("") != 0;
967 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
968 _theViewPanel->getSpacing(spc);
969 //Adding the manualContourControler to interface objects structure
970 //Adding the manualViewContour to interface objects structure
971 //_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.
972 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
975 if (staticContour==true)
977 Instant instant(&instantVector);
978 kernelManager->changeContourOfManager( theName , &instant );
981 }// for numberOfContours
985 void wxContourMainFrame::RefreshInterface(){
987 _theViewPanel->RefreshInterface();
988 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
989 //wxvtk2dbaseview->Refresh();
992 vtkImageData* wxContourMainFrame::getImageData(){
993 return _theViewPanel->getImageData();
996 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
998 //JCP 20-10-08 Undo redo implementation
1000 //JCP 20-10-08 Undo redo implementation
1003 int x = _theViewPanel->GetX();
1004 int y = _theViewPanel->GetY();
1005 int z = _theViewPanel->GetZ();
1006 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1010 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1013 int typeofcontour = 1;
1015 vtkImageData *imagedata = getImageData();
1017 //Tipo de pixeles a utilizar internamente en ITK
1018 typedef float InternalPixelType;
1019 const unsigned int Dimension = 2;
1020 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1022 //Tipo de pixeles de salida 1
1023 typedef unsigned char OutputPixelType;
1024 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1026 //Tipo de pixeles de salida 2
1027 typedef unsigned short OutputPixelType2;
1028 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1030 //DefiniciÛn del thresholder
1031 typedef itk::BinaryThresholdImageFilter<
1033 OutputImageType > ThresholdingFilterType;
1035 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1036 typedef itk::CastImageFilter<
1037 OutputImageType, OutputImageType2 > CastFilterType;
1039 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1040 typedef itk::CastImageFilter<
1041 OutputImageType2, InternalImageType > CastFilterType2;
1043 //Tercer tipo de conversiÛn
1044 typedef itk::RescaleIntensityImageFilter<
1046 OutputImageType > CastFilterType3;
1048 //Cuarto tipo de conversiÛn
1049 typedef itk::RescaleIntensityImageFilter<
1051 OutputImageType > CastFilterType4;
1053 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1055 thresholder->SetLowerThreshold( 0.0 );
1056 thresholder->SetUpperThreshold( 128 );
1058 thresholder->SetOutsideValue( 255 );
1059 thresholder->SetInsideValue( 0 );
1061 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1062 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1063 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1064 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1066 ConnectorType::Pointer connector= ConnectorType::New();
1067 ConnectorType2::Pointer connector2= ConnectorType2::New();
1070 CastFilterType::Pointer filter=CastFilterType::New();
1071 CastFilterType2::Pointer filter2=CastFilterType2::New();
1073 connector->SetInput( imagedata );
1074 filter2->SetInput(connector->GetOutput());
1076 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1078 InternalImageType > SmoothingFilterType;
1080 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1082 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1084 InternalImageType > GradientFilterType;
1086 typedef itk::SigmoidImageFilter<
1088 InternalImageType > SigmoidFilterType;
1090 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1092 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1094 sigmoid->SetOutputMinimum( 0.0 );
1095 sigmoid->SetOutputMaximum( 255.0 );
1098 typedef itk::FastMarchingImageFilter<
1100 InternalImageType > FastMarchingFilterType;
1103 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1105 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1106 InternalImageType > GeodesicActiveContourFilterType;
1107 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1108 GeodesicActiveContourFilterType::New();
1110 typedef itk::ZeroCrossingImageFilter<
1112 InternalImageType > ZeroCrossingFilterType;
1113 ZeroCrossingFilterType::Pointer zeroCrossing =
1114 ZeroCrossingFilterType::New();
1116 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1118 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1119 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1120 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1122 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1123 int it=atoi( crea::wx2std(iter).c_str() );
1124 geodesicActiveContour->SetNumberOfIterations( it );
1126 smoothing->SetInput( filter2->GetOutput() );
1127 gradientMagnitude->SetInput( smoothing->GetOutput() );
1128 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1129 fastMarching->SetInput( sigmoid->GetOutput() );
1130 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1131 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1133 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1134 //thresholder->SetInput( zeroCrossing->GetOutput() );
1135 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1136 connector2->SetInput( thresholder->GetOutput() );
1139 smoothing->SetTimeStep( 0.125 );
1140 smoothing->SetNumberOfIterations( 5 );
1141 smoothing->SetConductanceParameter( 9.0 );
1144 const double sigma = atof( crea::wx2std(sigm).c_str() );
1145 gradientMagnitude->SetSigma( sigma );
1147 const double alpha = atof( crea::wx2std(alf).c_str() );
1148 const double beta = atof( crea::wx2std(bet).c_str() );
1150 sigmoid->SetAlpha( alpha );
1151 sigmoid->SetBeta( beta );
1153 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1154 typedef FastMarchingFilterType::NodeType NodeType;
1156 NodeContainer::Pointer seeds = NodeContainer::New();
1158 InternalImageType::IndexType seedPosition;
1159 seedPosition[0] = x;
1160 seedPosition[1] = y;
1162 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1166 const double seedValue = - initialDistance;
1168 node.SetValue( seedValue );
1169 node.SetIndex( seedPosition );
1171 seeds->Initialize();
1172 seeds->InsertElement( 0, node );
1174 fastMarching->SetTrialPoints( seeds );
1176 fastMarching->SetSpeedConstant( 1.0 );
1178 fastMarching->SetOutputSize(
1179 connector->GetOutput()->GetBufferedRegion().GetSize() );
1181 fastMarching->SetStoppingValue( 800 );
1185 connector2->Update();
1186 vtkImageData *idata = connector2->GetOutput();
1188 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1190 cntVTK->SetInput( idata );
1192 cntVTK->SetNumberOfContours( 1 );
1193 cntVTK->SetValue( 0, 255 );
1195 cntVTK->UpdateInformation();
1197 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1198 cpd->SetInput( cntVTK->GetOutput( ) );
1200 cpd->UpdateInformation();
1202 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1203 conn->SetExtractionModeToLargestRegion( );
1204 conn->SetInput( cpd->GetOutput( ) );
1206 conn->UpdateInformation();
1208 vtkStripper* vtkstripper = vtkStripper::New( );
1209 vtkstripper->SetInput( conn->GetOutput() );
1210 vtkstripper->Update();
1211 vtkstripper->UpdateInformation();
1214 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1215 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1216 polyDataResult->Update( );
1217 polyDataResult->UpdateInformation();
1222 myfile.open ("C:/Creatis/example.txt");
1224 polyDataResult->Print(myfile);
1225 myfile << "-------------------------------------\n";
1226 polyDataResult->GetLines()->Print(myfile);
1234 //--Calculating control points
1236 std::vector<double> vecX;
1237 std::vector<double> vecY;
1238 std::vector<double> vecXo;
1239 std::vector<double> vecYo;
1240 std::vector<double>::iterator vecXoi;
1241 std::vector<double>::iterator vecYoi;
1242 std::vector<double> vecZ;
1244 std::vector<double> vecCtrlPointX;
1245 std::vector<double> vecCtrlPointY;
1246 std::vector<double> vecCtrlPointZ;
1252 int ii,size=polyDataResult->GetNumberOfPoints();
1254 myfile.open ("C:/Creatis/example2.txt");
1256 size=polyDataResult->GetNumberOfPoints();
1257 for (ii=0;ii<size;ii++)
1264 p = polyDataResult->GetPoint(ii);
1267 /*if(fabs(yAct-y)>20)
1269 if((xAct-x)>1 || (xAct-x)<-1)
1271 vecX.push_back( p[0] );
1272 vecY.push_back( p[1] );
1273 myfile <<p[0]<<","<<p[1]<<"\n";
1274 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1275 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1276 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1277 vecZ.push_back( 900 );
1283 vecXo.push_back(p[0]);
1284 vecYo.push_back(p[1]);
1288 else*/ if(fabs(xAct-x)>11)
1290 vecXo.push_back(p[0]);
1291 vecYo.push_back(p[1]);
1295 vecX.push_back( p[0] );
1296 myfile <<p[0]<<","<<p[1]<<"\n";
1297 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1298 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1299 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1300 vecY.push_back( p[1] );
1301 vecZ.push_back( 900 );
1309 while(!vecXo.empty())
1311 vecX.push_back(vecXo.back());
1312 std::cout<<" x Siguiente "<<vecXo.back();
1314 vecZ.push_back( 900 );
1316 while(!vecYo.empty())
1318 vecY.push_back(vecYo.back());
1323 /*for(int l=0;l<vecX.size();l++)
1327 vecXo.push_back(p[0]);
1328 vecYo.push_back(p[1]);
1339 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1341 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1345 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1347 else if (method==1){
1348 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1350 else if (method==2){
1351 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1352 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1354 //--Adding contour to the system
1356 std::vector<int> actualInstantVector;
1357 _instantPanel->getInstant( actualInstantVector );
1358 actualInstantVector[1]=z;
1360 int j,sizeCtrPt = vecCtrlPointX.size();
1362 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1363 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1365 for (j=0 ; j<sizeCtrPt ; j++)
1367 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1369 std::string theName;
1370 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1371 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1372 bool addedModel = theName.compare("") != 0;
1375 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1376 _theViewPanel->getSpacing(spc);
1377 //Adding the manualContourControler to interface objects structure
1378 //Adding the manualViewContour to interface objects structure
1379 //_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.
1380 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1381 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1387 WriterType::Pointer writer = WriterType::New();
1388 CastFilterType3::Pointer caster = CastFilterType3::New();
1390 caster->SetInput( gradientMagnitude->GetOutput() );
1391 writer->SetInput( caster->GetOutput() );
1392 writer->SetFileName("Gradient Magnitude.png");
1393 caster->SetOutputMinimum( 0 );
1394 caster->SetOutputMaximum( 255 );
1397 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1398 WriterType::Pointer writer2 = WriterType::New();
1400 caster2->SetInput( sigmoid->GetOutput() );
1401 writer2->SetInput( caster2->GetOutput() );
1402 writer2->SetFileName("Sigmoid.png");
1403 caster2->SetOutputMinimum( 0 );
1404 caster2->SetOutputMaximum( 255 );
1407 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1408 WriterType::Pointer writer3 = WriterType::New();
1410 caster3->SetInput( fastMarching->GetOutput() );
1411 writer3->SetInput( caster3->GetOutput() );
1412 writer3->SetFileName("FastMarching.bmp");
1413 caster3->SetOutputMinimum( 0 );
1414 caster3->SetOutputMaximum( 255 );
1417 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1418 WriterType::Pointer writer4 = WriterType::New();
1420 caster4->SetInput( geodesicActiveContour->GetOutput() );
1421 writer4->SetInput( caster4->GetOutput() );
1422 writer4->SetFileName("GeodesicActiveContour.png");
1423 caster4->SetOutputMinimum( 0 );
1424 caster4->SetOutputMaximum( 255 );
1427 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1428 WriterType::Pointer writer5 = WriterType::New();
1430 caster5->SetInput( zeroCrossing->GetOutput() );
1431 writer5->SetInput( caster5->GetOutput() );
1432 writer5->SetFileName("ZeroCrossing.bmp");
1433 caster5->SetOutputMinimum( 0 );
1434 caster5->SetOutputMaximum( 255 );
1437 catch( itk::ExceptionObject & excep )
1439 std::cerr << "Exception caught !" << std::endl;
1440 std::cerr << excep << std::endl;
1444 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1446 //JCP 20-10-08 Undo redo implementation
1448 //JCP 20-10-08 Undo redo implementation
1451 int x = _theViewPanel->GetX();
1452 int y = _theViewPanel->GetY();
1453 int z = _theViewPanel->GetZ();
1454 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1459 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1461 int typeofcontour = 1;
1462 //--Extracting Contour
1463 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1464 vtkImageData *imagedata = getImageData();
1465 // double *range = imagedata->GetScalarRange();
1468 vtkImageReslice *imageReslice = vtkImageReslice::New();
1471 // imagedata->GetSpacing(spc);
1476 imageReslice->SetInput( imagedata );
1477 imageReslice->SetInformationInput(imagedata);
1478 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1479 imageReslice->SetResliceAxesOrigin(0,0,z);
1480 imageReslice->SetOutputDimensionality(2);
1481 imageReslice->SetInterpolationModeToLinear();
1483 imagedata = imageReslice->GetOutput();
1484 imagedata->Update();
1485 imagedata->UpdateInformation();
1487 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1488 cntVTK->SetInput( imagedata );
1490 cntVTK->SetNumberOfContours( 1 );
1491 //cntVTK->SetValue( 0, vmin );
1492 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1493 cntVTK->SetValue( 1, isovalue );
1494 // cntVTK->SetValue( 1, vmax );
1496 cntVTK->UpdateInformation();
1498 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1499 cpd->SetInput( cntVTK->GetOutput( ) );
1500 cpd->ConvertLinesToPointsOff( );
1502 cpd->UpdateInformation();
1504 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1505 conn->SetExtractionModeToClosestPointRegion( );
1506 //conn->SetMaxRecursionDepth( 3000 );
1508 conn->SetInput( cpd->GetOutput( ) );
1510 conn->SetClosestPoint( x, y, 0 );
1512 conn->UpdateInformation();
1514 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1515 cpd2->SetInput( conn->GetOutput( ) );
1517 cpd2->UpdateInformation();
1519 vtkStripper* vtkstripper = vtkStripper::New( );
1520 vtkstripper->SetInput( cpd2->GetOutput() );
1521 vtkstripper->Update();
1522 vtkstripper->UpdateInformation();
1525 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1527 polyDataResult->Update( );
1528 polyDataResult->UpdateInformation();
1532 myfile.open ("c:/temp/example.txt");
1534 polyDataResult->Print(myfile);
1535 myfile << "-------------------------------------\n";
1536 polyDataResult->GetLines()->Print(myfile);
1546 //--Calculating control points
1548 std::vector<double> vecX;
1549 std::vector<double> vecY;
1550 std::vector<double> vecZ;
1552 std::vector<double> vecCtrlPointX;
1553 std::vector<double> vecCtrlPointY;
1554 std::vector<double> vecCtrlPointZ;
1558 int ii,size=polyDataResult->GetNumberOfPoints();
1560 for (ii=1;ii<=size;ii++)
1562 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1563 p = polyDataResult->GetPoint(id);
1566 vecX.push_back( p[0] );
1567 vecY.push_back( p[1] );
1568 vecZ.push_back( 900 );
1569 // vecZ.push_back( p[2] );
1573 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1574 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1577 /*if (methodRadiobox->GetSelection()==0){
1578 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1580 if (methodRadiobox->GetSelection()==1){
1581 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1583 if (methodRadiobox->GetSelection()==2){
1584 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1585 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1589 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1591 else if (method==1){
1592 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1594 else if (method==2){
1595 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1596 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1599 //--Adding contour to the system
1601 std::vector<int> actualInstantVector;
1602 _instantPanel->getInstant( actualInstantVector );
1603 actualInstantVector[1]=z;
1605 int j,sizeCtrPt = vecCtrlPointX.size();
1606 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1607 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1609 for (j=0 ; j<sizeCtrPt ; j++)
1611 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1613 std::string theName;
1614 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1615 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1616 bool addedModel = theName.compare("") != 0;
1619 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1620 _theViewPanel->getSpacing(spc);
1621 //Adding the manualContourControler to interface objects structure
1622 //Adding the manualViewContour to interface objects structure
1623 //_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.
1624 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1625 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1629 int wxContourMainFrame::GetImageDataSizeZ(){
1630 return _theViewPanel->GetImageDataSizeZ();
1633 void wxContourMainFrame::GetImageDataRange(double *range){
1634 _theViewPanel->GetImageDataRange(range);
1637 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1638 //JCP 20-10-08 Undo redo implementation
1640 //JCP 20-10-08 Undo redo implementation
1643 int x = _theViewPanel->GetX();
1644 int y = _theViewPanel->GetY();
1648 double totalZ = maxZ-minZ+1;
1649 for( z=minZ ; z<=maxZ ; z++ )
1651 porcent = 100.0* (z-minZ)/totalZ;
1652 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1653 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1654 //_staticTextSegmentation->SetLabel(tmpString);
1655 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1657 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1662 //Creates a reference line to be used as the axis of the mirroring
1663 void wxContourMainFrame::referenceLine()
1665 if (_refLineControl==NULL)
1670 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1671 vtkimagedata->GetSpacing(spc);
1673 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1675 _refLineControl = new manualLineControler();
1676 _refLineModel = new manualContourModelLine();
1677 _refLineView = new manualViewLine();
1678 _refLineView->SetModel( _refLineModel );
1679 _refLineView->SetWxVtkBaseView( viewer2D );
1680 _refLineView->SetRange( 2 );
1681 _refLineView->SetZ( 1200 );
1683 _refLineView->SetSpacing(spc);
1685 _refLineView->SetColorNormalContour(0, 0, 1);
1686 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1687 _refLineView->SetWidthLine(4);
1689 _refLineControl->SetModelView( _refLineModel , _refLineView );
1690 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1691 _refLineModel->SetCloseContour(false);
1692 _refLineControl->CreateNewManualContour();
1694 //EED?? double z = _refLineControl->GetZ();
1696 _refLineControl->AddPoint(50,100,z);
1697 _refLineControl->AddPoint(80,40,z);
1698 _refLineControl->SetCompleteCreation(true);
1700 _refLineModel->AddPoint(50,100,z);
1701 _refLineModel->AddPoint(80,40,z);
1702 _refLineModel->UpdateSpline();
1704 _refLineView->UpdateViewPoint(0);
1705 _refLineView->UpdateViewPoint(1);
1708 _refLineControl->SetActive(true);
1709 _refLineView->RefreshContour();
1713 //Hides the referenceLine
1714 void wxContourMainFrame::refLineHide()
1716 if (_refLineControl!=NULL)
1718 if (_refLineControl->GetActive())
1720 _refLineView->RemoveCompleteContourActor();
1721 _refLineControl->SetEditable(false);
1722 _refLineControl->SetActive(false);
1729 //Shows the referenceLine
1730 void wxContourMainFrame::refLineShow()
1732 if (_refLineControl!=NULL)
1734 if (_refLineControl->GetActive()==false)
1736 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1738 _refLineView->SetModel( _refLineModel );
1739 _refLineView->SetWxVtkBaseView( viewer2D );
1740 _refLineView->SetRange( 2 );
1741 _refLineView->SetZ( 1200 );
1743 _refLineControl->SetModelView( _refLineModel , _refLineView );
1744 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1745 _refLineControl->CreateNewManualContour();
1746 _refLineControl->SetActive(true);
1747 _refLineView->RefreshContour();
1754 void wxContourMainFrame::refLineChangeWidth(int width)
1756 _refLineView->SetWidthLine(width);
1757 _refLineView->RefreshContour();
1763 void wxContourMainFrame::onMirror()
1766 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1767 std::vector<std::string> filterCurrentSelection;
1769 std::vector<int> tempVector;
1770 _instantPanel->getInstant( tempVector );
1771 _performingOperation->reset();
1772 _performingOperation->setStartCommand( COPY );
1773 _performingOperation->setStartOperationInstantVector( tempVector );
1774 _performingOperation->setKeyNamesOperationElems( currentSelection );
1776 char theStartCommand = _performingOperation->getStartCommand();
1777 if ( theStartCommand == COPY )
1779 //JCP 20-10-08 Undo redo implementation
1781 //JCP 20-10-08 Undo redo implementation
1782 std::vector<int> tempVector;
1783 _instantPanel->getInstant( tempVector );
1784 _performingOperation->setEndOperationInstantVector ( tempVector );
1785 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1786 int i,size = elems.size();
1787 for( i=0; i<size; i++ )
1789 createMirrorContourOf( elems[i], tempVector, i>0 );
1793 //deleteContour( _refName );
1797 void wxContourMainFrame::onThreshold(int minVal, int maxVal)
1801 int z = _theViewPanel->GetZ();
1803 vtkImageData * img = getImageData();
1804 vtkImageReslice *imageReslice = vtkImageReslice::New();
1806 imageReslice->SetInput( img );
1807 imageReslice->SetInformationInput(img);
1808 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1809 imageReslice->SetResliceAxesOrigin(0,0,z);
1810 imageReslice->SetOutputDimensionality(2);
1811 imageReslice->SetInterpolationModeToLinear();
1813 img = imageReslice->GetOutput();
1815 img->UpdateInformation();
1817 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1820 img->GetScalarRange(range);
1822 int min = floor (range[0]);
1823 int max = ceil (range[1]);
1826 vtkLookupTable *lookup = vtkLookupTable::New();
1827 lookup->SetNumberOfTableValues(max+1);
1828 lookup->SetTableRange(range);
1829 lookup->SetAlphaRange(0, 1);
1830 lookup->SetValueRange(0, 1);
1831 lookup->SetSaturationRange(0, 0);
1832 lookup->SetRampToLinear( );
1834 //Assign a fake color for the upper image, and set the white as transparent
1836 for(i = min; i <= max; i++)
1838 if( i >= minVal && i <= maxVal )
1840 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1842 else if( i >= min && i < minVal )
1844 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1846 else if( i > maxVal && i < max )
1848 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1852 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1858 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
1859 mapperImage->SetLookupTable( lookup );
1860 mapperImage->SetInput( img );
1861 //mapperImage->SetOutputFormatToRGBA( );
1863 if (_thresholdActor==NULL)
1865 _thresholdActor = vtkImageActor::New( );
1866 _thresholdActor->SetOpacity( 0.6 );
1867 _thresholdActor->InterpolateOn( );
1869 printf("EED wxContourMainFrame::onThreshold \n");
1870 _thresholdActor->SetPosition( 0,0, z+1 );
1871 _thresholdActor->SetInput( mapperImage->GetOutput() );
1873 baseView->GetRenderer()->AddActor( _thresholdActor );
1874 _actorPresent = true;
1879 vtkImageViewer2* viewer = vtkImageViewer2::New();
1880 viewer->SetInput( upperImageActor->GetInput() );
1881 viewer->SetColorLevel((range[1]-range[0])/2);
1882 viewer->SetColorWindow(range[1]);
1883 viewer->GetRenderer()->AddActor( upperImageActor );
1889 void wxContourMainFrame::onThresholdChange(int minVal, int maxVal)
1893 int z = _theViewPanel->GetZ();
1895 vtkImageData * img = getImageData();
1896 vtkImageReslice *imageReslice = vtkImageReslice::New();
1898 imageReslice->SetInput( img );
1899 imageReslice->SetInformationInput(img);
1900 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1901 imageReslice->SetResliceAxesOrigin(0,0,z);
1902 imageReslice->SetOutputDimensionality(2);
1903 imageReslice->SetInterpolationModeToLinear();
1905 img = imageReslice->GetOutput();
1907 img->UpdateInformation();
1909 //EED?? wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1912 img->GetScalarRange(range);
1914 int min = floor (range[0]);
1915 int max = ceil (range[1]);
1918 vtkLookupTable *lookup = vtkLookupTable::New();
1919 lookup->SetNumberOfTableValues(max+1);
1920 lookup->SetTableRange(range);
1921 lookup->SetAlphaRange(0, 1);
1922 lookup->SetValueRange(0, 1);
1923 lookup->SetSaturationRange(0, 0);
1924 lookup->SetRampToLinear( );
1926 //Assign a fake color for the upper image, and set the white as transparent
1928 for(i = min; i <= max; i++)
1930 if( i >= minVal && i <= maxVal )
1932 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1934 else if( i >= min && i < minVal )
1936 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1938 else if( i > maxVal && i < max )
1940 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1944 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1950 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
1951 mapperImage->SetLookupTable( lookup );
1952 mapperImage->SetInput( img );
1953 //mapperImage->SetOutputFormatToRGBA( );
1955 _thresholdActor->SetInput( mapperImage->GetOutput() );
1956 printf("EED wxContourMainFrame::onThresholdChange \n");
1957 _thresholdActor->SetPosition( 0,0, z+1 );
1964 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
1966 if (_thresholdActor!=NULL)
1970 _thresholdActor->InterpolateOn( );
1975 _thresholdActor->InterpolateOff( );
1982 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
1986 _thresholdActor->SetOpacity(opacity*0.1);
1992 void wxContourMainFrame::onThresholdRemove()
1996 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1997 baseView->GetRenderer()->RemoveActor( _thresholdActor );
1998 _actorPresent = false;
2004 void wxContourMainFrame::showAxis(bool show)
2006 _theViewPanel->SetVisibleAxis(show);
2007 _theViewPanel->Refresh();
2011 void wxContourMainFrame::onRigidPressed(){
2012 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2013 int elementsSelected = currentSelection.size();
2015 if ( elementsSelected >= 1 ){
2016 //JCP 20-10-08 Undo redo implementation
2018 //JCP 20-10-08 Undo redo implementation
2020 std::vector<int> tempVector;
2021 _instantPanel->getInstant( tempVector );
2022 Instant instant(&tempVector);
2024 int i , size=currentSelection.size();
2025 for ( i=0 ; i<size ; i++ )
2027 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2032 void wxContourMainFrame::onWidthOfContour(double width){
2034 _theViewPanel->removeSceneContours();
2035 _theViewPanel->SetWidthContour(width);
2037 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2041 int wxContourMainFrame::getColorWindow(){
2042 return _theViewPanel->getColorWindow();
2044 int wxContourMainFrame::getWindowLevel(){
2045 return _theViewPanel->getWindowLevel();
2048 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2049 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2054 void wxContourMainFrame::onInterpolation(bool interpolate){
2055 _theViewPanel->onInterpolation(interpolate);
2059 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2060 _instantPanel->setConceptValue( name, actual );
2063 void wxContourMainFrame::resetAppend(){
2064 kernelManager->resetAppend();
2068 void wxContourMainFrame::onSpreadAdd(){
2069 std::vector<double> vecX;
2070 std::vector<double> vecY;
2071 std::vector<double> vecZ;
2072 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2074 std::vector<int> tempVector;
2075 _instantPanel->getInstant( tempVector );
2077 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2079 interfMainPanel::getInstance()->appendStringSpread(val);
2083 void wxContourMainFrame::onSpreadGo(int type){
2085 //JCP 20-10-08 Undo redo implementation
2087 //JCP 20-10-08 Undo redo implementation
2090 std::vector<double> vecCtrlPointX;
2091 std::vector<double> vecCtrlPointY;
2092 std::vector<double> vecCtrlPointZ;
2096 std::vector<int> tempVector;
2097 _instantPanel->getInstant( tempVector );
2100 kernelManager->getMaxMinZ(&minZ,&maxZ);
2101 //JSTG_16-07-08_----------------------------------------------------------------
2102 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2103 kernelManager->CalculeSplinePropagation();
2105 double totalZ = maxZ-minZ+1;
2108 //--------------------------------------------------------------------
2109 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2111 porcent = 100.0* (z-minZ)/totalZ;
2112 int numero = (int)(z-minZ+1)/(int)totalZ;
2113 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2115 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2117 int typeofcontour = 1;
2118 std::string theName;
2119 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2121 if( manModelContour!=NULL ){
2122 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2123 this->_theViewPanel->getSpacing(spc);
2124 //Adding the manualContourControler to interface objects structure
2125 //Adding the manualViewContour to interface objects structure
2126 //_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.
2127 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2132 int numero = (int)(z-minZ+1)/(int)totalZ;
2133 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2135 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2137 //RefreshInterface();
2140 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2144 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2145 std::vector<int> tempVector;
2146 _instantPanel->getInstant(tempVector);
2147 //Asignation of slide number should be different ex by name
2148 tempVector[1]=slide;
2149 return kernelManager->getOutlinesNameAtInstant(tempVector);
2152 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
2153 int maxContourGroup = 0;
2155 ContourExtractData *contourextractdata = new ContourExtractData();
2157 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2159 std::vector<manualContourModel*> lstManConMod;
2160 std::vector<manualContourModel*> lstManConModTmp;
2161 std::vector<manualContourModel*> lstManConModExp;
2162 std::vector<double> pLstValue;
2163 std::vector<double> pLstValuePosX;
2164 std::vector<double> pLstValuePosY;
2165 std::vector<double> pLstValuePosZ;
2168 int resultGrayRangeCount;
2171 double resultAverage;
2172 double resultStandardeviation;
2174 std::vector<int> tempVector;
2175 _instantPanel->getInstant( tempVector );
2177 vtkImageData *imagedata = _theViewPanel->getImageData();
2178 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2180 int ii,sizeLstContourThings;
2190 if (selection==0 ) // actual slice
2192 std::vector<int> tempVector;
2193 _instantPanel->getInstant( tempVector );
2194 int actualSlice = tempVector[1];
2198 else if (selection==2 ) // All slices
2203 else if (selection==1 ) // slice range
2210 totalZ = maxZ-minZ+1;
2211 contourextractdata->SetImage( imagedata);
2214 for ( z=minZ ; z<=maxZ ; z++ )
2217 porcent = 100.0* (z-minZ)/totalZ;
2218 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2220 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2221 //_staticTextInformation->SetLabel(tmpString);
2223 //Extraction data from contours of each slice
2224 contourextractdata->SetZtoBeAnalys( z);
2227 Instant instant(&tempVector);
2228 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2229 sizeLstContourThings = lstContourThings.size();
2231 lstManConMod.clear();
2232 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2234 ContourThing **contourthing = lstContourThings[ii];
2235 lstManConMod.push_back( (*contourthing)->getModel() );
2237 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2240 wxString tempString;
2241 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2242 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2243 //_grid->SetRowLabelValue(z, tempString );
2245 int iContourGroup,sizeContourGroup;
2246 if (typeContourGroup==3) // contour separete
2248 sizeContourGroup=lstManConModExp.size();
2249 if ( maxContourGroup<sizeContourGroup )
2251 maxContourGroup=sizeContourGroup;
2253 } else { // contour AND OR XOR
2262 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2263 lstManConModTmp.clear();
2264 if (typeContourGroup==3) // contour separete
2266 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2267 } else { // contour AND OR XOR
2268 lstManConModTmp = lstManConModExp;
2271 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2274 pLstValuePosX.clear();
2275 pLstValuePosY.clear();
2276 pLstValuePosZ.clear();
2277 contourextractdata->GetValuesInsideCrown( &pLstValue,
2281 // Statistics of each slice.
2282 contourextractdata->Statistics( &pLstValue,
2285 &resultGrayRangeCount,
2290 &resultStandardeviation);
2292 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2294 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2297 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2299 tempString.Printf(_T("%d"),resultSize);
2300 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2302 tempString.Printf(_T("%d"),resultGrayRangeCount);
2303 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2305 tempString.Printf(_T("%f"),resultMin);
2306 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2308 tempString.Printf(_T("%f"),resultMax);
2309 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2311 tempString.Printf(_T("%f"),resultAverage);
2312 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2314 tempString.Printf(_T("%f"),resultStandardeviation);
2315 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2318 } // for iContourGroup
2322 wxString tmpTitleString;
2324 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2326 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2327 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2328 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2330 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2331 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2332 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2333 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2334 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2335 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2336 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2339 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2340 delete contourextractdata;
2343 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2344 SaveValuesXYZ( directory , namefile, typeContourGroup );
2346 vtkImageData* mask, *value;
2347 this->getMaskValue(mask, value, typeContourGroup);
2348 this->SaveImageResult( directory , namefile, mask, value);
2351 FILE *pFile=fopen(filename.c_str(),"w+");
2353 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2356 int i,j,maxX,maxY=sizeZ;
2357 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2359 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2360 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2362 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2363 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2365 fprintf(pFile,"\n" );
2369 for ( j=0; j<maxY ; j++)
2371 fprintf(pFile,"%d\t" , j );
2372 for (i=0 ; i<maxX ; i++){
2373 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2374 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2376 fprintf(pFile,"\n" );
2382 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2385 ContourExtractData *contourextractdata = new ContourExtractData();
2386 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2387 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2389 std::vector<manualContourModel*> lstManConMod;
2390 std::vector<manualContourModel*> lstManConModTmp;
2391 std::vector<manualContourModel*> lstManConModExp;
2392 std::vector<double> pLstValue;
2393 std::vector<double> pLstValuePosX;
2394 std::vector<double> pLstValuePosY;
2395 std::vector<double> pLstValuePosZ;
2397 std::vector<int> tempVector;
2398 _instantPanel->getInstant( tempVector );
2400 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2401 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2403 int ii,sizeLstContourThings;
2410 minZ = 0;// _mbarrange->GetStart();
2411 maxZ = sizeZ;//_mbarrange->GetEnd();
2412 totalZ = maxZ-minZ+1;
2414 contourextractdata->SetImage( imagedata);
2417 for ( z=0 ; z<sizeZ ; z++)
2420 porcent = 100.0* (z-minZ)/totalZ;
2422 tmpString.Printf(_T("Saving Values"));
2423 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2424 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2425 //_staticTextInformation->SetLabel(tmpString);
2428 //Extraction data from contours of each slice
2429 contourextractdata->SetZtoBeAnalys( z);
2432 Instant instant(&tempVector);
2433 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2434 sizeLstContourThings = lstContourThings.size();
2436 lstManConMod.clear();
2437 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2439 ContourThing **contourthing = lstContourThings[ii];
2440 lstManConMod.push_back( (*contourthing)->getModel() );
2442 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2447 int iContourGroup,sizeContourGroup;
2448 if (typeContourGroup==3) // contour separete
2450 sizeContourGroup=lstManConModExp.size();
2451 } else { // contour AND OR XOR
2455 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2456 lstManConModTmp.clear();
2457 if (typeContourGroup==3) // contour separete
2459 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2460 } else { // contour AND OR XOR
2461 lstManConModTmp = lstManConModExp;
2464 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2467 pLstValuePosX.clear();
2468 pLstValuePosY.clear();
2469 pLstValuePosZ.clear();
2470 contourextractdata->GetValuesInsideCrown( &pLstValue,
2475 std::string temp = directory + "/" + namefile + "-slice";
2476 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2477 temp = temp + ".txt";
2479 // LG 14/01/09 : using crea
2480 wxString filename = crea::std2wx(temp);
2481 /*filename.Printf(_T("%s"),directory.c_str());
2482 filename.append(_T("\\"));
2483 filename.append(_T("%s"),namefile.c_str());
2484 filename.append(_T("-slice"));
2485 filename.append(_T("%d"),z);
2486 filename.append(_T("-cont"));
2487 filename.append(_T("%d"),iContourGroup);
2488 filename.append(_T(".txt"));*/
2489 // filename.Printf(temp.c_str());
2493 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2494 fprintf(pFile,"value \t x \t y \t z\n" );
2495 int iLstValue,sizeLstValue=pLstValue.size();
2496 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2498 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2501 } // for iContourGroup
2503 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2504 //_staticTextInformation->SetLabel( _T("") );
2505 delete contourextractdata;
2508 void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){
2510 ContourExtractData *contourextractdata = new ContourExtractData( true );
2511 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2512 if (typeContourGroup==3)
2516 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2518 std::vector<manualContourModel*> lstManConMod;
2519 std::vector<manualContourModel*> lstManConModTmp;
2520 std::vector<manualContourModel*> lstManConModExp;
2522 std::vector<int> tempVector;
2523 _instantPanel->getInstant( tempVector );
2525 vtkImageData *imagedata = _theViewPanel->getImageData();
2526 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2528 int ii,sizeLstContourThings;
2537 minZ = 0;// _mbarrange->GetStart();
2538 maxZ = sizeZ;//_mbarrange->GetEnd();
2539 totalZ = maxZ-minZ+1;
2541 contourextractdata->SetImage( imagedata);
2544 for ( z=0 ; z<sizeZ ; z++)
2547 porcent = 100.0* (z-minZ)/totalZ;
2548 tmpString.Printf(_T("Saving Values"));
2549 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2550 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2552 //Extraction data from contours of each slice
2553 contourextractdata->SetZtoBeAnalys( z);
2556 Instant instant(&tempVector);
2557 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2558 sizeLstContourThings = lstContourThings.size();
2560 lstManConMod.clear();
2561 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2563 ContourThing **contourthing = lstContourThings[ii];
2564 lstManConMod.push_back( (*contourthing)->getModel() );
2566 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2569 int iContourGroup,sizeContourGroup;
2570 if (typeContourGroup==3) // contour separete
2572 sizeContourGroup=lstManConModExp.size();
2573 } else { // contour AND OR XOR
2577 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2578 lstManConModTmp.clear();
2579 if (typeContourGroup==3) // contour separete
2581 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2582 } else { // contour AND OR XOR
2583 lstManConModTmp = lstManConModExp;
2586 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2587 contourextractdata->CalculateImageResult(); // with actual Z
2589 } // for iContourGroup
2592 value = contourextractdata->GetVtkImageValueResult();
2593 mask = contourextractdata->GetVtkImageMaskResult();
2594 delete contourextractdata;
2597 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2600 std::string temp = directory + "/" + namefile + "-Value.mhd";
2602 wxString filename = crea::std2wx(temp);
2604 // filename.Printf(_T(temp.c_str()));
2605 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2606 /*filename.Printf(_T("%s"),directory.c_str());
2607 filename.append(_T("\\"));
2608 filename.append(_T("%s"),namefile.c_str());
2609 filename.append(_T("-Value.mhd"));*/
2612 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2613 writerValueImage->SetInput( value );
2614 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2615 writerValueImage->SetFileDimensionality( 3 );
2616 writerValueImage->Write( );
2619 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2620 temp = directory + "/" + namefile + "-Mask.mhd";
2622 // LG 14/01/09 : using crea
2623 filename = crea::std2wx(temp);
2624 // filename.Printf(_T(temp.c_str()));
2626 /*filename.Printf(_T("%s"),directory.c_str());
2627 filename.append(_T("\\"));
2628 filename.append(_T("%s"),namefile.c_str());
2629 filename.append(_T("-Mask.mhd"));*/
2631 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2632 writerMaskImage->SetInput( mask );
2633 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2634 writerMaskImage->SetFileDimensionality( 3 );
2635 writerMaskImage->Write( );
2637 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2643 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2644 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2645 _theViewPanel->setActualVertical( value);
2647 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2648 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2654 void wxContourMainFrame::onSnakePressed(){
2655 std::vector<double> vecX;
2656 std::vector<double> vecY;
2657 std::vector<double> vecZ;
2658 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2660 if (vecX.size()!=0){
2661 std::vector<int> tempVector;
2662 _instantPanel->getInstant( tempVector );
2663 int i,size=vecZ.size();
2664 int actualSlice = tempVector[1];
2665 for ( i=0 ; i<size ; i++ )
2667 vecZ[i] = actualSlice;
2670 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2671 wxPanel* panel = new wxPanel(dialog,-1);
2672 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2673 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2674 dialog->ShowModal();
2679 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2680 std::string filename = kernelManager->getCurrentFileName();
2681 if(filename.compare("")!=0){
2682 saveFileWithContours(filename);
2687 void wxContourMainFrame::ShowToolsPanel(bool show){
2688 _pannew->Show(show);