X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk%2Fsrc%2FbbmaracasvisuShowNPoints.cxx;h=bd4ec4272aff02d3718599324a21cd8f685c3dd3;hb=f010d4e7f1754243c513cc659372169c42560d5f;hp=ccd3092010052435c663fe7927bd6435bdb9a0cb;hpb=3e9c68ee7f4cf675d205d937442f40971953d017;p=creaMaracasVisu.git diff --git a/bbtk/src/bbmaracasvisuShowNPoints.cxx b/bbtk/src/bbmaracasvisuShowNPoints.cxx index ccd3092..bd4ec42 100644 --- a/bbtk/src/bbmaracasvisuShowNPoints.cxx +++ b/bbtk/src/bbmaracasvisuShowNPoints.cxx @@ -5,43 +5,75 @@ #include "vtkSphereSource.h" #include "vtkPolyDataMapper.h" #include "vtkRenderWindow.h" +#include "vtkTextActor3D.h" namespace bbcreaMaracasVisu { //---------------------------------------------------------------------- - WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, vtkRenderer *renderer, ShowNPoints *box) + WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, bbcreaMaracasVisu::ShowNPoints *box) : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) { mbbShowNPoints = box; - this->renderer = renderer; + this->renderer = NULL; wxPanel *panel = this; wxSizer *sizer = NULL; - + // Widget interface - wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point")); - wxButton *btnEraseLstPoint = new wxButton( panel, -1, _T("Erase Last point")); - wxButton *btnDeleteAllPoints= new wxButton( panel, -1, _T("Delete all points")); + 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(" ")); + //NTU: Sliders for opacity and radio change - wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); -// sizer1->Add(new wxStaticText(panel,-1,_T(" "))); + wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity "))); + sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); - Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint); - Connect(btnEraseLstPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint); - Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints); + wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio "))); + sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); - sizer1->Add(btnAddPoint); - sizer1->Add(btnEraseLstPoint); - sizer1->Add(btnDeleteAllPoints); + wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); +// sizer1->Add(new wxStaticText(panel,-1,_T(" "))); + + 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); + + //NTU: Slider events + Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); + Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); + + sizer1->Add(textCtrl); + sizer1->Add(btnAddPoint); + sizer1->Add(btnRenamePoint); + sizer1->Add(btnErasePoint); + sizer1->Add(btnEraseLastPoint); + sizer1->Add(btnDeleteAllPoints); + sizer1->Add(txtNrPoints); + sizer1->Add(txOpacity); + sizer1->Add(sdrOpacity); + sizer1->Add(txRadio); + sizer1->Add(sdrRadio); + sizer1->Add(btnSavePoints); + sizer1->Add(btnLoadPoints); + + sizer = sizer1; + panel -> SetSizer(sizer); + panel -> SetAutoLayout(true); + panel -> Layout(); - sizer = sizer1; - panel -> SetSizer(sizer); - panel -> SetAutoLayout(true); - panel -> Layout(); - } @@ -52,7 +84,9 @@ WidgetShowNPoints::~WidgetShowNPoints() void WidgetShowNPoints::SetRadio(double radio) { - mradio=radio; + this->mradio=radio; + //NTU: For Slider + sdrRadio->SetValue(this->mradio); } //------------------------------------------------------------------------ @@ -73,6 +107,12 @@ std::vector WidgetShowNPoints::GetLstPointsZ() return lstPointsZ; } +//------------------------------------------------------------------------ + std::vector WidgetShowNPoints::GetLstLabels() +{ + return lstLabels; +} + @@ -92,6 +132,8 @@ void WidgetShowNPoints::SetColour(std::vector colour) void WidgetShowNPoints::SetOpacity(double opacity) { this->mopacity=opacity; + //NTU: For Slider + sdrOpacity->SetValue(this->mopacity*100.0); } //------------------------------------------------------------------------ @@ -100,80 +142,320 @@ void WidgetShowNPoints::SetImage(vtkImageData *image) this->mimage=image; } +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer) +{ + this->renderer = renderer; +} + +std::string WidgetShowNPoints::CleanSpaces(std::string ss) +{ + int i; + while( (i=ss.find(32))>=0 ) + { + ss.replace(i,1,"_"); + } + 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 ); + + //NTU: For updating points + + lstSourceSphere.push_back(vtksphere); + + vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); + sphereMapper->SetInput( vtksphere->GetOutput() ); + vtkActor *sphereActor = vtkActor::New(); + sphereActor->SetMapper(sphereMapper); + sphereActor->SetOrigin(0, 0, 0); + double spc[3]; + if(mimage==NULL){ + wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR); + dialog.ShowModal(); + return; + } + 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); + if(renderer==NULL){ + wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR); + dialog.ShowModal(); + return; + } + 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) { -// printf("EED %p WidgetShowNPoints::OnAddPoint %d,%d,%d \n", this,mpoint[0],mpoint[1],mpoint[2] ); - - if (mpoint.size()==3){ - lstPointsX.push_back( mpoint[0] ); - lstPointsY.push_back( mpoint[1] ); - lstPointsZ.push_back( mpoint[2] ); - - // 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 ); + if (this->renderer!=NULL){ + if (mpoint.size()==3){ + AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); + } else {//mpoint.size + printf("creaMaracasVisu::ShowNPoints (not match point) \n"); + } + } // renderer +} - lstActors.push_back(sphereActor); - renderer->AddActor( sphereActor ); + //------------------------------------------------------------------------ + void WidgetShowNPoints::SetOutputBox() + { renderer->GetRenderWindow()->Render(); + wxString strTmp; + strTmp.Printf(_T("Nbr of points: %d"), (int)(lstPointsX.size()) ); + txtNrPoints->SetLabel( strTmp ); //--BBTK - mbbShowNPoints->bbSignalOutputModification(std::string("Point")); + 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) + { + + 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) + { + FILE *ff; + std::string filename= (const char*) ( FD->GetPath().mb_str() ); + ff = fopen( filename.c_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 + } // dialog box } -} -//------------------------------------------------------------------------ -void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event) -{ - int id = lstActors.size()-1; - if (id>=0){ - renderer->RemoveActor( lstActors[id] ); - lstActors.erase( lstActors.begin()+id ); - lstPointsX.erase( lstPointsX.begin()+id ); - lstPointsY.erase( lstPointsY.begin()+id ); - lstPointsZ.erase( lstPointsZ.begin()+id ); - renderer->GetRenderWindow()->Render(); - //--BBTK - mbbShowNPoints->bbSignalOutputModification(std::string("Point")); + //------------------------------------------------------------------------ + 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; iShowModal(); + return -1; + }else{ + + 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) + { + if (this->renderer!=NULL){ + if (id>=0){ + renderer->RemoveActor( lstActorsSphere[id] ); + renderer->RemoveActor( lstActorsText[id] ); + lstActorsSphere[id]->Delete(); + lstActorsText[id]->Delete(); + lstSourceSphere[id]->Delete(); + lstActorsSphere.erase( lstActorsSphere.begin()+id ); + lstActorsText.erase( lstActorsText.begin()+id ); + lstSourceSphere.erase( lstSourceSphere.begin()+id ); + + lstPointsX.erase( lstPointsX.begin()+id ); + lstPointsY.erase( lstPointsY.begin()+id ); + lstPointsZ.erase( lstPointsZ.begin()+id ); + lstLabels.erase( lstLabels.begin()+id ); + + SetOutputBox(); + + } // if id + } // if renderer + } + + //------------------------------------------------------------------------ + void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event) + { + ErasePoint( GetNearestPoint() ); + } + + //------------------------------------------------------------------------ + void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event) + { + ErasePoint(lstActorsSphere.size()-1); } -} //------------------------------------------------------------------------ void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event) { - int i,size=lstActors.size(); - for (i=0;i=0;id--) { - renderer->RemoveActor( lstActors[i] ); + ErasePoint(id); } - lstActors.clear(); - lstPointsX.clear(); - lstPointsY.clear(); - lstPointsZ.clear(); - renderer->GetRenderWindow()->Render(); - //--BBTK - mbbShowNPoints->bbSignalOutputModification(std::string("Point")); + } +//NTU: Method for updating points opacity and Radio + +//------------------------------------------------------------------------ +void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event) +{ + //Difference in Radio for text placement + int difradio = sdrRadio->GetValue() - this->mradio; + + this->mopacity = sdrOpacity->GetValue()/100.0; + this->mradio = sdrRadio->GetValue(); + + //NTU refresh the inputs + mbbShowNPoints->bbSetInputOpacity(this->mopacity); + mbbShowNPoints->bbSetInputRadio(this->mradio); + + int size = (int) this->lstActorsSphere.size(); + int i; + for(i = 0; i < size; i ++) + { + this->lstSourceSphere[i]->SetRadius(mradio); + this->lstActorsSphere[i]->GetProperty()->SetOpacity(mopacity); + this->lstActorsText[i]->SetPosition(this->lstActorsText[i]->GetPosition()[0]+difradio,this->lstActorsText[i]->GetPosition()[1], this->lstActorsText[i]->GetPosition()[2]); + } + //NTU: For updating + SetOutputBox(); +} @@ -183,22 +465,24 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox); void ShowNPoints::Process() { if (mwxwidget!=NULL){ - mwxwidget->SetPoint( bbGetInputIn() ); - mwxwidget->SetImage( bbGetInputImage() ); - mwxwidget->SetColour( bbGetInputColour() ); - mwxwidget->SetOpacity( bbGetInputOpacity() ); - mwxwidget->SetRadio( bbGetInputRadio() ); + mwxwidget->SetRenderer( bbGetInputRenderer() ); + mwxwidget->SetPoint( bbGetInputIn() ); + mwxwidget->SetImage( bbGetInputImage() ); + mwxwidget->SetColour( bbGetInputColour() ); + mwxwidget->SetOpacity( bbGetInputOpacity() ); + mwxwidget->SetRadio( bbGetInputRadio() ); bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() ); bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() ); bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() ); + bbSetOutputlstLabels( mwxwidget->GetLstLabels() ); } // mwxwidget } void ShowNPoints::CreateWidget(wxWindow* parent) { - mwxwidget = new WidgetShowNPoints( parent , bbGetInputRenderer(), this); + mwxwidget = new WidgetShowNPoints( parent , this); mwxwidget->SetPoint( bbGetInputIn() ); if (bbGetInputImage()==NULL) @@ -206,31 +490,37 @@ void ShowNPoints::CreateWidget(wxWindow* parent) printf("Missing Image (ShowNPoints) \n"); } - bbSetOutputWidget( mwxwidget ); - Process(); + bbSetOutputWidget( mwxwidget ); } -void ShowNPoints::bbUserConstructor() +void ShowNPoints::bbUserSetDefaultValues() { mwxwidget = NULL; + + bbSetInputRadio(1); + bbSetInputOpacity(1); + std::vector colour; colour.push_back(1.0); colour.push_back(0.0); colour.push_back(0.0); bbSetInputColour(colour); - bbSetInputOpacity(1); + bbSetInputImage(NULL); - bbSetInputRadio(0.5); + bbSetInputRenderer(NULL); } + //----------------------------------------------------------------- + void ShowNPoints::bbUserInitializeProcessing() + { + } -void ShowNPoints::bbUserCopyConstructor(bbtk::BlackBox::Pointer) -{ -} + //----------------------------------------------------------------- + void ShowNPoints::bbUserFinalizeProcessing() + { + } -void ShowNPoints::bbUserDestructor() -{ -} + //----------------------------------------------------------------- } // EO namespace bbcreaMaracasVisu