]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxSTLWidget_03.cxx
BUG histogram
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxSTLWidget_03.cxx
index cbecc1a7f8c1a57e0aee73b95aca17708eaf16ac..d8568557e8591bf595fbb34bbde01127d7b35a79 100644 (file)
@@ -68,7 +68,7 @@ wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent)//, marInterface* mar)
        _wxMaracasMPR           = NULL;
        _maxSize                = 2000;
        _minSize                = 300;
-
+       _imagedata = NULL;
        _stlMarchingCubesLevel  = 128;
        _stlDeltaGaussLevel             = 100;
 
@@ -89,9 +89,7 @@ wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent)//, marInterface* mar)
        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 );
@@ -110,9 +108,7 @@ printf("EED wxSTLWidget_03::wxSTLWidget_03 02\n");
        _2_isoActorMC6          = NULL;
        _2_isoMC6               = NULL;
 
-       //DHC STL SURFACES
-       stlInterna              = NULL;
-       stlExterna              = NULL;
+       
 
        _loadSTLMapper          = NULL;
        _loadActorSTL           = NULL;
@@ -123,7 +119,15 @@ printf("EED wxSTLWidget_03::wxSTLWidget_03 02\n");
        joinMarchingCubes       = NULL;
     joinMapper                 = NULL; 
        joinActor               = NULL;
-printf("EED wxSTLWidget_03::wxSTLWidget_03 03\n");
+
+       //DHC STL SURFACES
+       stlExterna = NULL;
+       stlInterna = NULL;
+       dsm1=NULL;
+       actorInternal = NULL;
+       dsm2 = NULL;
+       actorExternal=NULL;
+       _thresh=NULL;
 
 
 }
@@ -143,55 +147,51 @@ wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
        //vtkImageData *imagedata;
        //imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
        //imagedata->Update();  
-printf("EED wxSTLWidget_03::CreateViewPanel  01 \n");
        _wxMaracasMPR = new wxMaracasMPR( panel);//JCP 10-03-2009, new marImageData(imagedata), 1 );
-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;
 }
 
 void wxSTLWidget_03::setImage(vtkImageData* img){
 
-
-       _wxMaracasMPR->setMarImage(new marImageData(img), 1);
+       _wxMaracasMPR->setImageData(img, 1);
        _wxMaracasMPR->ConfigureVTK();
+
+
+       this->ConfigureProcessing(img,0,0,0);
+       this->ConfigureSTL();
+
+       _wxMaracasMPR->Refresh();
+       
+       //this->Refresh();
 }
 //-------------------------------------------------------------------
 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;
@@ -395,19 +395,13 @@ wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
 //-------------------------------------------------------------------
 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);
@@ -417,7 +411,6 @@ printf("EED wxSTLWidget_03::CreateControlPanel 06\n");
        panel->SetSize(400,600);
        panel->Layout();
 
-printf("EED wxSTLWidget_03::CreateControlPanel 07\n");
        return panel;
 }
 //------------------------------------------------------------------------
@@ -431,14 +424,11 @@ void wxSTLWidget_03::Refresh()
 //------------------------------------------------------------------------
 
 
-void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
+void wxSTLWidget_03::ConfigureProcessing(vtkImageData *img, int x, int y, int z)
 {
     wxBusyCursor wait;
 
-       _imagedata=marimagedata->GetImageData(); // image t=0
-       _imagedata->UpdateInformation();
-       _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
-       _imagedata->Update();
+       _imagedata=img;
 
 
        double puntoactualprov[3];
@@ -484,63 +474,71 @@ void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int
 
 //     _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//
+    
+       if(_thresh==NULL){
+               _thresh = vtkImageThreshold::New();
+               //_thresh->ReleaseDataFlagOff();
+               _thresh->SetInValue(255);
+               _thresh->SetOutputScalarTypeToUnsignedShort();
+               _thresh->SetOutValue(0);
+               //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
+               //SIL//
+               _cast = vtkImageCast::New();
+               _cast->SetInput(_thresh->GetOutput());
+               _cast->SetOutputScalarTypeToUnsignedChar();
+
+               _connect = vtkImageSeedConnectivity::New();
+               _connect->SetInput(_cast->GetOutput());
+               _connect->SetInputConnectValue(255);
+               _connect->SetOutputConnectedValue(255);
+               _connect->SetOutputUnconnectedValue(0);
+
+               cast3 = vtkImageCast::New();
+               cast3->SetInput(_connect->GetOutput());
+               cast3->SetOutputScalarTypeToUnsignedShort();
+
+               _thresh2 = vtkImageThreshold::New();
+               //_thresh2->ReleaseDataFlagOff();
+               _thresh2->SetInValue(255);
+               _thresh2->SetOutputScalarTypeToUnsignedShort();
+               _thresh2->SetOutValue(0);
+               //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
+
+               cast2 = vtkImageCast::New();
+               cast2->SetInput(_thresh2->GetOutput());
+               cast2->SetOutputScalarTypeToUnsignedChar();
+               _connect2 = vtkImageSeedConnectivity::New();
+               _connect2->SetInput(cast2->GetOutput());
+               _connect2->SetInputConnectValue(255);
+               _connect2->SetOutputConnectedValue(255);
+               _connect2->SetOutputUnconnectedValue(0);
+
+               cast4 = vtkImageCast::New();
+               cast4->SetInput(_connect2->GetOutput());
+               cast4->SetOutputScalarTypeToUnsignedShort();
+       }
+       _thresh->RemoveAllInputs();
+       _thresh->SetInput(_imagedata);  
+       _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());    
+       _thresh->Update();
        
