]> Creatis software - creaContours.git/blobdiff - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
#3161 creaContours Bug New Normal - Interpolate Image - Color and Threshold Layer...
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxContourMainFrame.cxx
index 2bf2f0a825bec796a7ee39ed520f7c09bf3d671a..2077380295561cc75bb6d6ec772a039e30ee2a51 100644 (file)
@@ -93,8 +93,8 @@ char wxContourMainFrame::COPY = 'C';
                _viewMaskImagePanel                     = NULL;
                _viewThresholdImage                     = NULL;
                _viewThresholdImagePanel        = NULL;
-               _viewColorLayerImage            = NULL;
                _viewColorLayerImagePanel       = NULL;
+               _frameShowResultImages          = NULL;
        }
 
        wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
@@ -104,7 +104,6 @@ char wxContourMainFrame::COPY = 'C';
                _contourGroup                           = 1;
                _creatingContoursActive         = false;
                _theViewPanel                           = NULL;
-
                _instantPanel                           = NULL;
                _refLineControl                         = NULL;
                _refLineModel                           = NULL;
@@ -114,29 +113,21 @@ char wxContourMainFrame::COPY = 'C';
                _viewMaskImagePanel                     = NULL;
                _viewThresholdImage                     = NULL;
                _viewThresholdImagePanel        = NULL;
-               _viewColorLayerImage            = NULL;
                _viewColorLayerImagePanel       = NULL;
-
                // set up default notebook style
-               m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
-               m_notebook_theme = 0;
+               m_notebook_style                        = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
+               m_notebook_theme                        = 0;
                //wxContour_ActionCommandsID a;
-               _numberOfVariablesStatistics = 7;
-
-               _datadir = datadir;
-
-
-               inredo = 0;
-               inundo = 0;
-
+               _numberOfVariablesStatistics= 7;
+               _datadir                                        = datadir;
+               inredo                                          = 0;
+               inundo                                          = 0;
                _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
                _performingOperation = new PerformingOperation();
-
                if(images.size() > 0)
                {
                        this->setVectImages(images);
                }
-
                _contourextractdata                     = NULL;
 }
 
@@ -652,21 +643,27 @@ void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, i
        nTypeView.push_back(2);
        nTypeView.push_back(0);
 
-       wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
-       wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
-       m_mgr_noteBookViewerResult->SetManagedWindow(frame);
+       if (_frameShowResultImages==NULL)
+       {
+//             wxFrame *_frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
+               _frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), 
+                    wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION |  wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER  );
+
+               wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
+               m_mgr_noteBookViewerResult->SetManagedWindow(_frameShowResultImages);
 
-       wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
-       m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
+               wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(_frameShowResultImages, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
+               m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
 
-       wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
-       wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
+               wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
+               wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
 
 
-       noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
-       noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
-       m_mgr_noteBookViewerResult->Update();
-       frame->Show();
+               noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
+               noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
+               m_mgr_noteBookViewerResult->Update();
+               _frameShowResultImages->Show();
+       } // if _frameShowResultImages
 }
 
 
@@ -699,13 +696,6 @@ void wxContourMainFrame::changeInstant()
                        }
                }
 
-       // Refresh Threshold image
-               if(_viewColorLayerImage!=NULL){
-                       _viewColorLayerImage->SetZ(actualSlice);
-                       if (_viewColorLayerImagePanel->IsVisible()==true){
-                               _viewColorLayerImage->onThreshold();
-                       }
-               }
 
                updateInstantOutlines();
                updateInstantImageData();
