]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/Copie de wxSTLWidget_03.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / Copie de wxSTLWidget_03.cxx
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/Copie de wxSTLWidget_03.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/Copie de wxSTLWidget_03.cxx
new file mode 100644 (file)
index 0000000..1afdbfb
--- /dev/null
@@ -0,0 +1,1033 @@
+
+#include "vtkObjectFactory.h"
+
+#include "vtkActor.h"
+#include "vtkCylinderSource.h"
+#include "vtkPolyDataMapper.h"
+#include "vtkRenderer.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderWindowInteractor.h"
+#include "vtkProperty.h"
+#include "vtkCamera.h"
+#include "vtkPoints.h"
+#include "vtkCellArray.h"
+#include "vtkPolyData.h"
+#include "vtkPolyDataMapper.h"
+#include "vtkPolyDataWriter.h"
+#include "vtkPolyDataReader.h"
+#include "vtkImageReader.h"
+#include "vtkImageViewer.h"
+#include "vtkImageViewer2.h"
+#include "vtkImageToStructuredPoints.h"
+#include <vtkImageThreshold.h> 
+#include "vtkImageWriter.h"
+
+
+#include "vtkExtractVOI.h"
+#include "vtkImageClip.h"
+#include "vtkImageResample.h"
+#include "vtkImageThreshold.h"
+#include "vtkImageCast.h"
+#include "vtkImageSeedConnectivity.h"
+#include "vtkImageData.h"
+#include "vtkMarchingCubes.h"
+#include "vtkImageReslice.h"
+#include "vtkTransform.h"
+#include "vtkSphereSource.h"
+#include "vtkDoubleArray.h"
+#include "vtkPointData.h"
+#include "vtkCommand.h"
+#include "vtkCallbackCommand.h"
+#include "vtkImageResample.h"
+#include "vtkMath.h"
+#include "vtkStripper.h"
+#include <vtkSTLReader.h> 
+#include "vtkMetaImageWriter.h"
+
+
+#include "vtkTriangleFilter.h"
+#include "vtkSTLWriter.h"
+#include "vtkPolyDataConnectivityFilter.h"
+#include "vtkClosePolyData.h"
+#include "vtkAppendFilter.h"
+
+#include "wxSTLWidget_03.h"
+
+#include <wx/splitter.h>
+
+#include <wx/filedlg.h>
+
+
+
+//-------------------------------------------------------------------
+//-------------------------------------------------------------------
+//-------------------------------------------------------------------
+wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent, marInterface* mar)
+: wxPanel( parent, -1) 
+{
+       _wxMaracasMPR           = NULL;
+       _maxSize                = 2000;
+       _minSize                = 300;
+
+       _stlMarchingCubesLevel  = 128;
+       _stlDeltaGaussLevel             = 100;
+
+       _mar=new marInterface();        
+       _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
+       _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
+       _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
+       _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
+       _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
+       _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
+       int voi[6];
+       mar->_experiment->getVOI( voi );
+       _mar->_experiment->setVOI( voi );
+       _mar->SetDicom(mar->_dicom);
+       _mar->initExperiment( );
+        
+
+       wxBoxSizer              *sizer          = new wxBoxSizer(wxVERTICAL  );
+       wxSplitterWindow        *pnlSplitter    = new wxSplitterWindow( this , -1);
+       wxPanel                 *viewPanel      = CreateViewPanel(pnlSplitter);
+printf("EED wxSTLWidget_03::wxSTLWidget_03 01\n");
+       wxPanel                 *controlPanel   = CreateControlPanel(pnlSplitter);
+printf("EED wxSTLWidget_03::wxSTLWidget_03 02\n");
+
+       sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
+       pnlSplitter     -> SetMinimumPaneSize( 150 );
+       pnlSplitter     -> SplitVertically( viewPanel, controlPanel, 600 );
+
+//     pnlSplitter     -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
+//     pnlSplitter     -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
+
+       this            -> SetSizer(sizer);
+
+       // Result 2: Volume + Axis
+//     _2_prgov                = NULL;
+       _2_mapfinal             = NULL;
+       _2_stripfinal           = NULL;
+       _2_isoMapperMC6         = NULL;
+       _2_isoActorMC6          = NULL;
+       _2_isoMC6               = NULL;
+
+       //DHC STL SURFACES
+       stlInterna              = NULL;
+       stlExterna              = NULL;
+
+       _loadSTLMapper          = NULL;
+       _loadActorSTL           = NULL;
+
+       
+       //JOIN REGIONS
+       arteryImageData         = NULL;
+       joinMarchingCubes       = NULL;
+    joinMapper                 = NULL; 
+       joinActor               = NULL;
+printf("EED wxSTLWidget_03::wxSTLWidget_03 03\n");
+
+
+}
+//-------------------------------------------------------------------
+wxSTLWidget_03::~wxSTLWidget_03(){
+       ResetTree2_JF();
+       Reset_vtk_STLFile();
+}
+//-------------------------------------------------------------------
+wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
+{
+       wxPanel *panel          =       new wxPanel(parent,-1);
+    wxBoxSizer *sizer  =       new wxBoxSizer(wxVERTICAL);
+
+
+   // MPR
+       vtkImageData *imagedata;
+       imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
+       imagedata->Update();    
+printf("EED wxSTLWidget_03::CreateViewPanel  01 \n");
+       _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
+printf("EED wxSTLWidget_03::CreateViewPanel  02 \n");
+       _wxMaracasMPR->ConfigureVTK();
+printf("EED wxSTLWidget_03::CreateViewPanel  03 \n");
+       
+       sizer->Add(     _wxMaracasMPR , 1, wxEXPAND, 0);
+       panel->SetSizer(sizer);
+       panel->SetAutoLayout(true);
+       panel->SetSize(400,400);
+       panel->Layout();
+printf("EED wxSTLWidget_03::CreateViewPanel  04 \n");
+       return panel;
+}
+//-------------------------------------------------------------------
+wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
+{
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  01\n");
+       wxPanel *panel          = new wxPanel(parent,-1);
+
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  02\n");
+
+    wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  03\n");
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  04\n");
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  05\n");
+
+       sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  06\n");
+
+       panel->SetSizer(sizer);
+       panel->SetAutoLayout(true);
+       panel->SetSize(400,600);
+       panel->Layout();
+printf("EED wxSTLWidget_03::CreateSelectAPointPanel  07\n");
+
+
+       return panel;
+}
+//-------------------------------------------------------------------
+wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
+{
+       wxPanel *panel          = new wxPanel(parent,-1);
+
+
+       _opacity_Vol            = new wxSlider( panel, -1, 40, 0, 100                            , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
+       _opacity_Vol    ->SetSize(250,20);  
+       /*SIL
+       _sl_maxSize                     = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS );
+       _sl_minSize                     = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS );
+       
+       _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
+       _sl_minSizeSpin->SetRange(1,8);
+       _sl_minSizeSpin->SetValue(5);
+
+       _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
+       _sl_maxSizeSpin->SetRange(1,8);
+       _sl_maxSizeSpin->SetValue(5);
+
+       */
+
+       _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
+       _sl_RangeSizeSpin->SetRange(1,8);
+       _sl_RangeSizeSpin->SetValue(5);
+
+
+       //SIL//
+       sl_barrange_segmentation = new mBarRange(panel, 300,70);
+       sl_barrange_segmentation -> setVisibleLabels ( true );
+       sl_barrange_segmentation -> setIfWithActualDrawed( false );
+       sl_barrange_segmentation -> setActiveStateTo ( true );
+       sl_barrange_segmentation -> setRepresentedValues (0,  2000);
+       sl_barrange_segmentation -> setDeviceBlitStart (10,10);
+       sl_barrange_segmentation -> setDeviceEndMargin(10);
+       parent->SetBackgroundColour(wxColour(255,255,255));
+       sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
+
+
+       wxButton *btnExtract                            = new wxButton(panel,-1,_T("Segmentation"));
+       wxButton *btnSaveBinaryFile                     = new wxButton(panel,-1,_T("Save Binary File"));
+
+//SIL//        Connect(_sl_minSizeSpin->GetId()        , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin ); 
+//SIL//        Connect(_sl_maxSizeSpin->GetId()        , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin ); 
+       Connect(_opacity_Vol->GetId()           , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol                                        ); 
+       Connect(btnExtract->GetId()                     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction                                      ); 
+       Connect(btnSaveBinaryFile->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile                          ); 
+
+       //SIL//
+       Connect(_sl_RangeSizeSpin->GetId()      , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin ); 
+       Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction)  &wxSTLWidget_03::OnStartChanged_range );
+       Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction)  &wxSTLWidget_03::OnEndChanged_range );      
+       Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction)  &wxSTLWidget_03::OnBarMoved_range );
+
+    wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  - - -  Segmentation - - - ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
+       
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
+
+       /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
+       sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
+       //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
+
+       sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
+       sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
+       sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
+       
+       //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
+       //SIL//sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
+       //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
+       //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
+       
+       sizer->Add(btnExtract);
+       sizer->Add(new wxStaticText(panel,-1,_T(" ")));
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
+       sizer->Add(_opacity_Vol);
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(btnSaveBinaryFile);
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       
+       panel->SetSizer(sizer);
+       panel->SetAutoLayout(true);
+       panel->SetSize(400,600);
+       panel->Layout();
+
+       return panel;
+}
+//-------------------------------------------------
+wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
+{
+       wxPanel *panel          = new wxPanel(parent,-1);
+
+       stlSliderDeltaGauss     = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
+       stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
+       stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
+       stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
+       wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
+
+       Connect(btnFileSTL->GetId()                             , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL                   );
+       Connect(stlSliderDeltaGauss->GetId()    , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel                );
+       Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
+       Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal                 );
+       Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal                 );
+
+
+    wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+       sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       
+       sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
+       sizer->Add(stlSliderDeltaGauss);
+
+       sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
+       sizer->Add(stlSliderMarchingCubes);
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+       sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
+       sizer->Add(stlSliderOpacityInternal);
+
+       sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
+       sizer->Add(stlSliderOpacityExternal);
+
+       sizer->Add(btnFileSTL);
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+
+       panel->SetSizer(sizer);
+       panel->SetAutoLayout(true);
+       panel->SetSize(400,600);
+       panel->Layout();
+       return panel;
+}
+//-------------------------------------------------
+wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
+{
+       wxPanel *panel          = new wxPanel(parent,-1);
+
+       wxButton *btnReadSTLFile                        = new wxButton(panel,-1,_T("Read STL File"));
+       wxButton *btnEraseReadSTLFile           = new wxButton(panel,-1,_T("Erase STL File"));
+       _sl_opacity_STL_file                            = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
+
+       Connect(btnReadSTLFile->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad                     ); 
+       Connect(btnEraseReadSTLFile->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase                    ); 
+       Connect(_sl_opacity_STL_file->GetId()   , wxEVT_SCROLL_THUMBRELEASE     , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile                             ); 
+
+
+    wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+       sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+       sizer->Add(new wxStaticText(panel,-1,_T("  ")));
+
+       sizer->Add(btnReadSTLFile );
+       sizer->Add(btnEraseReadSTLFile );
+       sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
+       sizer->Add(_sl_opacity_STL_file);
+
+
+       panel->SetSizer(sizer);
+       panel->SetAutoLayout(true);
+       panel->SetSize(400,600);
+       panel->Layout();
+       return panel;
+}
+//-------------------------------------------------------------------
+wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
+{
+printf("EED wxSTLWidget_03::CreateControlPanel 01\n");
+       wxPanel *panel                  = new wxPanel(parent,-1);
+
+       wxNotebook *noteBook    = new wxNotebook(panel, -1);
+printf("EED wxSTLWidget_03::CreateControlPanel 02\n");
+       noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
+printf("EED wxSTLWidget_03::CreateControlPanel 03\n");
+       noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
+printf("EED wxSTLWidget_03::CreateControlPanel 04\n");
+       noteBook->AddPage(CreateSmoothingPanel(noteBook)   ,_T("2 ->") );
+printf("EED wxSTLWidget_03::CreateControlPanel 05\n");
+       noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 "  ) );
+printf("EED wxSTLWidget_03::CreateControlPanel 06\n");
+       noteBook->SetSelection(0);
+       noteBook->SetSize(350,250);
+    wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
+       sizer->Add(noteBook);
+       panel->SetSizer(sizer);
+       panel->SetAutoLayout(true);
+       panel->SetSize(400,600);
+       panel->Layout();
+
+printf("EED wxSTLWidget_03::CreateControlPanel 07\n");
+       return panel;
+}
+//------------------------------------------------------------------------
+void wxSTLWidget_03::Refresh()
+{
+       if (_wxMaracasMPR!=NULL){
+               _wxMaracasMPR->RefreshView();
+       }
+}
+
+//------------------------------------------------------------------------
+
+
+void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
+{
+    wxBusyCursor wait;
+
+       _imagedata=marimagedata->GetImageData(); // image t=0
+       _imagedata->UpdateInformation();
+       _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
+       _imagedata->Update();
+
+
+       double puntoactualprov[3];
+       puntoactualprov[0] = x;
+       puntoactualprov[1] = y;
+       puntoactualprov[2] = z;
+
+       double espprin[3];
+       int extprin[6];                         
+       
+       _imagedata->GetSpacing(espprin);
+       _imagedata->GetExtent(extprin);
+
+
+// MAZV 27 sep 2006
+//     puntoactualprov[0]=puntoactualprov[0]*espprin[0];
+//     puntoactualprov[1]=puntoactualprov[1]*espprin[1];
+//     puntoactualprov[2]=puntoactualprov[2]*espprin[2];
+       
+    _imagedata->GetScalarRange( _range );
+
+       // Update Controls
+       //SIL//
+       /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
+       _sl_minSize->SetValue( (int)(_range[1]/4) );
+
+       _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
+       _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
+
+       //SIL//
+       minRangeValue = _range[0];
+       maxRangeValue = _range[1];
+
+       sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
+       sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
+       sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
+       sl_barrange_segmentation -> RefreshForce();     
+       lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;       
+
+// MAZV 27 sep 2006
+//     _highthreshold->SetRange(_range[0], _range[1]);
+//     _highthreshold->SetValue( _range[1] );
+
+//     _zslice->SetRange(extprin[4], extprin[5]);
+//     _zslice->SetValue(extprin[5]/2);
+       
+       _thresh = vtkImageThreshold::New();
+       _thresh->SetInput(_imagedata);
+       //_thresh->ReleaseDataFlagOff();
+       _thresh->SetInValue(255);
+       _thresh->SetOutputScalarTypeToUnsignedShort();
+       _thresh->SetOutValue(0);
+       //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
+       //SIL//
+       _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd()); 
+
+       vtkImageCast *cast = vtkImageCast::New();
+       cast->SetInput(_thresh->GetOutput());
+       cast->SetOutputScalarTypeToUnsignedChar();
+       cast->Update();
+
+  
+       _connect = vtkImageSeedConnectivity::New();
+       _connect->SetInput(cast->GetOutput());
+       _connect->SetInputConnectValue(255);
+       _connect->SetOutputConnectedValue(255);
+       _connect->SetOutputUnconnectedValue(0);
+       _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
+//     _connect->Update();
+
+       cast3 = vtkImageCast::New();
+       cast3->SetInput(_connect->GetOutput());
+       cast3->SetOutputScalarTypeToUnsignedShort();
+       cast3->Update();
+//SIL//
+       
+       _thresh2 = vtkImageThreshold::New();
+       _thresh2->SetInput(_imagedata);
+       //_thresh2->ReleaseDataFlagOff();
+       _thresh2->SetInValue(255);
+       _thresh2->SetOutputScalarTypeToUnsignedShort();
+       _thresh2->SetOutValue(0);
+       //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
+       _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
+       
+       cast2 = vtkImageCast::New();
+       cast2->SetInput(_thresh2->GetOutput());
+       cast2->SetOutputScalarTypeToUnsignedChar();
+       cast2->Update();
+
+       _connect2 = vtkImageSeedConnectivity::New();
+       _connect2->SetInput(cast2->GetOutput());
+       _connect2->SetInputConnectValue(255);
+       _connect2->SetOutputConnectedValue(255);
+       _connect2->SetOutputUnconnectedValue(0);
+       _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
+       _connect2->Update();
+
+       cast4 = vtkImageCast::New();
+       cast4->SetInput(_connect2->GetOutput());
+       cast4->SetOutputScalarTypeToUnsignedShort();
+       cast4->Update();
+}
+
+//------------------------------------------------------------------------
+
+
+
+void wxSTLWidget_03::ConfigureVTK()
+{
+       wxBusyCursor wait;
+//     vtkImageData    *imagedata              = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
+       marImageData    *marimagedata           = _mar->_experiment->getDynData( )->GetMarImageData();
+       
+       //CONFIGURACION ADICIONAL
+       this->ConfigureSTL();
+       this->ConfigureProcessing(marimagedata,0,0,0);
+       
+}
+
+//------------------------------------------------------------------------
+
+void wxSTLWidget_03::ResetTree2_JF()
+{
+       // Remove 
+       vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
+
+    if (_2_isoActorMC6){
+               ren->RemoveActor(_2_isoActorMC6);
+       }
+    if (_2_stripfinal){
+               ren->RemoveActor(_2_stripfinal);
+       }
+
+       // Delete 
+//     if (_2_prgov            ) {     _2_prgov                -> Delete(); }
+       if (_2_mapfinal         ) {     _2_mapfinal             -> Delete(); }
+       if (_2_stripfinal       ) {     _2_stripfinal   -> Delete(); }
+       if (_2_isoMapperMC6     ) {     _2_isoMapperMC6 -> Delete(); }
+       if (_2_isoActorMC6      ) {     _2_isoActorMC6  -> Delete(); }
+       if (_2_isoMC6           ) {     _2_isoMC6               -> Delete(); }
+
+       // Init
+//     _2_prgov                = NULL;
+       _2_mapfinal             = NULL;
+       _2_stripfinal   = NULL;
+       _2_isoMapperMC6 = NULL;
+       _2_isoActorMC6  = NULL;
+       _2_isoMC6               = NULL;
+}
+
+
+
+
+
+
+//------------------------------------------------------------------------
+void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
+{
+       
+       double opacityvol               = ((double)_opacity_Vol->GetValue())/100;
+//     vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
+
+       double  puntoactualprov[3];
+       double  espprin[3];
+       int             extprin[6];                             
+
+
+       puntoactualprov[0]      =       x;
+       puntoactualprov[1]      =       y;
+       puntoactualprov[2]      =       z;
+       
+       _imagedata->UpdateInformation();
+       _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
+       _imagedata->Update();
+
+       _imagedata->GetSpacing(espprin);
+       _imagedata->GetExtent(extprin);
+
+
+
+
+       _connect->RemoveAllSeeds ();
+       _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
+       _connect->Update();
+       cast3->Update();
+
+
+
+       _thresh->ThresholdBetween(3000, 3002 );
+       _thresh2->ThresholdBetween(3000, 3001);
+//     _thresh->Update();
+//     _thresh2->Update();
+
+       _thresh->ThresholdBetween(_minSize, _range[1] );
+       _thresh->Update();
+
+       _thresh2->ThresholdBetween(_minSize, _maxSize);
+       _thresh2->Update();
+
+       cast2->Update();
+       _connect2->RemoveAllSeeds ();
+       _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
+       _connect2->Update();
+       cast4->Update();
+
+
+
+
+       // Visualisation - result volume
+   
+    _2_isoMC6 = vtkMarchingCubes::New();
+       _2_isoMC6->SetInput(cast4->GetOutput());
+
+    _2_isoMC6->SetValue(0, 128);
+       _2_isoMC6->Update();
+
+       _2_isoMapperMC6 = vtkPolyDataMapper::New();
+    _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
+    _2_isoMapperMC6->ScalarVisibilityOff();
+    _2_isoMapperMC6->ImmediateModeRenderingOn();
+
+       vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
+
+       if (_2_isoActorMC6!=NULL)
+       {
+               ren->RemoveActor(_2_isoActorMC6);
+       }
+
+
+       _2_isoActorMC6 = vtkActor::New();
+    _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
+    _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
+    _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
+    
+       // Interface Update
+
+       ren->AddActor(_2_isoActorMC6);
+
+}
+
+//------------------------------------------------------------------------
+void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
+{
+       if (_2_isoActorMC6!=NULL){
+               double value = ((double)_opacity_Vol->GetValue())/100;
+               _2_isoActorMC6->GetProperty( )->SetOpacity( value );
+               Refresh();
+       }
+}
+//------------------------------------------------------------------------
+
+void wxSTLWidget_03::OnMinSpin         (       wxScrollEvent &          event           )      
+{
+       /*wxSlider *sl_A=_sl_minSize;
+       wxSlider *sl_B=_sl_minSizeSpin;
+       int value = sl_A->GetValue();
+       int delta=(int)pow( 4 , sl_B->GetValue() );
+       int min=value - delta/2;
+       int max=value + delta/2;
+       if (min<0)
+       {
+               min=0;
+               max=delta;
+       }
+       sl_A->SetRange(min,max);
+
+
+       */
+}
+
+//------------------------------------------------------------------------
+
+void wxSTLWidget_03::OnMaxSpin         (       wxScrollEvent &          event           )      
+{
+       /*wxSlider *sl_A=_sl_maxSize;
+       wxSlider *sl_B=_sl_maxSizeSpin;
+       int value = sl_A->GetValue();
+       int delta = (int)pow( 4 , sl_B->GetValue() );
+       int min=value - delta/2;
+       int max=value + delta/2;
+       if (min<0)
+       {
+               min=0;
+               max=delta;
+       }
+       sl_A->SetRange(min,max);*/      
+}
+
+//------------------------------------------------------------------------
+
+void wxSTLWidget_03::OnRangeSpin       (       wxScrollEvent &          event           )      
+{
+       wxSlider *sl_B=_sl_RangeSizeSpin;
+
+       int value = lastResizeRef_Value;
+       int delta = (int)pow( 4 , sl_B->GetValue() );
+       int startResized = value - delta/2;
+       int endResized = value + delta/2;
+
+       if( startResized < minRangeValue )
+               startResized = minRangeValue;
+
+       if( endResized > maxRangeValue )
+               endResized = maxRangeValue;
+
+       sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
+       sl_barrange_segmentation -> RefreshForce();     
+}
+
+//------------------------------------------------------------------------
+void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
+{
+       lastResizeRef_Value = sl_barrange_segmentation->GetStart();
+}
+//------------------------------------------------------------------------
+void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
+{
+       lastResizeRef_Value = sl_barrange_segmentation->GetEnd();   
+}
+//------------------------------------------------------------------------
+void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
+{
+       lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
+}
+//------------------------------------------------------------------------
+
+void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
+{
+       wxString dirSTL = _mar->_parameters->getStringParam( 
+    marParameters::e_installation_directory ); 
+       dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
+       wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
+       dirSTL: wxGetHomeDir( ) );
+
+       if( dialog.ShowModal( ) == wxID_OK ) 
+       {
+               vtkMetaImageWriter  *writer= vtkMetaImageWriter::New();
+               writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );     
+               writer->SetInput(cast4->GetOutput());
+               writer->Write();
+               writer->Delete();
+       }
+}
+
+//------------------------------------------------------------------------
+void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
+{
+       /*wxBusyCursor wait;
+       _minSize = _sl_minSize->GetValue();
+       _maxSize = _sl_maxSize->GetValue();
+
+       double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
+       double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
+       double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
+       ExtractSurface((int)(px),(int)(py),(int)(pz));
+       generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
+
+       Refresh();
+*/
+       //SIL//
+       wxBusyCursor wait;
+       _minSize = sl_barrange_segmentation->GetStart();
+       _maxSize = sl_barrange_segmentation->GetEnd();
+
+       double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
+       double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
+       double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
+       ExtractSurface((int)(px),(int)(py),(int)(pz));
+       generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
+
+       Refresh();
+}
+
+//------------------------------------------------------------------------
+void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
+{
+       if (_loadActorSTL!=NULL)
+       {
+               double value = ((double)_sl_opacity_STL_file->GetValue())/100;
+               _loadActorSTL->GetProperty( )->SetOpacity( value );
+               Refresh();
+       }
+}
+//------------------------------------------------------------------------
+void wxSTLWidget_03::Reset_vtk_STLFile()
+{
+       // Remove
+       vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
+    if (_loadActorSTL){
+               ren->RemoveActor(_loadActorSTL);
+       }
+
+       // Delete 
+       if (_loadSTLMapper              ) {     _loadSTLMapper          -> Delete(); }
+       if (_loadActorSTL               ) {     _loadActorSTL           -> Delete(); }
+
+       // Init
+       _loadSTLMapper          = NULL;
+       _loadActorSTL           = NULL;
+
+}
+//------------------------------------------------------------------------
+void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
+{
+       Reset_vtk_STLFile();
+       Refresh();
+}
+//------------------------------------------------------------------------
+void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
+{
+       wxString dirSTL = _mar->_parameters->getStringParam( 
+    marParameters::e_installation_directory ); 
+       dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
+       wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
+       dirSTL: wxGetHomeDir( ) );
+
+       if( dialog.ShowModal( ) == wxID_OK ) 
+       {
+               Reset_vtk_STLFile();
+               vtkSTLReader *imgReader= vtkSTLReader::New();
+               imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );  
+               _loadSTLMapper = vtkPolyDataMapper::New();
+               _loadSTLMapper->SetInput(imgReader->GetOutput());
+               _loadActorSTL = vtkActor::New();
+               _loadActorSTL->SetMapper(_loadSTLMapper);
+               _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
+               _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
+               vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
+               ren->AddActor(_loadActorSTL);
+               imgReader->Delete();
+       }
+       //By default *always* update e_installation_directory:
+       _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
+       _mar->saveParameters( );
+}
+
+
+
+// ------------------------------------------------------------------------
+// END JOIN FUNCTIONS - DHC
+// ------------------------------------------------------------------------
+
+// ------------------------------------------------------------------------
+// START STL FUNCTIONS - DHC
+// ------------------------------------------------------------------------
+
+void wxSTLWidget_03::ConfigureSTL()
+{
+       stlExterna = vtkPolyData::New();
+       stlInterna = vtkPolyData::New();
+
+       dsm1 = vtkPolyDataMapper ::New();
+    dsm1->SetInput (stlInterna); 
+    dsm1->ScalarVisibilityOff();
+
+    actorInternal = vtkActor::New();
+    actorInternal->SetMapper (dsm1);
+    actorInternal->GetProperty()->SetColor (0,1,0);
+
+    dsm2 = vtkPolyDataMapper ::New();
+    dsm2->SetInput (stlExterna);
+    dsm2->ScalarVisibilityOff();
+
+    actorExternal= vtkActor::New();
+    actorExternal->SetMapper (dsm2);
+    actorExternal->GetProperty()->SetRepresentationToWireframe();
+
+//    vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
+       vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
+    ren->AddActor(actorInternal);
+    ren->AddActor(actorExternal);
+
+       stlExtractor = new vtkSTLExtractor();  
+}
+
+void wxSTLWidget_03::generateSTLSurfaces()
+{
+// EED 09Janvier2007
+//     stlExtractor->setVolume(_2_prgov->GetVolumen());
+
+       stlExtractor->setVolume(cast4->GetOutput());
+
+       stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
+       stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
+       stlExtractor->calculate();
+       stlInterna->DeepCopy(stlExtractor->getInnerSurface());
+       stlExterna->DeepCopy(stlExtractor->getOuterSurface());
+}
+
+
+void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
+       double value = ((double)stlSliderOpacityExternal->GetValue())/100;
+    actorExternal->GetProperty( )->SetOpacity( value );
+       Refresh();
+}
+
+
+void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
+       double value = ((double)stlSliderOpacityInternal->GetValue())/100;
+    actorInternal->GetProperty( )->SetOpacity( value );
+       Refresh();
+}
+
+void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
+{
+
+       wxString dirSTL = _mar->_parameters->getStringParam( 
+    marParameters::e_installation_directory ); 
+       dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
+
+       
+//     wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
+       wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
+
+
+       if( dialog.ShowModal( ) == wxID_OK ) 
+       {
+          
+       
+               // ------------------------------------------------------------------------
+               //  1.  GENERATE STL FILES
+               // ------------------------------------------------------------------------
+//             const char* fileprefix = "c:\\Creatis\\";
+               std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
+               std::string filename;
+
+               // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
+
+        vtkTriangleFilter *filtro = vtkTriangleFilter::New();
+               filtro->SetInput(stlInterna);
+               vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
+        pdcf->SetInput( filtro->GetOutput() );
+        vtkClosePolyData *cpd = vtkClosePolyData::New();
+        cpd->SetInput( pdcf->GetOutput() );
+
+               // 1.2 se escribe a disco el archivo stl de la superficie interna
+        cpd->Update();
+        vtkSTLWriter *writerI = vtkSTLWriter::New();
+        writerI->SetInput( cpd->GetOutput() );
+//        prefix = fileprefix;
+               filename=prefix+"_internal.stl";
+        writerI->SetFileName(filename.c_str());
+        writerI->SetFileTypeToASCII();
+        writerI->Write();
+        writerI->Delete();
+
+               // 1.3 se escribe a disco el archivo stl de la superficie externa
+               filtro->SetInput(stlExterna);
+        cpd->Update();
+        vtkSTLWriter *writerE = vtkSTLWriter::New();
+        writerE->SetInput( cpd->GetOutput() );
+//        prefix = fileprefix;
+               filename=prefix+"_external.stl";
+        writerE->SetFileName( filename.c_str() );
+        writerE->SetFileTypeToASCII();
+        writerE->Write();
+        writerE->Delete();
+   
+        filtro->Delete();
+        cpd->Delete();
+        pdcf->Delete();
+       }
+
+       //By default *always* update e_installation_directory:
+       _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
+       _mar->saveParameters( );
+}
+
+
+void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
+{
+       wxBusyCursor wait;
+       _stlDeltaGaussLevel  = ((double)stlSliderDeltaGauss->GetValue())/100;
+       generateSTLSurfaces();
+       Refresh();
+}
+
+
+void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
+{
+       wxBusyCursor wait;
+       _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
+       generateSTLSurfaces();
+       Refresh();
+       
+}
+
+
+// ------------------------------------------------------------------------
+// END STL FUNCTIONS - DHC
+// ------------------------------------------------------------------------
+
+
+
+
+
+
+