]> Creatis software - creaContours.git/blobdiff - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
#3388 wxContourMainFrame_tool box BBTK
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxContourMainFrame.cxx
index c0b9dd263a2d008a69bc51d548ac0b3d5645362b..986a08ef45278f6de839d0090a7d12c740a34cbb 100644 (file)
@@ -126,12 +126,22 @@ char wxContourMainFrame::COPY = 'C';
                _performingOperation        = new PerformingOperation();
                if(images.size() > 0)
                {
-                       this->setVectImages(images);
+                       this->configure(images);
                }
                _contourextractdata                     = NULL;
 }
 
-void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
+
+void wxContourMainFrame::changeImage(int id, vtkImageData *img)
+{
+    if ( id<_images.size() ) _images[id]=img;
+    kernelManager->changeImage(id,img);
+    _theViewPanel->changeImage(img);
+//    updateInstantImageData();
+    
+}
+
+void wxContourMainFrame::configure(std::vector<vtkImageData*> imgs)
 {
        _images = imgs;
        #if defined(_WIN32)
@@ -159,7 +169,7 @@ void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
 }
 
 
-       wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
+       wxContourMainFrame* wxContourMainFrame::getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
        {
                if(instance == NULL)
                {
@@ -214,9 +224,9 @@ void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
        //
        wxAuiNotebook * wxContourMainFrame::createNotebook()
        {
-               wxSize client_size = GetClientSize();
+               wxSize client_size      = GetClientSize();
                wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
-               wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
+               wxBitmap page_bmp       = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
                return noteBook;
        }
 
@@ -734,7 +744,6 @@ void wxContourMainFrame::updateInstantImageData()
 {
        std::vector<int> inst;
        _instantPanel->getInstant(inst);
-
        vtkImageData* img = kernelManager->getImageAtInstant(inst);
        if(img!=NULL)
        {
@@ -863,7 +872,7 @@ void wxContourMainFrame ::loadState(std::string filename)
        onLoadContours(filename,false);
 }
 
-void wxContourMainFrame::onLoad()
+void wxContourMainFrame::onLoad(bool interactiveInterface)   // interactiveInterface default true
 {
        std::string fileNameContourROI = GetFileLocation();
 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
@@ -881,7 +890,7 @@ void wxContourMainFrame::onLoad()
                        fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
                } // if dialog
        } // if FileLocation
-       onLoadContours(fileNameContourROI,true);
+       onLoadContours(fileNameContourROI, interactiveInterface );
 }
 
 void  wxContourMainFrame::SetZForAllContours(int pz)
@@ -894,7 +903,6 @@ void  wxContourMainFrame::SetZForAllContours(int pz)
        sizeLstNameThings       = lstNameThings.size(); 
        for (i=0 ; i<sizeLstNameThings ; i++)
        {
-printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
                manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
                sizeLstPoints = manualModel->GetSizeLstPoints();
                for (ii=0 ; ii<sizeLstPoints ; ii++)
@@ -1066,70 +1074,49 @@ void wxContourMainFrame::saveFileWithContours( std::string filename )
        fprintf(pFileData,"--CreaContour--\n");
        fprintf(pFileData,"Version %s\n", "1.0.3" );
        fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
-
 //------------------------------------------------------------------------------------------------------------
-
        vtkImageData *image = _images[0];
-
        int dimRange[3];
        image->GetDimensions(dimRange);
-
        fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
-
        double spaRange[3];
        image->GetSpacing(spaRange);
-
        fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
-
        // Normal Contours
-
        lstNameThings           = kernelManager->GetLstNameThings();
        sizeLstNameThings       = lstNameThings.size();
        fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
-
 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
        fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
 //------------------------------------------------------------------------------------------------------------
-
-
 // EED 2017-05-30
        double spc[3];
        spc[0]=1; 
        spc[1]=1; 
-       spc[2]=1; 
-
+       spc[2]=1;
        for (i=0 ; i<sizeLstNameThings ; i++)
        {
 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
                manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
-
 // EED 2017-05-30
 //             double sizeInPixel = manualModel ->GetPathSize(  );
                double sizeInPixel = manualModel ->GetPathSize( spc );
-
                double realContourSize = sizeInPixel*_onePixelSize;
                manualModel ->SetRealSize(realContourSize);
 //------------------------------------------------------------------------------------------------------------
-
        //int size= kernelManager->GetLstNameThings().size();
-
                kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
                _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
        }// for i
-
        //-- Static Contours
-
 //     fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
 //     fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
-
        lstNameThings           = kernelManager->GetLstNameThingsStatic();
        sizeLstNameThings       = lstNameThings.size();
        fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
-
 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
        fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
 //------------------------------------------------------------------------------------------------------------
-
        for (i=0 ; i<sizeLstNameThings ; i++)
        {
                kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
@@ -1177,10 +1164,11 @@ void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
 //                     wxBoxSizer              *dialSizer = new wxBoxSizer(wxVERTICAL);
                        wxFlexGridSizer *dialSizer = new wxFlexGridSizer(1);
 
-                       wxString lstOptOperation[2];
-                       lstOptOperation[0]=_T("By Dimension");
-                       lstOptOperation[1]=_T("By Spacing");
-                       wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,90), 2 , lstOptOperation,  2, wxRA_SPECIFY_COLS);
+                       wxString lstOptOperation[3];
+                       lstOptOperation[0]=_T("By Dimension (XY)");
+                       lstOptOperation[1]=_T("By Spacing   (XY)");
+                       lstOptOperation[2]=_T("By Spacing   (XYZ)");
+                       wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(370,200), 3 , lstOptOperation,  3, wxRA_SPECIFY_ROWS);
 
                        dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the "))  , 0, wxGROW );
                        dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?"))  , 0, wxGROW );