@@ -983,7 +973,6 @@ void wxContourMainFrame::onLoad()
 
 void  wxContourMainFrame::SetZForAllContours(int pz)
 {
-       printf("EED wxContourMainFrame::SetZForAllContours\n");
 
        //-- Normal Contours
 
@@ -1203,11 +1192,22 @@ void wxContourMainFrame::saveFileWithContours( std::string filename )
        fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
 //------------------------------------------------------------------------------------------------------------
 
+
+// EED 2017-05-30
+       double spc[3];
+       spc[0]=1; 
+       spc[1]=1; 
+       spc[2]=1; 
+
        for (i=0 ; i<sizeLstNameThings ; i++)
        {
 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
                manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
-               double sizeInPixel = manualModel ->GetPathSize();
+
+// EED 2017-05-30
+//             double sizeInPixel = manualModel ->GetPathSize(  );
+               double sizeInPixel = manualModel ->GetPathSize( spc );
+
                double realContourSize = sizeInPixel*_onePixelSize;
                manualModel ->SetRealSize(realContourSize);
 //------------------------------------------------------------------------------------------------------------
@@ -1781,19 +1781,18 @@ printf("EED wxContourMainFrame::SegmentationOneSliceITK  Skypping this code.  No
                {
                        vecXo.push_back(p[0]);
                        vecYo.push_back(p[1]);
-               }
-               else
-               {
-               vecX.push_back( p[0] );
-               myfile <<p[0]<<","<<p[1]<<"\n";
-               //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
-               //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
-               //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
-               vecY.push_back( p[1] );
-               vecZ.push_back( 900 );
-               xAct=x;
-               yAct=y;
-               }
+               } else {
+                       vecX.push_back( p[0] );
+                       myfile <<p[0]<<","<<p[1]<<"\n";
+                       //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
+                       //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
+                       //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
+                       vecY.push_back( p[1] );
+//EED 2017-12-16
+                       vecZ.push_back( -900 );
+                       xAct = x;
+                       yAct = y;
+               } // if xAct
 
 
        }
@@ -1803,7 +1802,8 @@ printf("EED wxContourMainFrame::SegmentationOneSliceITK  Skypping this code.  No
                vecX.push_back(vecXo.back());
                //std::cout<<" x Siguiente "<<vecXo.back();
                vecXo.pop_back();
-               vecZ.push_back( 900 );
+//EED 2017-12-16
+               vecZ.push_back( -900 );
        }
        while(!vecYo.empty())
        {
@@ -2059,7 +2059,8 @@ myfile.close();
 //             double y=p[1];
                vecX.push_back( p[0] );
                vecY.push_back( p[1] );
-               vecZ.push_back( 900 );
+//EED 2017-12-16
+               vecZ.push_back( -900 );
 //                     vecZ.push_back( p[2] );
        }
 
@@ -2513,7 +2514,6 @@ void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
 
 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
 {
-//EED01Juillet2009     GenerateContourExtractData();
 
        wxString tempString;
        int maxContourGroup     =       0;
@@ -2538,8 +2538,6 @@ void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int sel
        std::vector<int> tempVector;
        _instantPanel->getInstant( tempVector );
 
-//EED01Juillet2009     vtkImageData *imagedata = _theViewPanel->getImageData();
-//     int sizeZ = _theViewPanel->GetImageDataSizeZ();
        int z;
        int ii,sizeLstContourThings;
 
@@ -2562,7 +2560,6 @@ void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int sel
 
 
        totalZ  = maxZ-minZ+1;
-//EED01Juillet2009     _contourextractdata->SetImage( imagedata);
 
        _contourextractdata->InitVolumeStatistics();
 
@@ -2826,7 +2823,6 @@ void wxContourMainFrame::onSaveResults(std::string directory,std::string namefil
 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
 {
        wxBusyCursor wait;
-//EED01Juillet2009     GenerateContourExtractData();
 
        //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
        _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
@@ -2842,7 +2838,6 @@ void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefil
        std::vector<int> tempVector;
        _instantPanel->getInstant( tempVector );
 
-//EED01Juillet2009     vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
        int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
        int z;
        int ii,sizeLstContourThings;
@@ -2856,7 +2851,6 @@ void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefil
        maxZ    = sizeZ;//_mbarrange->GetEnd();
        totalZ  = maxZ-minZ+1;
 
-//EED01Juillet2009     _contourextractdata->SetImage( imagedata);
 
 // For each slice..
        for ( z=0 ; z<sizeZ ; z++)
@@ -2954,7 +2948,6 @@ void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefil
 
 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
        wxBusyCursor wait;
-//EED01Juillet2009     GenerateContourExtractData();
 
        //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
        if (typeContourGroup==3)
@@ -2977,7 +2970,6 @@ void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value
        int z;
        int ii,sizeLstContourThings;
 
-
        double totalZ;
        double porcent;
 
@@ -2993,7 +2985,6 @@ void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value
 
        totalZ  = maxZ-minZ;
 
-//EED01Juillet2009     _contourextractdata->SetImage( imagedata);
 
        // cleanning image before range
        for (z=0; z<minZ; z++){
@@ -3059,13 +3050,41 @@ void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value
 
 }
 
-void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
+std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
 {
+       std::string result="";
+       if ( image->GetScalarType()==VTK_CHAR )
+       {
+               result="CHAR";
+       } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
+               result="UCHAR";
+       } else if ( image->GetScalarType()==VTK_FLOAT ){
+               result="FLOAT";
+       } else if ( image->GetScalarType()==VTK_DOUBLE ){
+               result="DOUBLE";
+       } else if ( image->GetScalarType()==VTK_INT ){
+               result="INT";
+       } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
+               result="UINT";
+       } else if ( image->GetScalarType()==VTK_SHORT ){
+               result="SHORT";
+       } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
+               result="USHORT";
+       } else if ( image->GetScalarType()==VTK_LONG ){
+               result="LONG";
+       } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
+               result="ULONG";
+       }
+       return result;
+}
 
