From: Eduardo Davila Date: Mon, 8 Jun 2009 12:37:31 +0000 (+0000) Subject: bbmaracasvisuShowNPoints.cxx X-Git-Tag: EED.02Oct2009~46 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a20d4d20b94e9e8648b51599107e5d2229a8d648;p=creaMaracasVisu.git bbmaracasvisuShowNPoints.cxx --- diff --git a/bbtk/src/bbmaracasvisuShowNPoints.cxx b/bbtk/src/bbmaracasvisuShowNPoints.cxx index cf0a4de..d5f702b 100644 --- a/bbtk/src/bbmaracasvisuShowNPoints.cxx +++ b/bbtk/src/bbmaracasvisuShowNPoints.cxx @@ -24,29 +24,39 @@ namespace bbcreaMaracasVisu // Widget interface textCtrl = new wxTextCtrl(panel, -1); wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point")); + wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point")); wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point")); wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point")); 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")); wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); // sizer1->Add(new wxStaticText(panel,-1,_T(" "))); - Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint); - Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint); - Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint); - Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints); - - sizer1->Add(textCtrl); - sizer1->Add(btnAddPoint); - sizer1->Add(btnErasePoint); - sizer1->Add(btnEraseLastPoint); - sizer1->Add(btnDeleteAllPoints); - - sizer = sizer1; - panel -> SetSizer(sizer); - panel -> SetAutoLayout(true); - panel -> Layout(); + Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint); + Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint); + Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint); + Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint); + Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints); + Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints); + Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints); + + sizer1->Add(textCtrl); + sizer1->Add(btnAddPoint); + sizer1->Add(btnRenamePoint); + sizer1->Add(btnErasePoint); + sizer1->Add(btnEraseLastPoint); + sizer1->Add(btnDeleteAllPoints); + sizer1->Add(txtNrPoints); + sizer1->Add(btnSavePoints); + sizer1->Add(btnLoadPoints); + + sizer = sizer1; + panel -> SetSizer(sizer); + panel -> SetAutoLayout(true); + panel -> Layout(); } @@ -119,7 +129,17 @@ void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer) } - +std::string WidgetShowNPoints::CleanSpaces(std::string ss) +{ + int i; + while( (i=ss.find(32))>=0 ) + { + ss.replace(i,1,"_"); + } + return ss; +} + + //------------------------------------------------------------------------ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) { @@ -128,7 +148,10 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) lstPointsX.push_back( mpoint[0] ); lstPointsY.push_back( mpoint[1] ); lstPointsZ.push_back( mpoint[2] ); - lstLabels.push_back( (const char*) ( textCtrl->GetValue().mb_str() ) ); + + std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) ); + + lstLabels.push_back( strLabel ); // Sphere vtkSphereSource *vtksphere = vtkSphereSource::New(); @@ -152,11 +175,9 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) // Actor vtkTextActor3D *textActor = vtkTextActor3D::New(); textActor->SetPosition( mradio+spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] ); - textActor->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) ); + textActor->SetInput( strLabel.c_str() ); renderer->AddActor( textActor ); lstActorsText.push_back(textActor); - - renderer->GetRenderWindow()->Render(); SetOutputBox(); @@ -166,19 +187,93 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) } // renderer } + + //------------------------------------------------------------------------ void WidgetShowNPoints::SetOutputBox() { + renderer->GetRenderWindow()->Render(); + wxString strTmp; + strTmp.Printf("Number of points: %d", (int)(lstPointsX.size()) ); + txtNrPoints->SetLabel( strTmp ); + //--BBTK - mbbShowNPoints->bbSetOutputlstPointsX( GetLstPointsX() ); - mbbShowNPoints->bbSetOutputlstPointsY( GetLstPointsY() ); - mbbShowNPoints->bbSetOutputlstPointsZ( GetLstPointsZ() ); - mbbShowNPoints->bbSetOutputlstLabels( GetLstLabels() ); + mbbShowNPoints->bbSetOutputlstPointsX( lstPointsX ); + mbbShowNPoints->bbSetOutputlstPointsY( lstPointsY ); + mbbShowNPoints->bbSetOutputlstPointsZ( lstPointsZ ); + mbbShowNPoints->bbSetOutputlstLabels( lstLabels ); mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX")); mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY")); mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ")); mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels")); } + //------------------------------------------------------------------------ + 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) + { + 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 + + } + + //------------------------------------------------------------------------ + void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event) + { + } + + int WidgetShowNPoints::GetNearestPoint() + { + int id=-1; + int i, size=(int)(lstActorsSphere.size()); + double spc[3]; + mimage->GetSpacing(spc); + + for ( i=0 ; i=0) + { + std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) ); + lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ; + lstActorsText[id]->SetInput( lstLabels[id].c_str() ); + SetOutputBox(); + } + } + //------------------------------------------------------------------------ void WidgetShowNPoints::ErasePoint(int id) { @@ -196,7 +291,6 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) lstPointsZ.erase( lstPointsZ.begin()+id ); lstLabels.erase( lstLabels.begin()+id ); - renderer->GetRenderWindow()->Render(); SetOutputBox(); } // if id @@ -206,22 +300,7 @@ void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) //------------------------------------------------------------------------ void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event) { - int id=-1; - int i, size=(int)(lstActorsSphere.size()); - double spc[3]; - mimage->GetSpacing(spc); - - for ( i=0 ; i