00001
00002
00003
00004 #include "wxContourMainFrame.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "NameWrapper.h"
00014 #include "wx/artprov.h"
00015 #include "ConceptDataWrap.h"
00016 #include <creaWx.h>
00017
00018 #include <string>
00019 using namespace std;
00020
00021
00022
00023
00026
00027
00028
00029
00030 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
00031 char wxContourMainFrame::COPY = 'C';
00032
00033 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
00034
00035
00036 : wxPanel(parent, id, pos, size, style)
00037 {
00038 m_mgr.SetManagedWindow(this);
00039 _contourGroup = 1;
00040 _creatingContoursActive = false;
00041 _theViewPanel = NULL;
00042
00043 _instantPanel = NULL;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 _numberOfVariablesStatistics = 6+1;
00055
00056 _refLineControl = NULL;
00057 _refLineModel = NULL;
00058 _refLineView = NULL;
00059
00060
00061
00062
00063
00064
00065
00066 _contourextractdata = NULL;
00067 _viewMaskImage = NULL;
00068 _viewMaskImagePanel = NULL;
00069 _viewThresholdImage = NULL;
00070 _viewThresholdImagePanel = NULL;
00071 _viewColorLayerImage = NULL;
00072 _viewColorLayerImagePanel = NULL;
00073 }
00074
00075 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
00076 : wxPanel(parent, id, pos, size, style)
00077 {
00078 m_mgr.SetManagedWindow(this);
00079 _contourGroup = 1;
00080 _creatingContoursActive = false;
00081 _theViewPanel = NULL;
00082
00083 _instantPanel = NULL;
00084 _refLineControl = NULL;
00085 _refLineModel = NULL;
00086 _refLineView = NULL;
00087
00088 _viewMaskImage = NULL;
00089 _viewMaskImagePanel = NULL;
00090 _viewThresholdImage = NULL;
00091 _viewThresholdImagePanel = NULL;
00092 _viewColorLayerImage = NULL;
00093 _viewColorLayerImagePanel = NULL;
00094
00095
00096 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
00097 m_notebook_theme = 0;
00098
00099 _numberOfVariablesStatistics = 7;
00100
00101 _datadir = datadir;
00102
00103
00104 inredo = 0;
00105 inundo = 0;
00106
00107 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");
00108 _performingOperation = new PerformingOperation();
00109
00110 if(images.size() > 0)
00111 {
00112 this->setVectImages(images);
00113 }
00114
00115 _contourextractdata = NULL;
00116 }
00117
00118 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
00119 {
00120
00121 _images = imgs;
00122
00123 #if defined(__GNUC__)
00124 std::string str_home(getenv("HOME"));
00125 #elif defined(_WIN32)
00126 std::string str_home(getenv("USERPROFILE"));
00127 #endif
00128 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
00129
00130 std::vector<std::string> conceptNameVect;
00131 std::vector<int> conceptSizeVect;
00132
00133 notebook = this->createNotebook();
00134
00135
00136 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
00137
00138
00139 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
00140 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
00141
00142
00143 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
00144 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
00145
00146
00147 double val = _theViewPanel->getCurrentDeep();
00148 _instantPanel->setConceptValue( "Axe Depth", (int)val );
00149
00150 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
00151
00152 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
00153
00154 this->configurePanels( );
00155
00156 }
00157
00158
00159 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 )
00160 {
00161 if(instance == NULL){
00162 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
00163 }
00164 return instance;
00165 }
00166
00167 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
00168 {
00169 return kernelManager->getVectImages();
00170 }
00171
00172 wxContourMainFrame* wxContourMainFrame :: getInstance()
00173 {
00174 return instance;
00175 }
00176
00177 void wxContourMainFrame :: resetInstance()
00178 {
00179 instance->Destroy();
00180 }
00181
00182 wxContourMainFrame :: ~wxContourMainFrame()
00183 {
00184 delete _contourextractdata;
00185 deleteAllContours();
00186 _pannew->Close();
00187 interfMainPanel::resetInstance();
00188 delete kernelManager;
00189 instance = NULL;
00190
00191
00192
00193 m_mgr.UnInit();
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 }
00205
00206
00207
00208
00209
00210
00211 wxAuiNotebook * wxContourMainFrame :: createNotebook()
00212 {
00213 wxSize client_size = GetClientSize();
00214 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
00215 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
00216 return noteBook;
00217 }
00218
00219
00220
00221
00222
00223 bool wxContourMainFrame :: configurePanels( )
00224 {
00225 bool configured = _theViewPanel!=NULL;
00226
00227 configured &= _theViewPanel!=NULL;
00228 if( _theViewPanel!=NULL )
00229 {
00230 notebook->AddPage( _theViewPanel, wxT(" View ") );
00231 m_mgr.Update();
00232 }
00233
00234
00235 if( configured )
00236 {
00237 notebook->AddPage( _instantPanel, wxT("Instant Page") );
00238 m_mgr.Update();
00239 }
00240
00241 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
00242 m_mgr.Update();
00243
00244 SetMinSize(wxSize(300,300));
00245 m_mgr.Update();
00246 return configured;
00247 }
00248
00249
00250 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
00251 {
00252 bool configured = panel!=NULL;
00253 configured &= panel!=NULL;
00254
00255 if( configured )
00256 {
00257 notebook->AddPage( panel, wxT(" Viewer "), true );
00258 m_mgr.Update();
00259 }
00260 return configured;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
00270 {
00271 _instantPanel = theInstantChooserPanel;
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 void wxContourMainFrame::onCreateContourSpline( ){
00317
00318
00319 saveState();
00320
00321 createContour( 1 );
00322
00323 }
00324 void wxContourMainFrame::onCreateContourRectangle( ){
00325
00326 saveState();
00327
00328 createContour( 2 );
00329 }
00330 void wxContourMainFrame::onCreateContourCircle( ){
00331
00332 saveState();
00333
00334 createContour( 3 );
00335 }
00336
00337 void wxContourMainFrame::onCreateContourLine( ){
00338
00339 saveState();
00340
00341 createContour( 6 );
00342 }
00343
00344
00345 void wxContourMainFrame::onCreateContourPoints( ){
00346
00347 saveState();
00348
00349 createContour( 7 );
00350 }
00351
00352
00353
00354 void wxContourMainFrame::onCreateContourPolygon( ){
00355
00356 saveState();
00357
00358 createContour( 10 );
00359 }
00360
00361
00362
00363
00364 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
00365 {
00366
00367 manualBaseModel * manModelContour = factoryManualContourModel(panel );
00368
00369 std::vector<int> instantVector;
00370 _instantPanel->getInstant( instantVector );
00371 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
00372
00373
00374
00375
00376
00377 bool addedModel = theName.compare("") != 0;
00378
00379 if( addedModel )
00380 {
00381 double spc[3];
00382 _theViewPanel->getSpacing(spc);
00383
00384
00385
00386 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
00387 }
00388 }
00389 void wxContourMainFrame :: createContour( int typeContour )
00390 {
00391
00392 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
00393
00394 std::vector<int> instantVector;
00395 _instantPanel->getInstant( instantVector );
00396 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
00397
00398
00399
00400
00401
00402 bool addedModel = theName.compare("") != 0;
00403 if( addedModel )
00404 {
00405 double spc[3];
00406 _theViewPanel->getSpacing(spc);
00407
00408
00409
00410 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
00411 }
00412
00413 }
00414 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
00415
00416 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
00417 manualBaseModel *manModelContour=NULL;
00418 manModelContour = manModelContourBullEye;
00419 if (panel!=NULL){
00420 int iCrown,sizeCrowns,iSector,sizeSectors;
00421 double radioA,radioB,ang,angDelta ;
00422 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
00423 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
00424 {
00425 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
00426 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
00427 if (iCrown==sizeCrowns-1)
00428 {
00429 radioA = 0;
00430 } else {
00431 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
00432 }
00433 radioA=radioA/100.0;
00434 radioB=radioB/100.0;
00435 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
00436 {
00437 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
00438 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
00439 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
00440 }
00441 }
00442 }
00443
00444 return manModelContour;
00445 }
00446 void wxContourMainFrame :: saveState(){
00447
00448 std::string temp = kernelManager->saveState();
00449 saveFileWithContours(temp);
00450 }
00451
00452 void wxContourMainFrame::onDeleteContour(){
00453
00454 saveState();
00455
00456
00457 std::vector<std::string> lstKeyNameToBeErase;
00458 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
00459 deleteContours( lstKeyNameToBeErase );
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 }
00503
00504 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
00505 {
00506 int i,size=keyNamesVector.size();
00507 for (i=0;i<size;i++)
00508 {
00509 deleteContour( keyNamesVector[i] );
00510 }
00511 }
00512
00513 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
00524 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
00525
00526 if (isedit && ispartofstaticlst)
00527 {
00528 _theViewPanel->removeFromScene(theKeyName);
00529
00530 kernelManager->deleteCModel(theKeyName);
00531
00532
00533
00534
00535
00536
00537
00538 }
00539
00540 }
00541
00542 void wxContourMainFrame::onDeleteContoursActSlice(){
00543
00544 saveState();
00545
00546 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
00547 }
00548 void wxContourMainFrame::onDeleteAllContours(){
00549
00550 saveState();
00551 deleteAllContours();
00552 }
00553 void wxContourMainFrame::deleteAllContours(){
00554
00555
00556 wxBusyCursor wait;
00557 std::vector<int> tempVector;
00558 _instantPanel->getInstant( tempVector );
00559
00560
00561
00562
00563
00564
00565
00566 int minZ, maxZ;
00567
00568 minZ = 0;
00569 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
00570
00571
00572
00573 _theViewPanel->getSceneManager()->removeSceneContours( );
00574 _theViewPanel->getSceneManager()->removeAllOutlines();
00575 kernelManager->removeAllOutlines();
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600 }
00601
00602 void wxContourMainFrame::setConceptValue( std::string name, int value ){
00603 _instantPanel->setConceptValue(name, value);
00604 }
00605
00606
00607 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
00608 return _instantPanel->getLastConceptData();
00609 }
00610
00611
00612 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
00613 return _instantPanel->getIfConceptCheckedAt( name, pos );
00614 }
00615
00616
00617
00618 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
00619 {
00620 vtkImageData * mask;
00621 vtkImageData * value;
00622 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
00623
00624 std::vector<int> nTypeView;
00625 nTypeView.push_back(5);
00626 nTypeView.push_back(1);
00627 nTypeView.push_back(2);
00628 nTypeView.push_back(0);
00629
00630 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
00631 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
00632 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
00633
00634 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
00635 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
00636
00637 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
00638 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
00639
00640
00641 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
00642 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
00643 m_mgr_noteBookViewerResult->Update();
00644 frame->Show();
00645 }
00646
00647
00648
00649
00650 void wxContourMainFrame::changeInstant()
00651 {
00652 std::vector<int> instantVect;
00653 _instantPanel->getInstant( instantVect );
00654 int actualSlice = instantVect[1];
00655
00656 kernelManager->setInstant(instantVect);
00657
00658
00659 if(_viewMaskImage!=NULL){
00660 _viewMaskImage->SetZ(actualSlice);
00661 if (_viewMaskImagePanel->IsVisible()==true)
00662 {
00663 vtkImageData *mask, *value;
00664 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
00665 _viewMaskImage->onThreshold();
00666 }
00667 }
00668
00669
00670 if(_viewThresholdImage!=NULL){
00671 _viewThresholdImage->SetZ(actualSlice);
00672 if (_viewThresholdImagePanel->IsVisible()==true){
00673 _viewThresholdImage->onThreshold();
00674 }
00675 }
00676
00677
00678 if(_viewColorLayerImage!=NULL){
00679 _viewColorLayerImage->SetZ(actualSlice);
00680 if (_viewColorLayerImagePanel->IsVisible()==true){
00681 _viewColorLayerImage->onThreshold();
00682 }
00683 }
00684
00685 updateInstantOutlines();
00686 updateInstantImageData();
00687 updateInstantAxes();
00688 }
00689
00690
00691
00692 void wxContourMainFrame :: updateInstantOutlines()
00693 {
00694 _theViewPanel->removeSceneContours();
00695 _theViewPanel->addNameWrapperToScene();
00696
00697
00698
00699
00700
00701 }
00702
00703 int wxContourMainFrame::getNamesWrappingSize(){
00704 return kernelManager->getNamesWrappingSize();
00705 }
00706 std::string wxContourMainFrame::getNameWrapping(int i){
00707 return kernelManager->getNameWrapping(i);
00708 }
00709
00710 void wxContourMainFrame::updateInstantImageData()
00711 {
00712 std::vector<int> inst;
00713 _instantPanel->getInstant(inst);
00714
00715 vtkImageData* img = kernelManager->getImageAtInstant(inst);
00716 if(img!=NULL){
00717 _theViewPanel->changeImage(img);
00718 showAxis(false);
00719 }else{
00720 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
00721 _theViewPanel->setImageSlice(z);
00722 }
00723 }
00724
00725 void wxContourMainFrame::updateInstantAxes()
00726 {
00727 }
00728
00729
00730 void wxContourMainFrame::onChangeDeep(int val){
00731 _instantPanel->setConceptValue( "Axe Depth", (int)val );
00732 changeInstant();
00733 }
00734
00735
00736 void wxContourMainFrame::onCopy(){
00737 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
00738
00739 std::vector<int> tempVector;
00740 _instantPanel->getInstant( tempVector );
00741 _performingOperation->reset();
00742 _performingOperation->setStartCommand( COPY );
00743 _performingOperation->setStartOperationInstantVector( tempVector );
00744 _performingOperation->setKeyNamesOperationElems( currentSelection );
00745 }
00746
00747 void wxContourMainFrame::onPaste(){
00748
00749
00750 char theStartCommand = _performingOperation->getStartCommand();
00751 if ( theStartCommand == COPY )
00752 {
00753
00754 saveState();
00755
00756 std::vector<int> tempVector;
00757 _instantPanel->getInstant( tempVector );
00758 _performingOperation->setEndOperationInstantVector ( tempVector );
00759 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
00760 int i,size = elems.size();
00761 for( i=0; i<size; i++ )
00762 {
00763 createCopyContourOf( elems[i], tempVector, i>0 );
00764 }
00765 }
00766 }
00767 void wxContourMainFrame::onUndo(){
00768 std::string filename;
00769 if(kernelManager->onUndoSaveFile(filename)){
00770 saveFileWithContours(filename);
00771 }
00772 if(kernelManager->onUndo(filename)){
00773 loadState(filename);
00774 }
00775 }
00776 void wxContourMainFrame::onRedo(){
00777 std::string filename;
00778 if(kernelManager->onRedo(filename)){
00779 loadState(filename);
00780 }
00781
00782 }
00783 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
00784 {
00785 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
00786 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
00787 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
00788 }
00789
00791 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
00792 {
00793 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
00794 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
00795
00796 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
00797 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
00798
00799 double pnt1X = refPoint1->GetX();
00800 double pnt1Y = refPoint1->GetY();
00801
00802 double pnt2X = refPoint2->GetX();
00803 double pnt2Y = refPoint2->GetY();
00804
00805
00806 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
00807 vtkTransform *t = vtkTransform::New();
00808
00809 t->PostMultiply();
00810 t->Identity();
00811 t->Translate(-pnt1X, -pnt1Y, 0);
00812 t->RotateZ(-angle);
00813 t->Scale(-1,1,1);
00814 t->RotateZ(angle);
00815 t->Translate(pnt1X, pnt1Y, 0);
00816 t->Update();
00817
00818 int i,size=manualModel->GetSizeLstPoints();
00819 for (i=0;i<size;i++)
00820 {
00821 manualPoint * mp = manualModel->GetManualPoint(i);
00822 float vecIn[3];
00823 float vecOut[3];
00824 vecIn[0]=mp->GetX();
00825 vecIn[1]=mp->GetY();
00826 vecIn[2]=mp->GetZ();
00827 t->TransformPoint( vecIn, vecOut );
00828 mp->SetPointX( vecOut[0] );
00829 mp->SetPointY( vecOut[1] );
00830 mp->SetPointZ( vecOut[2] );
00831 }
00832
00833 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
00834 }
00835
00836
00837 void wxContourMainFrame ::loadState(std::string filename){
00838
00839 deleteAllContours();
00840 onLoadContours(filename,false);
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 }
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941 void wxContourMainFrame::onLoad()
00942 {
00943 std::string fileNameContourROI = GetFileLocation();
00944
00945 if(GetFileLocation().empty())
00946 {
00947
00948 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
00949 if (dialog.ShowModal() == wxID_OK)
00950 {
00951 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
00952 }
00953 }
00954
00955 onLoadContours(fileNameContourROI,true);
00956 }
00957
00958
00959 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
00960 {
00961 char tmp[255];
00962 char tmpD[255];
00963
00964 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
00965
00966
00967
00968 if(pFile != NULL)
00969 {
00970
00971 fileNameContourROI.append("data");
00972 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
00973 if(pFileData != NULL)
00974 {
00975 fscanf(pFileData,"%s",tmpD);
00976 fscanf(pFileData,"%s",tmpD);
00977 fscanf(pFileData,"%s",tmpD);
00978
00979 fscanf(pFileData,"%s",tmpD);
00980 fscanf(pFileData,"%s",tmpD);
00981 _onePixelSize = atof(tmpD);
00982 fscanf(pFileData,"%s",tmpD);
00983 fscanf(pFileData,"%s",tmpD);
00984 }
00985
00986 fscanf(pFile,"%s",tmp);
00987
00988 fscanf(pFile,"%s",tmp);
00989 fscanf(pFile,"%s",tmp);
00990 std::string version(tmp);
00991
00992
00993 _tmpReadFileTypeOfTransformation=-1;
00994 if (version=="1.0.3")
00995 {
00996 readDimSpc(pFile,interactiveInterface);
00997 openContours(pFile,pFileData,false);
00998 openContours(pFile,pFileData,true);
00999 }
01000
01001 if (version=="1.0.2")
01002 {
01003
01004 readDimSpc(pFile,interactiveInterface);
01005 openContours(pFile,pFileData,false);
01006 readDimSpc(pFile,false);
01007 openContours(pFile,pFileData,true);
01008 }
01009
01010
01011 else if (version=="1.0.1")
01012 {
01013 openContours(pFile,pFileData,false);
01014 openContours(pFile,pFileData,true);
01015 }
01016
01017
01018 else if (version=="1.0.0")
01019 {
01020 openContours(pFile,pFileData,false);
01021 }
01022
01023 fclose(pFile);
01024
01025 if(pFileData != NULL)
01026 {
01027 fclose(pFileData);
01028 }
01029 }
01030 _theViewPanel->getSceneManager()->removeSceneContours();
01031 changeInstant();
01032
01033 }
01034
01035
01036
01037 void wxContourMainFrame::onImport(){
01038 std::string filename, filenamecontours;
01039 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
01040
01041 if (dialog.ShowModal() == wxID_OK)
01042 {
01043 filename = dialog.GetPath().mb_str();
01044 filenamecontours = kernelManager->parseOsirixFile(filename);
01045
01046 if(filenamecontours.compare("") != 0){
01047 onLoadContours(filenamecontours,true);
01048 }
01049
01050 }
01051 }
01052 void wxContourMainFrame::onTest(){
01053 std::string filename, filenamecontours;
01054 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
01055
01056 if (dialog.ShowModal() == wxID_OK)
01057 {
01058 filename = dialog.GetPath().mb_str();
01059 std::cout << "This is the filename: " << filename << std::endl;
01060 }
01061 }
01062
01063
01064
01065 void wxContourMainFrame::onSave(){
01066
01067 if(GetFileLocation().empty())
01068 {
01069
01070 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
01071 if (dialog.ShowModal() == wxID_OK)
01072 {
01073 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
01074 kernelManager->setCurrentFileName(fileNameContourROI);
01075 saveFileWithContours( fileNameContourROI );
01076 }
01077 }
01078
01079 else
01080 {
01081 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
01082 std::string fileNameContourROI = GetFileLocation();
01083 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
01084 kernelManager->setCurrentFileName(fileNameContourROI);
01085 saveFileWithContours( fileNameContourROI);
01086 }
01087
01088 }
01089
01090
01091 void wxContourMainFrame::saveFileWithContours( std::string filename )
01092 {
01093
01094 FILE *pFile=fopen(filename.c_str(),"w+");
01095
01096
01097 filename.append("data");
01098 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
01099 FILE *pFileData=fopen(filename.c_str(),"w+");
01100
01101
01102 std::vector< std::string > lstNameThings;
01103 int i,sizeLstNameThings;
01104
01105 fprintf(pFile,"--CreaContour--\n");
01106 fprintf(pFile,"Version %s\n", "1.0.3" );
01107
01108
01109 fprintf(pFileData,"--CreaContour--\n");
01110 fprintf(pFileData,"Version %s\n", "1.0.3" );
01111 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
01112
01113
01114
01115 vtkImageData *image = _images[0];
01116
01117 int dimRange[3];
01118 image->GetDimensions(dimRange);
01119
01120 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
01121
01122 double spaRange[3];
01123 image->GetSpacing(spaRange);
01124
01125 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
01126
01127
01128
01129 lstNameThings = kernelManager->GetLstNameThings();
01130 sizeLstNameThings = lstNameThings.size();
01131 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
01132
01133
01134 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
01135
01136
01137 for (i=0 ; i<sizeLstNameThings ; i++)
01138 {
01139
01140 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
01141 double sizeInPixel = manualModel ->GetPathSize();
01142 double realContourSize = sizeInPixel*_onePixelSize;
01143 manualModel ->SetRealSize(realContourSize);
01144
01145
01146
01147
01148 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
01149 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
01150 }
01151
01152
01153
01154
01155
01156
01157 lstNameThings = kernelManager->GetLstNameThingsStatic();
01158 sizeLstNameThings = lstNameThings.size();
01159 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
01160
01161
01162 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
01163
01164
01165 for (i=0 ; i<sizeLstNameThings ; i++)
01166 {
01167 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
01168 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
01169 }
01170 fclose(pFile);
01171 fclose(pFileData);
01172 }
01173
01174
01175
01176 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
01177 {
01178 char tmp[255];
01179 int imageDim[3];
01180 double imageSpac[3];
01181 vtkImageData *image = _images[0];
01182 image->GetDimensions(imageDim);
01183 image->GetSpacing(imageSpac);
01184
01185 fscanf(pFile,"%s",tmp);
01186 fscanf(pFile,"%s",tmp);
01187 _tmpReadFileImageDim[0] = atoi(tmp);
01188 fscanf(pFile,"%s",tmp);
01189 _tmpReadFileImageDim[1] = atoi(tmp);
01190 fscanf(pFile,"%s",tmp);
01191 _tmpReadFileImageDim[2] = atoi(tmp);
01192
01193 fscanf(pFile,"%s",tmp);
01194 fscanf(pFile,"%s",tmp);
01195 _tmpReadFileImageSpac[0] = atof(tmp);
01196 fscanf(pFile,"%s",tmp);
01197 _tmpReadFileImageSpac[1] = atof(tmp);
01198 fscanf(pFile,"%s",tmp);
01199 _tmpReadFileImageSpac[2] = atof(tmp);
01200
01201
01202 if (interactiveOption==true)
01203 {
01204
01205 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
01206 {
01207 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
01208 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
01209 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
01210
01211 wxString lstOptOperation[2];
01212 lstOptOperation[0]=_T("By Dimension");
01213 lstOptOperation[1]=_T("By Spacing");
01214 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
01215
01216 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
01217 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
01218 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
01219 dialSizer->Add(radioOpts,0,wxGROW);
01220 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
01221 dialSizer->Add(buttonsSizer,0,wxGROW);
01222 dial->SetSizer(dialSizer, true);
01223 dial->Layout();
01224 dial->ShowModal();
01225
01226 int _tmpReadFileTypeOfTransformation = -1;
01227
01228
01229 if (dial->GetReturnCode() == wxID_OK)
01230 {
01231 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
01232 }
01233
01234 }
01235 }
01236 }
01237
01238
01239
01240
01241
01242 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
01243 {
01244
01245 char tmp[255];
01246
01247 vtkImageData *image = _images[0];
01248
01249 int imageDim[3];
01250 double imageSpac[3];
01251 image->GetDimensions(imageDim);
01252 image->GetSpacing(imageSpac);
01253
01254
01255 fscanf(pFile,"%s",tmp);
01256 fscanf(pFile,"%s",tmp);
01257 int numberOfContours = atoi(tmp);
01258
01259 std::vector<int> instantVector;
01260 int typeContourModel;
01261 manualBaseModel *manModelContour;
01262 int typeView;
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328 int i;
01329 for (i=0;i<numberOfContours;i++)
01330 {
01331 instantVector.clear();
01332 fscanf(pFile,"%s",tmp);
01333
01334 fscanf(pFile,"%s",tmp);
01335 instantVector.push_back( atoi(tmp) );
01336 fscanf(pFile,"%s",tmp);
01337 instantVector.push_back( atoi(tmp) );
01338 fscanf(pFile,"%s",tmp);
01339 instantVector.push_back( atoi(tmp) );
01340 fscanf(pFile,"%s",tmp);
01341 instantVector.push_back( atoi(tmp) );
01342 fscanf(pFile,"%s",tmp);
01343 instantVector.push_back( atoi(tmp) );
01344 fscanf(pFile,"%s",tmp);
01345 instantVector.push_back( atoi(tmp) );
01346
01347 fscanf(pFile,"%s",tmp);
01348 fscanf(pFile,"%s",tmp);
01349 typeContourModel = atoi(tmp);
01350
01351 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
01352 manModelContour->Open(pFile);
01353 if(pFileData != NULL)
01354 {
01355 manModelContour->OpenData(pFileData);
01356 }
01357
01358 if (_tmpReadFileTypeOfTransformation==-1){
01359
01360 } else if (_tmpReadFileTypeOfTransformation==0){
01361 double transX, transY;
01362 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
01363 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
01364 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
01365 } else if (_tmpReadFileTypeOfTransformation==1) {
01366 double transX, transY;
01367 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
01368 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
01369 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
01370 }
01371
01372 fscanf(pFile,"%s",tmp);
01373 fscanf(pFile,"%s",tmp);
01374 typeView = atoi(tmp);
01375
01376 std::string theName;
01377 theName = kernelManager->createOutline( manModelContour, instantVector );
01378 bool addedModel = theName.compare("") != 0;
01379 if( addedModel )
01380 {
01381 double spc[3];
01382 _theViewPanel->getSpacing(spc);
01383
01384
01385
01386 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
01387 }
01388
01389 if (staticContour)
01390 {
01391 Instant instant(&instantVector);
01392 kernelManager->changeContourOfManager( theName , &instant );
01393 }
01394 }
01395
01396
01397
01398 }
01399
01400 void wxContourMainFrame::RefreshInterface(){
01401 changeInstant();
01402 _theViewPanel->RefreshInterface();
01403
01404
01405 }
01406
01407 vtkImageData* wxContourMainFrame::getImageData(){
01408 return _theViewPanel->getImageData();
01409 }
01410
01411 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
01412 {
01413
01414 saveState();
01415
01416
01417 wxBusyCursor wait;
01418 int x = _theViewPanel->GetX();
01419 int y = _theViewPanel->GetY();
01420 int z = _theViewPanel->GetZ();
01421 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
01422 RefreshInterface();
01423 }
01424
01425 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
01426 {
01427 int typeofcontour = 1;
01428
01429 vtkImageData *imagedata = getImageData();
01430
01431
01432 typedef float InternalPixelType;
01433 const unsigned int Dimension = 2;
01434 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
01435
01436
01437 typedef unsigned char OutputPixelType;
01438 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
01439
01440
01441 typedef unsigned short OutputPixelType2;
01442 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
01443
01444
01445 typedef itk::BinaryThresholdImageFilter<
01446 InternalImageType,
01447 OutputImageType > ThresholdingFilterType;
01448
01449
01450 typedef itk::CastImageFilter<
01451 OutputImageType, OutputImageType2 > CastFilterType;
01452
01453
01454 typedef itk::CastImageFilter<
01455 OutputImageType2, InternalImageType > CastFilterType2;
01456
01457
01458 typedef itk::RescaleIntensityImageFilter<
01459 InternalImageType,
01460 OutputImageType > CastFilterType3;
01461
01462
01463 typedef itk::RescaleIntensityImageFilter<
01464 OutputImageType,
01465 OutputImageType > CastFilterType4;
01466
01467 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
01468
01469 thresholder->SetLowerThreshold( 0.0 );
01470 thresholder->SetUpperThreshold( 128 );
01471
01472 thresholder->SetOutsideValue( 255 );
01473 thresholder->SetInsideValue( 0 );
01474
01475
01476 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
01477 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
01478
01479
01480 ConnectorType::Pointer connector= ConnectorType::New();
01481 ConnectorType2::Pointer connector2= ConnectorType2::New();
01482
01483
01484 CastFilterType::Pointer filter=CastFilterType::New();
01485 CastFilterType2::Pointer filter2=CastFilterType2::New();
01486
01487 connector->SetInput( imagedata );
01488 filter2->SetInput(connector->GetOutput());
01489
01490 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
01491 InternalImageType,
01492 InternalImageType > SmoothingFilterType;
01493
01494 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
01495
01496 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
01497 InternalImageType,
01498 InternalImageType > GradientFilterType;
01499
01500 typedef itk::SigmoidImageFilter<
01501 InternalImageType,
01502 InternalImageType > SigmoidFilterType;
01503
01504 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
01505
01506 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
01507
01508 sigmoid->SetOutputMinimum( 0.0 );
01509 sigmoid->SetOutputMaximum( 255.0 );
01510
01511
01512 typedef itk::FastMarchingImageFilter<
01513 InternalImageType,
01514 InternalImageType > FastMarchingFilterType;
01515
01516
01517 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
01518
01519 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
01520 InternalImageType > GeodesicActiveContourFilterType;
01521 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
01522 GeodesicActiveContourFilterType::New();
01523
01524 typedef itk::ZeroCrossingImageFilter<
01525 InternalImageType,
01526 InternalImageType > ZeroCrossingFilterType;
01527 ZeroCrossingFilterType::Pointer zeroCrossing =
01528 ZeroCrossingFilterType::New();
01529
01530 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
01531
01532 geodesicActiveContour->SetPropagationScaling( propagationScaling );
01533 geodesicActiveContour->SetCurvatureScaling( 1.0 );
01534 geodesicActiveContour->SetAdvectionScaling( 1.0 );
01535
01536 geodesicActiveContour->SetMaximumRMSError( 0.02 );
01537 int it=atoi( crea::wx2std(iter).c_str() );
01538 geodesicActiveContour->SetNumberOfIterations( it );
01539
01540 smoothing->SetInput( filter2->GetOutput() );
01541 gradientMagnitude->SetInput( smoothing->GetOutput() );
01542 sigmoid->SetInput( gradientMagnitude->GetOutput() );
01543 fastMarching->SetInput( sigmoid->GetOutput() );
01544 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
01545 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
01546
01547 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
01548
01549 thresholder->SetInput( geodesicActiveContour->GetOutput() );
01550 connector2->SetInput( thresholder->GetOutput() );
01551
01552
01553 smoothing->SetTimeStep( 0.125 );
01554 smoothing->SetNumberOfIterations( 5 );
01555 smoothing->SetConductanceParameter( 9.0 );
01556
01557
01558 const double sigma = atof( crea::wx2std(sigm).c_str() );
01559 gradientMagnitude->SetSigma( sigma );
01560
01561 const double alpha = atof( crea::wx2std(alf).c_str() );
01562 const double beta = atof( crea::wx2std(bet).c_str() );
01563
01564 sigmoid->SetAlpha( alpha );
01565 sigmoid->SetBeta( beta );
01566
01567 typedef FastMarchingFilterType::NodeContainer NodeContainer;
01568 typedef FastMarchingFilterType::NodeType NodeType;
01569
01570 NodeContainer::Pointer seeds = NodeContainer::New();
01571
01572 InternalImageType::IndexType seedPosition;
01573 seedPosition[0] = x;
01574 seedPosition[1] = y;
01575
01576 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
01577
01578 NodeType node;
01579
01580 const double seedValue = - initialDistance;
01581
01582 node.SetValue( seedValue );
01583 node.SetIndex( seedPosition );
01584
01585 seeds->Initialize();
01586 seeds->InsertElement( 0, node );
01587
01588 fastMarching->SetTrialPoints( seeds );
01589
01590 fastMarching->SetSpeedConstant( 1.0 );
01591
01592 fastMarching->SetOutputSize(
01593 connector->GetOutput()->GetBufferedRegion().GetSize() );
01594
01595 fastMarching->SetStoppingValue( 800 );
01596 try
01597 {
01598
01599 connector2->Update();
01600 vtkImageData *idata = connector2->GetOutput();
01601
01602 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
01603
01604 cntVTK->SetInput( idata );
01605
01606 cntVTK->SetNumberOfContours( 1 );
01607 cntVTK->SetValue( 0, 255 );
01608 cntVTK->Update( );
01609 cntVTK->UpdateInformation();
01610
01611 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
01612 cpd->SetInput( cntVTK->GetOutput( ) );
01613 cpd->Update( );
01614 cpd->UpdateInformation();
01615
01616 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
01617 conn->SetExtractionModeToLargestRegion( );
01618 conn->SetInput( cpd->GetOutput( ) );
01619 conn->Update( );
01620 conn->UpdateInformation();
01621
01622 vtkStripper* vtkstripper = vtkStripper::New( );
01623 vtkstripper->SetInput( conn->GetOutput() );
01624 vtkstripper->Update();
01625 vtkstripper->UpdateInformation();
01626
01627 vtkPolyData* polyDataResult = cntVTK->GetOutput();
01628
01629 polyDataResult->Update( );
01630 polyDataResult->UpdateInformation();
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642 cntVTK -> Delete();
01643 cpd -> Delete();
01644 conn -> Delete();
01645
01646
01647
01648
01649 std::vector<double> vecX;
01650 std::vector<double> vecY;
01651 std::vector<double> vecXo;
01652 std::vector<double> vecYo;
01653 std::vector<double>::iterator vecXoi;
01654 std::vector<double>::iterator vecYoi;
01655 std::vector<double> vecZ;
01656
01657 std::vector<double> vecCtrlPointX;
01658 std::vector<double> vecCtrlPointY;
01659 std::vector<double> vecCtrlPointZ;
01660
01661
01662 double *p;
01663 double xAct=0;
01664 double yAct=0;
01665 int ii,size=polyDataResult->GetNumberOfPoints();
01666 ofstream myfile;
01667 myfile.open ("C:/Creatis/example2.txt");
01668
01669 size=polyDataResult->GetNumberOfPoints();
01670 for (ii=0;ii<size;ii++)
01671 {
01672 if(ii==0)
01673 {
01674 xAct=x;
01675 yAct=y;
01676 }
01677 p = polyDataResult->GetPoint(ii);
01678 double x=p[0];
01679 double y=p[1];
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701 if(fabs(xAct-x)>11)
01702 {
01703 vecXo.push_back(p[0]);
01704 vecYo.push_back(p[1]);
01705 }
01706 else
01707 {
01708 vecX.push_back( p[0] );
01709 myfile <<p[0]<<","<<p[1]<<"\n";
01710
01711
01712
01713 vecY.push_back( p[1] );
01714 vecZ.push_back( 900 );
01715 xAct=x;
01716 yAct=y;
01717 }
01718
01719
01720 }
01721
01722 while(!vecXo.empty())
01723 {
01724 vecX.push_back(vecXo.back());
01725
01726 vecXo.pop_back();
01727 vecZ.push_back( 900 );
01728 }
01729 while(!vecYo.empty())
01730 {
01731 vecY.push_back(vecYo.back());
01732 vecYo.pop_back();
01733 }
01734 myfile.close();
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
01753
01754 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
01755
01756 int method=2;
01757 if (method==0){
01758 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01759 }
01760 else if (method==1){
01761 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01762 }
01763 else if (method==2){
01764 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
01765 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
01766 }
01767
01768
01769 std::vector<int> actualInstantVector;
01770 _instantPanel->getInstant( actualInstantVector );
01771 actualInstantVector[1]=z;
01772
01773 int j,sizeCtrPt = vecCtrlPointX.size();
01774
01775 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
01776 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
01777 if (sizeCtrPt>=3){
01778 for (j=0 ; j<sizeCtrPt ; j++)
01779 {
01780 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
01781 }
01782 std::string theName;
01783
01784 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
01785 bool addedModel = theName.compare("") != 0;
01786 if( addedModel )
01787 {
01788 double spc[3];
01789 _theViewPanel->getSpacing(spc);
01790
01791
01792
01793 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
01794
01795 }
01796 }
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851 }
01852 catch( itk::ExceptionObject & excep )
01853 {
01854 std::cerr << "Exception caught !" << std::endl;
01855 std::cerr << excep << std::endl;
01856 }
01857 }
01858
01859 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
01860
01861
01862 saveState();
01863
01864
01865 wxBusyCursor wait;
01866 int x = _theViewPanel->GetX();
01867 int y = _theViewPanel->GetY();
01868 int z = _theViewPanel->GetZ();
01869 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
01870 RefreshInterface();
01871 }
01872
01873
01874 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
01875 {
01876 int typeofcontour = 1;
01877
01878
01879 vtkImageData *imagedata = getImageData();
01880
01881
01882
01883 vtkImageReslice *imageReslice = vtkImageReslice::New();
01884
01885
01886
01887
01888
01889
01890
01891 imageReslice->SetInput( imagedata );
01892 imageReslice->SetInformationInput(imagedata);
01893 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
01894 imageReslice->SetResliceAxesOrigin(0,0,z);
01895 imageReslice->SetOutputDimensionality(2);
01896 imageReslice->SetInterpolationModeToLinear();
01897
01898 imagedata = imageReslice->GetOutput();
01899 imagedata->Update();
01900 imagedata->UpdateInformation();
01901
01902 vtkContourFilter* cntVTK = vtkContourFilter::New( );
01903 cntVTK->SetInput( imagedata );
01904
01905 cntVTK->SetNumberOfContours( 1 );
01906
01907
01908 cntVTK->SetValue( 1, isovalue );
01909
01910 cntVTK->Update( );
01911 cntVTK->UpdateInformation();
01912
01913 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
01914 cpd->SetInput( cntVTK->GetOutput( ) );
01915 cpd->ConvertLinesToPointsOff( );
01916 cpd->Update( );
01917 cpd->UpdateInformation();
01918
01919 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
01920 conn->SetExtractionModeToClosestPointRegion( );
01921
01922
01923 conn->SetInput( cpd->GetOutput( ) );
01924
01925 conn->SetClosestPoint( x, y, 0 );
01926 conn->Update( );
01927 conn->UpdateInformation();
01928
01929 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
01930 cpd2->SetInput( conn->GetOutput( ) );
01931 cpd2->Update();
01932 cpd2->UpdateInformation();
01933
01934 vtkStripper* vtkstripper = vtkStripper::New( );
01935 vtkstripper->SetInput( cpd2->GetOutput() );
01936 vtkstripper->Update();
01937 vtkstripper->UpdateInformation();
01938
01939
01940 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
01941
01942 polyDataResult->Update( );
01943 polyDataResult->UpdateInformation();
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955 cntVTK -> Delete();
01956 cpd2 -> Delete();
01957 cpd -> Delete();
01958 conn -> Delete();
01959
01960
01961
01962
01963 std::vector<double> vecX;
01964 std::vector<double> vecY;
01965 std::vector<double> vecZ;
01966
01967 std::vector<double> vecCtrlPointX;
01968 std::vector<double> vecCtrlPointY;
01969 std::vector<double> vecCtrlPointZ;
01970
01971
01972 double *p;
01973 int ii,size=polyDataResult->GetNumberOfPoints();
01974 int id;
01975 for (ii=1;ii<=size;ii++)
01976 {
01977 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
01978 p = polyDataResult->GetPoint(id);
01979
01980
01981 vecX.push_back( p[0] );
01982 vecY.push_back( p[1] );
01983 vecZ.push_back( 900 );
01984
01985 }
01986
01987
01988 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
01989 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003 if (method==0){
02004 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02005 }
02006 else if (method==1){
02007 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02008 }
02009 else if (method==2){
02010 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
02011 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
02012 }
02013
02014
02015
02016 std::vector<int> actualInstantVector;
02017 _instantPanel->getInstant( actualInstantVector );
02018 actualInstantVector[1]=z;
02019
02020 int j,sizeCtrPt = vecCtrlPointX.size();
02021 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
02022 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
02023 if (sizeCtrPt>=3){
02024 for (j=0 ; j<sizeCtrPt ; j++)
02025 {
02026 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
02027 }
02028 std::string theName;
02029
02030 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
02031 bool addedModel = theName.compare("") != 0;
02032 if( addedModel )
02033 {
02034 double spc[3];
02035 _theViewPanel->getSpacing(spc);
02036
02037
02038
02039 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
02040
02041 }
02042 }
02043 }
02044 int wxContourMainFrame::GetImageDataSizeZ(){
02045 return _theViewPanel->GetImageDataSizeZ();
02046 }
02047
02048 void wxContourMainFrame::GetImageDataRange(double *range){
02049 _theViewPanel->GetImageDataRange(range);
02050 }
02051
02052 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
02053
02054 saveState();
02055
02056
02057 wxBusyCursor wait;
02058 int x = _theViewPanel->GetX();
02059 int y = _theViewPanel->GetY();
02060 int z;
02061 double porcent;
02062 wxString tmpString;
02063 double totalZ = maxZ-minZ+1;
02064 for( z=minZ ; z<=maxZ ; z++ )
02065 {
02066 porcent = 100.0* (z-minZ)/totalZ;
02067 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
02068 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
02069
02070 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
02071 }
02072 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
02073 RefreshInterface();
02074 }
02075
02076
02077
02078 void wxContourMainFrame::referenceLine()
02079 {
02080 if (_refLineControl==NULL)
02081 {
02082 wxBusyCursor wait;
02083 double spc[3];
02084
02085 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
02086 vtkimagedata->GetSpacing(spc);
02087
02088 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
02089
02090 _refLineControl = new manualLineControler();
02091 _refLineModel = new manualContourModelLine();
02092 _refLineView = new manualViewLine();
02093 _refLineView->SetModel( _refLineModel );
02094 _refLineView->SetWxVtkBaseView( viewer2D );
02095 _refLineView->SetRange( 2 );
02096 _refLineView->SetZ( 1200 );
02097
02098 _refLineView->SetSpacing(spc);
02099
02100 _refLineView->SetColorNormalContour(0, 0, 1);
02101 _refLineView->SetColorEditContour(0, 0.5, 0.5);
02102 _refLineView->SetWidthLine(4);
02103
02104 _refLineControl->SetModelView( _refLineModel , _refLineView );
02105 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
02106 style->AddInteractorStyleMaracas( _refLineControl );
02107 _refLineModel->SetCloseContour(false);
02108 _refLineControl->CreateNewManualContour();
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132 _refLineControl->SetActive(true);
02133 _refLineView->RefreshContour();
02134 }
02135 }
02136
02137
02138 void wxContourMainFrame::refLineHide()
02139 {
02140 if (_refLineControl!=NULL)
02141 {
02142 if (_refLineControl->GetActive())
02143 {
02144 _refLineView->RemoveCompleteContourActor();
02145 _refLineControl->SetEditable(false);
02146 _refLineControl->SetActive(false);
02147
02148 RefreshInterface();
02149 }
02150 }
02151 }
02152
02153
02154 void wxContourMainFrame::refLineShow()
02155 {
02156 if (_refLineControl!=NULL)
02157 {
02158 if (_refLineControl->GetActive()==false)
02159 {
02160 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
02161
02162 _refLineView->SetModel( _refLineModel );
02163 _refLineView->SetWxVtkBaseView( viewer2D );
02164 _refLineView->SetRange( 2 );
02165 _refLineView->SetZ( 1200 );
02166
02167 _refLineControl->SetModelView( _refLineModel , _refLineView );
02168 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
02169 style->AddInteractorStyleMaracas( _refLineControl );
02170 _refLineControl->CreateNewManualContour();
02171 _refLineControl->SetActive(true);
02172 _refLineView->RefreshContour();
02173
02174 RefreshInterface();
02175 }
02176 }
02177 }
02178
02179 void wxContourMainFrame::refLineChangeWidth(int width)
02180 {
02181 _refLineView->SetWidthLine(width);
02182 _refLineView->RefreshContour();
02183
02184 RefreshInterface();
02185 }
02186
02187
02188 void wxContourMainFrame::onMirror()
02189 {
02190
02191 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
02192 std::vector<std::string> filterCurrentSelection;
02193
02194 std::vector<int> tempVector;
02195 _instantPanel->getInstant( tempVector );
02196 _performingOperation->reset();
02197 _performingOperation->setStartCommand( COPY );
02198 _performingOperation->setStartOperationInstantVector( tempVector );
02199 _performingOperation->setKeyNamesOperationElems( currentSelection );
02200
02201 char theStartCommand = _performingOperation->getStartCommand();
02202 if ( theStartCommand == COPY )
02203 {
02204
02205 saveState();
02206
02207 std::vector<int> tempVector;
02208 _instantPanel->getInstant( tempVector );
02209 _performingOperation->setEndOperationInstantVector ( tempVector );
02210 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
02211 int i,size = elems.size();
02212 for( i=0; i<size; i++ )
02213 {
02214 createMirrorContourOf( elems[i], tempVector, i>0 );
02215 }
02216 }
02217
02218
02219
02220 }
02221
02222
02223 void wxContourMainFrame::showAxis(bool show)
02224 {
02225 _theViewPanel->SetVisibleAxis(show);
02226 _theViewPanel->Refresh();
02227 }
02228
02229
02230 void wxContourMainFrame::onRigidPressed(){
02231 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
02232 int elementsSelected = currentSelection.size();
02233
02234 if ( elementsSelected >= 1 ){
02235
02236 saveState();
02237
02238
02239 std::vector<int> tempVector;
02240 _instantPanel->getInstant( tempVector );
02241 Instant instant(&tempVector);
02242
02243 int i , size=currentSelection.size();
02244 for ( i=0 ; i<size ; i++ )
02245 {
02246 kernelManager->changeContourOfManager(currentSelection[i], &instant);
02247 }
02248 }
02249 }
02250
02251 void wxContourMainFrame::onWidthOfContour(double width){
02252
02253 _theViewPanel->removeSceneContours();
02254 _theViewPanel->SetWidthContour(width);
02255
02256
02257
02258 RefreshInterface();
02259 }
02260
02261 int wxContourMainFrame::getColorWindow()
02262 {
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272 return _theViewPanel->getColorWindow();
02273 }
02274
02275 int wxContourMainFrame::getWindowLevel()
02276 {
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286 return _theViewPanel->getWindowLevel();
02287 }
02288
02289 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
02290 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
02291
02292 RefreshInterface();
02293 }
02294
02295 void wxContourMainFrame::onInterpolation(bool interpolate){
02296 _theViewPanel->onInterpolation(interpolate);
02297 RefreshInterface();
02298 }
02299
02300 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
02301 _instantPanel->setConceptValue( name, actual );
02302 }
02303
02304
02305 void wxContourMainFrame::resetAppend(){
02306 kernelManager->resetAppend();
02307
02308 }
02309
02310
02311 void wxContourMainFrame::onSpreadAdd(){
02312 std::vector<double> vecX;
02313 std::vector<double> vecY;
02314 std::vector<double> vecZ;
02315 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
02316 std::vector<int> tempVector;
02317 _instantPanel->getInstant( tempVector );
02318 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
02319 interfMainPanel::getInstance()->appendStringSpread(val);
02320 }
02321
02322
02323 void wxContourMainFrame::onSpreadAddAll(){
02324
02325 std::vector<int> tempVector;
02326 _instantPanel->getInstant( tempVector );
02327 int minZ,maxZ;
02328 minZ = 0;
02329 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
02330 int z;
02331 int sizeLstContourThings;
02332 for ( z=minZ ; z<=maxZ ; z++ )
02333 {
02334 tempVector[1]=z;
02335 Instant instant(&tempVector);
02336 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
02337 sizeLstContourThings = lstContourThings.size();
02338 if (sizeLstContourThings>=1)
02339 {
02340 std::vector<double> vecX;
02341 std::vector<double> vecY;
02342 std::vector<double> vecZ;
02343 ContourThing **contourthing = lstContourThings[0];
02344 manualBaseModel *cModel = (*contourthing)->getModel();
02345 int i,size = cModel->GetNumberOfPointsSpline();
02346 double x,y,z;
02347 for (i=0; i<size; i++)
02348 {
02349 cModel->GetSpline_i_Point(i, &x, &y, &z);
02350 vecX.push_back(x);
02351 vecY.push_back(y);
02352 vecZ.push_back(z);
02353 }
02354 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
02355 interfMainPanel::getInstance()->appendStringSpread(val);
02356 }
02357 }
02358 }
02359
02360
02361 void wxContourMainFrame::onSpreadGo(int type){
02362
02363 saveState();
02364
02365 wxBusyCursor wait;
02366 std::vector<double> vecCtrlPointX;
02367 std::vector<double> vecCtrlPointY;
02368 std::vector<double> vecCtrlPointZ;
02369 double minZ,maxZ;
02370 int z;
02371
02372 std::vector<int> tempVector;
02373 _instantPanel->getInstant( tempVector );
02374
02375
02376 kernelManager->getMaxMinZ(&minZ,&maxZ);
02377
02378
02379 kernelManager->CalculeSplinePropagation();
02380
02381 double totalZ = maxZ-minZ+1;
02382 double porcent;
02383 wxString tmpString;
02384
02385 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
02386 {
02387 porcent = 100.0* (z-minZ)/totalZ;
02388 int numero = (int)(z-minZ+1)/(int)totalZ;
02389 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
02390
02391 interfMainPanel::getInstance()->setStringSpread(stringtemp);
02392
02393 int typeofcontour = 1;
02394 std::string theName;
02395 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
02396
02397 if( manModelContour!=NULL ){
02398 double spc[3];
02399 this->_theViewPanel->getSpacing(spc);
02400
02401
02402
02403 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
02404 }
02405 }
02406 if(z > maxZ){
02407 porcent = 100.0;
02408 int numero = (int)(z-minZ+1)/(int)totalZ;
02409 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
02410
02411 interfMainPanel::getInstance()->setStringSpread(stringtemp);
02412 }
02413
02414 }
02415
02416 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
02417
02418 }
02419
02420 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
02421 std::vector<int> tempVector;
02422 _instantPanel->getInstant(tempVector);
02423
02424 tempVector[1]=slide;
02425 return kernelManager->getOutlinesNameAtInstant(tempVector);
02426 }
02427
02428
02429 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
02430 {
02431 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
02432 }
02433
02434
02435 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
02436 {
02437
02438
02439 wxString tempString;
02440 int maxContourGroup = 0;
02441
02442 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
02443
02444 std::vector<manualBaseModel*> lstManConMod;
02445 std::vector<manualBaseModel*> lstManConModTmp;
02446 std::vector<manualBaseModel*> lstManConModExp;
02447 std::vector<double> pLstValue;
02448 std::vector<double> pLstValuePosX;
02449 std::vector<double> pLstValuePosY;
02450 std::vector<double> pLstValuePosZ;
02451
02452 int resultSize;
02453 int resultGrayRangeCount;
02454 double resultMin;
02455 double resultMax;
02456 double resultAverage;
02457 double resultStandardeviation;
02458
02459 std::vector<int> tempVector;
02460 _instantPanel->getInstant( tempVector );
02461
02462
02463
02464 int z;
02465 int ii,sizeLstContourThings;
02466
02467
02468 int minZ,maxZ;
02469 double totalZ;
02470 double porcent;
02471 wxString tmpString;
02472
02473
02474 if (selection==0 )
02475 {
02476 int actualSlice = tempVector[1];
02477 minZ = actualSlice;
02478 maxZ = actualSlice;
02479 } else {
02480 minZ = minimumZ;
02481 maxZ = maximumZ;
02482 }
02483
02484
02485 totalZ = maxZ-minZ+1;
02486
02487
02488 _contourextractdata->InitVolumeStatistics();
02489
02490
02491 for ( z=minZ ; z<=maxZ ; z++ )
02492 {
02493
02494 porcent = 100.0* (z-minZ)/totalZ;
02495 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
02496
02497 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
02498
02499
02500
02501 _contourextractdata->SetZtoBeAnalys(z);
02502
02503 tempVector[1]=z;
02504 Instant instant(&tempVector);
02505 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
02506 sizeLstContourThings = lstContourThings.size();
02507
02508 lstManConMod.clear();
02509 for (ii=0 ; ii<sizeLstContourThings ; ii++)
02510 {
02511 ContourThing **contourthing = lstContourThings[ii];
02512 lstManConMod.push_back( (*contourthing)->getModel() );
02513 }
02514
02515 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
02516
02517 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
02518 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
02519
02520
02521 int iContourGroup,sizeContourGroup;
02522 if (typeContourGroup==3)
02523 {
02524 sizeContourGroup=lstManConModExp.size();
02525 if ( maxContourGroup<sizeContourGroup )
02526 {
02527 maxContourGroup=sizeContourGroup;
02528 }
02529 } else {
02530 sizeContourGroup=1;
02531 maxContourGroup=1;
02532 }
02533
02534 int tmpIntA;
02535
02536 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
02537 lstManConModTmp.clear();
02538
02539
02540
02541 if (typeContourGroup==3)
02542 {
02543 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
02544 } else {
02545 lstManConModTmp = lstManConModExp;
02546 }
02547
02548 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
02549 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
02550
02551 pLstValue.clear();
02552 pLstValuePosX.clear();
02553 pLstValuePosY.clear();
02554 pLstValuePosZ.clear();
02555
02556
02557 int numberOfPixels;
02558 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
02559 &pLstValue,
02560 &pLstValuePosX,
02561 &pLstValuePosY,
02562 &pLstValuePosZ);
02563
02564 resultSize=numberOfPixels;
02565
02566 _contourextractdata->Statistics( &pLstValue,
02567 grayRangeMin,
02568 grayRangeMax,
02569 &resultGrayRangeCount,
02570 &resultSize,
02571 &resultMin,
02572 &resultMax,
02573 &resultAverage,
02574 &resultStandardeviation);
02575
02576 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
02577 {
02578 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
02579 }
02580
02581 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
02582
02583 tempString.Printf(_T("%d"),numberOfPixels);
02584
02585 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
02586
02587 tempString.Printf(_T("%d"),resultGrayRangeCount);
02588 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
02589
02590 tempString.Printf(_T("%f"),resultMin);
02591 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
02592
02593 tempString.Printf(_T("%f"),resultMax);
02594 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
02595
02596 tempString.Printf(_T("%f"),resultAverage);
02597 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
02598
02599 tempString.Printf(_T("%f"),resultStandardeviation);
02600 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
02601
02602
02603 }
02604 }
02605
02606
02607
02608
02609 int vol_rCountRange;
02610 int vol_rsize;
02611 double vol_minValue;
02612 double vol_maxValue;
02613 double vol_average;
02614 double vol_standardeviation;
02615
02616 if (selection!=0 )
02617 {
02618
02619 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
02620 &vol_minValue, &vol_maxValue,
02621 &vol_average, &vol_standardeviation);
02622
02623 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
02624
02625 tempString.Printf(_T("%d"),vol_rsize);
02626 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
02627
02628 tempString.Printf(_T("%d"),vol_rCountRange);
02629 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
02630
02631 tempString.Printf(_T("%f"),vol_minValue);
02632 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
02633
02634 tempString.Printf(_T("%f"),vol_maxValue);
02635 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
02636
02637 tempString.Printf(_T("%f"),vol_average);
02638 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
02639
02640 tempString.Printf(_T("%f"),vol_standardeviation);
02641 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
02642 }
02643
02644
02645 int iTitleGroup;
02646 wxString tmpTitleString;
02647 int tmpIntB;
02648 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
02649 {
02650 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
02651 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
02652 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
02653
02654 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
02655 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
02656 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
02657 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
02658 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
02659 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
02660 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
02661 }
02662 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
02663 }
02664
02665
02666 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
02667 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
02668 {
02669 if (XYZValues)
02670 {
02671 SaveValuesXYZ( directory , namefile, typeContourGroup );
02672 }
02673
02674 if (contourImage)
02675 {
02676 vtkImageData * mask;
02677 vtkImageData * value;
02678 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
02679 this->SaveImageResult( directory , namefile, mask, value);
02680 }
02681
02682 if (statistics)
02683 {
02684 std::ostringstream name;
02685 name << filename << ".xls";
02686
02687
02688 FILE *pFile=fopen(name.str().c_str(),"w+");
02689
02690
02691 wxString tmpString;
02692 int i,j,maxX;
02693
02694
02695
02696
02697 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();
02698
02699
02700 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
02701 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
02702 {
02703
02704 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
02705 }
02706 fprintf(pFile,"\n\n" );
02707
02708
02709
02710 if (selection==0 )
02711 {
02712 std::vector<int> tempVector;
02713 _instantPanel->getInstant( tempVector );
02714 int actualSlice = tempVector[1];
02715 minZ = actualSlice;
02716 maxZ = actualSlice;
02717 }
02718
02719
02720 for ( j=minZ; j<=maxZ ; j++)
02721 {
02722 fprintf(pFile,"%d\t" , j );
02723 for (i=0 ; i<maxX ; i++){
02724 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);
02725 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
02726 }
02727 fprintf(pFile,"\n" );
02728 }
02729
02730
02731
02732 if (selection!=0)
02733 {
02734 fprintf(pFile,"\n Total:\t" );
02735 for (i=0 ; i<maxX ; i++){
02736 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);
02737 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
02738 }
02739 fprintf(pFile,"\n" );
02740 }
02741
02742 fclose(pFile);
02743 }
02744 }
02745
02746
02747 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
02748 {
02749 wxBusyCursor wait;
02750
02751
02752
02753 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
02754
02755 std::vector<manualBaseModel*> lstManConMod;
02756 std::vector<manualBaseModel*> lstManConModTmp;
02757 std::vector<manualBaseModel*> lstManConModExp;
02758 std::vector<double> pLstValue;
02759 std::vector<double> pLstValuePosX;
02760 std::vector<double> pLstValuePosY;
02761 std::vector<double> pLstValuePosZ;
02762
02763 std::vector<int> tempVector;
02764 _instantPanel->getInstant( tempVector );
02765
02766
02767 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
02768 int z;
02769 int ii,sizeLstContourThings;
02770
02771
02772 int minZ,maxZ;
02773 double totalZ;
02774 double porcent;
02775 wxString tmpString;
02776 minZ = 0;
02777 maxZ = sizeZ;
02778 totalZ = maxZ-minZ+1;
02779
02780
02781
02782
02783 for ( z=0 ; z<sizeZ ; z++)
02784 {
02785
02786 porcent = 100.0* (z-minZ)/totalZ;
02787
02788 tmpString.Printf(_T("Saving Values"));
02789 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
02790 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
02791
02792
02793
02794
02795 _contourextractdata->SetZtoBeAnalys( z);
02796
02797 tempVector[1]=z;
02798 Instant instant(&tempVector);
02799 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);
02800 sizeLstContourThings = lstContourThings.size();
02801
02802 lstManConMod.clear();
02803 for (ii=0 ; ii<sizeLstContourThings ; ii++)
02804 {
02805 ContourThing **contourthing = lstContourThings[ii];
02806 lstManConMod.push_back( (*contourthing)->getModel() );
02807 }
02808 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
02809
02810
02811
02812
02813 int iContourGroup,sizeContourGroup;
02814 if (typeContourGroup==3)
02815 {
02816 sizeContourGroup=lstManConModExp.size();
02817 } else {
02818 sizeContourGroup=1;
02819 }
02820
02821 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
02822 lstManConModTmp.clear();
02823 if (typeContourGroup==3)
02824 {
02825 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
02826 } else {
02827 lstManConModTmp = lstManConModExp;
02828 }
02829
02830 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
02831
02832 pLstValue.clear();
02833 pLstValuePosX.clear();
02834 pLstValuePosY.clear();
02835 pLstValuePosZ.clear();
02836 int numberOfPixels;
02837 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
02838 &pLstValue,
02839 &pLstValuePosX,
02840 &pLstValuePosY,
02841 &pLstValuePosZ);
02842
02843 std::string temp = directory + "/" + namefile + "-slice";
02844 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
02845 temp = temp + ".txt";
02846
02847
02848 wxString filename = crea::std2wx(temp);
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
02862 fprintf(pFile,"value \t x \t y \t z\n" );
02863 int iLstValue,sizeLstValue=pLstValue.size();
02864 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
02865 {
02866 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
02867 }
02868 fclose(pFile);
02869 }
02870 }
02871 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
02872
02873
02874 }
02875
02876 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
02877 wxBusyCursor wait;
02878
02879
02880
02881 if (typeContourGroup==3)
02882 {
02883 typeContourGroup=1;
02884 }
02885 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
02886
02887 std::vector<manualBaseModel*> lstManConMod;
02888 std::vector<manualBaseModel*> lstManConModTmp;
02889 std::vector<manualBaseModel*> lstManConModExp;
02890
02891 std::vector<int> tempVector;
02892 _instantPanel->getInstant( tempVector );
02893
02894 vtkImageData *imagedata = _theViewPanel->getImageData();
02895 int ext[6];
02896 imagedata->GetExtent(ext);
02897 int sizeZimage = ext[5]-ext[4]+1;
02898 int z;
02899 int ii,sizeLstContourThings;
02900
02901
02902 double totalZ;
02903 double porcent;
02904
02905 wxString tmpString;
02906
02907
02908 if (selection==0 )
02909 {
02910 int actualSlice = tempVector[1];
02911 minZ = actualSlice;
02912 maxZ = actualSlice;
02913 }
02914
02915 totalZ = maxZ-minZ;
02916
02917
02918
02919
02920 for (z=0; z<minZ; z++){
02921 _contourextractdata->ResetImageResult(z);
02922 }
02923
02924 for (z=maxZ+1; z<sizeZimage; z++){
02925 _contourextractdata->ResetImageResult(z);
02926 }
02927
02928
02929
02930 for ( z=minZ ; z<=maxZ ; z++)
02931 {
02932
02933 porcent = 100.0* (z-minZ)/totalZ;
02934 tmpString.Printf(_T("Saving Values"));
02935 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
02936 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
02937
02938
02939 _contourextractdata->SetZtoBeAnalys( z);
02940
02941 tempVector[1]=z;
02942 Instant instant(&tempVector);
02943 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
02944 sizeLstContourThings = lstContourThings.size();
02945
02946 lstManConMod.clear();
02947 for (ii=0 ; ii<sizeLstContourThings ; ii++)
02948 {
02949 ContourThing **contourthing = lstContourThings[ii];
02950 lstManConMod.push_back( (*contourthing)->getModel() );
02951 }
02952 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
02953
02954
02955 int iContourGroup,sizeContourGroup;
02956 if (typeContourGroup==3)
02957 {
02958 sizeContourGroup=lstManConModExp.size();
02959 } else {
02960 sizeContourGroup=1;
02961 }
02962
02963 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
02964 lstManConModTmp.clear();
02965 if (typeContourGroup==3)
02966 {
02967 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
02968 } else {
02969 lstManConModTmp = lstManConModExp;
02970 }
02971
02972 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
02973 _contourextractdata->CalculateImageResult();
02974
02975 }
02976 }
02977
02978 (*value) = _contourextractdata->GetVtkImageValueResult();
02979 (*mask) = _contourextractdata->GetVtkImageMaskResult();
02980
02981 }
02982
02983 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
02984 {
02985
02986 double spc[3];
02987 kernelManager->GetSpacing(spc,0);
02988
02989 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
02990
02991 wxString filename = crea::std2wx(temp);
02992
02993
02994
02995 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
02996 valueChInfo->SetInput(value);
02997 valueChInfo->SetSpacingScale(spc);
02998 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
02999 writerValueImage->SetInput( valueChInfo->GetOutput() );
03000 writerValueImage->SetFileName( (const char *)filename.mb_str() );
03001 writerValueImage->SetFileDimensionality( 3 );
03002 writerValueImage->SetCompression(false);
03003 writerValueImage->Write( );
03004
03005
03006 temp = directory + "/" + namefile + "-image-Mask.mhd";
03007
03008
03009 filename = crea::std2wx(temp);
03010
03011
03012
03013 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
03014 maskChInfo->SetInput(mask);
03015 maskChInfo->SetSpacingScale(spc);
03016 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
03017 writerMaskImage->SetInput( maskChInfo->GetOutput() );
03018 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
03019 writerMaskImage->SetFileDimensionality( 3 );
03020 writerMaskImage->SetCompression(false);
03021 writerMaskImage->Write( );
03022
03023 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
03024
03025 }
03026
03027
03028
03029 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
03030 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
03031 _theViewPanel->setActualVertical( value);
03032 }
03033 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
03034 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
03035 }
03036
03037 changeInstant();
03038 }
03039
03040 void wxContourMainFrame::onSnakePressed(){
03041 std::vector<double> vecX;
03042 std::vector<double> vecY;
03043 std::vector<double> vecZ;
03044 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
03045
03046 if (vecX.size()!=0){
03047 std::vector<int> tempVector;
03048 _instantPanel->getInstant( tempVector );
03049 int i,size=vecZ.size();
03050 int actualSlice = tempVector[1];
03051 for ( i=0 ; i<size ; i++ )
03052 {
03053 vecZ[i] = actualSlice;
03054 }
03055
03056 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
03057 wxPanel* panel = new wxPanel(dialog,-1);
03058
03059 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
03060 dialog->ShowModal();
03061 }
03062
03063 }
03064
03065 void wxContourMainFrame::saveFileWithContoursAutomatique(){
03066 std::string filename = kernelManager->getCurrentFileName();
03067 if(filename.compare("")!=0){
03068 saveFileWithContours(filename);
03069 }else{
03070 onSave();
03071 }
03072 }
03073 void wxContourMainFrame::ShowToolsPanel(bool show){
03074 _pannew->Show(show);
03075 }
03076
03077
03078
03079 void wxContourMainFrame::SetContourGroup(int contourGroup)
03080 {
03081 _contourGroup = contourGroup;
03082 }
03083
03084
03085 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
03086 {
03087
03088 if (_viewMaskImagePanel==NULL)
03089 {
03090 _contourextractdata = new ContourExtractData(true);
03091 _contourextractdata->SetImage( _theViewPanel->getImageData() );
03092
03093
03094
03095
03096 int min = 254;
03097 int max = 256;
03098 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
03099 _viewMaskImage = new ThresholdImageView();
03100 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
03101 _viewMaskImage->SetminMaxValue( min, max);
03102 _viewMaskImage->SetBaseColor( 0,0,1 );
03103 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
03104 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
03105 }
03106 return _viewMaskImagePanel;
03107 }
03108
03109
03110 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
03111 {
03112 if (_viewColorLayerImagePanel==NULL)
03113 {
03114 double range[2];
03115 _theViewPanel->getImageData()->GetScalarRange(range);
03116 int min = (int)floor (range[0]);
03117 int max = (int)ceil (range[1]);
03118 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max , 1);
03119 _viewColorLayerImage = new ColorLayerImageView();
03120
03121 _viewColorLayerImage->SetImage( NULL );
03122 _viewColorLayerImagePanel->SetColorLayerImageView( _viewColorLayerImage );
03123 _viewColorLayerImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
03124 }
03125 return _viewColorLayerImagePanel;
03126 }
03127
03128
03129 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
03130 {
03131 if (_viewThresholdImagePanel==NULL)
03132 {
03133 double range[2];
03134 _theViewPanel->getImageData()->GetScalarRange(range);
03135 int min = (int)floor (range[0]);
03136 int max = (int)ceil (range[1]);
03137 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
03138 _viewThresholdImage = new ThresholdImageView();
03139 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
03140 _viewThresholdImage->SetminMaxValue( min, max);
03141 _viewThresholdImage->SetBaseColor( 1,0,0 );
03142 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
03143 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
03144 }
03145 return _viewThresholdImagePanel;
03146 }
03147
03148
03149 int wxContourMainFrame::getType ()
03150 {
03151 int tipo = 0;
03152 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
03153
03154 if(!currentSelection.empty())
03155 {
03156 std::string cloneName = currentSelection [0];
03157 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
03158 tipo = manualModel-> GetTypeModel();
03159 }
03160 return tipo;
03161 }
03162
03163 double wxContourMainFrame::getContourSizeInPixels()
03164 {
03165 double contourSize = 0;
03166
03167 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
03168 if(!currentSelection.empty())
03169 {
03170 std::string cloneName = currentSelection [0];
03171
03172 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
03173 contourSize = manualModel-> GetPathSize();
03174 }
03175 return contourSize;
03176 }
03177 manualBaseModel * wxContourMainFrame::getContour ()
03178 {
03179 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
03180
03181 if(!currentSelection.empty())
03182 {
03183 std::string cloneName = currentSelection [0];
03184 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
03185 return manualModel;
03186 }
03187 return NULL;
03188 }
03189 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
03190 {
03191 std::string labelAscii(label.ToAscii());
03192 int pos = labelAscii.find(" ");
03193
03194 int j;
03195
03196 for (j=0 ; pos != string::npos;j++)
03197 {
03198 labelAscii.replace( pos, 1, "_" );
03199 pos= labelAscii.find(" ");
03200 }
03201
03202 manualModel -> SetLabel(labelAscii);
03203 }
03204 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
03205 {
03206 double sizeInPixel = manualModel ->GetPathSize();
03207 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
03208 double realContourSize = sizeInPixel*onePixelRealSize;
03209 manualModel ->SetRealSize(realContourSize);
03210 }
03211
03212 double wxContourMainFrame::onePixelSize( double value)
03213 {
03214 return _onePixelSize = value;
03215 }
03216
03217 std::string wxContourMainFrame::GetFileLocation()
03218 {
03219 return _fileLocation;
03220 }
03221
03222 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
03223 {
03224 _fileLocation = newFileLocation;
03225 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
03226 }
03227