-       _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());
+       _cast->Update();  
        
-       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);
+       _connect->RemoveAllSeeds();
+       _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
+       //_connect->Update();   
+       //cast3->Update();
+//SIL//        
+       _thresh2->RemoveAllInputs();
+       _thresh2->SetInput(_imagedata); 
+       _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
+       _thresh2->Update();
+       cast2->Update();
+       _connect2->RemoveAllSeeds();
        _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
-       _connect2->Update();
-
-       cast4 = vtkImageCast::New();
-       cast4->SetInput(_connect2->GetOutput());
-       cast4->SetOutputScalarTypeToUnsignedShort();
-       cast4->Update();
+       //_connect2->Update();  
+       //cast4->Update();
 }
 
 //------------------------------------------------------------------------
@@ -551,11 +549,11 @@ void wxSTLWidget_03::ConfigureVTK()
 {
        wxBusyCursor wait;
 //     vtkImageData    *imagedata              = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
-       marImageData    *marimagedata;//                = _mar->_experiment->getDynData( )->GetMarImageData();
+       //marImageData  *marimagedata;//                = _mar->_experiment->getDynData( )->GetMarImageData();
        
        //CONFIGURACION ADICIONAL
        this->ConfigureSTL();
-       this->ConfigureProcessing(marimagedata,0,0,0);
+       //this->ConfigureProcessing(marimagedata,0,0,0);
        
 }
 
@@ -564,30 +562,36 @@ void wxSTLWidget_03::ConfigureVTK()
 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);
-       }
+       try{
 
-       // 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(); }
+               vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
 
-       // Init
-//     _2_prgov                = NULL;
-       _2_mapfinal             = NULL;
-       _2_stripfinal   = NULL;
-       _2_isoMapperMC6 = NULL;
-       _2_isoActorMC6  = NULL;
-       _2_isoMC6               = NULL;
+               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;
+       }catch(char* e){
+               std::cout<<e<<std::endl;
+       }
 }
 
 
@@ -827,19 +831,23 @@ void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
 void wxSTLWidget_03::Reset_vtk_STLFile()
 {
        // Remove
-       vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
-    if (_loadActorSTL){
-               ren->RemoveActor(_loadActorSTL);
+       try{
+               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;
+       }catch(char * e){
+               std::cout<<e<<std::endl;
        }
 
-       // Delete 
-       if (_loadSTLMapper              ) {     _loadSTLMapper          -> Delete(); }
-       if (_loadActorSTL               ) {     _loadActorSTL           -> Delete(); }
-
-       // Init
-       _loadSTLMapper          = NULL;
-       _loadActorSTL           = NULL;
-
 }
 //------------------------------------------------------------------------
 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
@@ -888,31 +896,37 @@ void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
 
 void wxSTLWidget_03::ConfigureSTL()
 {
-       stlExterna = vtkPolyData::New();
-       stlInterna = vtkPolyData::New();
 
-       dsm1 = vtkPolyDataMapper ::New();
-    dsm1->SetInput (stlInterna); 
-    dsm1->ScalarVisibilityOff();
+       if(stlExterna == NULL){
+               stlExterna = vtkPolyData::New();
+               stlInterna = vtkPolyData::New();
 
-    actorInternal = vtkActor::New();
-    actorInternal->SetMapper (dsm1);
-    actorInternal->GetProperty()->SetColor (0,1,0);
+               dsm1 = vtkPolyDataMapper ::New();
+               dsm1->SetInput (stlInterna); 
+               dsm1->ScalarVisibilityOff();
 
-    dsm2 = vtkPolyDataMapper ::New();
-    dsm2->SetInput (stlExterna);
-    dsm2->ScalarVisibilityOff();
+               actorInternal = vtkActor::New();
+               actorInternal->SetMapper (dsm1);
+               actorInternal->GetProperty()->SetColor (0,1,0);
 
-    actorExternal= vtkActor::New();
-    actorExternal->SetMapper (dsm2);
-    actorExternal->GetProperty()->SetRepresentationToWireframe();
+               dsm2 = vtkPolyDataMapper ::New();
+               dsm2->SetInput (stlExterna);
+               dsm2->ScalarVisibilityOff();
 
-//    vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
-       vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
-    ren->AddActor(actorInternal);
-    ren->AddActor(actorExternal);
+               actorExternal= vtkActor::New();
+               actorExternal->SetMapper (dsm2);
+               actorExternal->GetProperty()->SetRepresentationToWireframe();
 
-       stlExtractor = new vtkSTLExtractor();  
+       //    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()