00001
00002 #include "vtkObjectFactory.h"
00003
00004 #include "vtkActor.h"
00005 #include "vtkCylinderSource.h"
00006 #include "vtkPolyDataMapper.h"
00007 #include "vtkRenderer.h"
00008 #include "vtkRenderWindow.h"
00009 #include "vtkRenderWindowInteractor.h"
00010 #include "vtkProperty.h"
00011 #include "vtkCamera.h"
00012 #include "vtkPoints.h"
00013 #include "vtkCellArray.h"
00014 #include "vtkPolyData.h"
00015 #include "vtkPolyDataMapper.h"
00016 #include "vtkPolyDataWriter.h"
00017 #include "vtkPolyDataReader.h"
00018 #include "vtkImageReader.h"
00019 #include "vtkImageViewer.h"
00020 #include "vtkImageViewer2.h"
00021 #include "vtkImageToStructuredPoints.h"
00022 #include <vtkImageThreshold.h>
00023 #include "vtkImageWriter.h"
00024
00025
00026 #include "vtkExtractVOI.h"
00027 #include "vtkImageClip.h"
00028 #include "vtkImageResample.h"
00029 #include "vtkImageThreshold.h"
00030 #include "vtkImageCast.h"
00031 #include "vtkImageSeedConnectivity.h"
00032 #include "vtkImageData.h"
00033 #include "vtkMarchingCubes.h"
00034 #include "vtkImageReslice.h"
00035 #include "vtkTransform.h"
00036 #include "vtkSphereSource.h"
00037 #include "vtkDoubleArray.h"
00038 #include "vtkPointData.h"
00039 #include "vtkCommand.h"
00040 #include "vtkCallbackCommand.h"
00041 #include "vtkImageResample.h"
00042 #include "vtkMath.h"
00043 #include "vtkStripper.h"
00044 #include <vtkSTLReader.h>
00045 #include "vtkMetaImageWriter.h"
00046
00047
00048 #include "vtkTriangleFilter.h"
00049 #include "vtkSTLWriter.h"
00050 #include "vtkPolyDataConnectivityFilter.h"
00051 #include "vtkClosePolyData.h"
00052 #include "vtkAppendFilter.h"
00053
00054 #include "wxSTLWidget_03.h"
00055
00056 #include <wx/splitter.h>
00057
00058 #include <wx/filedlg.h>
00059
00060
00061
00062
00063
00064
00065 wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent)
00066 : wxPanel( parent, -1)
00067 {
00068 _imagedata=NULL;
00069 cast2=NULL;
00070 cast3=NULL;
00071 cast4=NULL;
00072 _thresh=NULL;
00073 _thresh2=NULL;
00074 _cast=NULL;
00075 _connect=NULL;
00076 _connect2=NULL;
00077 _2_mapfinal=NULL;
00078 _2_stripfinal=NULL;
00079 _2_isoMapperMC6=NULL;
00080 _2_isoActorMC6=NULL;
00081 _2_isoMC6=NULL;
00082 _loadSTLMapper=NULL;
00083 _loadActorSTL=NULL;
00084 sl_barrange_segmentation=NULL;
00085 _imageviewer3D=NULL;
00086 _wxMaracasMPR=NULL;
00087 stlInterna=NULL;
00088 stlExterna=NULL;
00089 stlSliderDeltaGauss=NULL;
00090 stlSliderMarchingCubes=NULL;
00091 dsm1=NULL;
00092 actorInternal=NULL;
00093 stlSliderOpacityInternal=NULL;
00094 dsm2=NULL;
00095 actorExternal=NULL;
00096 stlSliderOpacityExternal=NULL;
00097 stlExtractor=NULL;
00098 _sl_opacity_STL_file=NULL;
00099 arteryImageData=NULL;
00100 joiner=NULL;
00101 joinMarchingCubes=NULL;
00102 joinMapper=NULL;
00103 joinActor=NULL;
00104 _maxSize = 2000;
00105 _minSize = 300;
00106
00107 _stlMarchingCubesLevel = 128;
00108 _stlDeltaGaussLevel = 100;
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
00125 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
00126 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
00127 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
00128
00129 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
00130 pnlSplitter -> SetMinimumPaneSize( 150 );
00131 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
00132
00133
00134
00135
00136 this -> SetSizer(sizer);
00137
00138
00139
00140 }
00141
00142 wxSTLWidget_03::~wxSTLWidget_03(){
00143
00144
00145
00146 if(_imagedata!=NULL){
00147 _imagedata->Delete();
00148 }
00149 if(cast2){cast2->Delete();}
00150 if(cast3){cast3->Delete();}
00151 if(cast4){cast4->Delete();}
00152 if(_thresh){_thresh->Delete();}
00153 if(_thresh2){_thresh2->Delete();}
00154 if(_cast){_cast->Delete();}
00155 if(_connect){_connect->Delete();}
00156 if(_connect2){_connect2->Delete();}
00157 if(_2_mapfinal){_2_mapfinal->Delete();}
00158 if(_2_stripfinal){_2_stripfinal->Delete();}
00159 if(_2_isoMapperMC6){_2_isoMapperMC6->Delete();}
00160 if(_2_isoActorMC6){_2_isoActorMC6->Delete();}
00161 if(_2_isoMC6){_2_isoMC6->Delete();}
00162
00163 if(_loadSTLMapper){_loadSTLMapper->Delete();}
00164 if(_loadActorSTL){_loadActorSTL->Delete();}
00165 if(sl_barrange_segmentation){delete sl_barrange_segmentation;}
00166 if(_imageviewer3D){delete _imageviewer3D;}
00167 if(_wxMaracasMPR){delete _wxMaracasMPR;}
00168 if(stlInterna){stlInterna->Delete();}
00169 if(stlExterna){stlExterna->Delete();}
00170 if(dsm1){dsm1->Delete();}
00171 if(actorInternal){actorInternal->Delete();}
00172 if(dsm2){dsm2->Delete();}
00173 if(actorExternal){actorExternal->Delete();}
00174
00175 if(arteryImageData){arteryImageData->Delete();}
00176 if(joiner){delete joiner;}
00177 if(joinMarchingCubes){joinMarchingCubes->Delete();}
00178 if(joinMapper){joinMapper->Delete(); }
00179 if(joinActor){joinActor->Delete();}
00180 }
00181
00182 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
00183 {
00184 wxPanel *panel = new wxPanel(parent,-1);
00185 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00186
00187
00188
00189
00190
00191
00192 _wxMaracasMPR = new wxMaracasMPR( panel);
00193 _wxMaracasMPR->ConfigureVTK();
00194
00195 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
00196 panel->SetSizer(sizer);
00197 panel->SetAutoLayout(true);
00198 panel->SetSize(400,400);
00199 panel->Layout();
00200 return panel;
00201 }
00202
00203 void wxSTLWidget_03::setImage(vtkImageData* img){
00204
00205 _wxMaracasMPR->setImageData(img, 1);
00206 _wxMaracasMPR->ConfigureVTK();
00207
00208
00209 this->ConfigureProcessing(img,0,0,0);
00210 this->ConfigureSTL();
00211
00212 _wxMaracasMPR->Refresh();
00213
00214
00215 }
00216
00217 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
00218 {
00219 wxPanel *panel = new wxPanel(parent,-1);
00220
00221
00222 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00223
00224 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00225 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00226
00227 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00228 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00229
00230 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
00231 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00232
00233 panel->SetSizer(sizer);
00234 panel->SetAutoLayout(true);
00235 panel->SetSize(400,600);
00236 panel->Layout();
00237
00238
00239 return panel;
00240 }
00241
00242 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
00243 {
00244 wxPanel *panel = new wxPanel(parent,-1);
00245
00246
00247 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00248 _opacity_Vol ->SetSize(250,20);
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
00264 _sl_RangeSizeSpin->SetRange(1,8);
00265 _sl_RangeSizeSpin->SetValue(5);
00266
00267
00268
00269 sl_barrange_segmentation = new mBarRange(panel, 300,70);
00270 sl_barrange_segmentation -> setVisibleLabels ( true );
00271 sl_barrange_segmentation -> setIfWithActualDrawed( false );
00272 sl_barrange_segmentation -> setActiveStateTo ( true );
00273 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
00274 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
00275 sl_barrange_segmentation -> setDeviceEndMargin(10);
00276 parent->SetBackgroundColour(wxColour(255,255,255));
00277 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
00278
00279
00280 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
00281 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
00282
00283
00284
00285 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
00286 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
00287 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
00288
00289
00290 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
00291 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
00292 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
00293 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
00294
00295 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00296
00297 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00298 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00299
00300
00301 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
00302 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00303
00304
00305 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00306 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00307
00308
00309
00310
00311
00312
00313 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
00314 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00315 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
00316 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
00317
00318
00319
00320
00321
00322
00323 sizer->Add(btnExtract);
00324 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00325
00326 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00327 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00328 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
00329 sizer->Add(_opacity_Vol);
00330
00331 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00332 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00333 sizer->Add(btnSaveBinaryFile);
00334 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00335
00336 panel->SetSizer(sizer);
00337 panel->SetAutoLayout(true);
00338 panel->SetSize(400,600);
00339 panel->Layout();
00340
00341 return panel;
00342 }
00343
00344 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
00345 {
00346 wxPanel *panel = new wxPanel(parent,-1);
00347
00348 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00349 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00350 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
00351 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
00352 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
00353
00354 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
00355 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
00356 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
00357 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
00358 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
00359
00360
00361 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00362
00363 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00364 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00365
00366 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
00367 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00368 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00369 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00370
00371 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
00372 sizer->Add(stlSliderDeltaGauss);
00373
00374 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
00375 sizer->Add(stlSliderMarchingCubes);
00376
00377 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00378 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00379 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00380 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00381
00382 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
00383 sizer->Add(stlSliderOpacityInternal);
00384
00385 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
00386 sizer->Add(stlSliderOpacityExternal);
00387
00388 sizer->Add(btnFileSTL);
00389 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00390
00391
00392 panel->SetSizer(sizer);
00393 panel->SetAutoLayout(true);
00394 panel->SetSize(400,600);
00395 panel->Layout();
00396 return panel;
00397 }
00398
00399 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
00400 {
00401 wxPanel *panel = new wxPanel(parent,-1);
00402
00403 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
00404 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
00405 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00406
00407 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
00408 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
00409 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
00410
00411
00412 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00413
00414 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00415 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00416 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00417 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00418
00419 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
00420 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00421
00422 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00423 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00424
00425 sizer->Add(btnReadSTLFile );
00426 sizer->Add(btnEraseReadSTLFile );
00427 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
00428 sizer->Add(_sl_opacity_STL_file);
00429
00430
00431 panel->SetSizer(sizer);
00432 panel->SetAutoLayout(true);
00433 panel->SetSize(400,600);
00434 panel->Layout();
00435 return panel;
00436 }
00437
00438 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
00439 {
00440 wxPanel *panel = new wxPanel(parent,-1);
00441
00442 wxNotebook *noteBook = new wxNotebook(panel, -1);
00443 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
00444 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
00445 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
00446 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
00447 noteBook->SetSelection(0);
00448 noteBook->SetSize(350,250);
00449 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00450 sizer->Add(noteBook);
00451 panel->SetSizer(sizer);
00452 panel->SetAutoLayout(true);
00453 panel->SetSize(400,600);
00454 panel->Layout();
00455
00456 return panel;
00457 }
00458
00459 void wxSTLWidget_03::Refresh()
00460 {
00461 if (_wxMaracasMPR!=NULL){
00462 _wxMaracasMPR->RefreshView();
00463 }
00464 }
00465
00466
00467
00468
00469 void wxSTLWidget_03::ConfigureProcessing(vtkImageData *img, int x, int y, int z)
00470 {
00471 wxBusyCursor wait;
00472
00473 _imagedata=img;
00474
00475
00476 double puntoactualprov[3];
00477 puntoactualprov[0] = x;
00478 puntoactualprov[1] = y;
00479 puntoactualprov[2] = z;
00480
00481 double espprin[3];
00482 int extprin[6];
00483
00484 _imagedata->GetSpacing(espprin);
00485 _imagedata->GetExtent(extprin);
00486
00487
00488
00489
00490
00491
00492
00493 _imagedata->GetScalarRange( _range );
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 minRangeValue = _range[0];
00505 maxRangeValue = _range[1];
00506
00507 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
00508 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
00509 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
00510 sl_barrange_segmentation -> RefreshForce();
00511 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
00512
00513
00514
00515
00516
00517
00518
00519
00520 if(_thresh==NULL){
00521 _thresh = vtkImageThreshold::New();
00522
00523 _thresh->SetInValue(255);
00524 _thresh->SetOutputScalarTypeToUnsignedShort();
00525 _thresh->SetOutValue(0);
00526
00527
00528 _cast = vtkImageCast::New();
00529 _cast->SetInput(_thresh->GetOutput());
00530 _cast->SetOutputScalarTypeToUnsignedChar();
00531
00532 _connect = vtkImageSeedConnectivity::New();
00533 _connect->SetInput(_cast->GetOutput());
00534 _connect->SetInputConnectValue(255);
00535 _connect->SetOutputConnectedValue(255);
00536 _connect->SetOutputUnconnectedValue(0);
00537
00538 cast3 = vtkImageCast::New();
00539 cast3->SetInput(_connect->GetOutput());
00540 cast3->SetOutputScalarTypeToUnsignedShort();
00541
00542 _thresh2 = vtkImageThreshold::New();
00543
00544 _thresh2->SetInValue(255);
00545 _thresh2->SetOutputScalarTypeToUnsignedShort();
00546 _thresh2->SetOutValue(0);
00547
00548
00549 cast2 = vtkImageCast::New();
00550 cast2->SetInput(_thresh2->GetOutput());
00551 cast2->SetOutputScalarTypeToUnsignedChar();
00552 _connect2 = vtkImageSeedConnectivity::New();
00553 _connect2->SetInput(cast2->GetOutput());
00554 _connect2->SetInputConnectValue(255);
00555 _connect2->SetOutputConnectedValue(255);
00556 _connect2->SetOutputUnconnectedValue(0);
00557
00558 cast4 = vtkImageCast::New();
00559 cast4->SetInput(_connect2->GetOutput());
00560 cast4->SetOutputScalarTypeToUnsignedShort();
00561 }
00562 _thresh->RemoveAllInputs();
00563 _thresh->SetInput(_imagedata);
00564 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
00565 _thresh->Update();
00566
00567 _cast->Update();
00568
00569
00570 _connect->RemoveAllSeeds();
00571 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
00572
00573
00574
00575 _thresh2->RemoveAllInputs();
00576 _thresh2->SetInput(_imagedata);
00577 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
00578 _thresh2->Update();
00579 cast2->Update();
00580 _connect2->RemoveAllSeeds();
00581 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
00582
00583
00584 }
00585
00586
00587
00588
00589
00590 void wxSTLWidget_03::ConfigureVTK()
00591 {
00592 wxBusyCursor wait;
00593
00594
00595
00596
00597 this->ConfigureSTL();
00598
00599
00600 }
00601
00602
00603
00604 void wxSTLWidget_03::ResetTree2_JF()
00605 {
00606
00607
00608 try{
00609
00610
00611
00612
00613
00614 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
00615 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
00616 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
00617 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
00618 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
00619
00620
00621
00622 _2_mapfinal = NULL;
00623 _2_stripfinal = NULL;
00624 _2_isoMapperMC6 = NULL;
00625 _2_isoActorMC6 = NULL;
00626 _2_isoMC6 = NULL;
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639 }catch(char* e){
00640 std::cout<<e<<std::endl;
00641 }
00642 }
00643
00644
00645
00646
00647
00648
00649
00650 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
00651 {
00652
00653 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
00654
00655
00656 double puntoactualprov[3];
00657 double espprin[3];
00658 int extprin[6];
00659
00660
00661 puntoactualprov[0] = x;
00662 puntoactualprov[1] = y;
00663 puntoactualprov[2] = z;
00664
00665 _imagedata->UpdateInformation();
00666 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
00667 _imagedata->Update();
00668
00669 _imagedata->GetSpacing(espprin);
00670 _imagedata->GetExtent(extprin);
00671
00672
00673
00674
00675 _connect->RemoveAllSeeds ();
00676 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
00677 _connect->Update();
00678 cast3->Update();
00679
00680
00681
00682 _thresh->ThresholdBetween(3000, 3002 );
00683 _thresh2->ThresholdBetween(3000, 3001);
00684
00685
00686
00687 _thresh->ThresholdBetween(_minSize, _range[1] );
00688 _thresh->Update();
00689
00690 _thresh2->ThresholdBetween(_minSize, _maxSize);
00691 _thresh2->Update();
00692
00693 cast2->Update();
00694 _connect2->RemoveAllSeeds ();
00695 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
00696 _connect2->Update();
00697 cast4->Update();
00698
00699
00700
00701
00702
00703
00704 _2_isoMC6 = vtkMarchingCubes::New();
00705 _2_isoMC6->SetInput(cast4->GetOutput());
00706
00707 _2_isoMC6->SetValue(0, 128);
00708 _2_isoMC6->Update();
00709
00710 _2_isoMapperMC6 = vtkPolyDataMapper::New();
00711 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
00712 _2_isoMapperMC6->ScalarVisibilityOff();
00713 _2_isoMapperMC6->ImmediateModeRenderingOn();
00714
00715 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00716
00717 if (_2_isoActorMC6!=NULL)
00718 {
00719 ren->RemoveActor(_2_isoActorMC6);
00720 }
00721
00722
00723 _2_isoActorMC6 = vtkActor::New();
00724 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
00725 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
00726 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
00727
00728
00729
00730 ren->AddActor(_2_isoActorMC6);
00731
00732 }
00733
00734
00735 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
00736 {
00737 if (_2_isoActorMC6!=NULL){
00738 double value = ((double)_opacity_Vol->GetValue())/100;
00739 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
00740 Refresh();
00741 }
00742 }
00743
00744
00745 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
00746 {
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 }
00763
00764
00765
00766 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
00767 {
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780 }
00781
00782
00783
00784 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
00785 {
00786 wxSlider *sl_B=_sl_RangeSizeSpin;
00787
00788 int value = lastResizeRef_Value;
00789 int delta = (int)pow((double) 4 , (double)sl_B->GetValue() );
00790 int startResized = value - delta/2;
00791 int endResized = value + delta/2;
00792
00793 if( startResized < minRangeValue )
00794 startResized = minRangeValue;
00795
00796 if( endResized > maxRangeValue )
00797 endResized = maxRangeValue;
00798
00799 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
00800 sl_barrange_segmentation -> RefreshForce();
00801 }
00802
00803
00804 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
00805 {
00806 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
00807 }
00808
00809 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
00810 {
00811 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
00812 }
00813
00814 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
00815 {
00816 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
00817 }
00818
00819
00820 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
00821 {
00822 wxString dirSTL;
00823
00824 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
00825 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
00826 dirSTL: wxGetHomeDir( ) );
00827
00828 if( dialog.ShowModal( ) == wxID_OK )
00829 {
00830 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
00831 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
00832 writer->SetInput(cast4->GetOutput());
00833 writer->Write();
00834 writer->Delete();
00835 }
00836 }
00837
00838
00839 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
00840 {
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854 wxBusyCursor wait;
00855 _minSize = sl_barrange_segmentation->GetStart();
00856 _maxSize = sl_barrange_segmentation->GetEnd();
00857
00858 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
00859 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
00860 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
00861 ExtractSurface((int)(px),(int)(py),(int)(pz));
00862 generateSTLSurfaces();
00863
00864 Refresh();
00865 }
00866
00867
00868 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
00869 {
00870 if (_loadActorSTL!=NULL)
00871 {
00872 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
00873 _loadActorSTL->GetProperty( )->SetOpacity( value );
00874 Refresh();
00875 }
00876 }
00877
00878 void wxSTLWidget_03::Reset_vtk_STLFile()
00879 {
00880
00881 try{
00882 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00883 if (_loadActorSTL){
00884 ren->RemoveActor(_loadActorSTL);
00885 }
00886
00887
00888 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
00889 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
00890
00891
00892 _loadSTLMapper = NULL;
00893 _loadActorSTL = NULL;
00894 }catch(char * e){
00895 std::cout<<e<<std::endl;
00896 }
00897
00898 }
00899
00900 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
00901 {
00902 Reset_vtk_STLFile();
00903 Refresh();
00904 }
00905
00906 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
00907 {
00908 wxString dirSTL;
00909
00910 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
00911 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
00912 dirSTL: wxGetHomeDir( ) );
00913
00914 if( dialog.ShowModal( ) == wxID_OK )
00915 {
00916 Reset_vtk_STLFile();
00917 vtkSTLReader *imgReader= vtkSTLReader::New();
00918 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
00919 _loadSTLMapper = vtkPolyDataMapper::New();
00920 _loadSTLMapper->SetInput(imgReader->GetOutput());
00921 _loadActorSTL = vtkActor::New();
00922 _loadActorSTL->SetMapper(_loadSTLMapper);
00923 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
00924 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
00925 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00926 ren->AddActor(_loadActorSTL);
00927 imgReader->Delete();
00928 }
00929
00930
00931
00932 }
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944 void wxSTLWidget_03::ConfigureSTL()
00945 {
00946
00947 if(stlExterna == NULL){
00948 stlExterna = vtkPolyData::New();
00949 stlInterna = vtkPolyData::New();
00950
00951 dsm1 = vtkPolyDataMapper ::New();
00952 dsm1->SetInput (stlInterna);
00953 dsm1->ScalarVisibilityOff();
00954
00955 actorInternal = vtkActor::New();
00956 actorInternal->SetMapper (dsm1);
00957 actorInternal->GetProperty()->SetColor (0,1,0);
00958
00959 dsm2 = vtkPolyDataMapper ::New();
00960 dsm2->SetInput (stlExterna);
00961 dsm2->ScalarVisibilityOff();
00962
00963 actorExternal= vtkActor::New();
00964 actorExternal->SetMapper (dsm2);
00965 actorExternal->GetProperty()->SetRepresentationToWireframe();
00966
00967
00968 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00969 ren->AddActor(actorInternal);
00970 ren->AddActor(actorExternal);
00971
00972 stlExtractor = new vtkSTLExtractor();
00973
00974 }
00975
00976
00977 }
00978
00979 void wxSTLWidget_03::generateSTLSurfaces()
00980 {
00981
00982
00983
00984 stlExtractor->setVolume(cast4->GetOutput());
00985
00986 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
00987 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
00988 stlExtractor->calculate();
00989 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
00990 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
00991 }
00992
00993
00994 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
00995 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
00996 actorExternal->GetProperty( )->SetOpacity( value );
00997 Refresh();
00998 }
00999
01000
01001 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
01002 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
01003 actorInternal->GetProperty( )->SetOpacity( value );
01004 Refresh();
01005 }
01006
01007 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
01008 {
01009
01010 wxString dirSTL;
01011
01012 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
01013
01014
01015
01016 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
01017
01018
01019 if( dialog.ShowModal( ) == wxID_OK )
01020 {
01021
01022
01023
01024
01025
01026
01027 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
01028 std::string filename;
01029
01030
01031
01032 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
01033 filtro->SetInput(stlInterna);
01034 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
01035 pdcf->SetInput( filtro->GetOutput() );
01036 vtkClosePolyData *cpd = vtkClosePolyData::New();
01037 cpd->SetInput( pdcf->GetOutput() );
01038
01039
01040 cpd->Update();
01041 vtkSTLWriter *writerI = vtkSTLWriter::New();
01042 writerI->SetInput( cpd->GetOutput() );
01043
01044 filename=prefix+"_internal.stl";
01045 writerI->SetFileName(filename.c_str());
01046 writerI->SetFileTypeToASCII();
01047 writerI->Write();
01048 writerI->Delete();
01049
01050
01051 filtro->SetInput(stlExterna);
01052 cpd->Update();
01053 vtkSTLWriter *writerE = vtkSTLWriter::New();
01054 writerE->SetInput( cpd->GetOutput() );
01055
01056 filename=prefix+"_external.stl";
01057 writerE->SetFileName( filename.c_str() );
01058 writerE->SetFileTypeToASCII();
01059 writerE->Write();
01060 writerE->Delete();
01061
01062 filtro->Delete();
01063 cpd->Delete();
01064 pdcf->Delete();
01065 }
01066
01067
01068
01069
01070 }
01071
01072
01073 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
01074 {
01075 wxBusyCursor wait;
01076 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
01077 generateSTLSurfaces();
01078 Refresh();
01079 }
01080
01081
01082 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
01083 {
01084 wxBusyCursor wait;
01085 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
01086 generateSTLSurfaces();
01087 Refresh();
01088
01089 }
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101