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
00046
00047 #include "vtkTriangleFilter.h"
00048 #include "vtkSTLWriter.h"
00049 #include "vtkPolyDataConnectivityFilter.h"
00050 #include "vtkClosePolyData.h"
00051 #include "vtkAppendFilter.h"
00052
00053 #include "wxSTLWidget_02.h"
00054
00055 #include <wx/splitter.h>
00056
00057 #include <wx/filedlg.h>
00058
00059
00060
00061
00062
00063
00064 wxSTLWidget_02::wxSTLWidget_02(wxWindow *parent, marInterface* mar)
00065 : wxPanel( parent, -1)
00066 {
00067 _sensibility_JF = 0.5;
00068 _maxSphereSize_JF = 30;
00069 _minSphereSize_JF = 5;
00070
00071 _stlMarchingCubesLevel = 128;
00072 _stlDeltaGaussLevel = 100;
00073
00074 _mar=new marInterface();
00075 _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
00076 _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
00077 _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
00078 _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
00079 _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
00080 _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
00081 int voi[6];
00082 mar->_experiment->getVOI( voi );
00083 _mar->_experiment->setVOI( voi );
00084 _mar->SetDicom(mar->_dicom);
00085 _mar->initExperiment( );
00086
00087
00088 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
00089 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
00090 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
00091 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
00092
00093 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
00094 pnlSplitter -> SetMinimumPaneSize( 150 );
00095 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
00096 this -> SetSizer(sizer);
00097
00098
00099 _2_prgov = NULL;
00100 _2_mapfinal = NULL;
00101 _2_stripfinal = NULL;
00102 _2_isoMapperMC6 = NULL;
00103 _2_isoActorMC6 = NULL;
00104 _2_isoMC6 = NULL;
00105
00106
00107
00108 stlInterna = NULL;
00109 stlExterna = NULL;
00110
00111 _loadSTLMapper = NULL;
00112 _loadActorSTL = NULL;
00113
00114
00115
00116 arteryImageData = NULL;
00117 joinMarchingCubes = NULL;
00118 joinMapper = NULL;
00119 joinActor = NULL;
00120
00121
00122 }
00123
00124 wxSTLWidget_02::~wxSTLWidget_02(){
00125 ResetTree2_JF();
00126 Reset_vtk_STLFile();
00127 }
00128
00129 wxPanel* wxSTLWidget_02::CreateViewPanel(wxWindow *parent)
00130 {
00131 wxPanel *panel = new wxPanel(parent,-1);
00132 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00133
00134
00135
00136 vtkImageData *imagedata;
00137 imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
00138 imagedata->Update();
00139 _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
00140 _wxMaracasMPR->ConfigureVTK();
00141
00142 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
00143 panel->SetSizer(sizer);
00144 panel->SetAutoLayout(true);
00145 panel->SetSize(400,400);
00146 panel->Layout();
00147 return panel;
00148 }
00149
00150 wxPanel* wxSTLWidget_02::CreateControlPanel(wxWindow *parent)
00151 {
00152 wxPanel *panel = new wxPanel(parent,-1);
00153
00154 _opacity_Res2VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00155 _sl_sensibility_JF = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00156 _sl_maxSphereSize_JF = new wxSlider( panel, -1, _maxSphereSize_JF, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00157 _sl_minSphereSize_JF = new wxSlider( panel, -1, _minSphereSize_JF , 0, 20 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00158
00159
00160 int tmp_sensibility= (int)(_sensibility_JF*100.0);
00161 _sl_sensibility_JF->SetValue( tmp_sensibility );
00162
00163 _opacity_Res2VolJF ->SetSize(250,20);
00164
00165
00166 wxButton *btnExtractTree2_JF = new wxButton(panel,-1,_T("Extract Tree 2 JF"));
00167 wxButton *btnEraseTree2_JF = new wxButton(panel,-1,_T("Erase Tree 2 JF"));
00168
00169
00170 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
00171 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
00172 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00173
00174
00175 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
00176 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00177 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00178
00179
00180 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
00181 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00182 sizer->Add(new wxStaticText(panel,-1,_T(" % Sensibility")));
00183 sizer->Add(_sl_sensibility_JF);
00184 sizer->Add(new wxStaticText(panel,-1,_T(" Biggest radium")));
00185 sizer->Add(_sl_maxSphereSize_JF);
00186 sizer->Add(new wxStaticText(panel,-1,_T(" Minimum radium")));
00187 sizer->Add(_sl_minSphereSize_JF);
00188
00189
00190 sizer->Add(btnExtractTree2_JF);
00191 sizer->Add(btnEraseTree2_JF);
00192
00193 wxButton *btnJoinRegions = new wxButton(panel,-1,_T("Join Regions"));
00194 sizer->Add(btnJoinRegions);
00195 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00196
00197
00198 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00199 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00200 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
00201 sizer->Add(_opacity_Res2VolJF);
00202 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00203 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00204 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00205 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00206
00207
00208
00209
00210 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00211 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00212 sizer->Add(new wxStaticText(panel,-1,_T(" - - - STL - - - ")));
00213 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00214 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00215 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
00216
00217
00218
00219 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
00220 sizer->Add(stlSliderDeltaGauss);
00221
00222 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
00223 sizer->Add(stlSliderMarchingCubes);
00224
00225 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
00226 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
00227
00228 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
00229 sizer->Add(stlSliderOpacityInternal);
00230
00231 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
00232 sizer->Add(stlSliderOpacityExternal);
00233
00234 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
00235 sizer->Add(btnFileSTL);
00236 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00237
00238
00239
00240 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00241 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00242 sizer->Add(btnReadSTLFile );
00243 sizer->Add(btnEraseReadSTLFile );
00244 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
00245 sizer->Add(_sl_opacity_STL_file);
00246
00247 panel->SetSizer(sizer);
00248 panel->SetAutoLayout(true);
00249 panel->SetSize(400,600);
00250 panel->Layout();
00251
00252 Connect(_opacity_Res2VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacity_Res2VolJF );
00253 Connect(_sl_sensibility_JF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnSensibility );
00254 Connect(_sl_maxSphereSize_JF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnMaxSphereSize_JF );
00255 Connect(_sl_minSphereSize_JF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnMinSphereSize_JF );
00256
00257
00258 Connect(btnExtractTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnExtractTree2_JF );
00259 Connect(btnEraseTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnEraseTree2_JF );
00260 Connect(btnJoinRegions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_02::OnJoinRegions );
00261
00262
00263 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnSTLFileLoad );
00264 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnSTLFileErase );
00265 Connect(_sl_opacity_STL_file->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacitySTLFile );
00266
00267
00268
00269 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnCreateFileSTL );
00270 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_02::OnChangeSTLGaussLevel );
00271 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_02::OnChangeSTLMarchingCubesLevel);
00272 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacitySTLInternal);
00273 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacitySTLExternal);
00274
00275
00276 return panel;
00277 }
00278
00279
00280
00281 void wxSTLWidget_02::Refresh()
00282 {
00283 _wxMaracasMPR->RefreshView();
00284 }
00285
00286
00287
00288 void wxSTLWidget_02::ConfigureVTK()
00289 {
00290 wxBusyCursor wait;
00291 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
00292
00293
00294 this->ConfigureSTL();
00295 this->ConfigureJoinRegions();
00296
00297
00298 }
00299
00300
00301 void wxSTLWidget_02::ResetTree2_JF()
00302 {
00303
00304 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00305
00306 if (_2_isoActorMC6){
00307 ren->RemoveActor(_2_isoActorMC6);
00308 }
00309 if (_2_stripfinal){
00310 ren->RemoveActor(_2_stripfinal);
00311 }
00312
00313
00314 if (_2_prgov ) { _2_prgov -> Delete(); }
00315 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
00316 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
00317 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
00318 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
00319 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
00320
00321
00322 _2_prgov = NULL;
00323 _2_mapfinal = NULL;
00324 _2_stripfinal = NULL;
00325 _2_isoMapperMC6 = NULL;
00326 _2_isoActorMC6 = NULL;
00327 _2_isoMC6 = NULL;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336 void wxSTLWidget_02::ExtractTree2_JF(int x, int y, int z)
00337 {
00338
00339 double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
00340 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
00341
00342 double puntoactualprov[3];
00343 double espprin[3];
00344 int extprin[6];
00345
00346 puntoactualprov[0]=x;
00347 puntoactualprov[1]=y;
00348 puntoactualprov[2]=z;
00349
00350 imagedata->GetSpacing(espprin);
00351 imagedata->GetExtent(extprin);
00352
00353 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
00354 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
00355 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
00356
00357 _2_prgov= axisExtractor02::New();
00358 _2_prgov->SetParam(1);
00359 _2_prgov->SetParam2(1);
00360 _2_prgov->SetParam3(_sensibility_JF);
00361 _2_prgov->SetMaxant(_maxSphereSize_JF);
00362 _2_prgov->SetMinant(_minSphereSize_JF);
00363 _2_prgov->SetInput(imagedata);
00364 _2_prgov->SetPoint(puntoactualprov);
00365 _2_prgov->Update();
00366
00367
00368
00369
00370 marAxis *maraxis = this->_mar->_experiment->getAxis( );
00371
00372
00373 if (maraxis!=NULL) {
00374 vtkPolyData *inputAxisRadio = maraxis->GetAxisData();
00375 _2_prgov->distanciaejes(inputAxisRadio,_2_prgov->GetOutput());
00376
00377
00378 }
00379
00380
00381
00382
00383
00384 if (arteryImageData){
00385 arteryImageData = joiner->join(arteryImageData, _2_prgov->GetVolumen());
00386 }
00387 else{
00388 arteryImageData = _2_prgov->GetVolumen();
00389 }
00390
00391
00392
00393
00394
00395
00396
00397 vtkPolyData *polydata = _2_prgov->GetOutput();
00398 _2_mapfinal = vtkPolyDataMapper::New();
00399 _2_mapfinal->SetInput(polydata);
00400
00401 _2_stripfinal = vtkActor::New();
00402 _2_stripfinal->SetMapper(_2_mapfinal);
00403 _2_stripfinal->GetProperty()->SetColor(0.0, 0.0, 1.0);
00404 _2_stripfinal->GetProperty()->SetLineWidth(2);
00405 _2_stripfinal->GetProperty()->BackfaceCullingOff();
00406
00407
00408
00409 _2_isoMC6 = vtkMarchingCubes::New();
00410
00411 _2_isoMC6->SetInput(arteryImageData);
00412 _2_isoMC6->SetValue(0, 128);
00413 _2_isoMC6->Update();
00414
00415 _2_isoMapperMC6 = vtkPolyDataMapper::New();
00416 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
00417 _2_isoMapperMC6->ScalarVisibilityOff();
00418 _2_isoMapperMC6->ImmediateModeRenderingOn();
00419
00420 _2_isoActorMC6 = vtkActor::New();
00421 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
00422 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
00423 _2_isoActorMC6->GetProperty()->SetOpacity( opacity_Res2VolJF );
00424
00425
00426
00427 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00428 ren->AddActor(_2_isoActorMC6);
00429 ren->AddActor(_2_stripfinal);
00430
00431 }
00432
00433
00434 void wxSTLWidget_02::OnSensibility(wxScrollEvent& event)
00435 {
00436 _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;
00437 }
00438
00439 void wxSTLWidget_02::OnOpacity_Res2VolJF(wxScrollEvent& event)
00440 {
00441 if (_2_isoActorMC6!=NULL){
00442 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
00443 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
00444 Refresh();
00445 }
00446 }
00447
00448 void wxSTLWidget_02::OnMaxSphereSize_JF(wxScrollEvent& event)
00449 {
00450 _maxSphereSize_JF = _sl_maxSphereSize_JF->GetValue();
00451 }
00452
00453 void wxSTLWidget_02::OnMinSphereSize_JF(wxScrollEvent& event)
00454 {
00455 _minSphereSize_JF = _sl_minSphereSize_JF->GetValue();
00456 }
00457
00458 void wxSTLWidget_02::OnBtnExtractTree2_JF(wxCommandEvent& event)
00459 {
00460 wxBusyCursor wait;
00461 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
00462 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
00463 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
00464 ExtractTree2_JF( (int)(px) , (int)(py) , (int)(pz) );
00465
00466 generateSTLSurfaces();
00467
00468 Refresh();
00469 }
00470
00471 void wxSTLWidget_02::OnBtnEraseTree2_JF(wxCommandEvent& event)
00472 {
00473 ResetTree2_JF();
00474 Refresh();
00475 }
00476
00477 void wxSTLWidget_02::OnOpacitySTLFile(wxScrollEvent& event)
00478 {
00479 if (_loadActorSTL!=NULL)
00480 {
00481 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
00482 _loadActorSTL->GetProperty( )->SetOpacity( value );
00483 Refresh();
00484 }
00485 }
00486
00487 void wxSTLWidget_02::Reset_vtk_STLFile()
00488 {
00489
00490 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00491 if (_loadActorSTL){
00492 ren->RemoveActor(_loadActorSTL);
00493 }
00494
00495
00496 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
00497 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
00498
00499
00500 _loadSTLMapper = NULL;
00501 _loadActorSTL = NULL;
00502
00503 }
00504
00505 void wxSTLWidget_02::OnBtnSTLFileErase(wxCommandEvent& event)
00506 {
00507 Reset_vtk_STLFile();
00508 Refresh();
00509 }
00510
00511 void wxSTLWidget_02::OnBtnSTLFileLoad(wxCommandEvent& event)
00512 {
00513 wxString dirSTL = _mar->_parameters->getStringParam(
00514 marParameters::e_installation_directory );
00515 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
00516 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
00517 dirSTL: wxGetHomeDir( ) );
00518
00519 if( dialog.ShowModal( ) == wxID_OK )
00520 {
00521 Reset_vtk_STLFile();
00522 vtkSTLReader *imgReader= vtkSTLReader::New();
00523 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
00524 _loadSTLMapper = vtkPolyDataMapper::New();
00525 _loadSTLMapper->SetInput(imgReader->GetOutput());
00526 _loadActorSTL = vtkActor::New();
00527 _loadActorSTL->SetMapper(_loadSTLMapper);
00528 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
00529 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
00530 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00531 ren->AddActor(_loadActorSTL);
00532 imgReader->Delete();
00533 }
00534
00535 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
00536 _mar->saveParameters( );
00537 }
00538
00539
00540
00541
00542 void wxSTLWidget_02::ConfigureJoinRegions()
00543 {
00544 arteryImageData = NULL;
00545 joiner = new vtkJoiner();
00546 }
00547
00548
00549 void wxSTLWidget_02::OnJoinRegions(wxCommandEvent& event)
00550 {
00551
00552
00553 joinMarchingCubes= vtkMarchingCubes::New();
00554 joinMarchingCubes->SetInput(arteryImageData);
00555 joinMarchingCubes->SetValue(0, 128);
00556 joinMarchingCubes->Update();
00557
00558 joinMapper = vtkPolyDataMapper::New();
00559 joinMapper->SetInput(joinMarchingCubes->GetOutput());
00560 joinMapper->ScalarVisibilityOff();
00561 joinMapper->ImmediateModeRenderingOn();
00562
00563 joinActor = vtkActor::New();
00564 joinActor->SetMapper(joinMapper);
00565 joinActor->GetProperty()->SetColor(1.0, 0.3, 1.0);
00566 joinActor->GetProperty()->SetOpacity( 0.9 );
00567
00568
00569
00570 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00571 ren->AddActor(joinActor);
00572
00573 }
00574
00575
00576
00577
00578
00579
00580
00581
00582 void wxSTLWidget_02::ConfigureSTL()
00583 {
00584 stlExterna = vtkPolyData::New();
00585 stlInterna = vtkPolyData::New();
00586
00587 dsm1 = vtkPolyDataMapper ::New();
00588 dsm1->SetInput (stlInterna);
00589 dsm1->ScalarVisibilityOff();
00590
00591 actorInternal = vtkActor::New();
00592 actorInternal->SetMapper (dsm1);
00593 actorInternal->GetProperty()->SetColor (0,1,0);
00594
00595 dsm2 = vtkPolyDataMapper ::New();
00596 dsm2->SetInput (stlExterna);
00597 dsm2->ScalarVisibilityOff();
00598
00599 actorExternal= vtkActor::New();
00600 actorExternal->SetMapper (dsm2);
00601 actorExternal->GetProperty()->SetRepresentationToWireframe();
00602
00603
00604 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
00605 ren->AddActor(actorInternal);
00606 ren->AddActor(actorExternal);
00607
00608 stlExtractor = new vtkSTLExtractor();
00609 }
00610
00611 void wxSTLWidget_02::generateSTLSurfaces()
00612 {
00613 stlExtractor->setVolume(_2_prgov->GetVolumen());
00614 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
00615 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
00616 stlExtractor->calculate();
00617 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
00618 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
00619 }
00620
00621
00622 void wxSTLWidget_02::OnOpacitySTLExternal(wxScrollEvent& event){
00623 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
00624 actorExternal->GetProperty( )->SetOpacity( value );
00625 Refresh();
00626 }
00627
00628
00629 void wxSTLWidget_02::OnOpacitySTLInternal(wxScrollEvent& event){
00630 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
00631 actorInternal->GetProperty( )->SetOpacity( value );
00632 Refresh();
00633 }
00634
00635 void wxSTLWidget_02::OnBtnCreateFileSTL(wxCommandEvent& event)
00636 {
00637
00638 wxString dirSTL = _mar->_parameters->getStringParam(
00639 marParameters::e_installation_directory );
00640 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
00641 wxDirDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
00642 dirSTL: wxGetHomeDir( ) );
00643
00644 if( dialog.ShowModal( ) == wxID_OK )
00645 {
00646
00647
00648
00649
00650
00651
00652 std::string prefix( dialog.GetPath().mb_str(wxConvUTF8) );
00653 std::string filename;
00654
00655
00656
00657 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
00658 filtro->SetInput(stlInterna);
00659 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
00660 pdcf->SetInput( filtro->GetOutput() );
00661 vtkClosePolyData *cpd = vtkClosePolyData::New();
00662 cpd->SetInput( pdcf->GetOutput() );
00663
00664
00665 cpd->Update();
00666 vtkSTLWriter *writerI = vtkSTLWriter::New();
00667 writerI->SetInput( cpd->GetOutput() );
00668
00669 filename=prefix+"\\internal.stl";
00670 writerI->SetFileName(filename.c_str());
00671 writerI->SetFileTypeToASCII();
00672 writerI->Write();
00673 writerI->Delete();
00674
00675
00676 filtro->SetInput(stlExterna);
00677 cpd->Update();
00678 vtkSTLWriter *writerE = vtkSTLWriter::New();
00679 writerE->SetInput( cpd->GetOutput() );
00680
00681 filename=prefix+"\\external.stl";
00682 writerE->SetFileName( filename.c_str() );
00683 writerE->SetFileTypeToASCII();
00684 writerE->Write();
00685 writerE->Delete();
00686
00687 filtro->Delete();
00688 cpd->Delete();
00689 pdcf->Delete();
00690 }
00691
00692
00693 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
00694 _mar->saveParameters( );
00695 }
00696
00697
00698 void wxSTLWidget_02::OnChangeSTLGaussLevel(wxScrollEvent& event)
00699 {
00700 wxBusyCursor wait;
00701 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
00702 generateSTLSurfaces();
00703 Refresh();
00704 }
00705
00706
00707 void wxSTLWidget_02::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
00708 {
00709 wxBusyCursor wait;
00710 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
00711 generateSTLSurfaces();
00712 Refresh();
00713
00714 }
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726