@@ -1192,7 +1180,7 @@ void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
                        dial->Layout();
                        dial->ShowModal();
 
-                       int _tmpReadFileTypeOfTransformation = -1;
+                       _tmpReadFileTypeOfTransformation = -1;
 //EED                  bool transform = false;
 
                        if (dial->GetReturnCode() == wxID_OK)
@@ -1210,7 +1198,6 @@ void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
 //AD:04-06-09
 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
 {
-
        char tmp[255];
 
        vtkImageData    *image = _images[0];
@@ -1328,14 +1315,22 @@ void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool static
                 //nothing to do..
             } else if (_tmpReadFileTypeOfTransformation==0){
                 double transX, transY;
-                transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
-                transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
-                manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
+                transX = (double) imageDim[0]/_tmpReadFileImageDim[0];                    // X
+                transY = (double) imageDim[1]/_tmpReadFileImageDim[1];                    // Y
+                manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);                
             } else if (_tmpReadFileTypeOfTransformation==1) {
                 double transX, transY;
-                transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
-                transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
+                transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0];                  // X
+                transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1];                  // Y
+                manModelContour->Transform_Ax_Plus_B(transX,0,transY,0); 
+            } else if (_tmpReadFileTypeOfTransformation==2) {  // with Z include
+                double transX, transY;
+                transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0];                   // X
+                transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1];                   // Y 
+                instantVector[1]=instantVector[1]*_tmpReadFileImageSpac[2]/imageSpac[2];   // Z
                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
+            }else {
+                   printf ("EED Warnning! wxContourMainFrame::openContours _tmpReadFileTypeOfTransformation not set. \n");
             }
 
                        fscanf(pFile,"%s",tmp); // TypeView
@@ -1725,20 +1720,17 @@ void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int me
        int                                     x                                       = _theViewPanel->GetX();
        int                                     y                                       = _theViewPanel->GetY();
        int                                     z                                       = _theViewPanel->GetZ();
-       SegmentationOneSlice( x,y,z,isovalue, sampling, method );
+       SegmentationOneSlice( x,y,z,isovalue, sampling, method , getImageData() );
        RefreshInterface();
 }
 
 
