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
00024 #include "vtkExtractVOI.h"
00025 #include "vtkImageClip.h"
00026 #include "vtkImageResample.h"
00027 #include "vtkImageThreshold.h"
00028 #include "vtkImageCast.h"
00029 #include "vtkImageSeedConnectivity.h"
00030 #include "vtkImageData.h"
00031 #include "vtkMarchingCubes.h"
00032 #include "vtkImageReslice.h"
00033 #include "vtkTransform.h"
00034 #include "vtkSphereSource.h"
00035 #include "vtkDoubleArray.h"
00036 #include "vtkPointData.h"
00037 #include "vtkCommand.h"
00038 #include "vtkCallbackCommand.h"
00039 #include "vtkImageResample.h"
00040 #include "vtkMath.h"
00041 #include "vtkStripper.h"
00042
00043 #include "wxEmptyPanelWidget_2.h"
00044
00045 #include <wx/splitter.h>
00046
00047
00048
00049
00050
00051
00052 vtkStandardNewMacro(TreeExtraction_MH_JFC);
00053
00054
00055 TreeExtraction_MH_JFC::TreeExtraction_MH_JFC(){
00056 _branchLevel = 2;
00057 _imagedataResult = NULL;
00058 _cleanLevel = 400;
00059 }
00060
00061 TreeExtraction_MH_JFC::~TreeExtraction_MH_JFC(){
00062 Reset();
00063 }
00064
00065 void TreeExtraction_MH_JFC::Reset(){
00066 if (_imagedataResult!=NULL){
00067 _imagedataResult->Delete();
00068 }
00069 }
00070
00071 void TreeExtraction_MH_JFC::SetInput(marExperiment *input){
00072 _marExperiment = input;
00073 }
00074
00075
00076 void TreeExtraction_MH_JFC::BruleVolume(vtkImageData *imagedata, int x,int y,int z,int r , int value)
00077 {
00078 int ext[6];
00079 int i, j, k, ii,jj,kk;
00080 imagedata->GetExtent(ext);
00081 unsigned short *ptr;
00082 int x1=x-r;
00083 int x2=x+r;
00084 int y1=y-r;
00085 int y2=y+r;
00086 int z1=z-r;
00087 int z2=z+r;
00088 double tmpsqrt;
00089 for(i=x1;i<=x2;i++){
00090 for(j=y1;j<=y2;j++){
00091 for(k=z1;k<=z2;k++){
00092 ptr=(unsigned short *) imagedata->GetScalarPointer(i,j,k);
00093 ii=i-x;
00094 jj=j-y;
00095 kk=k-z;
00096 tmpsqrt=ii*ii + jj*jj + kk*kk;
00097 if ((ptr!=NULL) && ( sqrt(tmpsqrt)<=r))
00098 {
00099 if (value==0){
00100 *ptr=value;
00101 } else {
00102 if (*ptr==0) {
00103 *ptr=value;
00104 }
00105 }
00106 }
00107 }
00108 }
00109 }
00110 }
00111
00112
00113 void TreeExtraction_MH_JFC::BruleVolume(vtkImageData *imagedata,vtkPolyData *inputAxisRadio, int value)
00114 {
00115 int x,y,z,r;
00116 double point[3],radio;
00117 double fractpart, intpart;
00118 int i,maxPoints=inputAxisRadio->GetPoints()->GetNumberOfPoints();
00119 vtkDoubleArray *allRadios = (vtkDoubleArray*)(inputAxisRadio->GetPointData()->GetScalars("radio"));
00120 for (i=0; i<maxPoints; i++){
00121 inputAxisRadio->GetPoints()->GetPoint(i,point);
00122 radio=allRadios->GetValue(i);
00123 x = (int)(point[0]);
00124 y = (int)(point[1]);
00125 z = (int)(point[2]);
00126 fractpart = modf (radio , &intpart);
00127 if (fractpart>=0.5){
00128 intpart++;
00129 }
00130 r = (int)( intpart );
00131 BruleVolume(imagedata,x,y,z,r,value);
00132 }
00133 }
00134
00135
00136
00137
00138 void TreeExtraction_MH_JFC::FindVit( marExperiment *newExperiment , int actualAxis , double *pointBif , double *vit )
00139 {
00140 double dist,min=-1;
00141 double point[3];
00142 double dx,dy,dz;
00143 int jPoint,maxPoints;
00144 int iAxis,maxAxis;
00145
00146 maxAxis=newExperiment->getNumberOfAxes();
00147 for (iAxis=0;iAxis<maxAxis;iAxis++){
00148 if (iAxis!=actualAxis){
00149 newExperiment->setAxis(iAxis);
00150 marAxis *maraxis = newExperiment->getAxis( );
00151 if (maraxis!=NULL) {
00152 vtkPolyData *axisVtk = maraxis->GetAxisData();
00153 maxPoints=axisVtk->GetPoints()->GetNumberOfPoints();
00154 for (jPoint=0; jPoint<maxPoints; jPoint++){
00155 axisVtk->GetPoints()->GetPoint(jPoint,point);
00156 dx = pointBif[0]-point[0];
00157 dy = pointBif[1]-point[1];
00158 dz = pointBif[2]-point[2];
00159 dist = sqrt( dx*dx + dy*dy + dz*dz );
00160 if ((min==-1) || (dist<min)) {
00161 min=dist;
00162 vit[0] = dx;
00163 vit[1] = dy;
00164 vit[2] = dz;
00165 }
00166 }
00167 }
00168 }
00169 }
00170 }
00171
00172
00173 void TreeExtraction_MH_JFC::Execute(int count, int sens, double *vit, int cleanLevel)
00174 {
00175
00176
00177 count--;
00178
00179
00180
00181
00182
00183 int idActualAxis_Before = _marExperiment->getNumberOfAxes();
00184 _marExperiment->extractVascularTree( sens , vit, cleanLevel );
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 int idActualAxis = _marExperiment->getNumberOfAxes();
00195
00196 marAxis *maraxis = _marExperiment->getAxis( );
00197 if ((maraxis!=NULL) && (idActualAxis_Before!=idActualAxis)) {
00198 vtkImageData *imagedata = _marExperiment->getDynData( )->getVolume( )->castVtk();
00199 vtkPolyData *inputAxisRadio = maraxis->GetAxisData();
00200
00201 if (count>0){
00202
00203
00204
00205 _prgov = carotidaBifurcacion::New();
00206 _prgov->SetMaxPropRadio(5);
00207 _prgov->SetHumbral(0.45);
00208 _prgov->SetMaxPropMasa(10);
00209 _prgov->SetMinPropMasa(0.01);
00210 _prgov->SetInput( inputAxisRadio );
00211 _prgov->SetInput2( imagedata );
00212 _prgov->Update();
00213
00214
00215
00216
00217
00218
00219
00220 }
00221
00222
00223 BruleVolume(imagedata , inputAxisRadio , 0 );
00224 BruleVolume(_imagedataResult , inputAxisRadio , idActualAxis );
00225 inputAxisRadio->Delete();
00226
00227
00228 if (count>0){
00229
00230 vtkPolyData *bifurcations = _prgov->GetOutput();
00231 int i,maxPoints = bifurcations->GetPoints()->GetNumberOfPoints();
00232 int x,y,z;
00233 double point[3], vit[3];
00234 for (i=0; i<maxPoints; i++){
00235 bifurcations->GetPoints()->GetPoint(i,point);
00236 x = (int)(point[0]);
00237 y = (int)(point[1]);
00238 z = (int)(point[2]);
00239 FindVit( _marExperiment , idActualAxis , point , vit );
00240 _marExperiment->setStartPoint( x , y , z );
00241
00242 Execute(count, 0 , vit , (int)_cleanLevel );
00243 }
00244 bifurcations->Delete();
00245
00246
00247 }
00248
00249 }
00250 }
00251
00252
00253 void TreeExtraction_MH_JFC::InitImagaDataResult(){
00254 Reset();
00255 vtkImageData *imagedata = _marExperiment->getDynData( )->getVolume( )->castVtk();
00256 imagedata->Update();
00257 _imagedataResult = vtkImageData::New();
00258 int dim[3];
00259 imagedata->GetDimensions(dim);
00260 _imagedataResult->SetScalarType(imagedata->GetScalarType());
00261
00262 _imagedataResult->SetDimensions(dim[0],dim[1],dim[2]);
00263 _imagedataResult->SetExtent( 0 , dim[0]-1 , 0 , dim[1]-1 , 0 , dim[2]-1 );
00264 _imagedataResult->SetWholeExtent(0 , dim[0]-1 , 0 , dim[1]-1 , 0 , dim[2]-1 );
00265 _imagedataResult->SetSpacing( imagedata->GetSpacing() );
00266 _imagedataResult->SetOrigin( 0,0,0 );
00267 _imagedataResult->Update();
00268 _imagedataResult->UpdateData();
00269 unsigned short *ptr;
00270 int i,j,k;
00271 for ( i=0 ; i<dim[0] ; i++ ){
00272 for ( j=0 ; j<dim[1] ; j++ ){
00273 for ( k=0 ; k<dim[2] ; k++ ){
00274 ptr = (unsigned short *) _imagedataResult->GetScalarPointer(i,j,k);
00275 *ptr = 0;
00276 }
00277 }
00278 }
00279 }
00280
00281 void TreeExtraction_MH_JFC::Update(){
00282
00283
00284
00285
00286
00287 InitImagaDataResult();
00288 Execute(_branchLevel);
00289 }
00290
00291 marExperiment* TreeExtraction_MH_JFC::GetInput(){
00292 return _marExperiment;
00293 }
00294
00295 vtkImageData* TreeExtraction_MH_JFC::GetVolume(){
00296 return _imagedataResult;
00297 }
00298
00299 void TreeExtraction_MH_JFC::SetBranchLevel(int branchLevel){
00300 _branchLevel = branchLevel;
00301 }
00302
00303 void TreeExtraction_MH_JFC::SetCleanTreeLevel( int cleanLevel ){
00304 _cleanLevel = (double)cleanLevel;
00305 }
00306
00307
00308
00309
00310 wxEmptyPanelWidget_2::wxEmptyPanelWidget_2(wxWindow *parent, marInterface* mar)
00311 : wxPanel( parent, -1)
00312 {
00313
00314 _sensibility_JF = 0.5;
00315
00316 _mar = mar;
00317 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
00318 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
00319 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
00320 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
00321
00322 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
00323 pnlSplitter -> SetMinimumPaneSize( 150 );
00324 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
00325 this -> SetSizer(sizer);
00326
00327
00328 _mCubes = NULL;
00329 _surfMapper = NULL;
00330 _surfActor = NULL;
00331
00332
00333 _1_prgov = NULL;
00334 _1_mapfinal = NULL;
00335 _1_stripfinal = NULL;
00336 _1_isoMapperMC6 = NULL;
00337 _1_isoActorMC6 = NULL;
00338 _1_isoMC6 = NULL;
00339
00340
00341 _2_prgov = NULL;
00342 _2_mapfinal = NULL;
00343 _2_stripfinal = NULL;
00344 _2_isoMapperMC6 = NULL;
00345 _2_isoActorMC6 = NULL;
00346 _2_isoMC6 = NULL;
00347
00348
00349 _isoMapperMC1 = NULL;
00350 _isoActorMC1 = NULL;
00351 _isoMC1 = NULL;
00352 _imageThresholdMC1 = NULL;
00353
00354
00355 _treeExtraction = NULL;
00356
00357 }
00358
00359 wxEmptyPanelWidget_2::~wxEmptyPanelWidget_2(){
00360
00361 if (_mCubes ) { _mCubes -> Delete(); }
00362 if (_surfMapper ) { _surfMapper -> Delete(); }
00363 if (_surfActor ) { _surfActor -> Delete(); }
00364
00365
00366 ResetTree1_JF();
00367 ResetTree2_JF();
00368 ResetTree_MH_JFC();
00369 }
00370
00371 wxPanel* wxEmptyPanelWidget_2::CreateViewPanel(wxWindow *parent)
00372 {
00373 wxPanel *panel = new wxPanel(parent,-1);
00374 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00375 _maracasSurfaceWidget = new wxSurfaceWidget(panel);
00376 sizer->Add(_maracasSurfaceWidget , 1, wxEXPAND, 0);
00377 panel->SetSizer(sizer);
00378 panel->SetAutoLayout(true);
00379 panel->SetSize(400,400);
00380 panel->Layout();
00381 return panel;
00382 }
00383
00384 wxPanel* wxEmptyPanelWidget_2::CreateControlPanel(wxWindow *parent)
00385 {
00386 wxPanel *panel = new wxPanel(parent,-1);
00387 _opacity_OrigVol = new wxSlider( panel, -1, 30, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00388 _isoValue = new wxSlider( panel, -1, 0 , 0, 3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00389 _opacity_Res1VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00390 _opacity_Res2VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00391 _sl_sensibility_JF = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00392 _branchLevel = new wxSlider( panel, -1, 2 , 1, 10 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00393 _opacity_ResVolMHJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00394 _isoValue_MH_JFC = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00395 _cleanTree_MH_JFC = new wxSlider( panel, -1, 400 , 0, 1000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00396
00397 int tmp_sensibility= (int)(_sensibility_JF*100.0);
00398 _sl_sensibility_JF->SetValue( tmp_sensibility );
00399
00400
00401 _opacity_OrigVol ->SetSize(250,20);
00402 _isoValue ->SetSize(250,20);
00403 _opacity_Res1VolJF ->SetSize(250,20);
00404 _opacity_Res2VolJF ->SetSize(250,20);
00405 _branchLevel ->SetSize(250,20);
00406 _opacity_ResVolMHJF ->SetSize(250,20);
00407
00408
00409 wxButton *btnExtractTree1_JF = new wxButton(panel,-1,_T("Extract Tree 1 JF"));
00410 wxButton *btnEraseTree1_JF = new wxButton(panel,-1,_T("Erase Tree 1 JF"));
00411
00412
00413 wxButton *btnExtractTree2_JF = new wxButton(panel,-1,_T("Extract Tree 2 JF"));
00414 wxButton *btnEraseTree2_JF = new wxButton(panel,-1,_T("Erase Tree 2 JF"));
00415
00416
00417 wxButton *btnExtractTree_MH_JFC = new wxButton(panel,-1,_T("Extract Tree MH + JFC"));
00418 wxButton *btnEraseTree_MH_JFC = new wxButton(panel,-1,_T("Erase Tree MH + JFC"));
00419
00420
00421 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
00422 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00423 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00424 sizer->Add(new wxStaticText(panel,-1,_T("Isovalue - Original Volume")));
00425 sizer->Add(_isoValue);
00426 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Original Volume")));
00427 sizer->Add(_opacity_OrigVol);
00428
00429 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00430 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00431 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Juan Francisco Module 1 - - - ")));
00432 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00433 sizer->Add(btnExtractTree1_JF);
00434 sizer->Add(btnEraseTree1_JF);
00435 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00436 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
00437 sizer->Add(_opacity_Res1VolJF);
00438
00439 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00440 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00441 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Juan Francisco Module 2 - - - ")));
00442 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00443 sizer->Add(new wxStaticText(panel,-1,_T(" % Sensibility")));
00444 sizer->Add(_sl_sensibility_JF);
00445 sizer->Add(btnExtractTree2_JF);
00446 sizer->Add(btnEraseTree2_JF);
00447 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00448 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
00449 sizer->Add(_opacity_Res2VolJF);
00450
00451
00452 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00453 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00454 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00455 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00456 sizer->Add(new wxStaticText(panel,-1,_T(" - - - MH + JFC - - - ")));
00457 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00458 sizer->Add(btnExtractTree_MH_JFC);
00459 sizer->Add(btnEraseTree_MH_JFC);
00460 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00461 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00462 sizer->Add(new wxStaticText(panel,-1,_T("Branch Level MH+JFC")));
00463 sizer->Add(_branchLevel);
00464 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00465 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume MH+JFC")));
00466 sizer->Add(_opacity_ResVolMHJF);
00467 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00468 sizer->Add(new wxStaticText(panel,-1,_T("IsoValue - Result Volume MH+JFC")));
00469 sizer->Add(_isoValue_MH_JFC);
00470 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00471 sizer->Add(new wxStaticText(panel,-1,_T("signal level (Clean Tree)")));
00472 sizer->Add(_cleanTree_MH_JFC);
00473
00474 panel->SetSizer(sizer);
00475 panel->SetAutoLayout(true);
00476 panel->SetSize(400,400);
00477 panel->Layout();
00478 Connect(_opacity_OrigVol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_OrigVol );
00479 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnIsoValue );
00480 Connect(_opacity_Res1VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_Res1VolJF );
00481 Connect(_opacity_Res2VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_Res2VolJF );
00482 Connect(_sl_sensibility_JF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnSensibility );
00483
00484 Connect(btnExtractTree1_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree1_JF );
00485 Connect(btnEraseTree1_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree1_JF );
00486 Connect(btnExtractTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree2_JF );
00487 Connect(btnEraseTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree2_JF );
00488
00489 Connect(btnExtractTree_MH_JFC->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree_MH_JFC);
00490 Connect(btnEraseTree_MH_JFC->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree_MH_JFC );
00491 Connect(_branchLevel->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBranchLevel );
00492 Connect(_opacity_ResVolMHJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_ResVolMHJF );
00493 Connect(_isoValue_MH_JFC->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnIsoValue_MH_JFC );
00494 Connect(_cleanTree_MH_JFC->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnCleanTree_MH_JFC );
00495
00496 return panel;
00497 }
00498
00499 void wxEmptyPanelWidget_2::Refresh()
00500 {
00501 _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->Render();
00502 }
00503
00504 void wxEmptyPanelWidget_2::ConfigureVTK()
00505 {
00506 wxBusyCursor wait;
00507
00508 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
00509 double opacity_OrigVol = ((double)(_opacity_OrigVol->GetValue()))/100;
00510 double isoValue;
00511
00512
00513 double range[2];
00514 imagedata->GetScalarRange( range );
00515 isoValue=range[1] / 8;
00516
00517 _mCubes = vtkMarchingCubes::New( );
00518 _mCubes->SetInput( imagedata );
00519 _mCubes->SetValue( 0, isoValue );
00520
00521 vtkStripper *stripper = vtkStripper::New();
00522 stripper->SetInput( _mCubes->GetOutput( ) );
00523
00524 _surfMapper = vtkPolyDataMapper::New( );
00525 _surfMapper->SetInput( stripper->GetOutput() );
00526 _surfMapper->ScalarVisibilityOff( );
00527 stripper->Delete();
00528
00529 _surfActor = vtkActor::New( );
00530 _surfActor->SetMapper( _surfMapper );
00531 _surfActor->PickableOff( );
00532 _surfActor->GetProperty( )->SetColor( 0, 0, 0.8 );
00533 _surfActor->GetProperty( )->SetOpacity( opacity_OrigVol );
00534
00535
00536 _isoValue->SetRange( (int)(range[0]), (int)(range[1]) );
00537 _isoValue->SetValue( (int)isoValue );
00538
00539
00540 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00541 ren->AddActor(_surfActor);
00542
00543
00544 _maracasSurfaceWidget->ShowMARACASData( _mar );
00545 }
00546
00547
00548
00549 void wxEmptyPanelWidget_2::ResetTree1_JF()
00550 {
00551
00552 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00553 if (_1_isoActorMC6){
00554 ren->RemoveActor(_1_isoActorMC6);
00555 }
00556 if (_1_stripfinal){
00557 ren->RemoveActor(_1_stripfinal);
00558 }
00559
00560
00561 if (_1_prgov ) { _1_prgov -> Delete(); }
00562 if (_1_mapfinal ) { _1_mapfinal -> Delete(); }
00563 if (_1_stripfinal ) { _1_stripfinal -> Delete(); }
00564 if (_1_isoMapperMC6 ) { _1_isoMapperMC6 -> Delete(); }
00565 if (_1_isoActorMC6 ) { _1_isoActorMC6 -> Delete(); }
00566 if (_1_isoMC6 ) { _1_isoMC6 -> Delete(); }
00567
00568
00569 _1_prgov = NULL;
00570 _1_mapfinal = NULL;
00571 _1_stripfinal = NULL;
00572 _1_isoMapperMC6 = NULL;
00573 _1_isoActorMC6 = NULL;
00574 _1_isoMC6 = NULL;
00575 }
00576
00577
00578 void wxEmptyPanelWidget_2::ResetTree2_JF()
00579 {
00580
00581 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00582 if (_2_isoActorMC6){
00583 ren->RemoveActor(_2_isoActorMC6);
00584 }
00585 if (_2_stripfinal){
00586 ren->RemoveActor(_2_stripfinal);
00587 }
00588
00589
00590 if (_2_prgov ) { _2_prgov -> Delete(); }
00591 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
00592 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
00593 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
00594 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
00595 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
00596
00597
00598 _2_prgov = NULL;
00599 _2_mapfinal = NULL;
00600 _2_stripfinal = NULL;
00601 _2_isoMapperMC6 = NULL;
00602 _2_isoActorMC6 = NULL;
00603 _2_isoMC6 = NULL;
00604 }
00605
00606
00607
00608
00609 void wxEmptyPanelWidget_2::ExtractTree1_JF(int x, int y, int z)
00610 {
00611 double opacity_Res1VolJF = ((double)_opacity_Res1VolJF->GetValue())/100;
00612 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
00613
00614 double puntoactualprov[3];
00615 double espprin[3];
00616 int extprin[6];
00617
00618 puntoactualprov[0]=x;
00619 puntoactualprov[1]=y;
00620 puntoactualprov[2]=z;
00621
00622 imagedata->GetSpacing(espprin);
00623 imagedata->GetExtent(extprin);
00624
00625 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
00626 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
00627 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
00628
00629
00630 _1_prgov= axisExtractor::New();
00631 _1_prgov->SetHumbral(0.45);
00632 _1_prgov->SetInput(imagedata);
00633 _1_prgov->SetPoint(puntoactualprov);
00634 _1_prgov->Update();
00635
00636
00637 _1_mapfinal = vtkPolyDataMapper::New();
00638 _1_mapfinal->SetInput(_1_prgov->GetOutput());
00639
00640 _1_stripfinal = vtkActor::New();
00641 _1_stripfinal->SetMapper(_1_mapfinal);
00642 _1_stripfinal->GetProperty()->SetColor(1, 1, 1);
00643 _1_stripfinal->GetProperty()->SetLineWidth(2);
00644 _1_stripfinal->GetProperty()->BackfaceCullingOff();
00645
00646
00647 vtkImageData *imageOut = _1_prgov->GetVolumen();
00648 imageOut->Update();
00649
00650 _1_isoMC6 = vtkMarchingCubes::New();
00651 _1_isoMC6->SetInput(imageOut);
00652 _1_isoMC6->SetValue(0, 1);
00653 _1_isoMC6->Update();
00654
00655 _1_isoMapperMC6 = vtkPolyDataMapper::New();
00656 _1_isoMapperMC6->SetInput(_1_isoMC6->GetOutput());
00657 _1_isoMapperMC6->ScalarVisibilityOff();
00658 _1_isoMapperMC6->ImmediateModeRenderingOn();
00659
00660 _1_isoActorMC6 = vtkActor::New();
00661 _1_isoActorMC6->SetMapper(_1_isoMapperMC6);
00662 _1_isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
00663 _1_isoActorMC6->GetProperty()->SetOpacity( opacity_Res1VolJF );
00664
00665
00666
00667 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00668 ren->AddActor(_1_isoActorMC6);
00669 ren->AddActor(_1_stripfinal);
00670 }
00671
00672
00673
00674 void wxEmptyPanelWidget_2::ExtractTree2_JF(int x, int y, int z)
00675 {
00676 double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
00677 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
00678
00679 double puntoactualprov[3];
00680 double espprin[3];
00681 int extprin[6];
00682
00683 puntoactualprov[0]=x;
00684 puntoactualprov[1]=y;
00685 puntoactualprov[2]=z;
00686
00687 imagedata->GetSpacing(espprin);
00688 imagedata->GetExtent(extprin);
00689
00690 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
00691 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
00692 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
00693
00694 _2_prgov= axisExtractor02::New();
00695 _2_prgov->SetParam(1);
00696 _2_prgov->SetParam2(1);
00697 _2_prgov->SetParam3(_sensibility_JF);
00698 _2_prgov->SetMaxant(20);
00699 _2_prgov->SetMinant(5);
00700 _2_prgov->SetInput(imagedata);
00701 _2_prgov->SetPoint(puntoactualprov);
00702 _2_prgov->Update();
00703
00704
00705 _2_mapfinal = vtkPolyDataMapper::New();
00706 _2_mapfinal->SetInput(_2_prgov->GetOutput());
00707
00708 _2_stripfinal = vtkActor::New();
00709 _2_stripfinal->SetMapper(_2_mapfinal);
00710 _2_stripfinal->GetProperty()->SetColor(0.3, 0.3, 0.3);
00711 _2_stripfinal->GetProperty()->SetLineWidth(2);
00712 _2_stripfinal->GetProperty()->BackfaceCullingOff();
00713
00714
00715 vtkImageData *imageOut = _2_prgov->GetVolumen();
00716 imageOut->Update();
00717
00718 _2_isoMC6 = vtkMarchingCubes::New();
00719 _2_isoMC6->SetInput(imageOut);
00720 _2_isoMC6->SetValue(0, 1);
00721 _2_isoMC6->Update();
00722
00723 _2_isoMapperMC6 = vtkPolyDataMapper::New();
00724 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
00725 _2_isoMapperMC6->ScalarVisibilityOff();
00726 _2_isoMapperMC6->ImmediateModeRenderingOn();
00727
00728 _2_isoActorMC6 = vtkActor::New();
00729 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
00730 _2_isoActorMC6->GetProperty()->SetColor( 1, 1, 0);
00731 _2_isoActorMC6->GetProperty()->SetOpacity( opacity_Res2VolJF );
00732
00733
00734 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00735 ren->AddActor(_2_isoActorMC6);
00736 ren->AddActor(_2_stripfinal);
00737 }
00738
00739
00740 void wxEmptyPanelWidget_2::OnOpacity_OrigVol(wxScrollEvent& event)
00741 {
00742 double value = ((double)_opacity_OrigVol->GetValue())/100;
00743 _surfActor->GetProperty( )->SetOpacity( value );
00744 Refresh();
00745 }
00746
00747 void wxEmptyPanelWidget_2::OnOpacity_Res1VolJF(wxScrollEvent& event)
00748 {
00749 if (_1_isoActorMC6!=NULL){
00750 double value = ((double)_opacity_Res1VolJF->GetValue())/100;
00751 _1_isoActorMC6->GetProperty( )->SetOpacity( value );
00752 Refresh();
00753 }
00754 }
00755
00756 void wxEmptyPanelWidget_2::OnOpacity_Res2VolJF(wxScrollEvent& event)
00757 {
00758 if (_2_isoActorMC6!=NULL){
00759 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
00760 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
00761 Refresh();
00762 }
00763 }
00764
00765
00766 void wxEmptyPanelWidget_2::OnIsoValue(wxScrollEvent& event)
00767 {
00768 wxBusyCursor wait;
00769 _mCubes->SetValue(0, _isoValue->GetValue());
00770 Refresh();
00771 }
00772
00773 void wxEmptyPanelWidget_2::OnBtnExtractTree1_JF(wxCommandEvent& event)
00774 {
00775 if (_1_prgov==NULL){
00776 wxBusyCursor wait;
00777 vtk3DSurfaceWidget *world3D = _maracasSurfaceWidget->GetVtk3DSurfaceWidget();
00778 if( world3D->GetInitialSphere() ){
00779 double point[3];
00780 world3D->GetSphereCenter( point );
00781 ExtractTree1_JF((int)point[0],(int)point[1],(int)point[2]);
00782 }
00783 Refresh();
00784 }
00785 }
00786
00787 void wxEmptyPanelWidget_2::OnBtnExtractTree2_JF(wxCommandEvent& event)
00788 {
00789 if (_2_prgov==NULL){
00790 wxBusyCursor wait;
00791 vtk3DSurfaceWidget *world3D = _maracasSurfaceWidget->GetVtk3DSurfaceWidget();
00792 if( world3D->GetInitialSphere() ){
00793 double point[3];
00794 world3D->GetSphereCenter( point );
00795 ExtractTree2_JF((int)point[0],(int)point[1],(int)point[2]);
00796 }
00797 Refresh();
00798 }
00799 }
00800
00801 void wxEmptyPanelWidget_2::OnBtnEraseTree1_JF(wxCommandEvent& event)
00802 {
00803 ResetTree1_JF();
00804 Refresh();
00805 }
00806
00807 void wxEmptyPanelWidget_2::OnBtnEraseTree2_JF(wxCommandEvent& event)
00808 {
00809 ResetTree2_JF();
00810 Refresh();
00811 }
00812
00813
00814 void wxEmptyPanelWidget_2::PaintVascularTree_MH_JFC(marExperiment * newExperiment)
00815 {
00816 vtkActor *branchActor;
00817 vtkPolyData *axisVtk;
00818 vtkPolyDataMapper *branchMapper;
00819 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00820
00821 int i,maxAxis=newExperiment->getNumberOfAxes();
00822 for (i=0;i<maxAxis;i++){
00823 newExperiment->setAxis(i);
00824 marAxis *maraxis =newExperiment->getAxis( );
00825 if (maraxis!=NULL) {
00826 axisVtk = maraxis->Draw();
00827 branchMapper = vtkPolyDataMapper::New( );
00828 branchMapper->SetInput( axisVtk );
00829 branchMapper->Update();
00830 branchActor = vtkActor::New( );
00831 branchActor->SetMapper( branchMapper );
00832 branchActor->GetProperty()->SetColor( 1, 1, 1 );
00833 if (i== 0) { branchActor->GetProperty()->SetColor( 0 , 0 , 0.3 ); }
00834 if (i== 1) { branchActor->GetProperty()->SetColor( 0 , 0.3 , 0.3 ); }
00835 if (i== 2) { branchActor->GetProperty()->SetColor( 0.3, 0.3 , 0.3 ); }
00836 if (i== 3) { branchActor->GetProperty()->SetColor( 0.0, 0.0 , 0.6 ); }
00837 if (i== 4) { branchActor->GetProperty()->SetColor( 0.0, 0.6 , 0.6 ); }
00838 if (i== 5) { branchActor->GetProperty()->SetColor( 0.6, 0.6 , 0.6 ); }
00839 if (i== 7) { branchActor->GetProperty()->SetColor( 0.0, 0.0 , 0.9 ); }
00840 if (i== 8) { branchActor->GetProperty()->SetColor( 0.0, 0.9 , 0.9 ); }
00841 if (i== 9) { branchActor->GetProperty()->SetColor( 0.9, 0.9 , 0.9 ); }
00842 if (i==10) { branchActor->GetProperty()->SetColor( 0.9, 0.0 , 0.0 ); }
00843 if (i==11) { branchActor->GetProperty()->SetColor( 0.6, 0.0 , 0.0 ); }
00844 if (i==12) { branchActor->GetProperty()->SetColor( 0.3, 0.0 , 0.0 ); }
00845 if (i==13) { branchActor->GetProperty()->SetColor( 0.6, 0.6 , 0.0 ); }
00846 if (i==14) { branchActor->GetProperty()->SetColor( 0.3, 0.3 , 0.0 ); }
00847 if (i==15) { branchActor->GetProperty()->SetColor( 0.9, 0.9 , 0.0 ); }
00848 branchActor->GetProperty()->SetLineWidth( 2.0 );
00849 ren->AddActor( branchActor );
00850
00851 _lstAxisVtk.push_back( axisVtk );
00852 _lstBranchActor.push_back( branchActor );
00853 _lstBranchMapper.push_back( branchMapper );
00854 }
00855 }
00856 }
00857
00858
00859
00860 void wxEmptyPanelWidget_2::PaintVascularVolume_MH_JFC(vtkImageData * image)
00861 {
00862
00863
00864 image->Update();
00865
00866 _imageThresholdMC1=vtkImageThreshold::New();
00867 _imageThresholdMC1->SetInput(image);
00868 _imageThresholdMC1->ThresholdBetween(0,100);
00869 _imageThresholdMC1->SetOutValue ( 0 );
00870 _imageThresholdMC1->Update();
00871
00872 _isoMC1 = vtkMarchingCubes::New();
00873 _isoMC1->SetInput(_imageThresholdMC1->GetOutput() );
00874 _isoMC1->SetValue(0, 1);
00875 _isoMC1->Update();
00876
00877 _isoMapperMC1 = vtkPolyDataMapper::New();
00878 _isoMapperMC1->SetInput(_isoMC1->GetOutput());
00879 _isoMapperMC1->ScalarVisibilityOff();
00880 _isoMapperMC1->ImmediateModeRenderingOn();
00881 _isoMapperMC1->Update();
00882
00883 _isoActorMC1 = vtkActor::New();
00884 _isoActorMC1->SetMapper(_isoMapperMC1);
00885 _isoActorMC1->GetProperty()->SetColor( 1, 0, 0);
00886 _isoActorMC1->GetProperty()->SetOpacity( 0.4 );
00887
00888
00889 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00890 ren->AddActor(_isoActorMC1);
00891 }
00892
00893
00894 void wxEmptyPanelWidget_2::WriteSignals(marExperiment *newExperiment){
00895 int i = 0;
00896 int j = 0;
00897 bool ok = true;
00898 int value = 0;
00899 int maxAxis = newExperiment->getNumberOfAxes();
00900
00901 FILE *ff;
00902 ff=fopen("c:/Temp/MaracasTEMP.TXT", "w");
00903
00904 while (ok==true){
00905 ok=false;
00906 for (i=0;i<maxAxis;i++){
00907 newExperiment->setAxis(i);
00908 marAxis *maraxis =newExperiment->getAxis( );
00909 if (maraxis!=NULL) {
00910 if ( j < maraxis->getNumberOfControlPoints() ){
00911 ok=true;
00912 value= (int) (maraxis->getSignal((uint)j) );
00913 fprintf(ff,"%d\t", value );
00914 } else {
00915 fprintf(ff,"\t");
00916 }
00917 }
00918 }
00919 fprintf(ff,"\n" );
00920 j++;
00921 }
00922 fclose(ff);
00923
00924 }
00925
00926
00927
00928 void wxEmptyPanelWidget_2::OnBtnExtractTree_MH_JFC(wxCommandEvent& event)
00929 {
00930 if ((_lstBranchActor.size()==0)
00931 &&
00932 (_maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetInitialSphere() ) )
00933 {
00934 wxBusyCursor wait;
00935
00936
00937 int voiA[6];
00938 int voiB[6];
00939 _mar->_experiment->getVOI(voiA);
00940 voiB[0]=0;
00941 voiB[1]=voiA[1]-voiA[0];
00942 voiB[2]=0;
00943 voiB[3]=voiA[3]-voiA[2];
00944 voiB[4]=0;
00945 voiB[5]=voiA[5]-voiA[4];
00946 marExperiment *newExperiment = new marExperiment( _mar->_experiment->getParameters() );
00947 newExperiment->setVOI( voiB );
00948 newExperiment->initExperiment( _mar->_experiment->getDynData( )->getVolume() );
00949
00950 double point[3];
00951 int extent[ 6 ];
00952 _mar->_experiment->getDynData( )->getVolume( )->castVtk()->GetExtent( extent );
00953 _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetSphereCenter( point );
00954 int x = (int)point[0] - extent[0];
00955 int y = (int)point[1] - extent[2];
00956 int z = (int)point[2] - extent[4];
00957 newExperiment->setStartPoint( x, y, z);
00958
00959
00960 _treeExtraction = TreeExtraction_MH_JFC::New();
00961 _treeExtraction->SetInput(newExperiment);
00962 _treeExtraction->SetCleanTreeLevel( _cleanTree_MH_JFC->GetValue() );
00963 _treeExtraction->SetBranchLevel( _branchLevel->GetValue() );
00964 _treeExtraction->Update();
00965
00966
00967 PaintVascularTree_MH_JFC(newExperiment);
00968
00969 PaintVascularVolume_MH_JFC( _treeExtraction->GetVolume() );
00970 Refresh( );
00971
00972 WriteSignals(newExperiment);
00973
00974
00975 delete newExperiment;
00976 }
00977 }
00978
00979 void wxEmptyPanelWidget_2::OnBtnEraseTree_MH_JFC(wxCommandEvent& event)
00980 {
00981 ResetTree_MH_JFC();
00982 Refresh();
00983 }
00984
00985
00986 void wxEmptyPanelWidget_2::ResetTree_MH_JFC()
00987 {
00988
00989 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
00990 int i,size;
00991 size=_lstAxisVtk.size();
00992 size=_lstBranchMapper.size();
00993 size=_lstBranchActor.size();
00994 for (i=0;i<size;i++){
00995 if (_lstBranchActor[i]!=NULL){
00996 ren->RemoveActor( _lstBranchActor[i] );
00997 }
00998 }
00999 for (i=0;i<size;i++){
01000
01001 if (_lstAxisVtk[i] != NULL ) { _lstAxisVtk[i] -> Delete(); }
01002
01003 if (_lstBranchActor[i] != NULL ) { _lstBranchActor[i] -> Delete(); }
01004
01005 _lstAxisVtk[i] = NULL;
01006 _lstBranchActor[i] = NULL;
01007 _lstBranchMapper[i] = NULL;
01008 }
01009 _lstAxisVtk.clear();
01010 _lstBranchActor.clear();
01011 _lstBranchMapper.clear();
01012
01013
01014 if (_isoActorMC1){
01015 ren->RemoveActor(_isoActorMC1);
01016 }
01017
01018
01019 if (_isoMapperMC1 ) { _isoMapperMC1 -> Delete(); }
01020 if (_isoActorMC1 ) { _isoActorMC1 -> Delete(); }
01021 if (_isoMC1 ) { _isoMC1 -> Delete(); }
01022 if (_imageThresholdMC1 ) { _imageThresholdMC1 -> Delete(); }
01023
01024
01025
01026 _isoMapperMC1 = NULL;
01027 _isoActorMC1 = NULL;
01028 _isoMC1 = NULL;
01029 _imageThresholdMC1 = NULL;
01030
01031
01032
01033
01034
01035 }
01036
01037
01038 void wxEmptyPanelWidget_2::OnOpacity_ResVolMHJF(wxScrollEvent& event)
01039 {
01040 if (_isoActorMC1!=NULL){
01041 double value = ((double)_opacity_ResVolMHJF->GetValue())/100;
01042 _isoActorMC1->GetProperty( )->SetOpacity( value );
01043 }
01044 Refresh();
01045 }
01046
01047 void wxEmptyPanelWidget_2::OnBranchLevel(wxScrollEvent& event)
01048 {
01049
01050 }
01051
01052 void wxEmptyPanelWidget_2::OnIsoValue_MH_JFC(wxScrollEvent& event)
01053 {
01054 if (_imageThresholdMC1!=NULL){
01055 wxBusyCursor wait;
01056 double threshold = _isoValue_MH_JFC->GetValue();
01057 if (threshold!=0){
01058 _imageThresholdMC1->ThresholdBetween(threshold, threshold );
01059 } else {
01060 _imageThresholdMC1->ThresholdBetween(0, 1000 );
01061 }
01062 Refresh();
01063 }
01064 }
01065
01066 void wxEmptyPanelWidget_2::OnCleanTree_MH_JFC(wxScrollEvent& event)
01067 {
01068
01069 }
01070
01071 void wxEmptyPanelWidget_2::OnSensibility(wxScrollEvent& event)
01072 {
01073 _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;
01074 }
01075