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()
168 wxContourMainFrame :: ~wxContourMainFrame()
172 interfMainPanel::resetInstance();
173 //_pannew->Destroy();
179 //El problema al cerrar la aplicacion puede estar asociado
180 //a que wxAUINotebook esta en la aplicacion
181 //principal (wxContourGUIExample)tambien
182 //EED???? delete _theViewPanel;
183 //EED???? delete _instantPanel;
184 //EED???? delete _buttonsBar;
185 //EED???? delete _actualInstant;
186 //EED???? delete _sceneManager;
190 //------------------------------------------------------------------------------------------------------------
191 // Creational and initialization methods using WxAui
192 //------------------------------------------------------------------------------------------------------------
194 wxAuiNotebook * wxContourMainFrame :: createNotebook()
196 wxSize client_size = GetClientSize();
197 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
198 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
203 //------------------------------------------------------------------------------------------------------------
204 // Creational and initialization methods
205 //------------------------------------------------------------------------------------------------------------
206 bool wxContourMainFrame :: configurePanels( )
208 bool configured = _theViewPanel!=NULL;
210 configured &= _theViewPanel!=NULL;
211 if( _theViewPanel!=NULL )
213 notebook->AddPage( _theViewPanel, wxT(" View ") );
220 notebook->AddPage( _instantPanel, wxT("Instant Page") );
224 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
227 SetMinSize(wxSize(300,300));
233 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
235 bool configured = panel!=NULL;
236 configured &= panel!=NULL;
240 notebook->AddPage( panel, wxT(" Viewer "), true );
246 //------------------------------------------------------------------------------------------------------------
247 // Attributes getters and setters
248 //------------------------------------------------------------------------------------------------------------
252 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
254 _instantPanel = theInstantChooserPanel;
257 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
259 // _buttonsBar = theButtonsBar;
262 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
264 // _gridPanel = theGridPanel;
267 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
269 // _drawToolsPanel = theDrawToolsPanel;
272 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
274 // _operationsToolsPanel = theOperationsToolsPanel;
277 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
279 // _autoFormsPanel = theAutoFormsPanel;
282 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
284 // _standardToolsPanel= theStandardToolsPanel;
287 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
289 // _editionToolsPanel = theEditionToolsPanel;
292 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
294 // _listViewPanel = theListViewPanel;
299 void wxContourMainFrame::onCreateContourSpline( ){
301 //JCP 20-10-08 Undo redo implementation
303 //JCP 20-10-08 Undo redo implementation
307 void wxContourMainFrame::onCreateContourRectangle( ){
308 //JCP 20-10-08 Undo redo implementation
310 //JCP 20-10-08 Undo redo implementation
313 void wxContourMainFrame::onCreateContourCircle( ){
314 //JCP 20-10-08 Undo redo implementation
316 //JCP 20-10-08 Undo redo implementation
320 void wxContourMainFrame::onCreateContourLine( ){
321 //JCP 20-10-08 Undo redo implementation
323 //JCP 20-10-08 Undo redo implementation
327 //------------------------------------------------------------------------------------------------------------
329 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
331 //Creating the manualContourModel and including in the model
332 manualContourModel * manModelContour = factoryManualContourModel(panel );
334 std::vector<int> instantVector;
335 _instantPanel->getInstant( instantVector );
336 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
338 /*std::vector<int> instantVector;
339 _instantPanel->getInstant( instantVector );
341 theName= _modelManager->createOutline( manModelContour, instantVector );*/
342 bool addedModel = theName.compare("") != 0;//??
346 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
347 _theViewPanel->getSpacing(spc);
348 //Adding the manualContourControler to interface objects structure
349 //Adding the manualViewContour to interface objects structure
350 //_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.
351 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
354 void wxContourMainFrame :: createContour( int typeContour )
356 //Creating the manualContourModel and including in the model
357 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
360 std::vector<int> instantVector;
361 _instantPanel->getInstant( instantVector );
362 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
364 /*std::vector<int> instantVector;
365 _instantPanel->getInstant( instantVector );
367 theName= _modelManager->createOutline( manModelContour, instantVector );*/
368 bool addedModel = theName.compare("") != 0;//??
371 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
372 _theViewPanel->getSpacing(spc);
373 //Adding the manualContourControler to interface objects structure
374 //Adding the manualViewContour to interface objects structure
375 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
376 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
380 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
382 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
383 manualContourModel *manModelContour=NULL;
384 manModelContour = manModelContourBullEye;
386 int iCrown,sizeCrowns,iSector,sizeSectors;
387 double radioA,radioB,ang,angDelta ;
388 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
389 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
391 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
392 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
393 if (iCrown==sizeCrowns-1)
397 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
401 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
403 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
404 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
405 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
408 } // if _panelBullEyeOptions
410 return manModelContour;
412 void wxContourMainFrame :: saveState(){
414 std::string temp = kernelManager->saveState();
415 saveFileWithContours(temp);
418 void wxContourMainFrame::onDeleteContour(){
419 //JCP 20-10-08 Undo redo implementation
421 //JCP 20-10-08 Undo redo implementation
423 std::vector<std::string> lstKeyNameToBeErase;
424 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
425 deleteContours( lstKeyNameToBeErase );
427 int i,size=_sceneManager->getSelectedObjects().size();
430 std::string keyName = _sceneManager->getSelectedObjects()[i];
431 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
432 if ( ispartofstaticlist>=0 )
434 std::vector<int> tempVector;
435 _instantPanel->getInstant( tempVector );
436 Instant instant(&tempVector);
437 this->_modelManager->ChangeContourOfList(keyName, &instant);
441 std::vector<std::string> lstKeyName;
442 std::vector<std::string> lstKeyNameActualSlice;
443 std::vector<std::string> lstKeyNameToBeErase;
445 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
446 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
447 int k,kSize=lstKeyNameToBeErase.size();
448 int j,jSize=lstKeyNameActualSlice.size();
450 for (k=0;k<kSize; k++)
453 for (j=0;j<jSize; j++)
455 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
462 lstKeyName.push_back( lstKeyNameToBeErase[k] );
466 deleteContours( lstKeyName );
470 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
472 int i,size=keyNamesVector.size();
475 deleteContour( keyNamesVector[i] );
479 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
481 manualContourModel * cModel;
482 manualViewBaseContour * cViewer;
483 manualContourBaseControler * cControler;
485 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
486 cControler = conwrapviewControl->getControler();*/
489 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
490 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
492 if (isedit && ispartofstaticlst)
494 _theViewPanel->removeFromScene(theKeyName);
496 kernelManager->deleteCModel(theKeyName);
497 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
498 //cViewer = conwrapviewControl->getViewer();
499 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
500 //cControler* conwrapviewControl->getControler();
502 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
503 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
504 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
508 // delete cControler;
513 void wxContourMainFrame::onDeleteContoursActSlice(){
514 //JCP 20-10-08 Undo redo implementation
516 //JCP 20-10-08 Undo redo implementation
517 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
519 void wxContourMainFrame::onDeleteAllContours(){
520 //JCP 20-10-08 Undo redo implementation
524 void wxContourMainFrame::deleteAllContours(){
525 //JCP 20-10-08 Undo redo implementation
528 std::vector<int> tempVector;
529 _instantPanel->getInstant( tempVector );
531 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
532 // the values in GetStart and GetEnd will then not be initialize also.
533 // We use instead the values given when initializing the _deletepanel.
535 //int minZ = _mbarrangeDeleteAll->GetStart();
536 //int maxZ = _mbarrangeDeleteAll->GetEnd();
540 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
544 _theViewPanel->getSceneManager()->removeSceneContours( );
545 _theViewPanel->getSceneManager()->removeAllOutlines();
546 kernelManager->removeAllOutlines();
549 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
551 _theViewPanel->getSceneManager()->removeSceneContours( );
552 _modelManager->removeAllOutlines();
553 _theViewPanel->getSceneManager()->removeAllOutlines();
556 for ( z=minZ ; z<=maxZ ; z++)
559 Instant instant(&tempVector);
560 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
562 sizeLstContourThings = lstContourThings.size();
563 for (ii=0 ; ii<sizeLstContourThings ; ii++)
565 ContourThing **contourthing = lstContourThings[ii];
566 deleteContour( (*contourthing)->getName() );
573 void wxContourMainFrame::setConceptValue( std::string name, int value ){
574 _instantPanel->setConceptValue(name, value);
577 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
578 return _instantPanel->getLastConceptData();
580 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
581 return _instantPanel->getIfConceptCheckedAt( name, pos );
584 void wxContourMainFrame::changeInstant()
586 std::vector<int> instantVect;
587 _instantPanel->getInstant( instantVect );
588 // Instant * theInstant = new Instant ( &instantVect );
590 //Setting the actual instant
591 //_actualInstant = theInstant;
593 kernelManager->setInstant(instantVect);
594 //_modelManager->setInstant( _actualInstant );
596 updateInstantOutlines();
597 updateInstantImageData();
603 void wxContourMainFrame :: updateInstantOutlines()
605 _theViewPanel->removeSceneContours();
606 _theViewPanel->addNameWrapperToScene();
608 //for( int i=0; i<size; i++)
610 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
614 int wxContourMainFrame::getNamesWrappingSize(){
615 return kernelManager->getNamesWrappingSize();
617 std::string wxContourMainFrame::getNameWrapping(int i){
618 return kernelManager->getNameWrapping(i);
621 void wxContourMainFrame::updateInstantImageData()
623 std::vector<int> inst;
624 _instantPanel->getInstant(inst);
626 vtkImageData* img = kernelManager->getImageAtInstant(inst);
628 _theViewPanel->changeImage(img);
631 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
632 _theViewPanel->setImageSlice(z);
636 void wxContourMainFrame::updateInstantAxes()
640 void wxContourMainFrame :: updateActor()
645 _pannew->onThresholdInstantChange(minMax);
647 int z = _theViewPanel->GetZ();
649 vtkImageData * img = getImageData();
650 vtkImageReslice *imageReslice = vtkImageReslice::New();
652 imageReslice->SetInput( img );
653 imageReslice->SetInformationInput(img);
654 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
655 imageReslice->SetResliceAxesOrigin(0,0,z);
656 imageReslice->SetOutputDimensionality(2);
657 imageReslice->SetInterpolationModeToLinear();
659 img = imageReslice->GetOutput();
661 img->UpdateInformation();
663 //EED??? wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
666 img->GetScalarRange(range);
668 int min = floor (range[0]);
669 int max = ceil (range[1]);
672 vtkLookupTable *lookup = vtkLookupTable::New();
673 lookup->SetNumberOfTableValues(max+1);
674 lookup->SetTableRange(range);
675 lookup->SetAlphaRange(0, 1);
676 lookup->SetValueRange(0, 1);
677 lookup->SetSaturationRange(0, 0);
678 lookup->SetRampToLinear( );
680 //Assign a fake color for the upper image, and set the white as transparent
682 int minVal = minMax[0];
683 int maxVal = minMax[1];
685 for(i = min; i <= max; i++)
687 if( i >= minVal && i <= maxVal )
689 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
691 else if( i >= min && i < minVal )
693 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
695 else if( i > maxVal && i < max )
697 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
701 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
707 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
708 mapperImage->SetLookupTable( lookup );
709 mapperImage->SetInput( img );
710 //mapperImage->SetOutputFormatToRGBA( );
712 _thresholdActor->SetInput( mapperImage->GetOutput() );
716 void wxContourMainFrame::onChangeDeep(int val){
717 _instantPanel->setConceptValue( "Axe Depth", (int)val );
722 void wxContourMainFrame::onCopy(){
723 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
725 std::vector<int> tempVector;
726 _instantPanel->getInstant( tempVector );
727 _performingOperation->reset();
728 _performingOperation->setStartCommand( COPY );
729 _performingOperation->setStartOperationInstantVector( tempVector );
730 _performingOperation->setKeyNamesOperationElems( currentSelection );
733 void wxContourMainFrame::onPaste(){
736 char theStartCommand = _performingOperation->getStartCommand();
737 if ( theStartCommand == COPY )
739 //JCP 20-10-08 Undo redo implementation
741 //JCP 20-10-08 Undo redo implementation
742 std::vector<int> tempVector;
743 _instantPanel->getInstant( tempVector );
744 _performingOperation->setEndOperationInstantVector ( tempVector );
745 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
746 int i,size = elems.size();
747 for( i=0; i<size; i++ )
749 createCopyContourOf( elems[i], tempVector, i>0 );
753 void wxContourMainFrame::onUndo(){
754 std::string filename;
755 if(kernelManager->onUndoSaveFile(filename)){
756 saveFileWithContours(filename);
758 if(kernelManager->onUndo(filename)){
762 void wxContourMainFrame::onRedo(){
763 std::string filename;
764 if(kernelManager->onRedo(filename)){
769 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
771 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
772 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
773 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
776 ///AD: 03-09 Copy the object and apply the given transformation
777 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
779 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
780 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
782 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
783 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
785 double pnt1X = refPoint1->GetX();
786 double pnt1Y = refPoint1->GetY();
787 // double pnt1Z = refPoint1->GetZ();
788 double pnt2X = refPoint2->GetX();
789 double pnt2Y = refPoint2->GetY();
790 // double pnt2Z = refPoint2->GetZ();
792 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
793 vtkTransform *t = vtkTransform::New();
797 t->Translate(-pnt1X, -pnt1Y, 0);
801 t->Translate(pnt1X, pnt1Y, 0);
804 int i,size=manualModel->GetSizeLstPoints();
807 manualPoint * mp = manualModel->GetManualPoint(i);
813 t->TransformPoint( vecIn, vecOut );
814 mp->SetPointX( vecOut[0] );
815 mp->SetPointY( vecOut[1] );
816 mp->SetPointZ( vecOut[2] );
819 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
822 void wxContourMainFrame ::loadState(std::string filename){
824 FILE *pFile=fopen(filename.c_str(),"r+");
826 fscanf(pFile,"%s",tmp); // --CreaContour--
828 fscanf(pFile,"%s",tmp); // Version
829 fscanf(pFile,"%s",tmp); // 1.0.1
830 std::string version(tmp);
834 openContours(pFile,false);
835 if (version!="1.0.0"){
836 openContours(pFile,true);
841 //_theViewPanel->getSceneManager()->removeSceneContours();
846 void wxContourMainFrame::onLoad(){
848 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
849 if (dialog.ShowModal() == wxID_OK)
851 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
852 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
854 fscanf(pFile,"%s",tmp); // --CreaContour--
856 fscanf(pFile,"%s",tmp); // Version
857 fscanf(pFile,"%s",tmp); // 1.0.1
858 std::string version(tmp);
860 openContours(pFile,false);
861 if (version!="1.0.0"){
862 openContours(pFile,true);
864 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
868 _theViewPanel->getSceneManager()->removeSceneContours();
871 void wxContourMainFrame::onSave(){
872 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
873 if (dialog.ShowModal() == wxID_OK)
875 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
876 kernelManager->setCurrentFileName(fileNameContourROI);
877 saveFileWithContours( fileNameContourROI );
880 void wxContourMainFrame::saveFileWithContours( std::string filename ){
882 FILE *pFile=fopen(filename.c_str(),"w+");
883 std::vector< std::string > lstNameThings;
884 int i,sizeLstNameThings;
886 fprintf(pFile,"--CreaContour--\n");
887 fprintf(pFile,"Version %s\n", "1.0.1" );
890 lstNameThings = kernelManager->GetLstNameThings();
891 sizeLstNameThings = lstNameThings.size();
892 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
893 for (i=0 ; i<sizeLstNameThings ; i++)
895 kernelManager->SaveThingName( pFile, lstNameThings[i] );
896 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
899 //-- Contours Statics
900 lstNameThings = kernelManager->GetLstNameThingsStatic();
901 sizeLstNameThings = lstNameThings.size();
902 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
903 for (i=0 ; i<sizeLstNameThings ; i++)
905 kernelManager->SaveThingName( pFile, lstNameThings[i] );
906 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
911 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
913 fscanf(pFile,"%s",tmp); // NumberOfContours
914 fscanf(pFile,"%s",tmp); // ##
915 int numberOfContours = atoi(tmp);
917 std::vector<int> instantVector;
918 int typeContourModel;
919 manualContourModel *manModelContour;
923 for (i=0;i<numberOfContours;i++)
925 instantVector.clear();
926 fscanf(pFile,"%s",tmp); // Instant
928 fscanf(pFile,"%s",tmp); // 1
929 instantVector.push_back( atoi(tmp) );
930 fscanf(pFile,"%s",tmp); // 2
931 instantVector.push_back( atoi(tmp) );
932 fscanf(pFile,"%s",tmp); // 3
933 instantVector.push_back( atoi(tmp) );
934 fscanf(pFile,"%s",tmp); // 4
935 instantVector.push_back( atoi(tmp) );
936 fscanf(pFile,"%s",tmp); // 5
937 instantVector.push_back( atoi(tmp) );
938 fscanf(pFile,"%s",tmp); // 6
939 instantVector.push_back( atoi(tmp) );
942 fscanf(pFile,"%s",tmp); // TypeContourModel
943 fscanf(pFile,"%s",tmp); // ##
944 typeContourModel = atoi(tmp);
946 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
947 manModelContour->Open(pFile);
949 fscanf(pFile,"%s",tmp); // TypeView
950 fscanf(pFile,"%s",tmp); // ##
951 typeView = atoi(tmp);
960 theName = kernelManager->createOutline( manModelContour, instantVector );
961 bool addedModel = theName.compare("") != 0;
964 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
965 _theViewPanel->getSpacing(spc);
966 //Adding the manualContourControler to interface objects structure
967 //Adding the manualViewContour to interface objects structure
968 //_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.
969 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
972 if (staticContour==true)
974 Instant instant(&instantVector);
975 kernelManager->changeContourOfManager( theName , &instant );
978 }// for numberOfContours
982 void wxContourMainFrame::RefreshInterface(){
984 _theViewPanel->RefreshInterface();
985 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
986 //wxvtk2dbaseview->Refresh();
989 vtkImageData* wxContourMainFrame::getImageData(){
990 return _theViewPanel->getImageData();
993 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
995 //JCP 20-10-08 Undo redo implementation
997 //JCP 20-10-08 Undo redo implementation
1000 int x = _theViewPanel->GetX();
1001 int y = _theViewPanel->GetY();
1002 int z = _theViewPanel->GetZ();
1003 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1007 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1010 int typeofcontour = 1;
1012 vtkImageData *imagedata = getImageData();
1014 //Tipo de pixeles a utilizar internamente en ITK
1015 typedef float InternalPixelType;
1016 const unsigned int Dimension = 2;
1017 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1019 //Tipo de pixeles de salida 1
1020 typedef unsigned char OutputPixelType;
1021 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1023 //Tipo de pixeles de salida 2
1024 typedef unsigned short OutputPixelType2;
1025 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1027 //DefiniciÛn del thresholder
1028 typedef itk::BinaryThresholdImageFilter<
1030 OutputImageType > ThresholdingFilterType;
1032 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1033 typedef itk::CastImageFilter<
1034 OutputImageType, OutputImageType2 > CastFilterType;
1036 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1037 typedef itk::CastImageFilter<
1038 OutputImageType2, InternalImageType > CastFilterType2;
1040 //Tercer tipo de conversiÛn
1041 typedef itk::RescaleIntensityImageFilter<
1043 OutputImageType > CastFilterType3;
1045 //Cuarto tipo de conversiÛn
1046 typedef itk::RescaleIntensityImageFilter<
1048 OutputImageType > CastFilterType4;
1050 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1052 thresholder->SetLowerThreshold( 0.0 );
1053 thresholder->SetUpperThreshold( 128 );
1055 thresholder->SetOutsideValue( 255 );
1056 thresholder->SetInsideValue( 0 );
1058 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1059 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1060 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1061 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1063 ConnectorType::Pointer connector= ConnectorType::New();
1064 ConnectorType2::Pointer connector2= ConnectorType2::New();
1067 CastFilterType::Pointer filter=CastFilterType::New();
1068 CastFilterType2::Pointer filter2=CastFilterType2::New();
1070 connector->SetInput( imagedata );
1071 filter2->SetInput(connector->GetOutput());
1073 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1075 InternalImageType > SmoothingFilterType;
1077 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1079 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1081 InternalImageType > GradientFilterType;
1083 typedef itk::SigmoidImageFilter<
1085 InternalImageType > SigmoidFilterType;
1087 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1089 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1091 sigmoid->SetOutputMinimum( 0.0 );
1092 sigmoid->SetOutputMaximum( 255.0 );
1095 typedef itk::FastMarchingImageFilter<
1097 InternalImageType > FastMarchingFilterType;
1100 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1102 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1103 InternalImageType > GeodesicActiveContourFilterType;
1104 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1105 GeodesicActiveContourFilterType::New();
1107 typedef itk::ZeroCrossingImageFilter<
1109 InternalImageType > ZeroCrossingFilterType;
1110 ZeroCrossingFilterType::Pointer zeroCrossing =
1111 ZeroCrossingFilterType::New();
1113 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1115 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1116 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1117 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1119 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1120 int it=atoi( crea::wx2std(iter).c_str() );
1121 geodesicActiveContour->SetNumberOfIterations( it );
1123 smoothing->SetInput( filter2->GetOutput() );
1124 gradientMagnitude->SetInput( smoothing->GetOutput() );
1125 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1126 fastMarching->SetInput( sigmoid->GetOutput() );
1127 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1128 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1130 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1131 //thresholder->SetInput( zeroCrossing->GetOutput() );
1132 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1133 connector2->SetInput( thresholder->GetOutput() );
1136 smoothing->SetTimeStep( 0.125 );
1137 smoothing->SetNumberOfIterations( 5 );
1138 smoothing->SetConductanceParameter( 9.0 );
1141 const double sigma = atof( crea::wx2std(sigm).c_str() );
1142 gradientMagnitude->SetSigma( sigma );
1144 const double alpha = atof( crea::wx2std(alf).c_str() );
1145 const double beta = atof( crea::wx2std(bet).c_str() );
1147 sigmoid->SetAlpha( alpha );
1148 sigmoid->SetBeta( beta );
1150 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1151 typedef FastMarchingFilterType::NodeType NodeType;
1153 NodeContainer::Pointer seeds = NodeContainer::New();
1155 InternalImageType::IndexType seedPosition;
1156 seedPosition[0] = x;
1157 seedPosition[1] = y;
1159 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1163 const double seedValue = - initialDistance;
1165 node.SetValue( seedValue );
1166 node.SetIndex( seedPosition );
1168 seeds->Initialize();
1169 seeds->InsertElement( 0, node );
1171 fastMarching->SetTrialPoints( seeds );
1173 fastMarching->SetSpeedConstant( 1.0 );
1175 fastMarching->SetOutputSize(
1176 connector->GetOutput()->GetBufferedRegion().GetSize() );
1178 fastMarching->SetStoppingValue( 800 );
1182 connector2->Update();
1183 vtkImageData *idata = connector2->GetOutput();
1185 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1187 cntVTK->SetInput( idata );
1189 cntVTK->SetNumberOfContours( 1 );
1190 cntVTK->SetValue( 0, 255 );
1192 cntVTK->UpdateInformation();
1194 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1195 cpd->SetInput( cntVTK->GetOutput( ) );
1197 cpd->UpdateInformation();
1199 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1200 conn->SetExtractionModeToLargestRegion( );
1201 conn->SetInput( cpd->GetOutput( ) );
1203 conn->UpdateInformation();
1205 vtkStripper* vtkstripper = vtkStripper::New( );
1206 vtkstripper->SetInput( conn->GetOutput() );
1207 vtkstripper->Update();
1208 vtkstripper->UpdateInformation();
1211 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1212 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1213 polyDataResult->Update( );
1214 polyDataResult->UpdateInformation();
1219 myfile.open ("C:/Creatis/example.txt");
1221 polyDataResult->Print(myfile);
1222 myfile << "-------------------------------------\n";
1223 polyDataResult->GetLines()->Print(myfile);
1231 //--Calculating control points
1233 std::vector<double> vecX;
1234 std::vector<double> vecY;
1235 std::vector<double> vecXo;
1236 std::vector<double> vecYo;
1237 std::vector<double>::iterator vecXoi;
1238 std::vector<double>::iterator vecYoi;
1239 std::vector<double> vecZ;
1241 std::vector<double> vecCtrlPointX;
1242 std::vector<double> vecCtrlPointY;
1243 std::vector<double> vecCtrlPointZ;
1249 int ii,size=polyDataResult->GetNumberOfPoints();
1251 myfile.open ("C:/Creatis/example2.txt");
1253 size=polyDataResult->GetNumberOfPoints();
1254 for (ii=0;ii<size;ii++)
1261 p = polyDataResult->GetPoint(ii);
1264 /*if(fabs(yAct-y)>20)
1266 if((xAct-x)>1 || (xAct-x)<-1)
1268 vecX.push_back( p[0] );
1269 vecY.push_back( p[1] );
1270 myfile <<p[0]<<","<<p[1]<<"\n";
1271 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1272 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1273 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1274 vecZ.push_back( 900 );
1280 vecXo.push_back(p[0]);
1281 vecYo.push_back(p[1]);
1285 else*/ if(fabs(xAct-x)>11)
1287 vecXo.push_back(p[0]);
1288 vecYo.push_back(p[1]);
1292 vecX.push_back( p[0] );
1293 myfile <<p[0]<<","<<p[1]<<"\n";
1294 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1295 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1296 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1297 vecY.push_back( p[1] );
1298 vecZ.push_back( 900 );
1306 while(!vecXo.empty())
1308 vecX.push_back(vecXo.back());
1309 std::cout<<" x Siguiente "<<vecXo.back();
1311 vecZ.push_back( 900 );
1313 while(!vecYo.empty())
1315 vecY.push_back(vecYo.back());
1320 /*for(int l=0;l<vecX.size();l++)
1324 vecXo.push_back(p[0]);
1325 vecYo.push_back(p[1]);
1336 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1338 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1342 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1344 else if (method==1){
1345 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1347 else if (method==2){
1348 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1349 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1351 //--Adding contour to the system
1353 std::vector<int> actualInstantVector;
1354 _instantPanel->getInstant( actualInstantVector );
1355 actualInstantVector[1]=z;
1357 int j,sizeCtrPt = vecCtrlPointX.size();
1359 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1360 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1362 for (j=0 ; j<sizeCtrPt ; j++)
1364 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1366 std::string theName;
1367 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1368 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1369 bool addedModel = theName.compare("") != 0;
1372 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1373 _theViewPanel->getSpacing(spc);
1374 //Adding the manualContourControler to interface objects structure
1375 //Adding the manualViewContour to interface objects structure
1376 //_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.
1377 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1378 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1384 WriterType::Pointer writer = WriterType::New();
1385 CastFilterType3::Pointer caster = CastFilterType3::New();
1387 caster->SetInput( gradientMagnitude->GetOutput() );
1388 writer->SetInput( caster->GetOutput() );
1389 writer->SetFileName("Gradient Magnitude.png");
1390 caster->SetOutputMinimum( 0 );
1391 caster->SetOutputMaximum( 255 );
1394 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1395 WriterType::Pointer writer2 = WriterType::New();
1397 caster2->SetInput( sigmoid->GetOutput() );
1398 writer2->SetInput( caster2->GetOutput() );
1399 writer2->SetFileName("Sigmoid.png");
1400 caster2->SetOutputMinimum( 0 );
1401 caster2->SetOutputMaximum( 255 );
1404 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1405 WriterType::Pointer writer3 = WriterType::New();
1407 caster3->SetInput( fastMarching->GetOutput() );
1408 writer3->SetInput( caster3->GetOutput() );
1409 writer3->SetFileName("FastMarching.bmp");
1410 caster3->SetOutputMinimum( 0 );
1411 caster3->SetOutputMaximum( 255 );
1414 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1415 WriterType::Pointer writer4 = WriterType::New();
1417 caster4->SetInput( geodesicActiveContour->GetOutput() );
1418 writer4->SetInput( caster4->GetOutput() );
1419 writer4->SetFileName("GeodesicActiveContour.png");
1420 caster4->SetOutputMinimum( 0 );
1421 caster4->SetOutputMaximum( 255 );
1424 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1425 WriterType::Pointer writer5 = WriterType::New();
1427 caster5->SetInput( zeroCrossing->GetOutput() );
1428 writer5->SetInput( caster5->GetOutput() );
1429 writer5->SetFileName("ZeroCrossing.bmp");
1430 caster5->SetOutputMinimum( 0 );
1431 caster5->SetOutputMaximum( 255 );
1434 catch( itk::ExceptionObject & excep )
1436 std::cerr << "Exception caught !" << std::endl;
1437 std::cerr << excep << std::endl;
1441 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1443 //JCP 20-10-08 Undo redo implementation
1445 //JCP 20-10-08 Undo redo implementation
1448 int x = _theViewPanel->GetX();
1449 int y = _theViewPanel->GetY();
1450 int z = _theViewPanel->GetZ();
1451 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1456 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1458 int typeofcontour = 1;
1459 //--Extracting Contour
1460 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1461 vtkImageData *imagedata = getImageData();
1462 // double *range = imagedata->GetScalarRange();
1465 vtkImageReslice *imageReslice = vtkImageReslice::New();
1468 // imagedata->GetSpacing(spc);
1473 imageReslice->SetInput( imagedata );
1474 imageReslice->SetInformationInput(imagedata);
1475 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1476 imageReslice->SetResliceAxesOrigin(0,0,z);
1477 imageReslice->SetOutputDimensionality(2);
1478 imageReslice->SetInterpolationModeToLinear();
1480 imagedata = imageReslice->GetOutput();
1481 imagedata->Update();
1482 imagedata->UpdateInformation();
1484 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1485 cntVTK->SetInput( imagedata );
1487 cntVTK->SetNumberOfContours( 1 );
1488 //cntVTK->SetValue( 0, vmin );
1489 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1490 cntVTK->SetValue( 1, isovalue );
1491 // cntVTK->SetValue( 1, vmax );
1493 cntVTK->UpdateInformation();
1495 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1496 cpd->SetInput( cntVTK->GetOutput( ) );
1497 cpd->ConvertLinesToPointsOff( );
1499 cpd->UpdateInformation();
1501 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1502 conn->SetExtractionModeToClosestPointRegion( );
1503 //conn->SetMaxRecursionDepth( 3000 );
1505 conn->SetInput( cpd->GetOutput( ) );
1507 conn->SetClosestPoint( x, y, 0 );
1509 conn->UpdateInformation();
1511 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1512 cpd2->SetInput( conn->GetOutput( ) );
1514 cpd2->UpdateInformation();
1516 vtkStripper* vtkstripper = vtkStripper::New( );
1517 vtkstripper->SetInput( cpd2->GetOutput() );
1518 vtkstripper->Update();
1519 vtkstripper->UpdateInformation();
1522 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1524 polyDataResult->Update( );
1525 polyDataResult->UpdateInformation();
1529 myfile.open ("c:/temp/example.txt");
1531 polyDataResult->Print(myfile);
1532 myfile << "-------------------------------------\n";
1533 polyDataResult->GetLines()->Print(myfile);
1543 //--Calculating control points
1545 std::vector<double> vecX;
1546 std::vector<double> vecY;
1547 std::vector<double> vecZ;
1549 std::vector<double> vecCtrlPointX;
1550 std::vector<double> vecCtrlPointY;
1551 std::vector<double> vecCtrlPointZ;
1555 int ii,size=polyDataResult->GetNumberOfPoints();
1557 for (ii=1;ii<=size;ii++)
1559 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1560 p = polyDataResult->GetPoint(id);
1563 vecX.push_back( p[0] );
1564 vecY.push_back( p[1] );
1565 vecZ.push_back( 900 );
1566 // vecZ.push_back( p[2] );
1570 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1571 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1574 /*if (methodRadiobox->GetSelection()==0){
1575 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1577 if (methodRadiobox->GetSelection()==1){
1578 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1580 if (methodRadiobox->GetSelection()==2){
1581 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1582 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1586 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1588 else if (method==1){
1589 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1591 else if (method==2){
1592 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1593 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1596 //--Adding contour to the system
1598 std::vector<int> actualInstantVector;
1599 _instantPanel->getInstant( actualInstantVector );
1600 actualInstantVector[1]=z;
1602 int j,sizeCtrPt = vecCtrlPointX.size();
1603 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1604 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1606 for (j=0 ; j<sizeCtrPt ; j++)
1608 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1610 std::string theName;
1611 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1612 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1613 bool addedModel = theName.compare("") != 0;
1616 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1617 _theViewPanel->getSpacing(spc);
1618 //Adding the manualContourControler to interface objects structure
1619 //Adding the manualViewContour to interface objects structure
1620 //_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.
1621 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1622 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1626 int wxContourMainFrame::GetImageDataSizeZ(){
1627 return _theViewPanel->GetImageDataSizeZ();
1630 void wxContourMainFrame::GetImageDataRange(double *range){
1631 _theViewPanel->GetImageDataRange(range);
1634 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1635 //JCP 20-10-08 Undo redo implementation
1637 //JCP 20-10-08 Undo redo implementation
1640 int x = _theViewPanel->GetX();
1641 int y = _theViewPanel->GetY();
1645 double totalZ = maxZ-minZ+1;
1646 for( z=minZ ; z<=maxZ ; z++ )
1648 porcent = 100.0* (z-minZ)/totalZ;
1649 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1650 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1651 //_staticTextSegmentation->SetLabel(tmpString);
1652 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1654 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1659 //Creates a reference line to be used as the axis of the mirroring
1660 void wxContourMainFrame::referenceLine()
1662 if (_refLineControl==NULL)
1667 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1668 vtkimagedata->GetSpacing(spc);
1670 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1672 _refLineControl = new manualLineControler();
1673 _refLineModel = new manualContourModelLine();
1674 _refLineView = new manualViewLine();
1675 _refLineView->SetModel( _refLineModel );
1676 _refLineView->SetWxVtkBaseView( viewer2D );
1677 _refLineView->SetRange( 2 );
1678 _refLineView->SetZ( 1200 );
1680 _refLineView->SetSpacing(spc);
1682 _refLineView->SetColorNormalContour(0, 0, 1);
1683 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1684 _refLineView->SetWidthLine(4);
1686 _refLineControl->SetModelView( _refLineModel , _refLineView );
1687 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1688 _refLineModel->SetCloseContour(false);
1689 _refLineControl->CreateNewManualContour();
1691 //EED?? double z = _refLineControl->GetZ();
1693 _refLineControl->AddPoint(50,100,z);
1694 _refLineControl->AddPoint(80,40,z);
1695 _refLineControl->SetCompleteCreation(true);
1697 _refLineModel->AddPoint(50,100,z);
1698 _refLineModel->AddPoint(80,40,z);
1699 _refLineModel->UpdateSpline();
1701 _refLineView->UpdateViewPoint(0);
1702 _refLineView->UpdateViewPoint(1);
1705 _refLineControl->SetActive(true);
1706 _refLineView->RefreshContour();
1710 //Hides the referenceLine
1711 void wxContourMainFrame::refLineHide()
1713 if (_refLineControl!=NULL)
1715 if (_refLineControl->GetActive())
1717 _refLineView->RemoveCompleteContourActor();
1718 _refLineControl->SetEditable(false);
1719 _refLineControl->SetActive(false);
1726 //Shows the referenceLine
1727 void wxContourMainFrame::refLineShow()
1729 if (_refLineControl!=NULL)
1731 if (_refLineControl->GetActive()==false)
1733 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1735 _refLineView->SetModel( _refLineModel );
1736 _refLineView->SetWxVtkBaseView( viewer2D );
1737 _refLineView->SetRange( 2 );
1738 _refLineView->SetZ( 1200 );
1740 _refLineControl->SetModelView( _refLineModel , _refLineView );
1741 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1742 _refLineControl->CreateNewManualContour();
1743 _refLineControl->SetActive(true);
1744 _refLineView->RefreshContour();
1751 void wxContourMainFrame::refLineChangeWidth(int width)
1753 _refLineView->SetWidthLine(width);
1754 _refLineView->RefreshContour();
1760 void wxContourMainFrame::onMirror()
1763 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1764 std::vector<std::string> filterCurrentSelection;
1766 std::vector<int> tempVector;
1767 _instantPanel->getInstant( tempVector );
1768 _performingOperation->reset();
1769 _performingOperation->setStartCommand( COPY );
1770 _performingOperation->setStartOperationInstantVector( tempVector );
1771 _performingOperation->setKeyNamesOperationElems( currentSelection );
1773 char theStartCommand = _performingOperation->getStartCommand();
1774 if ( theStartCommand == COPY )
1776 //JCP 20-10-08 Undo redo implementation
1778 //JCP 20-10-08 Undo redo implementation
1779 std::vector<int> tempVector;
1780 _instantPanel->getInstant( tempVector );
1781 _performingOperation->setEndOperationInstantVector ( tempVector );
1782 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1783 int i,size = elems.size();
1784 for( i=0; i<size; i++ )
1786 createMirrorContourOf( elems[i], tempVector, i>0 );
1790 //deleteContour( _refName );
1794 void wxContourMainFrame::onThreshold(int minVal, int maxVal)
1798 int z = _theViewPanel->GetZ();
1800 vtkImageData * img = getImageData();
1801 vtkImageReslice *imageReslice = vtkImageReslice::New();
1803 imageReslice->SetInput( img );
1804 imageReslice->SetInformationInput(img);
1805 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1806 imageReslice->SetResliceAxesOrigin(0,0,z);
1807 imageReslice->SetOutputDimensionality(2);
1808 imageReslice->SetInterpolationModeToLinear();
1810 img = imageReslice->GetOutput();
1812 img->UpdateInformation();
1814 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1817 img->GetScalarRange(range);
1819 int min = floor (range[0]);
1820 int max = ceil (range[1]);
1823 vtkLookupTable *lookup = vtkLookupTable::New();
1824 lookup->SetNumberOfTableValues(max+1);
1825 lookup->SetTableRange(range);
1826 lookup->SetAlphaRange(0, 1);
1827 lookup->SetValueRange(0, 1);
1828 lookup->SetSaturationRange(0, 0);
1829 lookup->SetRampToLinear( );
1831 //Assign a fake color for the upper image, and set the white as transparent
1833 for(i = min; i <= max; i++)
1835 if( i >= minVal && i <= maxVal )
1837 lookup->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1839 else if( i >= min && i < minVal )
1841 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1843 else if( i > maxVal && i < max )
1845 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1849 lookup->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1855 vtkImageMapToColors *mapperImage = vtkImageMapToColors::New( );
1856 mapperImage->SetLookupTable( lookup );
1857 mapperImage->SetInput( img );
1858 //mapperImage->SetOutputFormatToRGBA( );
1860 if (_thresholdActor==NULL)
1862 _thresholdActor = vtkImageActor::New( );
1863 _thresholdActor->SetInput( mapperImage->GetOutput() );
1864 _thresholdActor->SetOpacity( 0.6 );
1865 _thresholdActor->SetPosition( 0,0, z+1 );
1866 _thresholdActor->InterpolateOn( );
1870 _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() );
1961 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
1963 if (_thresholdActor!=NULL)
1967 _thresholdActor->InterpolateOn( );
1972 _thresholdActor->InterpolateOff( );
1979 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
1983 _thresholdActor->SetOpacity(opacity*0.1);
1989 void wxContourMainFrame::onThresholdRemove()
1993 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1994 baseView->GetRenderer()->RemoveActor( _thresholdActor );
1995 _actorPresent = false;
2001 void wxContourMainFrame::showAxis(bool show)
2003 _theViewPanel->SetVisibleAxis(show);
2004 _theViewPanel->Refresh();
2008 void wxContourMainFrame::onRigidPressed(){
2009 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2010 int elementsSelected = currentSelection.size();
2012 if ( elementsSelected >= 1 ){
2013 //JCP 20-10-08 Undo redo implementation
2015 //JCP 20-10-08 Undo redo implementation
2017 std::vector<int> tempVector;
2018 _instantPanel->getInstant( tempVector );
2019 Instant instant(&tempVector);
2021 int i , size=currentSelection.size();
2022 for ( i=0 ; i<size ; i++ )
2024 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2029 void wxContourMainFrame::onWidthOfContour(double width){
2031 _theViewPanel->removeSceneContours();
2032 _theViewPanel->SetWidthContour(width);
2034 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2038 int wxContourMainFrame::getColorWindow(){
2039 return _theViewPanel->getColorWindow();
2041 int wxContourMainFrame::getWindowLevel(){
2042 return _theViewPanel->getWindowLevel();
2045 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2046 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2051 void wxContourMainFrame::onInterpolation(bool interpolate){
2052 _theViewPanel->onInterpolation(interpolate);
2056 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2057 _instantPanel->setConceptValue( name, actual );
2060 void wxContourMainFrame::resetAppend(){
2061 kernelManager->resetAppend();
2065 void wxContourMainFrame::onSpreadAdd(){
2066 std::vector<double> vecX;
2067 std::vector<double> vecY;
2068 std::vector<double> vecZ;
2069 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2071 std::vector<int> tempVector;
2072 _instantPanel->getInstant( tempVector );
2074 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2076 interfMainPanel::getInstance()->appendStringSpread(val);
2080 void wxContourMainFrame::onSpreadGo(int type){
2082 //JCP 20-10-08 Undo redo implementation
2084 //JCP 20-10-08 Undo redo implementation
2087 std::vector<double> vecCtrlPointX;
2088 std::vector<double> vecCtrlPointY;
2089 std::vector<double> vecCtrlPointZ;
2093 std::vector<int> tempVector;
2094 _instantPanel->getInstant( tempVector );
2097 kernelManager->getMaxMinZ(&minZ,&maxZ);
2098 //JSTG_16-07-08_----------------------------------------------------------------
2099 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2100 kernelManager->CalculeSplinePropagation();
2102 double totalZ = maxZ-minZ+1;
2105 //--------------------------------------------------------------------
2106 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2108 porcent = 100.0* (z-minZ)/totalZ;
2109 int numero = (int)(z-minZ+1)/(int)totalZ;
2110 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2112 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2114 int typeofcontour = 1;
2115 std::string theName;
2116 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2118 if( manModelContour!=NULL ){
2119 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2120 this->_theViewPanel->getSpacing(spc);
2121 //Adding the manualContourControler to interface objects structure
2122 //Adding the manualViewContour to interface objects structure
2123 //_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.
2124 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2129 int numero = (int)(z-minZ+1)/(int)totalZ;
2130 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2132 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2134 //RefreshInterface();
2137 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2141 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2142 std::vector<int> tempVector;
2143 _instantPanel->getInstant(tempVector);
2144 //Asignation of slide number should be different ex by name
2145 tempVector[1]=slide;
2146 return kernelManager->getOutlinesNameAtInstant(tempVector);
2149 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
2150 int maxContourGroup = 0;
2152 ContourExtractData *contourextractdata = new ContourExtractData();
2154 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2156 std::vector<manualContourModel*> lstManConMod;
2157 std::vector<manualContourModel*> lstManConModTmp;
2158 std::vector<manualContourModel*> lstManConModExp;
2159 std::vector<double> pLstValue;
2160 std::vector<double> pLstValuePosX;
2161 std::vector<double> pLstValuePosY;
2162 std::vector<double> pLstValuePosZ;
2165 int resultGrayRangeCount;
2168 double resultAverage;
2169 double resultStandardeviation;
2171 std::vector<int> tempVector;
2172 _instantPanel->getInstant( tempVector );
2174 vtkImageData *imagedata = _theViewPanel->getImageData();
2175 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2177 int ii,sizeLstContourThings;
2187 if (selection==0 ) // actual slice
2189 std::vector<int> tempVector;
2190 _instantPanel->getInstant( tempVector );
2191 int actualSlice = tempVector[1];
2195 else if (selection==2 ) // All slices
2200 else if (selection==1 ) // slice range
2207 totalZ = maxZ-minZ+1;
2208 contourextractdata->SetImage( imagedata);
2211 for ( z=minZ ; z<=maxZ ; z++ )
2214 porcent = 100.0* (z-minZ)/totalZ;
2215 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2217 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2218 //_staticTextInformation->SetLabel(tmpString);
2220 //Extraction data from contours of each slice
2221 contourextractdata->SetZtoBeAnalys( z);
2224 Instant instant(&tempVector);
2225 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2226 sizeLstContourThings = lstContourThings.size();
2228 lstManConMod.clear();
2229 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2231 ContourThing **contourthing = lstContourThings[ii];
2232 lstManConMod.push_back( (*contourthing)->getModel() );
2234 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2237 wxString tempString;
2238 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2239 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2240 //_grid->SetRowLabelValue(z, tempString );
2242 int iContourGroup,sizeContourGroup;
2243 if (typeContourGroup==3) // contour separete
2245 sizeContourGroup=lstManConModExp.size();
2246 if ( maxContourGroup<sizeContourGroup )
2248 maxContourGroup=sizeContourGroup;
2250 } else { // contour AND OR XOR
2259 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2260 lstManConModTmp.clear();
2261 if (typeContourGroup==3) // contour separete
2263 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2264 } else { // contour AND OR XOR
2265 lstManConModTmp = lstManConModExp;
2268 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2271 pLstValuePosX.clear();
2272 pLstValuePosY.clear();
2273 pLstValuePosZ.clear();
2274 contourextractdata->GetValuesInsideCrown( &pLstValue,
2278 // Statistics of each slice.
2279 contourextractdata->Statistics( &pLstValue,
2282 &resultGrayRangeCount,
2287 &resultStandardeviation);
2289 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2291 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2294 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2296 tempString.Printf(_T("%d"),resultSize);
2297 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2299 tempString.Printf(_T("%d"),resultGrayRangeCount);
2300 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2302 tempString.Printf(_T("%f"),resultMin);
2303 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2305 tempString.Printf(_T("%f"),resultMax);
2306 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2308 tempString.Printf(_T("%f"),resultAverage);
2309 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2311 tempString.Printf(_T("%f"),resultStandardeviation);
2312 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2315 } // for iContourGroup
2319 wxString tmpTitleString;
2321 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2323 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2324 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2325 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2327 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2328 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2329 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2330 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2331 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2332 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2333 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2336 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2337 delete contourextractdata;
2340 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2341 SaveValuesXYZ( directory , namefile, typeContourGroup );
2343 vtkImageData* mask, *value;
2344 this->getMaskValue(mask, value, typeContourGroup);
2345 this->SaveImageResult( directory , namefile, mask, value);
2348 FILE *pFile=fopen(filename.c_str(),"w+");
2350 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2353 int i,j,maxX,maxY=sizeZ;
2354 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2356 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2357 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2359 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2360 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2362 fprintf(pFile,"\n" );
2366 for ( j=0; j<maxY ; j++)
2368 fprintf(pFile,"%d\t" , j );
2369 for (i=0 ; i<maxX ; i++){
2370 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2371 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2373 fprintf(pFile,"\n" );
2379 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2382 ContourExtractData *contourextractdata = new ContourExtractData();
2383 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2384 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2386 std::vector<manualContourModel*> lstManConMod;
2387 std::vector<manualContourModel*> lstManConModTmp;
2388 std::vector<manualContourModel*> lstManConModExp;
2389 std::vector<double> pLstValue;
2390 std::vector<double> pLstValuePosX;
2391 std::vector<double> pLstValuePosY;
2392 std::vector<double> pLstValuePosZ;
2394 std::vector<int> tempVector;
2395 _instantPanel->getInstant( tempVector );
2397 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2398 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2400 int ii,sizeLstContourThings;
2407 minZ = 0;// _mbarrange->GetStart();
2408 maxZ = sizeZ;//_mbarrange->GetEnd();
2409 totalZ = maxZ-minZ+1;
2411 contourextractdata->SetImage( imagedata);
2414 for ( z=0 ; z<sizeZ ; z++)
2417 porcent = 100.0* (z-minZ)/totalZ;
2419 tmpString.Printf(_T("Saving Values"));
2420 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2421 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2422 //_staticTextInformation->SetLabel(tmpString);
2425 //Extraction data from contours of each slice
2426 contourextractdata->SetZtoBeAnalys( z);
2429 Instant instant(&tempVector);
2430 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2431 sizeLstContourThings = lstContourThings.size();
2433 lstManConMod.clear();
2434 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2436 ContourThing **contourthing = lstContourThings[ii];
2437 lstManConMod.push_back( (*contourthing)->getModel() );
2439 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2444 int iContourGroup,sizeContourGroup;
2445 if (typeContourGroup==3) // contour separete
2447 sizeContourGroup=lstManConModExp.size();
2448 } else { // contour AND OR XOR
2452 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2453 lstManConModTmp.clear();
2454 if (typeContourGroup==3) // contour separete
2456 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2457 } else { // contour AND OR XOR
2458 lstManConModTmp = lstManConModExp;
2461 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2464 pLstValuePosX.clear();
2465 pLstValuePosY.clear();
2466 pLstValuePosZ.clear();
2467 contourextractdata->GetValuesInsideCrown( &pLstValue,
2472 std::string temp = directory + "/" + namefile + "-slice";
2473 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2474 temp = temp + ".txt";
2476 // LG 14/01/09 : using crea
2477 wxString filename = crea::std2wx(temp);
2478 /*filename.Printf(_T("%s"),directory.c_str());
2479 filename.append(_T("\\"));
2480 filename.append(_T("%s"),namefile.c_str());
2481 filename.append(_T("-slice"));
2482 filename.append(_T("%d"),z);
2483 filename.append(_T("-cont"));
2484 filename.append(_T("%d"),iContourGroup);
2485 filename.append(_T(".txt"));*/
2486 // filename.Printf(temp.c_str());
2490 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2491 fprintf(pFile,"value \t x \t y \t z\n" );
2492 int iLstValue,sizeLstValue=pLstValue.size();
2493 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2495 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2498 } // for iContourGroup
2500 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2501 //_staticTextInformation->SetLabel( _T("") );
2502 delete contourextractdata;
2505 void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){
2507 ContourExtractData *contourextractdata = new ContourExtractData( true );
2508 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2509 if (typeContourGroup==3)
2513 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2515 std::vector<manualContourModel*> lstManConMod;
2516 std::vector<manualContourModel*> lstManConModTmp;
2517 std::vector<manualContourModel*> lstManConModExp;
2519 std::vector<int> tempVector;
2520 _instantPanel->getInstant( tempVector );
2522 vtkImageData *imagedata = _theViewPanel->getImageData();
2523 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2525 int ii,sizeLstContourThings;
2534 minZ = 0;// _mbarrange->GetStart();
2535 maxZ = sizeZ;//_mbarrange->GetEnd();
2536 totalZ = maxZ-minZ+1;
2538 contourextractdata->SetImage( imagedata);
2541 for ( z=0 ; z<sizeZ ; z++)
2544 porcent = 100.0* (z-minZ)/totalZ;
2545 tmpString.Printf(_T("Saving Values"));
2546 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2547 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2549 //Extraction data from contours of each slice
2550 contourextractdata->SetZtoBeAnalys( z);
2553 Instant instant(&tempVector);
2554 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2555 sizeLstContourThings = lstContourThings.size();
2557 lstManConMod.clear();
2558 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2560 ContourThing **contourthing = lstContourThings[ii];
2561 lstManConMod.push_back( (*contourthing)->getModel() );
2563 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2566 int iContourGroup,sizeContourGroup;
2567 if (typeContourGroup==3) // contour separete
2569 sizeContourGroup=lstManConModExp.size();
2570 } else { // contour AND OR XOR
2574 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2575 lstManConModTmp.clear();
2576 if (typeContourGroup==3) // contour separete
2578 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2579 } else { // contour AND OR XOR
2580 lstManConModTmp = lstManConModExp;
2583 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2584 contourextractdata->CalculateImageResult(); // with actual Z
2586 } // for iContourGroup
2589 value = contourextractdata->GetVtkImageValueResult();
2590 mask = contourextractdata->GetVtkImageMaskResult();
2591 delete contourextractdata;
2594 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2597 std::string temp = directory + "/" + namefile + "-Value.mhd";
2599 wxString filename = crea::std2wx(temp);
2601 // filename.Printf(_T(temp.c_str()));
2602 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2603 /*filename.Printf(_T("%s"),directory.c_str());
2604 filename.append(_T("\\"));
2605 filename.append(_T("%s"),namefile.c_str());
2606 filename.append(_T("-Value.mhd"));*/
2609 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2610 writerValueImage->SetInput( value );
2611 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2612 writerValueImage->SetFileDimensionality( 3 );
2613 writerValueImage->Write( );
2616 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2617 temp = directory + "/" + namefile + "-Mask.mhd";
2619 // LG 14/01/09 : using crea
2620 filename = crea::std2wx(temp);
2621 // filename.Printf(_T(temp.c_str()));
2623 /*filename.Printf(_T("%s"),directory.c_str());
2624 filename.append(_T("\\"));
2625 filename.append(_T("%s"),namefile.c_str());
2626 filename.append(_T("-Mask.mhd"));*/
2628 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2629 writerMaskImage->SetInput( mask );
2630 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2631 writerMaskImage->SetFileDimensionality( 3 );
2632 writerMaskImage->Write( );
2634 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2640 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2641 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2642 _theViewPanel->setActualVertical( value);
2644 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2645 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2651 void wxContourMainFrame::onSnakePressed(){
2652 std::vector<double> vecX;
2653 std::vector<double> vecY;
2654 std::vector<double> vecZ;
2655 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2657 if (vecX.size()!=0){
2658 std::vector<int> tempVector;
2659 _instantPanel->getInstant( tempVector );
2660 int i,size=vecZ.size();
2661 int actualSlice = tempVector[1];
2662 for ( i=0 ; i<size ; i++ )
2664 vecZ[i] = actualSlice;
2667 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2668 wxPanel* panel = new wxPanel(dialog,-1);
2669 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2670 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2671 dialog->ShowModal();
2676 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2677 std::string filename = kernelManager->getCurrentFileName();
2678 if(filename.compare("")!=0){
2679 saveFileWithContours(filename);