X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FInterface_ManagerContour_NDimensions%2FwxContourMainFrame.cxx;h=3536b2b0da69a62213b11f81e2c7f046ac8faa9e;hb=5eb79f7a883f051e67ac328afdb96e4259cff885;hp=e6a1eec84fc756e626e1892c515088358323c7b9;hpb=c9965cf71b0d0cf7c85e8877d0c3505c97b1c3e9;p=creaContours.git diff --git a/lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx b/lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx index e6a1eec..3536b2b 100644 --- a/lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx +++ b/lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx @@ -13,12 +13,6 @@ #include "NameWrapper.h" #include "wx/artprov.h" #include "ConceptDataWrap.h" - -#include -//#include "ImageSourceThing.h" -//#include "wxContour_ActionCommandsID.h" -//#include "OutlineModelBuilder.h" -//#include "wxContourEventHandler.h" #include //---------------------------------------------------------------------------------------------------------------- @@ -105,12 +99,14 @@ char wxContourMainFrame::COPY = 'C'; if(images.size() > 0) { + _images = images; this->setVectImages(images); } } -void wxContourMainFrame::setVectImages( std::vector images ){ +void wxContourMainFrame::setVectImages(std::vector imgs) +{ #if defined(__GNUC__) std::string str_home(getenv("HOME")); @@ -125,7 +121,7 @@ void wxContourMainFrame::setVectImages( std::vector images ){ notebook = this->createNotebook(); - kernelManager = new KernelManagerContour( images , _datadir+"/data/" , strCreaContourDataTmp ); + kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp ); _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" ); @@ -172,7 +168,7 @@ void wxContourMainFrame::setVectImages( std::vector images ){ wxContourMainFrame :: ~wxContourMainFrame() { - + deleteAllContours(); _pannew->Close(); interfMainPanel::resetInstance(); delete kernelManager; @@ -786,11 +782,18 @@ void wxContourMainFrame::onLoad(){ fscanf(pFile,"%s",tmp); // --CreaContour-- fscanf(pFile,"%s",tmp); // Version - fscanf(pFile,"%s",tmp); // 1.0.1 + fscanf(pFile,"%s",tmp); // 1.0.1 || 1.0.0 std::string version(tmp); - - openContours(pFile,false); - if (version!="1.0.0"){ + + //AD:02-06-09 + if (version=="1.0.1") + { + openContours(pFile,false); + } + + //AD:02-06-09 + else if (version=="1.0.0") + { openContours(pFile,true); } // _theViewPanel->getSceneManager()->openFileWithContours(ff); @@ -800,6 +803,8 @@ void wxContourMainFrame::onLoad(){ _theViewPanel->getSceneManager()->removeSceneContours(); changeInstant(); } + +//AD: 29-05-09 void wxContourMainFrame::onSave(){ wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE ); if (dialog.ShowModal() == wxID_OK) @@ -809,6 +814,8 @@ void wxContourMainFrame::onSave(){ saveFileWithContours( fileNameContourROI ); } } + +//AD: 29-05-09 void wxContourMainFrame::saveFileWithContours( std::string filename ) { @@ -823,6 +830,19 @@ void wxContourMainFrame::saveFileWithContours( std::string filename ) lstNameThings = kernelManager->GetLstNameThings(); sizeLstNameThings = lstNameThings.size(); fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings ); + + 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] ); + for (i=0 ; iSaveThingName( pFile, lstNameThings[i] ); @@ -841,6 +861,7 @@ void wxContourMainFrame::saveFileWithContours( std::string filename ) fclose(pFile); } +//AD:02-06-09: TODO: Adjust spacing and dimensions to Rois comming from images with different specifications void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){ char tmp[255]; fscanf(pFile,"%s",tmp); // NumberOfContours @@ -852,64 +873,105 @@ void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){ manualContourModel *manModelContour; int typeView; - int i; - for (i=0;iGetDimensions(imageDim); + double imageSpac[3]; + image->GetSpacing(imageSpac); + + int tempDim[3]; + double tempSpac[3]; + + fscanf(pFile,"%s",tmp); // ImageDimensions + fscanf(pFile,"%s",tmp); // X + tempDim[0] = atoi(tmp); + fscanf(pFile,"%s",tmp); // Y + tempDim[1] = atoi(tmp); + fscanf(pFile,"%s",tmp); // Z + tempDim[2] = atoi(tmp); + + fscanf(pFile,"%s",tmp); // ImageSpacing + fscanf(pFile,"%s",tmp); // X + tempSpac[0] = atof(tmp); + fscanf(pFile,"%s",tmp); // Y + tempSpac[1] = atof(tmp); + fscanf(pFile,"%s",tmp); // Z + tempSpac[2] = atof(tmp); + + bool compatible = true; + + //Compare Spacing and Dims in X and Y (Necessary in Z?) + if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] || + imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1]) { - instantVector.clear(); - fscanf(pFile,"%s",tmp); // Instant + compatible = false; + } - fscanf(pFile,"%s",tmp); // 1 - instantVector.push_back( atoi(tmp) ); - fscanf(pFile,"%s",tmp); // 2 - instantVector.push_back( atoi(tmp) ); - fscanf(pFile,"%s",tmp); // 3 - instantVector.push_back( atoi(tmp) ); - fscanf(pFile,"%s",tmp); // 4 - instantVector.push_back( atoi(tmp) ); - fscanf(pFile,"%s",tmp); // 5 - instantVector.push_back( atoi(tmp) ); - fscanf(pFile,"%s",tmp); // 6 - instantVector.push_back( atoi(tmp) ); + if (compatible==true) + { + int i; + for (i=0;ifactoryManualContourModel(typeContourModel); - manModelContour->Open(pFile); + fscanf(pFile,"%s",tmp); // TypeContourModel + fscanf(pFile,"%s",tmp); // ## + typeContourModel = atoi(tmp); - fscanf(pFile,"%s",tmp); // TypeView - fscanf(pFile,"%s",tmp); // ## - typeView = atoi(tmp); + manModelContour = kernelManager->factoryManualContourModel(typeContourModel); + manModelContour->Open(pFile); + fscanf(pFile,"%s",tmp); // TypeView + fscanf(pFile,"%s",tmp); // ## + typeView = atoi(tmp); -// if (typeView==1) -// { -// } + // if (typeView==1) + // { + // } - std::string theName; - theName = kernelManager->createOutline( manModelContour, instantVector ); - bool addedModel = theName.compare("") != 0; - if( addedModel ) - { - double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default - _theViewPanel->getSpacing(spc); - //Adding the manualContourControler to interface objects structure - //Adding the manualViewContour to interface objects structure - //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active. - _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ; - } - if (staticContour==true) - { - Instant instant(&instantVector); - kernelManager->changeContourOfManager( theName , &instant ); - } + std::string theName; + theName = kernelManager->createOutline( manModelContour, instantVector ); + bool addedModel = theName.compare("") != 0; + if( addedModel ) + { + double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default + _theViewPanel->getSpacing(spc); + //Adding the manualContourControler to interface objects structure + //Adding the manualViewContour to interface objects structure + //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active. + _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ; + } + + if (staticContour==true) + { + Instant instant(&instantVector); + kernelManager->changeContourOfManager( theName , &instant ); + } - }// for numberOfContours + }// for numberOfContours + } + else if (compatible==false) + { + wxMessageBox(_T("The actual image is not compatible with the selected Roi file"), _T("Error"), wxICON_ERROR | wxOK); + } } void wxContourMainFrame::RefreshInterface(){ @@ -1616,7 +1678,8 @@ void wxContourMainFrame::referenceLine() _refLineView->SetWidthLine(4); _refLineControl->SetModelView( _refLineModel , _refLineView ); - viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl ); + vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView(); + style->AddInteractorStyleMaracas( _refLineControl ); _refLineModel->SetCloseContour(false); _refLineControl->CreateNewManualContour(); @@ -1670,7 +1733,8 @@ void wxContourMainFrame::refLineShow() _refLineView->SetZ( 1200 ); _refLineControl->SetModelView( _refLineModel , _refLineView ); - viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl ); + vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView(); + style->AddInteractorStyleMaracas( _refLineControl ); _refLineControl->CreateNewManualContour(); _refLineControl->SetActive(true); _refLineView->RefreshContour(); @@ -1947,10 +2011,32 @@ void wxContourMainFrame::onWidthOfContour(double width){ RefreshInterface(); } -int wxContourMainFrame::getColorWindow(){ + +int wxContourMainFrame::getColorWindow() +{ + /* + double range[2]; + vtkImageData * img = getImageData(); + img->GetScalarRange(range); + + std::cout<<"Val 1: "<getColorWindow(); } -int wxContourMainFrame::getWindowLevel(){ + +int wxContourMainFrame::getWindowLevel() +{ + /* + double range[2]; + vtkImageData * img = getImageData(); + img->GetScalarRange(range); + + std::cout<<"Val 1: "<getWindowLevel(); } @@ -2058,7 +2144,8 @@ std::vector wxContourMainFrame::getOutlinesName(int slide){ return kernelManager->getOutlinesNameAtInstant(tempVector); } -void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){ +void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ) +{ int maxContourGroup = 0; ContourExtractData *contourextractdata = new ContourExtractData(); @@ -2130,7 +2217,7 @@ void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int sel //_staticTextInformation->SetLabel(tmpString); //Extraction data from contours of each slice - contourextractdata->SetZtoBeAnalys( z); + contourextractdata->SetZtoBeAnalys(z); tempVector[1]=z; Instant instant(&tempVector); @@ -2249,45 +2336,62 @@ void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int sel delete contourextractdata; } -void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){ - SaveValuesXYZ( directory , namefile, typeContourGroup ); - - vtkImageData* mask, *value; - this->getMaskValue(mask, value, typeContourGroup); - this->SaveImageResult( directory , namefile, mask, value); +//AD: 29-05-09 +void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, + int typeContourGroup, bool XYZValues, bool contourImage, bool statistics) +{ + if (XYZValues) + { + SaveValuesXYZ( directory , namefile, typeContourGroup ); + } + if (contourImage) + { + vtkImageData * mask; + vtkImageData * value; + this->getMaskValue(&mask, &value, typeContourGroup); + this->SaveImageResult( directory , namefile, mask, value); + } - FILE *pFile=fopen(filename.c_str(),"w+"); + if (statistics) + { + std::ostringstream name; + name << filename << ".xls"; + - int sizeZ = _theViewPanel->GetImageDataSizeZ(); + FILE *pFile=fopen(name.str().c_str(),"w+"); - wxString tmpString; - int i,j,maxX,maxY=sizeZ; - maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols(); + int sizeZ = _theViewPanel->GetImageDataSizeZ(); - int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics); - for ( iTitle=0; iTitlegetNumberColsInformationPanel();//this->_grid->GetNumberCols(); + int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics); + for ( iTitle=0; iTitlegetCellValue(j, i);//_grid->GetCellValue( j , i ); - fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) ); - } // for i - fprintf(pFile,"\n" ); - } // for j - fclose(pFile); + for ( j=0; jgetCellValue(j, i);//_grid->GetCellValue( j , i ); + fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) ); + } // for i + fprintf(pFile,"\n" ); + } // for j + + fclose(pFile); + } } +//AD: 29-05-09 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup) { wxBusyCursor wait; @@ -2414,7 +2518,7 @@ void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefil delete contourextractdata; } -void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int typeContourGroup){ +void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup){ wxBusyCursor wait; ContourExtractData *contourextractdata = new ContourExtractData( true ); //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection(); @@ -2498,8 +2602,8 @@ void wxContourMainFrame::getMaskValue(vtkImageData* mask,vtkImageData* value,int } // for iContourGroup } // for z - value = contourextractdata->GetVtkImageValueResult(); - mask = contourextractdata->GetVtkImageMaskResult(); + (*value) = contourextractdata->GetVtkImageValueResult(); + (*mask) = contourextractdata->GetVtkImageMaskResult(); delete contourextractdata; }