From: Eduardo Davila Date: Wed, 10 Jun 2009 11:43:30 +0000 (+0000) Subject: bug view MPR X-Git-Tag: EED.02Oct2009~42 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1c612b8cf37c03d29406db6f855870075432f6d5;p=creaMaracasVisu.git bug view MPR --- diff --git a/bbtk/src/bbmaracasvisuShowNPoints.cxx b/bbtk/src/bbmaracasvisuShowNPoints.cxx index d5f702b..21cb591 100644 --- a/bbtk/src/bbmaracasvisuShowNPoints.cxx +++ b/bbtk/src/bbmaracasvisuShowNPoints.cxx @@ -30,7 +30,7 @@ namespace bbcreaMaracasVisu wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points")); wxButton *btnSavePoints = new wxButton( panel, -1, _T("Save points")); wxButton *btnLoadPoints = new wxButton( panel, -1, _T("Load points")); - txtNrPoints = new wxStaticText(panel,-1, _T("Number of points: 0")); + txtNrPoints = new wxStaticText(panel,-1, _T(" ")); wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); // sizer1->Add(new wxStaticText(panel,-1,_T(" "))); @@ -139,48 +139,53 @@ std::string WidgetShowNPoints::CleanSpaces(std::string ss) return ss; } +//------------------------------------------------------------------------ +void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label) +{ + lstPointsX.push_back( x ); + lstPointsY.push_back( y ); + lstPointsZ.push_back( z ); + + std::string strLabel = CleanSpaces( label ); + + lstLabels.push_back( strLabel ); + + // Sphere + vtkSphereSource *vtksphere = vtkSphereSource::New(); + vtksphere->SetThetaResolution (20); + vtksphere->SetPhiResolution (20); + vtksphere->SetRadius( mradio ); + vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); + sphereMapper->SetInput( vtksphere->GetOutput() ); + vtkActor *sphereActor = vtkActor::New(); + sphereActor->SetMapper(sphereMapper); + sphereActor->SetOrigin(0, 0, 0); + double spc[3]; + mimage->GetSpacing(spc); + sphereActor->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z ); + sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] ); + sphereActor->GetProperty()->SetOpacity( mopacity ); + + lstActorsSphere.push_back(sphereActor); + renderer->AddActor( sphereActor ); + + // Actor + vtkTextActor3D *textActor = vtkTextActor3D::New(); + textActor->SetPosition( mradio+spc[0]*x , spc[1]*y , spc[2]*z ); + textActor->SetInput( strLabel.c_str() ); + renderer->AddActor( textActor ); + lstActorsText.push_back(textActor); + + SetOutputBox(); + +} //------------------------------------------------------------------------ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) { if (this->renderer!=NULL){ if (mpoint.size()==3){ - lstPointsX.push_back( mpoint[0] ); - lstPointsY.push_back( mpoint[1] ); - lstPointsZ.push_back( mpoint[2] ); - - std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) ); - - lstLabels.push_back( strLabel ); - - // Sphere - vtkSphereSource *vtksphere = vtkSphereSource::New(); - vtksphere->SetThetaResolution (20); - vtksphere->SetPhiResolution (20); - vtksphere->SetRadius( mradio ); - vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); - sphereMapper->SetInput( vtksphere->GetOutput() ); - vtkActor *sphereActor = vtkActor::New(); - sphereActor->SetMapper(sphereMapper); - sphereActor->SetOrigin(0, 0, 0); - double spc[3]; - mimage->GetSpacing(spc); - sphereActor->SetPosition( spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] ); - sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] ); - sphereActor->GetProperty()->SetOpacity( mopacity ); - - lstActorsSphere.push_back(sphereActor); - renderer->AddActor( sphereActor ); - - // Actor - vtkTextActor3D *textActor = vtkTextActor3D::New(); - textActor->SetPosition( mradio+spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] ); - textActor->SetInput( strLabel.c_str() ); - renderer->AddActor( textActor ); - lstActorsText.push_back(textActor); - - SetOutputBox(); - + AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); } else {//mpoint.size printf("creaMaracasVisu::ShowNPoints (not match point) \n"); } @@ -193,7 +198,7 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) { renderer->GetRenderWindow()->Render(); wxString strTmp; - strTmp.Printf("Number of points: %d", (int)(lstPointsX.size()) ); + strTmp.Printf("Nbr of points: %d", (int)(lstPointsX.size()) ); txtNrPoints->SetLabel( strTmp ); //--BBTK @@ -210,34 +215,92 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) //------------------------------------------------------------------------ void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event) { - FILE *ff; - wxString filename="/Users/davila/Desktop/PDL_2/bbs/test.xls"; - ff = fopen( (const char*) ( filename.mb_str() ) , "w+" ); - if (ff!=NULL) + + wxFileDialog* FD = new wxFileDialog( 0, + _T("Save points .."), + _T(""), + _T(""), + _T("(*.xls)|*.xls"), + wxSAVE | wxOVERWRITE_PROMPT, + wxDefaultPosition); + //EED + + int result_FD = FD->ShowModal(); + + // This line is need it by windows //EED + FD->SetReturnCode( result_FD ); + + if (FD->GetReturnCode()==wxID_OK) { - int i , size = (int) (lstActorsSphere.size()); - fprintf(ff,"NumberOfPoints %d \n",size); - fprintf(ff," X\tY\tZ\tvalue\tLabel\n"); - int x, y, z; - double value; - for (i=0; iGetPath().mb_str() ); + ff = fopen( filename.c_str() , "w+" ); + if (ff!=NULL) { - x=lstPointsX[i]; - y=lstPointsY[i]; - z=lstPointsZ[i]; - value= mimage->GetScalarComponentAsDouble(x,y,z,0); - fprintf(ff,"%d\t %d\t %d\t %f\t %s\n", x , y , z , value , lstLabels[i].c_str()); - } // for - fclose(ff); - } else { // else ff - printf("WidgetShowNPoints::OnSavePoints ...Error... creating file"); - } //ff + int i , size = (int) (lstActorsSphere.size()); + fprintf(ff,"NumberOfPoints %d \n",size); + fprintf(ff," X\tY\tZ\tvalue\tLabel\n"); + int x, y, z; + double value; + for (i=0; iGetScalarComponentAsDouble(x,y,z,0); + fprintf(ff,"%d\t %d\t %d\t %f\t %s\n", x , y , z , value , lstLabels[i].c_str()); + } // for + fclose(ff); + } else { // else ff + printf("WidgetShowNPoints::OnSavePoints ...Error... creating file"); + } //ff + } // dialog box } //------------------------------------------------------------------------ void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event) { + wxFileDialog* FD = new wxFileDialog( 0, + _T("Load points .."), + _T(""), + _T(""), + _T("(*.xls)|*.xls"), + wxOPEN | wxFILE_MUST_EXIST, + wxDefaultPosition); + //EED + + int result_FD = FD->ShowModal(); + + // This line is need it by windows //EED + FD->SetReturnCode( result_FD ); + + if (FD->GetReturnCode()==wxID_OK) + { + FILE *ff; + std::string filename= (const char*) ( FD->GetPath().mb_str() ); + ff = fopen( filename.c_str() , "r+" ); + if (ff!=NULL) + { + int i,size; + char chartmp[256]; + fscanf(ff," %s %d",chartmp,&size); + fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp ); + + float value; + int x,y,z; + for (i=0; i