From: Eduardo DAVILA Date: Sun, 4 Jun 2017 08:45:16 +0000 (+0200) Subject: #3096 creaMaracasVisu Feature New Normal - Box ShowNPoints_Reset X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaMaracasVisu.git;a=commitdiff_plain;h=b6280d5b96447f5e4db026549d346e0d099a86f6 #3096 creaMaracasVisu Feature New Normal - Box ShowNPoints_Reset --- diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.cxx b/bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.cxx new file mode 100644 index 0000000..044b309 --- /dev/null +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.cxx @@ -0,0 +1,76 @@ +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +#include "bbcreaMaracasVisuShowNPoints_Reset.h" +#include "bbcreaMaracasVisuPackage.h" +namespace bbcreaMaracasVisu +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints_Reset) +BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints_Reset,bbtk::AtomicBlackBox); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void ShowNPoints_Reset::Process() +{ + +// THE MAIN PROCESSING METHOD BODY +// Here we simply set the input 'In' value to the output 'Out' +// And print out the output value +// INPUT/OUTPUT ACCESSORS ARE OF THE FORM : +// void bbSet{Input|Output}NAME(const TYPE&) +// const TYPE& bbGet{Input|Output}NAME() const +// Where : +// * NAME is the name of the input/output +// (the one provided in the attribute 'name' of the tag 'input') +// * TYPE is the C++ type of the input/output +// (the one provided in the attribute 'type' of the tag 'input') + +// bbSetOutputOut( bbGetInputIn() ); +// std::cout << "Output value = " <DeleteAllPoints(); + bbGetInputWidgetShowNPoints()->GetModelShowNPoints()->SetFirstTime(true); + +} +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void ShowNPoints_Reset::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + + bbSetInputWidgetShowNPoints(NULL); + +} +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void ShowNPoints_Reset::bbUserInitializeProcessing() +{ + +// THE INITIALIZATION METHOD BODY : +// Here does nothing +// but this is where you should allocate the internal/output pointers +// if any + + +} +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +void ShowNPoints_Reset::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbcreaMaracasVisu + + diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.h b/bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.h new file mode 100644 index 0000000..5ccc014 --- /dev/null +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Reset.h @@ -0,0 +1,48 @@ +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +#ifndef __bbcreaMaracasVisuShowNPoints_Reset_h_INCLUDED__ +#define __bbcreaMaracasVisuShowNPoints_Reset_h_INCLUDED__ +#include "bbcreaMaracasVisu_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include "WidgetShowNPoints.h" + + +namespace bbcreaMaracasVisu +{ + +class bbcreaMaracasVisu_EXPORT ShowNPoints_Reset + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(ShowNPoints_Reset,bbtk::AtomicBlackBox); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== + BBTK_DECLARE_INPUT(WidgetShowNPoints,WidgetShowNPoints*); +// BBTK_DECLARE_OUTPUT(Out,double); + BBTK_PROCESS(Process); + void Process(); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(ShowNPoints_Reset,bbtk::AtomicBlackBox); + BBTK_NAME("ShowNPoints_Reset"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("empty"); + BBTK_INPUT(ShowNPoints_Reset,WidgetShowNPoints," WidgetShowNPoints ",WidgetShowNPoints*,""); + //BBTK_OUTPUT(ShowNPoints_Reset,Out,"First output",double,""); +BBTK_END_DESCRIBE_BLACK_BOX(ShowNPoints_Reset); +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +} +// EO namespace bbcreaMaracasVisu + +#endif // __bbcreaMaracasVisuShowNPoints_Reset_h_INCLUDED__ + diff --git a/bbtk/src/bbmaracasvisuShowNPoints.cxx b/bbtk/src/bbmaracasvisuShowNPoints.cxx index 488a3a4..440f361 100644 --- a/bbtk/src/bbmaracasvisuShowNPoints.cxx +++ b/bbtk/src/bbmaracasvisuShowNPoints.cxx @@ -26,882 +26,70 @@ #include "bbmaracasvisuShowNPoints.h" #include "bbcreaMaracasVisuPackage.h" -#include "vtkProperty.h" -#include "vtkSphereSource.h" -#include "vtkPolyDataMapper.h" -#include "vtkRenderWindow.h" -#include "vtkTextActor3D.h" -#include namespace bbcreaMaracasVisu { -//---------------------------------------------------------------------- -ModelShowNPoints::ModelShowNPoints() -{ -} -//---------------------------------------------------------------------- - -ModelShowNPoints::~ModelShowNPoints() -{ -} - -//------------------------------------------------------------------------ -void ModelShowNPoints::SetRadio(double radio) -{ - mradio = radio; -} - - -//------------------------------------------------------------------------ -double ModelShowNPoints::GetRadio() -{ - return mradio; -} - - -//------------------------------------------------------------------------ -std::vector ModelShowNPoints::GetLstPointsX() -{ - return lstPointsX; -} - -//------------------------------------------------------------------------ -std::vector ModelShowNPoints::GetLstPointsY() -{ - return lstPointsY; -} - -//------------------------------------------------------------------------ -std::vector ModelShowNPoints::GetLstPointsZ() -{ - return lstPointsZ; -} - -//------------------------------------------------------------------------ -std::vector ModelShowNPoints::GetLstLabels() -{ - return lstLabels; -} - -//------------------------------------------------------------------------ -void ModelShowNPoints::SetReferencePoint(std::vector ppoint) -{ - mReferencePoint = ppoint; -} - -//------------------------------------------------------------------------ -std::vector ModelShowNPoints::GetReferencePoint() -{ - return mReferencePoint; -} - -//------------------------------------------------------------------------ -void ModelShowNPoints::SetImage(vtkImageData *image) -{ - this->mimage=image; -} - - -//------------------------------------------------------------------------ -std::string ModelShowNPoints::CleanSpaces(std::string ss) -{ - int i; - while( (i=ss.find(32))>=0 ) - { - ss.replace(i,1,"_"); - } - return ss; -} - -//------------------------------------------------------------------------ -void ModelShowNPoints::GetIdPoint(int id, int *x, int *y, int *z) -{ - *x=lstPointsX[id]; - *y=lstPointsY[id]; - *z=lstPointsZ[id]; -} - -//------------------------------------------------------------------------ -std::string ModelShowNPoints::GetIdLabel(int id) -{ - return lstLabels[id]; -} - -//------------------------------------------------------------------------ -vtkImageData *ModelShowNPoints::GetImage() -{ - return mimage; -} - -//------------------------------------------------------------------------ -void ModelShowNPoints::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 ); -} - -//------------------------------------------------------------------------ -double ModelShowNPoints::Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1)//CFT -{ - return sqrt((dX1 - dX0)*(dX1 - dX0) + (dY1 - dY0)*(dY1 - dY0) + (dZ1 - dZ0)*(dZ1 - dZ0)); -} - -//------------------------------------------------------------------------ -int ModelShowNPoints::InsertPoint(int x, int y, int z, std::string label) -{ - if(lstPointsX.size()>1) - { - std::vector dTotal; - int pos = 1; - int a,b,res; - - //Calcule distance for each pair of points - for(int i = 0; i<(int)lstPointsX.size()-1 ; i++) - { - a = Distance(x, y, z, lstPointsX[i], lstPointsY[i], lstPointsZ[i]); - b = Distance(x, y, z, lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1]); - res = a + b; - dTotal.push_back (res); - } - //Gets the smallest distance - int smallTMP = dTotal[0]; - for (int j = 0; j < (int) dTotal.size(); j++) - { - if(dTotal[j]::iterator it; - //Insert the point in the list of points - it = lstPointsX.begin(); - lstPointsX.insert( it+pos, x ); - it = lstPointsY.begin(); - lstPointsY.insert( it+pos, y ); - it = lstPointsZ.begin(); - lstPointsZ.insert( it+pos, z ); - - std::string strLabel = CleanSpaces( label ); - - std::vector::iterator itS; - itS = lstLabels.begin(); - //Insert Label in list of labels - lstLabels.insert( itS+pos, strLabel ); - return pos; - } else { - return -1; - }// if size lst X - -} - - -//------------------------------------------------------------------------ -void ModelShowNPoints::SavePoints(std::string filename) -{ - std::string tmpLabel; - FILE *ff; - ff = fopen( filename.c_str() , "w+" ); - if (ff!=NULL) - { - int i , size = (int) (lstPointsX.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); - if (lstLabels[i]!="") - { - tmpLabel=lstLabels[i]; - } else{ - tmpLabel="<_VOID_>"; - } - fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value , tmpLabel.c_str()); - } // for - fclose(ff); - } else { // else ff - printf("ModelShowNPoints::SavePoints ...Error... creating file"); - } //ff -} - -//------------------------------------------------------------------------ -int ModelShowNPoints::ReadPoints(std::string filename) -{ - int i,size; - char chartmp[256]; - FILE *ff; - ff = fopen( filename.c_str() , "r+" ); - if (ff!=NULL) - { - 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")==0) { strcpy(chartmp,""); } - AddPoint(x,y,z, chartmp ); - } - fclose(ff); - } else { // else ff - printf("ModelShowNPoints::LoadPoints ...Error... reading file"); - } //ff - return size; -} - -//------------------------------------------------------------------------ -int ModelShowNPoints::GetNearestPoint() -{ - int id=-1; - int i, size=(int)(lstPointsX.size()); - double radioMin=10000000; - for ( i=0 ; iGetSpacing(spc); - for ( i=0 ; i=0) - { - std::string strLabel = CleanSpaces( label ); - lstLabels[id] = strLabel; - } - return id; -} - -//---------------------------------------------------------------------- -void ModelShowNPoints::ErasePoint(int id) -{ - lstPointsX.erase( lstPointsX.begin()+id ); - lstPointsY.erase( lstPointsY.begin()+id ); - lstPointsZ.erase( lstPointsZ.begin()+id ); - lstLabels.erase( lstLabels.begin()+id ); -} - - - -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- - WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, bbcreaMaracasVisu::ShowNPoints *box) - : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) - { - mmodelShowNPoints = new ModelShowNPoints(); - mbbShowNPoints = box; - this->renderer = NULL; - wxPanel *panel = this; - wxSizer *sizer = NULL; - - if (mbbShowNPoints->bbGetInputType()==0) - { - // Widget interface - askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR - textCtrl = new wxTextCtrl(panel, -1); - wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point")); - wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT - wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest 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 - wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity "))); - sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); - wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio "))); - sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); - - wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); - // sizer1->Add(new wxStaticText(panel,-1,_T(" "))); - - Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint); - Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT - Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint); - 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(askPointLabel); // JPR - sizer1->Add(textCtrl); - sizer1->Add(btnAddPoint); - sizer1->Add(btnInsertPoint);//CFT - sizer1->Add(btnSetPositionPoint); - sizer1->Add(btnRenamePoint); - sizer1->Add(btnErasePoint); - sizer1->Add(btnEraseLastPoint); - sizer1->Add(btnDeleteAllPoints); - sizer1->Add(txtNrPoints); - sizer1->Add(txOpacity); - sizer1->Add(sdrOpacity,1,wxGROW ); - sizer1->Add(txRadio); - sizer1->Add(sdrRadio,1,wxGROW ); - sizer1->Add(btnSavePoints); - sizer1->Add(btnLoadPoints); - sizer = sizer1; - } - - if (mbbShowNPoints->bbGetInputType()==1) - { - // Widget interface - wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point")); - txtNrPoints = new wxStaticText(panel,-1, _T(" ")); - - //NTU: Sliders for opacity and radio change - wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity "))); - sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); - wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio "))); - sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); - wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); - Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint); - Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); - Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); - - sizer1->Add(btnSetPositionPoint); - sizer1->Add(txtNrPoints); - sizer1->Add(txOpacity); - sizer1->Add(sdrOpacity,1,wxGROW ); - sizer1->Add(txRadio); - sizer1->Add(sdrRadio,1,wxGROW ); - sizer = sizer1; - } - - if (mbbShowNPoints->bbGetInputType() == 2) - { - askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR - wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point ")); - wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All ")); - wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR - textCtrl = new wxTextCtrl(panel, -1); - wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); - Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint); - Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints); - sizer1->Add(askPointLabel); - sizer1->Add(btnAddPoint); - sizer1->Add(btnDeleteAllPoints); - sizer1->Add(spacer); - sizer1->Add(textCtrl); - sdrOpacity = new wxSlider(); - sdrRadio = new wxSlider(); - txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n")); - sizer = sizer1; - } // bbGetInputType 2 - - if (sizer!=NULL) - { - panel->SetSizer(sizer); - panel->SetAutoLayout(true); - panel->Layout(); - } // if sizer -} //------------------------------------------------------------------------ -WidgetShowNPoints::~WidgetShowNPoints() -{ -} - -//------------------------------------------------------------------------ -ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints() -{ - return mmodelShowNPoints; -} - - //------------------------------------------------------------------------ -void WidgetShowNPoints::SetRadio(double radio) -{ - GetModelShowNPoints()->SetRadio(radio); - //NTU: For Slider - sdrRadio->SetValue(radio); -} - //------------------------------------------------------------------------ -void WidgetShowNPoints::SetColour(std::vector colour) -{ - this->mcolour = colour; -} - //------------------------------------------------------------------------ -void WidgetShowNPoints::SetImage(vtkImageData* image) +WidgetShowNPointsBox::WidgetShowNPointsBox(wxWindow *parent, bbcreaMaracasVisu::ShowNPoints *box, int type) + : WidgetShowNPoints( parent, type) { - GetModelShowNPoints()->SetImage(image); + mbbShowNPoints=box; } //------------------------------------------------------------------------ -void WidgetShowNPoints::SetOpacity(double opacity) +WidgetShowNPointsBox::~WidgetShowNPointsBox() { - this->mopacity=opacity; - //NTU: For Slider - sdrOpacity->SetValue(this->mopacity*100.0); } //------------------------------------------------------------------------ -void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer) +void WidgetShowNPointsBox::UpdatePoints(wxCommandEvent &event) { - this->renderer = renderer; -} - -//------------------------------------------------------------------------ - -void WidgetShowNPoints::RefreshPoint(int id) -{ - double spc[3]; - -//EED 2016/06/17 -// mimage->GetSpacing(spc); -// int x = lstPointsX[id]; -// int y = lstPointsY[id]; -// int z = lstPointsZ[id]; - int x,y,z; - GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z); - GetModelShowNPoints()->GetImage()->GetSpacing(spc); - std::string label = GetModelShowNPoints()->GetIdLabel(id); - double radio = GetModelShowNPoints()->GetRadio(); - - lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z ); - lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] ); - lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity ); - lstSourceSphere[id]->SetRadius( radio ); - - lstActorsText[id]->SetInput( label.c_str() ); - lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z ); -} - -//------------------------------------------------------------------------ -void WidgetShowNPoints::RefreshPoints() -{ - int id,size=lstActorsSphere.size(); - for (id=0;idGetRenderWindow()->Render(); -} - -//------------------------------------------------------------------------ -void WidgetShowNPoints::AddVtkPoint() -{ - // Sphere - vtkSphereSource *vtksphere = vtkSphereSource::New(); - vtksphere->SetThetaResolution (20); - vtksphere->SetPhiResolution (20); - vtksphere->SetRadius( 1 ); - //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); - - 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->SetInput( strLabel.c_str() ); - renderer->AddActor( textActor ); - lstActorsText.push_back(textActor); -} - +printf("EED WidgetShowNPointsBox::UpdatePoints start\n"); + WidgetShowNPoints::UpdatePoints(event); + //Difference in Radio for text placement +// double radio=GetModelShowNPoints()->GetRadio(); +// this->mopacity = sdrOpacity->GetValue()/100.0; +// GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ; +// radio = sdrRadio->GetValue(); + //NTU refresh the inputs + mbbShowNPoints->bbSetInputOpacity( GetOpacity() ); + mbbShowNPoints->bbSetInputRadio( GetRadio() ); + // EED +// RefreshPoints(); +printf("EED WidgetShowNPointsBox::UpdatePoints end\n"); -//------------------------------------------------------------------------ -void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label) -{ - GetModelShowNPoints()->AddPoint(x,y,z, label ); - AddVtkPoint(); - RefreshPoint(lstActorsSphere.size()-1); } - //------------------------------------------------------------------------ -void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT +void WidgetShowNPointsBox::SetOutputBox() { + WidgetShowNPoints::SetOutputBox(); +// wxString strTmp; +// strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() ); +// txtNrPoints->SetLabel( strTmp ); -//-- - if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 ) - { -/* - // Sphere - vtkSphereSource *vtksphere = vtkSphereSource::New(); - vtksphere->SetThetaResolution (20); - vtksphere->SetPhiResolution (20); - vtksphere->SetRadius( mradio ); - - //NTU: For updating points - std::vector::iterator itSS; - itSS = lstSourceSphere.begin(); - lstSourceSphere.insert( itSS+pos, vtksphere); - - vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); - sphereMapper->SetInput( vtksphere->GetOutput() ); - vtkActor *sphereActor = vtkActor::New(); - sphereActor->SetMapper(sphereMapper); - sphereActor->SetOrigin(0, 0, 0); - - std::vector::iterator itAS; - itAS = lstActorsSphere.begin(); - lstActorsSphere.insert( itAS+pos, 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->SetInput( strLabel.c_str() ); - renderer->AddActor( textActor ); - std::vector::iterator itTA; - itTA = lstActorsText.begin(); - lstActorsText.insert( itTA+pos , textActor); -*/ - - AddVtkPoint(); - } else { - AddPoint(x,y,z,label); - } - RefreshPoints(); - //end if -} - - -//------------------------------------------------------------------------ -void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) -{ - if (this->renderer==NULL) - { - return; - } - - std::vector point = GetModelShowNPoints()->GetReferencePoint(); - if (point.size()==3) - { - AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); - SetOutputBox(); - renderer->GetRenderWindow()->Render(); - } else {//mpoint.size - printf("creaMaracasVisu::ShowNPoints (not match point) \n"); - } + //--BBTK + mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() ); + mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() ); + mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() ); + mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() ); + mbbShowNPoints->bbSignalOutputModification(); } -//------------------------------------------------------------------------ -void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT -{ - if (this->renderer==NULL) - { - return; - } - - std::vector point = GetModelShowNPoints()->GetReferencePoint(); - if (point.size()==3) - { - InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); - SetOutputBox(); - } else {//mpoint.size - printf("creaMaracasVisu::ShowNPoints (not match point) \n"); - } -} - - -//------------------------------------------------------------------------ - void WidgetShowNPoints::SetOutputBox() - { -//EED renderer->GetRenderWindow()->Render(); - wxString strTmp; - strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() ); - txtNrPoints->SetLabel( strTmp ); - //--BBTK - mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() ); - mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() ); - mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() ); - mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() ); - mbbShowNPoints->bbSignalOutputModification(); - } - - -//------------------------------------------------------------------------ - 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) - { - std::string filename= (const char*) ( FD->GetPath().mb_str() ); - GetModelShowNPoints()->SavePoints( filename ); - } // 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); - int i; - //EED - int result_FD = FD->ShowModal(); - // This line is need it by windows //EED - FD->SetReturnCode( result_FD ); - if (FD->GetReturnCode()==wxID_OK) - { - - std::string filename= (const char*) ( FD->GetPath().mb_str() ); - int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename ); - for (i=0;iGetNearestPoint(); - if((id==-1) && (mbbShowNPoints->bbGetInputType()==1)) - { - id=0; - AddPoint(0,0,0,""); - SetOutputBox(); - } - - if (id>=0) - { - GetModelShowNPoints()->SetPointId_mReferencePoint(id); - RefreshPoint(id); - renderer->GetRenderWindow()->Render(); - } // if id - SetOutputBox(); - } - //------------------------------------------------------------------------ - void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event) - { - int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) ); - if (id>=0) - { - lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) ); - SetOutputBox(); - renderer->GetRenderWindow()->Render(); - } - } - //------------------------------------------------------------------------ - 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 ); - GetModelShowNPoints()->ErasePoint(id); - } // if id - } // if renderer - } - //------------------------------------------------------------------------ - void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event) - { - ErasePoint( GetModelShowNPoints()->IdInsidePoint() ); - SetOutputBox(); - renderer->GetRenderWindow()->Render(); - } - -//------------------------------------------------------------------------ - void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event) - { - ErasePoint(lstActorsSphere.size()-1); - SetOutputBox(); - renderer->GetRenderWindow()->Render(); - } - -//------------------------------------------------------------------------ -void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event) -{ - int id,size=lstActorsSphere.size(); - for (id=size-1;id>=0;id--) - { - ErasePoint(id); - } - SetOutputBox(); - renderer->GetRenderWindow()->Render(); -} - -//NTU: Method for updating points opacity and Radio - -//------------------------------------------------------------------------ -void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event) -{ - //Difference in Radio for text placement - double radio=GetModelShowNPoints()->GetRadio(); - this->mopacity = sdrOpacity->GetValue()/100.0; - GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ; - radio = sdrRadio->GetValue(); - //NTU refresh the inputs - mbbShowNPoints->bbSetInputOpacity(this->mopacity); - mbbShowNPoints->bbSetInputRadio( radio ); - // EED - RefreshPoints(); -} - -//------------------------------------------------------------------------ -void WidgetShowNPoints::SetReferencePoint(std::vector point) -{ - GetModelShowNPoints()->SetReferencePoint(point); -} - -//------------------------------------------------------------------------ -void WidgetShowNPoints::SetInitLstPoints( std::vector initLstPointsX, std::vector initLstPointsY, std::vector initLstPointsZ, std::vector initLstLabels ) -{ - if (this->renderer==NULL) - { - return; - } - - int i,sizeX,sizeY,sizeZ,sizeLabels; - sizeX=(int)initLstPointsX.size(); - sizeY=(int)initLstPointsY.size(); - sizeZ=(int)initLstPointsZ.size(); - sizeLabels=(int)initLstLabels.size(); - - int x,y,z; - std::string label; - - if ( (sizeX==sizeY) && (sizeX==sizeZ) ) - { - - for (i=0;iGetRenderWindow()->Render(); - - } // if size -} @@ -921,9 +109,9 @@ void ShowNPoints::Process() mwxwidget->SetOpacity( bbGetInputOpacity() ); mwxwidget->SetRadio( bbGetInputRadio() ); - if (firsttime==true) + if ( mwxwidget->GetModelShowNPoints()->GetFirstTime()==true ) { - firsttime=false; + mwxwidget->GetModelShowNPoints()->SetFirstTime(false); mwxwidget->SetInitLstPoints( bbGetInputInitLstPointsX() , bbGetInputInitLstPointsY() , bbGetInputInitLstPointsZ() , bbGetInputInitLstLabels() ); } @@ -931,34 +119,32 @@ void ShowNPoints::Process() bbSetOutputlstPointsY( mwxwidget->GetModelShowNPoints()->GetLstPointsY() ); bbSetOutputlstPointsZ( mwxwidget->GetModelShowNPoints()->GetLstPointsZ() ); bbSetOutputlstLabels( mwxwidget->GetModelShowNPoints()->GetLstLabels() ); + bbSetOutputWidgetShowNPoints( (WidgetShowNPoints*)mwxwidget ); } // mwxwidget } //----------------------------------------------------------------- void ShowNPoints::CreateWidget(wxWindow* parent) { - mwxwidget = new WidgetShowNPoints( parent, this); + mwxwidget = new WidgetShowNPointsBox( parent, this, bbGetInputType() ); bbSetOutputWidget( mwxwidget ); } //----------------------------------------------------------------- void ShowNPoints::bbUserSetDefaultValues() { - firsttime = true; mwxwidget = NULL; - bbSetInputRadio(10); bbSetInputOpacity(1); - std::vector colour; colour.push_back(1.0); colour.push_back(0.0); colour.push_back(0.0); bbSetInputColour(colour); - bbSetInputImage(NULL); bbSetInputType(0); bbSetInputRenderer(NULL); + bbSetOutputWidgetShowNPoints(NULL); } //----------------------------------------------------------------- diff --git a/bbtk/src/bbmaracasvisuShowNPoints.h b/bbtk/src/bbmaracasvisuShowNPoints.h index df37ddb..46ff3ec 100644 --- a/bbtk/src/bbmaracasvisuShowNPoints.h +++ b/bbtk/src/bbmaracasvisuShowNPoints.h @@ -27,123 +27,37 @@ #ifndef __bbcreaMaracasVisuShowNPoints_h_INCLUDED__ #define __bbcreaMaracasVisuShowNPoints_h_INCLUDED__ #include "bbtkWxBlackBox.h" -#include -#include "vtkActor.h" -#include "vtkSphereSource.h" + #include "vtkImageData.h" -#include "vtkRenderer.h" -#include "vtkTextActor3D.h" + +#include "WidgetShowNPoints.h" namespace bbcreaMaracasVisu { - class ModelShowNPoints - { - public: - ModelShowNPoints(); - ~ModelShowNPoints(); - std::vector GetLstPointsX(); - std::vector GetLstPointsY(); - std::vector GetLstPointsZ(); - void GetIdPoint(int id, int *x, int *y, int *z); - std::string GetIdLabel(int id); - std::vector GetLstLabels(); - void AddPoint(int x, int y, int z, std::string label); - double Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1); - int InsertPoint(int x, int y, int z, std::string label); - void SavePoints(std::string filename); - int ReadPoints(std::string filename); - int GetNearestPoint(); - - int GetLstPointsSize(); - void SetPointId_mReferencePoint(int id); - int IdInsidePoint(); - - void SetReferencePoint(std::vector ppoint); - std::vector GetReferencePoint(); - void SetImage(vtkImageData *image); - std::string CleanSpaces(std::string ss); - vtkImageData* GetImage(); - void SetRadio(double radio); - double GetRadio(); - int RenamePoint(std::string label); - void ErasePoint(int id); - - private: - std::vector lstPointsX; - std::vector lstPointsY; - std::vector lstPointsZ; - std::vector lstLabels; - std::vector mReferencePoint; - double mradio; - vtkImageData *mimage; - - }; - - - class ShowNPoints; - - //-------------------------------------------------------------------------- - class WidgetShowNPoints : public wxPanel - { - public: - WidgetShowNPoints( wxWindow *parent, ShowNPoints *box); - ~WidgetShowNPoints(); - void OnAddPoint(wxCommandEvent &event); - void OnInsertPoint (wxCommandEvent& event);//CFT - void OnSetPoint(wxCommandEvent& event); - void OnRenamePoint(wxCommandEvent& event); - void OnErasePoint(wxCommandEvent& event); - void OnEraseLastPoint(wxCommandEvent &event); - void OnDeleteAllPoints(wxCommandEvent &event); - void OnSavePoints(wxCommandEvent &event); - void OnLoadPoints(wxCommandEvent &event); - void UpdatePoints(wxCommandEvent &event); - - void RefreshPoint(int id); - - void SetColour(std::vector colour); - void SetOpacity(double opacity); - void SetRadio(double radio); - void SetImage(vtkImageData *image); - void SetRenderer(vtkRenderer *renderer); - void SetReferencePoint(std::vector point); - - void AddPoint(int x, int y, int z, std::string label); - void InsertPoint(int x, int y, int z, std::string label);//CFT - - ModelShowNPoints* GetModelShowNPoints(); - void RefreshPoints(); - void AddVtkPoint(); - void SetInitLstPoints( std::vector initLstPointsX, std::vector initLstPointsY, std::vector initLstPointsZ, std::vector initLstLabels ); - - - private: - void ErasePoint(int id); - void SetOutputBox(); - - ShowNPoints *mbbShowNPoints; - vtkRenderer *renderer; - - std::vector lstActorsSphere;//NTU changed from prop3D to Actor - std::vector lstActorsText; - - //NTU: For updating points - - std::vector lstSourceSphere; - - std::vector mcolour; - double mopacity; - wxStaticText *askPointLabel; - wxTextCtrl *textCtrl; - wxStaticText *txtNrPoints; - wxSlider *sdrOpacity; - wxSlider *sdrRadio; - - ModelShowNPoints *mmodelShowNPoints; - - }; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +class ShowNPoints; + +class WidgetShowNPointsBox : public WidgetShowNPoints +{ +public: + WidgetShowNPointsBox( wxWindow *parent, ShowNPoints *box, int type); + ~WidgetShowNPointsBox(); + void UpdatePoints(wxCommandEvent &event); +private: + void SetOutputBox(); + ShowNPoints *mbbShowNPoints; +}; + + + class /*BBTK_EXPORT*/ ShowNPoints : @@ -166,14 +80,14 @@ class /*BBTK_EXPORT*/ ShowNPoints BBTK_DECLARE_OUTPUT( lstPointsY, std::vector ); BBTK_DECLARE_OUTPUT( lstPointsZ, std::vector ); BBTK_DECLARE_OUTPUT( lstLabels, std::vector ); + BBTK_DECLARE_OUTPUT( WidgetShowNPoints, WidgetShowNPoints*); BBTK_PROCESS(Process); void Process(); BBTK_CREATE_WIDGET(CreateWidget); void CreateWidget(wxWindow*); private: - WidgetShowNPoints *mwxwidget; - bool firsttime; + WidgetShowNPointsBox *mwxwidget; }; BBTK_BEGIN_DESCRIBE_BLACK_BOX(ShowNPoints,bbtk::WxBlackBox); @@ -198,6 +112,7 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(ShowNPoints,bbtk::WxBlackBox); BBTK_OUTPUT(ShowNPoints , lstPointsY , " list of points Y ", std::vector ,""); BBTK_OUTPUT(ShowNPoints , lstPointsZ , " list of points Z ", std::vector ,""); BBTK_OUTPUT(ShowNPoints , lstLabels , " list of labels ", std::vector ,""); + BBTK_OUTPUT(ShowNPoints , WidgetShowNPoints , " WidgetShowNPoints ", WidgetShowNPoints* ,""); BBTK_END_DESCRIBE_BLACK_BOX(ShowNPoints); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx new file mode 100644 index 0000000..4f7eebb --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx @@ -0,0 +1,328 @@ + +#include + +#include "ModelShowNPoints.h" + + +//---------------------------------------------------------------------- +ModelShowNPoints::ModelShowNPoints() +{ + firsttime=true; +} +//---------------------------------------------------------------------- + +ModelShowNPoints::~ModelShowNPoints() +{ +} + +//------------------------------------------------------------------------ +void ModelShowNPoints::SetRadio(double radio) +{ + mradio = radio; +} + + +//------------------------------------------------------------------------ +double ModelShowNPoints::GetRadio() +{ + return mradio; +} + + +//------------------------------------------------------------------------ +std::vector ModelShowNPoints::GetLstPointsX() +{ + return lstPointsX; +} + +//------------------------------------------------------------------------ +std::vector ModelShowNPoints::GetLstPointsY() +{ + return lstPointsY; +} + +//------------------------------------------------------------------------ +std::vector ModelShowNPoints::GetLstPointsZ() +{ + return lstPointsZ; +} + +//------------------------------------------------------------------------ +std::vector ModelShowNPoints::GetLstLabels() +{ + return lstLabels; +} + +//------------------------------------------------------------------------ +void ModelShowNPoints::SetReferencePoint(std::vector ppoint) +{ + mReferencePoint = ppoint; +} + +//------------------------------------------------------------------------ +std::vector ModelShowNPoints::GetReferencePoint() +{ + return mReferencePoint; +} + +//------------------------------------------------------------------------ +void ModelShowNPoints::SetImage(vtkImageData *image) +{ + this->mimage=image; +} + + +//------------------------------------------------------------------------ +std::string ModelShowNPoints::CleanSpaces(std::string ss) +{ + int i; + while( (i=ss.find(32))>=0 ) + { + ss.replace(i,1,"_"); + } + return ss; +} + +//------------------------------------------------------------------------ +void ModelShowNPoints::GetIdPoint(int id, int *x, int *y, int *z) +{ + *x=lstPointsX[id]; + *y=lstPointsY[id]; + *z=lstPointsZ[id]; +} + +//------------------------------------------------------------------------ +std::string ModelShowNPoints::GetIdLabel(int id) +{ + return lstLabels[id]; +} + +//------------------------------------------------------------------------ +vtkImageData *ModelShowNPoints::GetImage() +{ + return mimage; +} + +//------------------------------------------------------------------------ +void ModelShowNPoints::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 ); +} + +//------------------------------------------------------------------------ +double ModelShowNPoints::Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1)//CFT +{ + return sqrt((dX1 - dX0)*(dX1 - dX0) + (dY1 - dY0)*(dY1 - dY0) + (dZ1 - dZ0)*(dZ1 - dZ0)); +} + +//------------------------------------------------------------------------ +int ModelShowNPoints::InsertPoint(int x, int y, int z, std::string label) +{ + if(lstPointsX.size()>1) + { + std::vector dTotal; + int pos = 1; + int a,b,res; + + //Calcule distance for each pair of points + for(int i = 0; i<(int)lstPointsX.size()-1 ; i++) + { + a = Distance(x, y, z, lstPointsX[i], lstPointsY[i], lstPointsZ[i]); + b = Distance(x, y, z, lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1]); + res = a + b; + dTotal.push_back (res); + } + //Gets the smallest distance + int smallTMP = dTotal[0]; + for (int j = 0; j < (int) dTotal.size(); j++) + { + if(dTotal[j]::iterator it; + //Insert the point in the list of points + it = lstPointsX.begin(); + lstPointsX.insert( it+pos, x ); + it = lstPointsY.begin(); + lstPointsY.insert( it+pos, y ); + it = lstPointsZ.begin(); + lstPointsZ.insert( it+pos, z ); + + std::string strLabel = CleanSpaces( label ); + + std::vector::iterator itS; + itS = lstLabels.begin(); + //Insert Label in list of labels + lstLabels.insert( itS+pos, strLabel ); + return pos; + } else { + return -1; + }// if size lst X + +} + + +//------------------------------------------------------------------------ +void ModelShowNPoints::SavePoints(std::string filename) +{ + std::string tmpLabel; + FILE *ff; + ff = fopen( filename.c_str() , "w+" ); + if (ff!=NULL) + { + int i , size = (int) (lstPointsX.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); + if (lstLabels[i]!="") + { + tmpLabel=lstLabels[i]; + } else{ + tmpLabel="<_VOID_>"; + } + fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value , tmpLabel.c_str()); + } // for + fclose(ff); + } else { // else ff + printf("ModelShowNPoints::SavePoints ...Error... creating file"); + } //ff +} + +//------------------------------------------------------------------------ +int ModelShowNPoints::ReadPoints(std::string filename) +{ + int i,size; + char chartmp[256]; + FILE *ff; + ff = fopen( filename.c_str() , "r+" ); + if (ff!=NULL) + { + 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")==0) { strcpy(chartmp,""); } + AddPoint(x,y,z, chartmp ); + } + fclose(ff); + } else { // else ff + printf("ModelShowNPoints::LoadPoints ...Error... reading file"); + } //ff + return size; +} + +//------------------------------------------------------------------------ +int ModelShowNPoints::GetNearestPoint() +{ + int id=-1; + int i, size=(int)(lstPointsX.size()); + double radioMin=10000000; + for ( i=0 ; iGetSpacing(spc); + for ( i=0 ; i=0) + { + std::string strLabel = CleanSpaces( label ); + lstLabels[id] = strLabel; + } + return id; +} + +//---------------------------------------------------------------------- +void ModelShowNPoints::ErasePoint(int id) +{ + lstPointsX.erase( lstPointsX.begin()+id ); + lstPointsY.erase( lstPointsY.begin()+id ); + lstPointsZ.erase( lstPointsZ.begin()+id ); + lstLabels.erase( lstLabels.begin()+id ); +} + +//---------------------------------------------------------------------- +void ModelShowNPoints::SetFirstTime(bool value) +{ + firsttime=value; +} + +//---------------------------------------------------------------------- +bool ModelShowNPoints::GetFirstTime() +{ + return firsttime; +} + + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h new file mode 100644 index 0000000..cee7495 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h @@ -0,0 +1,60 @@ + +#ifndef __ModelShowNPoints_h_INCLUDED__ +#define __ModelShowNPoints_h_INCLUDED__ + + +#include +#include +#include + + +class ModelShowNPoints + { + public: + ModelShowNPoints(); + ~ModelShowNPoints(); + std::vector GetLstPointsX(); + std::vector GetLstPointsY(); + std::vector GetLstPointsZ(); + void GetIdPoint(int id, int *x, int *y, int *z); + std::string GetIdLabel(int id); + std::vector GetLstLabels(); + void AddPoint(int x, int y, int z, std::string label); + double Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1); + int InsertPoint(int x, int y, int z, std::string label); + void SavePoints(std::string filename); + int ReadPoints(std::string filename); + int GetNearestPoint(); + + int GetLstPointsSize(); + void SetPointId_mReferencePoint(int id); + int IdInsidePoint(); + + void SetReferencePoint(std::vector ppoint); + std::vector GetReferencePoint(); + void SetImage(vtkImageData *image); + std::string CleanSpaces(std::string ss); + vtkImageData* GetImage(); + void SetRadio(double radio); + double GetRadio(); + int RenamePoint(std::string label); + void ErasePoint(int id); + void SetFirstTime(bool value); + bool GetFirstTime(); + + private: + std::vector lstPointsX; + std::vector lstPointsY; + std::vector lstPointsZ; + std::vector lstLabels; + std::vector mReferencePoint; + double mradio; + vtkImageData *mimage; + bool firsttime; + + }; + + +#endif // __ModelShowNPoints_h_INCLUDED__ + + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx new file mode 100644 index 0000000..0190f82 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx @@ -0,0 +1,575 @@ + + +#include "vtkActor.h" +#include "vtkSphereSource.h" +#include "vtkRenderer.h" +#include "vtkTextActor3D.h" + + +#include "vtkProperty.h" +#include "vtkPolyDataMapper.h" +#include "vtkRenderWindow.h" +#include + +#include +#include +#include +#include + +#include "WidgetShowNPoints.h" + + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- + WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type) + : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) + { + mmodelShowNPoints = new ModelShowNPoints(); + mtype = type; + SetType(mtype); + this->renderer = NULL; + wxPanel *panel = this; + wxSizer *sizer = NULL; + + if (mtype==0) + { + // Widget interface + askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR + textCtrl = new wxTextCtrl(panel, -1); + wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point")); + wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT + wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest 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 + wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity "))); + sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); + wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio "))); + sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); + + wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); + // sizer1->Add(new wxStaticText(panel,-1,_T(" "))); + + Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint); + Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT + Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint); + 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(askPointLabel); // JPR + sizer1->Add(textCtrl); + sizer1->Add(btnAddPoint); + sizer1->Add(btnInsertPoint);//CFT + sizer1->Add(btnSetPositionPoint); + sizer1->Add(btnRenamePoint); + sizer1->Add(btnErasePoint); + sizer1->Add(btnEraseLastPoint); + sizer1->Add(btnDeleteAllPoints); + sizer1->Add(txtNrPoints); + sizer1->Add(txOpacity); + sizer1->Add(sdrOpacity,1,wxGROW ); + sizer1->Add(txRadio); + sizer1->Add(sdrRadio,1,wxGROW ); + sizer1->Add(btnSavePoints); + sizer1->Add(btnLoadPoints); + sizer = sizer1; + } + + if (mtype==1) + { + // Widget interface + wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point")); + txtNrPoints = new wxStaticText(panel,-1, _T(" ")); + + //NTU: Sliders for opacity and radio change + wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity "))); + sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); + wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio "))); + sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS); + wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); + Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint); + Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); + Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints); + + sizer1->Add(btnSetPositionPoint); + sizer1->Add(txtNrPoints); + sizer1->Add(txOpacity); + sizer1->Add(sdrOpacity,1,wxGROW ); + sizer1->Add(txRadio); + sizer1->Add(sdrRadio,1,wxGROW ); + sizer = sizer1; + } + + if (mtype == 2) + { + askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR + wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point ")); + wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All ")); + wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR + textCtrl = new wxTextCtrl(panel, -1); + wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); + Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint); + Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints); + sizer1->Add(askPointLabel); + sizer1->Add(btnAddPoint); + sizer1->Add(btnDeleteAllPoints); + sizer1->Add(spacer); + sizer1->Add(textCtrl); + sdrOpacity = new wxSlider(); + sdrRadio = new wxSlider(); + txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n")); + sizer = sizer1; + } // bbGetInputType 2 + + if (sizer!=NULL) + { + panel->SetSizer(sizer); + panel->SetAutoLayout(true); + panel->Layout(); + } // if sizer +} + +//------------------------------------------------------------------------ +WidgetShowNPoints::~WidgetShowNPoints() +{ +} + +//------------------------------------------------------------------------ +ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints() +{ + return mmodelShowNPoints; +} + + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetRadio(double radio) +{ + GetModelShowNPoints()->SetRadio(radio); + //NTU: For Slider + sdrRadio->SetValue(radio); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetColour(std::vector colour) +{ + this->mcolour = colour; +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetImage(vtkImageData* image) +{ + GetModelShowNPoints()->SetImage(image); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetOpacity(double opacity) +{ + this->mopacity=opacity; + //NTU: For Slider + sdrOpacity->SetValue(this->mopacity*100.0); +} + + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer) +{ + this->renderer = renderer; +} + +//------------------------------------------------------------------------ + +void WidgetShowNPoints::RefreshPoint(int id) +{ + double spc[3]; + +//EED 2016/06/17 +// mimage->GetSpacing(spc); +// int x = lstPointsX[id]; +// int y = lstPointsY[id]; +// int z = lstPointsZ[id]; + int x,y,z; + GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z); + GetModelShowNPoints()->GetImage()->GetSpacing(spc); + std::string label = GetModelShowNPoints()->GetIdLabel(id); + double radio = GetModelShowNPoints()->GetRadio(); + + lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z ); + lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] ); + lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity ); + lstSourceSphere[id]->SetRadius( radio ); + + lstActorsText[id]->SetInput( label.c_str() ); + lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z ); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::RefreshPoints() +{ + int id,size=lstActorsSphere.size(); + for (id=0;idGetRenderWindow()->Render(); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::AddVtkPoint() +{ + // Sphere + vtkSphereSource *vtksphere = vtkSphereSource::New(); + vtksphere->SetThetaResolution (20); + vtksphere->SetPhiResolution (20); + vtksphere->SetRadius( 1 ); + //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); + + 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->SetInput( strLabel.c_str() ); + renderer->AddActor( textActor ); + lstActorsText.push_back(textActor); +} + + +//------------------------------------------------------------------------ +void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label) +{ + GetModelShowNPoints()->AddPoint(x,y,z, label ); + AddVtkPoint(); + RefreshPoint(lstActorsSphere.size()-1); +} + + + +//------------------------------------------------------------------------ +void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT +{ + +//-- + if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 ) + { + AddVtkPoint(); + } else { + AddPoint(x,y,z,label); + } + RefreshPoints(); + //end if +} + + +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event) +{ + if (this->renderer==NULL) + { + return; + } + + std::vector point = GetModelShowNPoints()->GetReferencePoint(); + if (point.size()==3) + { + AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); + SetOutputBox(); + renderer->GetRenderWindow()->Render(); + } else {//mpoint.size + printf("creaMaracasVisu::ShowNPoints (not match point) \n"); + } +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT +{ + if (this->renderer==NULL) + { + return; + } + + std::vector point = GetModelShowNPoints()->GetReferencePoint(); + if (point.size()==3) + { + InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) ); + SetOutputBox(); + } else {//mpoint.size + printf("creaMaracasVisu::ShowNPoints (not match point) \n"); + } +} + + +//------------------------------------------------------------------------ + void WidgetShowNPoints::SetOutputBox() + { +//EED renderer->GetRenderWindow()->Render(); + wxString strTmp; + strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() ); + txtNrPoints->SetLabel( strTmp ); + //--BBTK + +//EED 2017-06-03 +// mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() ); +// mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() ); +// mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() ); +// mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() ); +// mbbShowNPoints->bbSignalOutputModification(); + } + + +//------------------------------------------------------------------------ + 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) + { + std::string filename= (const char*) ( FD->GetPath().mb_str() ); + GetModelShowNPoints()->SavePoints( filename ); + } // 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); + int i; + //EED + int result_FD = FD->ShowModal(); + // This line is need it by windows //EED + FD->SetReturnCode( result_FD ); + if (FD->GetReturnCode()==wxID_OK) + { + + std::string filename= (const char*) ( FD->GetPath().mb_str() ); + int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename ); + for (i=0;iGetNearestPoint(); + if((id==-1) && (mtype==1)) + { + id=0; + AddPoint(0,0,0,""); + SetOutputBox(); + } + + if (id>=0) + { + GetModelShowNPoints()->SetPointId_mReferencePoint(id); + RefreshPoint(id); + renderer->GetRenderWindow()->Render(); + } // if id + SetOutputBox(); + } + +//------------------------------------------------------------------------ + void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event) + { + int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) ); + if (id>=0) + { + lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) ); + SetOutputBox(); + renderer->GetRenderWindow()->Render(); + } + } + +//------------------------------------------------------------------------ + 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 ); + GetModelShowNPoints()->ErasePoint(id); + } // if id + } // if renderer + } + +//------------------------------------------------------------------------ + void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event) + { + ErasePoint( GetModelShowNPoints()->IdInsidePoint() ); + SetOutputBox(); + renderer->GetRenderWindow()->Render(); + } + +//------------------------------------------------------------------------ + void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event) + { + ErasePoint(lstActorsSphere.size()-1); + SetOutputBox(); + renderer->GetRenderWindow()->Render(); + } + +//------------------------------------------------------------------------ +void WidgetShowNPoints::DeleteAllPoints() +{ + int id,size=lstActorsSphere.size(); + for (id=size-1;id>=0;id--) + { + ErasePoint(id); + } + SetOutputBox(); + renderer->GetRenderWindow()->Render(); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event) +{ + DeleteAllPoints(); +} + +//NTU: Method for updating points opacity and Radio + +//------------------------------------------------------------------------ +void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event) +{ + //Difference in Radio for text placement +// double radio=GetModelShowNPoints()->GetRadio(); + this->mopacity = sdrOpacity->GetValue()/100.0; + GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ; +// radio = sdrRadio->GetValue(); + //NTU refresh the inputs + +//EED 2017-06-03 +// mbbShowNPoints->bbSetInputOpacity(this->mopacity); +// mbbShowNPoints->bbSetInputRadio( radio ); + // EED + RefreshPoints(); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetReferencePoint(std::vector point) +{ + GetModelShowNPoints()->SetReferencePoint(point); +} + +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetInitLstPoints( std::vector initLstPointsX, std::vector initLstPointsY, std::vector initLstPointsZ, std::vector initLstLabels ) +{ + if (this->renderer==NULL) + { + return; + } + + int i,sizeX,sizeY,sizeZ,sizeLabels; + sizeX=(int)initLstPointsX.size(); + sizeY=(int)initLstPointsY.size(); + sizeZ=(int)initLstPointsZ.size(); + sizeLabels=(int)initLstLabels.size(); + + int x,y,z; + std::string label; + + if ( (sizeX==sizeY) && (sizeX==sizeZ) ) + { + + for (i=0;iGetRenderWindow()->Render(); + + } // if size +} +//------------------------------------------------------------------------ +void WidgetShowNPoints::WidgetShowNPoints::SetType(int type) +{ + mtype=type; +} + +//------------------------------------------------------------------------ +int WidgetShowNPoints::WidgetShowNPoints::GetType() +{ + return mtype; +} + + +//------------------------------------------------------------------------ +double WidgetShowNPoints::GetRadio() +{ + return sdrRadio->GetValue(); +} + +//------------------------------------------------------------------------ +double WidgetShowNPoints::GetOpacity() +{ + return mopacity; +} + + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h new file mode 100644 index 0000000..05fa5f1 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h @@ -0,0 +1,88 @@ + + +#ifndef __WidgetShowNPoints_h_INCLUDED__ +#define __WidgetShowNPoints_h_INCLUDED__ + + + + +#include "ModelShowNPoints.h" + +#include +#include +#include +#include +#include +#include +#include + + +class WidgetShowNPoints : public wxPanel +{ + public: + WidgetShowNPoints( wxWindow *parent , int type ); + ~WidgetShowNPoints(); + void OnAddPoint(wxCommandEvent &event); + void OnInsertPoint (wxCommandEvent& event);//CFT + void OnSetPoint(wxCommandEvent& event); + void OnRenamePoint(wxCommandEvent& event); + void OnErasePoint(wxCommandEvent& event); + void OnEraseLastPoint(wxCommandEvent &event); + void OnDeleteAllPoints(wxCommandEvent &event); + void OnSavePoints(wxCommandEvent &event); + void OnLoadPoints(wxCommandEvent &event); + + virtual void UpdatePoints(wxCommandEvent &event); + + void RefreshPoint(int id); + + void SetColour(std::vector colour); + void SetOpacity(double opacity); + void SetRadio(double radio); + void SetImage(vtkImageData *image); + void SetRenderer(vtkRenderer *renderer); + void SetReferencePoint(std::vector point); + + void AddPoint(int x, int y, int z, std::string label); + void InsertPoint(int x, int y, int z, std::string label);//CFT + void DeleteAllPoints(); + + ModelShowNPoints* GetModelShowNPoints(); + void RefreshPoints(); + void AddVtkPoint(); + void SetInitLstPoints( std::vector initLstPointsX, std::vector initLstPointsY, std::vector initLstPointsZ, std::vector initLstLabels ); + + void SetType(int type); + int GetType(); + + double GetRadio(); + double GetOpacity(); + + protected: + virtual void SetOutputBox(); + + private: + void ErasePoint(int id); + vtkRenderer *renderer; + std::vector lstActorsSphere;//NTU changed from prop3D to Actor + std::vector lstActorsText; + //NTU: For updating points + std::vector lstSourceSphere; + std::vector mcolour; + wxStaticText *askPointLabel; + wxTextCtrl *textCtrl; + wxStaticText *txtNrPoints; + wxSlider *sdrOpacity; + wxSlider *sdrRadio; + ModelShowNPoints *mmodelShowNPoints; + int mtype; + double mopacity; +}; + + + + + + +#endif // __WidgetShowNPoints_h_INCLUDED__ +