+void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
+{
+       std::string stringType;
        double spc[3];
        kernelManager->GetSpacing(spc,0);   // returns the spacing of the first image
-       
-       std::string temp = directory + "/" + namefile + "-image-Value.mhd";
+       stringType              = GetStringTypeImage(value);
+       std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
 
        wxString filename = crea::std2wx(temp);
 
@@ -3082,7 +3101,8 @@ void wxContourMainFrame::SaveImageResult(std::string directory,std::string namef
        writerValueImage->Write( );
 
 // Image Mask
-       temp = directory + "/" + namefile + "-image-Mask.mhd";
+       stringType              = GetStringTypeImage(mask);
+       temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
 
        // LG 14/01/09 : using crea
        filename = crea::std2wx(temp);
@@ -3163,7 +3183,7 @@ void wxContourMainFrame::SetContourGroup(int contourGroup)
 
 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
 {
-
        if      (_viewMaskImagePanel==NULL)
        {
                _contourextractdata = new ContourExtractData(true);
@@ -3172,15 +3192,29 @@ wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
 //             _theViewPanel->getImageData()->GetScalarRange(range);
                //int min = (int)floor (range[0]);
                //int max = (int)ceil (range[1]);
+
+//EED 2017-12-17
                int min = 254;
                int max = 256;
-               _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
+
+               _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1,  0);
                _viewMaskImage = new ThresholdImageView();
-               _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
+               _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
                _viewMaskImage->SetminMaxValue( min, max);
                _viewMaskImage->SetBaseColor( 0,0,1 );
+
+
+               std::vector<int> colorbarposition;
+               colorbarposition.push_back( -999 );
+               colorbarposition.push_back( -999 );
+               _viewMaskImage->SetColorBarPosition( colorbarposition );
+               double spc[3];
+               _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
+               _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
+
                _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
                _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
+               _viewMaskImage->onThresholdChangeOpacity( 25 );
        }
        return _viewMaskImagePanel;
 }
@@ -3194,12 +3228,23 @@ wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
                _theViewPanel->getImageData()->GetScalarRange(range);
                int min = (int)floor (range[0]);
                int max = (int)ceil (range[1]);
-               _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max , 1);
-               _viewColorLayerImage = new ColorLayerImageView();
-//             _viewColorLayerImage->SetImage( _theViewPanel->getImageData() );
-               _viewColorLayerImage->SetImage( NULL );
-               _viewColorLayerImagePanel->SetColorLayerImageView( _viewColorLayerImage );
-               _viewColorLayerImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
+               _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
+               _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
+       //    std::vector<double> range = bbGetInputlstRangeForColorBar();
+       //    clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
+               std::vector<int> colorbarposition;
+               colorbarposition.push_back( 50 );
+               colorbarposition.push_back( 105 );
+               _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
+       //    std::vector<double> base_color;
+       //    _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
+       //    std::vector<double> grey_level_boundaries;
+       //    clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
+               std::vector<double> transparence_level_boundaries;
+               transparence_level_boundaries.push_back(0);
+               _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
+               _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
+//             _viewColorLayerImagePanel->SetFittingMode( 3 );
        }
        return _viewColorLayerImagePanel;
 }
@@ -3213,13 +3258,25 @@ wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
                _theViewPanel->getImageData()->GetScalarRange(range);
                int min = (int)floor (range[0]);
                int max = (int)ceil (range[1]);
-               _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
+               int start= (max+min)/2 - (max-min)*0.25; 
+               int end= (max+min)/2 + (max-min)*0.25; 
+               _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
                _viewThresholdImage = new ThresholdImageView();
+               _viewThresholdImage->SetminMaxValue(start,end);
                _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
-               _viewThresholdImage->SetminMaxValue( min, max);
+               std::vector<int> colorbarposition;
+               colorbarposition.push_back( 10 );
+               colorbarposition.push_back( 105 );
+               _viewThresholdImage->SetColorBarPosition( colorbarposition );
+               double spc[3];
+               _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
+               _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
+
                _viewThresholdImage->SetBaseColor( 1,0,0 );
                _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
                _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
+               _viewThresholdImage->onThresholdChangeOpacity( 25 );
+               RefreshInterface();
        }
        return _viewThresholdImagePanel;
 }
@@ -3249,10 +3306,18 @@ double wxContourMainFrame::getContourSizeInPixels()
                std::string cloneName = currentSelection [0];
 
                manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
-               contourSize = manualModel-> GetPathSize();
+
+// EED 2017-05-30
+//             contourSize = manualModel->GetPathSize();
+               double spc[3];
+               spc[0]=1; 
+               spc[1]=1; 
+               spc[2]=1; 
+               contourSize = manualModel->GetPathSize( spc );
        }
        return contourSize;
 }
+
 manualBaseModel * wxContourMainFrame::getContour ()
 {
        std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
@@ -3282,9 +3347,16 @@ void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualMo
 }
 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
 {
-       double sizeInPixel = manualModel ->GetPathSize();
+// EED 2017-05-30
+//     double sizeInPixel      = manualModel ->GetPathSize(  );
+       double spc[3];
+       spc[0]=1; // ????
+       spc[1]=1; // ????
+       spc[2]=1; // ????
+       double sizeInPixel      = manualModel ->GetPathSize( spc );
+
        double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
-       double realContourSize = sizeInPixel*onePixelRealSize;
+       double realContourSize  = sizeInPixel*onePixelRealSize;
        manualModel ->SetRealSize(realContourSize);
 }