-void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
+void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method , vtkImageData *imagedata)
 {
-
-printf("EED wxContourMainFrame::SegmentationOneSlice Start=%d  %d\n",sampling,method );
-printf("EED wxContourMainFrame::SegmentationOneSlice %d %d %d  \n",x,y,z );
-
        int typeofcontour = 1;
        //--Extracting Contour
-       vtkImageData    *imagedata      = getImageData();
+// 2024-01-09
+//     vtkImageData    *imagedata      = getImageData();
 
        vtkImageReslice *imageReslice = vtkImageReslice::New();
 //EED
@@ -1883,39 +1875,32 @@ myfile.close();
        std::vector<double> vecCtrlPointY;
        std::vector<double> vecCtrlPointZ;
 
-printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
-
-int numberOfPointsInCell;
-int numberOfcells=polyDataResult->GetNumberOfCells();
-for (int jj=0; jj<numberOfcells ; jj++)
-{
-       vtkCell* vtkcell = polyDataResult->GetCell( jj );
-       numberOfPointsInCell=vtkcell->GetNumberOfPoints();
-       printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d  points=%d \n",jj,numberOfPointsInCell );
-}// for jj
-
-printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
-
-polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
+//printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
+//int numberOfPointsInCell;
+//int numberOfcells=polyDataResult->GetNumberOfCells();
+//for (int jj=0; jj<numberOfcells ; jj++)
+//{
+//     vtkCell* vtkcell = polyDataResult->GetCell( jj );
+//     numberOfPointsInCell=vtkcell->GetNumberOfPoints();
+//     printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d  points=%d \n",jj,numberOfPointsInCell );
+//}// for jj
+// printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
+// polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
 
 
        if (polyDataResult->GetNumberOfCells()>0)
        {
                double *p;
-       printf("EED wxContourMainFrame::SegmentationOneSlice A \n");
                vtkCell* vtkcell = polyDataResult->GetCell( 0 );
-       printf("EED wxContourMainFrame::SegmentationOneSlice B \n");
        //      int ii,size=polyDataResult->GetNumberOfPoints();
                int ii,size=vtkcell->GetNumberOfPoints();
-       printf("EED wxContourMainFrame::SegmentationOneSlice C \n");
                int id;
                for (ii=0;ii<size;ii++)
                {
        //              id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
        //              p       = polyDataResult->GetPoint(id);
                        p       = vtkcell->GetPoints()->GetPoint(ii);
-
-       printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d  px=%f py=%f\n",ii,id, p[0],p[1]);
+//     printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d  px=%f py=%f\n",ii,id, p[0],p[1]);
        //              double x=p[0];
        //              double y=p[1];
                        vecX.push_back( p[0] );
@@ -1924,10 +1909,8 @@ polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
                        vecZ.push_back( -900 );
        //                      vecZ.push_back( p[2] );
                }
-
                ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
                extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
-
        //PROOFS
                /*if (methodRadiobox->GetSelection()==0){
                        extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
@@ -1981,8 +1964,7 @@ polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
                        }       // if addedModel
                } // if sizeCtrPt
        } // if NumberOfCells > 0
-
-printf("EED wxContourMainFrame::SegmentationOneSlice  End\n");
+//printf("EED wxContourMainFrame::SegmentationOneSlice  End\n");
 }
 
 int wxContourMainFrame::GetImageDataSizeZ()
@@ -1995,7 +1977,40 @@ void wxContourMainFrame::GetImageDataRange(double *range)
        _theViewPanel->GetImageDataRange(range);
 }
 
-void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
+void wxContourMainFrame::onSegmentationAllSlices2(int step ,int isovalue,int sampling,int method,vtkImageData* imagedata)
+{
+    printf("wxContourMainFrame::onSegmentationAllSlices2 start\n");
+    
+    //JCP 20-10-08 Undo redo implementation
+    saveState();
+    //JCP 20-10-08 Undo redo implementation
+    wxBusyCursor wait;
+//    int                 x = _theViewPanel->GetX();
+//    int                 y = _theViewPanel->GetY();
+    int                 z;
+//    double              porcent;
+//    wxString            tmpString;
+//    double              totalZ = maxZ-minZ+1;
+    
+    int ext[6];
+    imagedata->GetExtent(ext);
+    int maxZ = ext[5]-ext[4]+1;
+    for( z=0 ; z<=maxZ ; z=z+step )
+    {
+        printf("wxContourMainFrame::onSegmentationAllSlices2 z=%d \n",z );
+//        porcent = 100.0* (z-minZ)/totalZ;
+//       tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
+//        interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
+        //_staticTextSegmentation->SetLabel(tmpString);
+        SegmentationOneSlice( 100,100,z,isovalue, sampling,method , imagedata );
+    }
+//    interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
+    RefreshInterface();
+    printf("wxContourMainFrame::onSegmentationAllSlices2 end\n");
+
+}
+
+void wxContourMainFrame::onSegmentationAllSlices(int minZ,int maxZ,int isovalue,int sampling,int method)
 {
        //JCP 20-10-08 Undo redo implementation
        saveState();
@@ -2014,7 +2029,7 @@ void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,i
                tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
                interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
                //_staticTextSegmentation->SetLabel(tmpString);
-               SegmentationOneSlice( x,y,z,isovalue, sampling,method );
+               SegmentationOneSlice( x,y,z,isovalue, sampling,method , getImageData() );
        }
        interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
        RefreshInterface();
@@ -2236,7 +2251,6 @@ int wxContourMainFrame::getWindowLevel()
 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
 {
        _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
-
        RefreshInterface();
 }
 
@@ -3089,7 +3103,6 @@ void wxContourMainFrame::onSnakePressed(){
 
 void wxContourMainFrame::saveFileWithContoursAutomatique()
 {
-printf("EED wxContourMainFrame::saveFileWithContoursAutomatique \n");
        std::string filename = kernelManager->getCurrentFileName();
        if(filename.compare("")!=0){
                saveFileWithContours(filename);
@@ -3097,22 +3110,19 @@ printf("EED wxContourMainFrame::saveFileWithContoursAutomatique \n");
                onSave();
        }
 }
+
 void wxContourMainFrame::ShowToolsPanel(bool show)
 {
        _pannew->Show(show);
 }
 
-
-
 void wxContourMainFrame::SetContourGroup(int contourGroup)
 {
        _contourGroup = contourGroup;
 }
 
-
 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
 {
        if      (_viewMaskImagePanel==NULL)
        {
                _contourextractdata = new ContourExtractData(true);
@@ -3184,8 +3194,9 @@ void wxContourMainFrame::SetColorLayerImage(vtkImageData* img)
        {
                if (img!=NULL)
                {
+                       _viewColorLayerImagePanel->SetActive(true);
                        _viewColorLayerImagePanel->SetImage( img );
-                       RefreshInterface();
+//                     RefreshInterface();
                } // img
        } // _viewColorLayerImagePanel
 }
@@ -3418,6 +3429,15 @@ void wxContourMainFrame::SetXY(int x, int y)
        _theViewPanel->SetXY(x,y);
 }
 
+wxVtkBaseView* wxContourMainFrame::GetWxVtkBaseView()
+{
+       if (_theViewPanel!=NULL)
+       {
+               return _theViewPanel->getWxVtkBaseView();;
+       } else {
+               return NULL;
+       }
+}