4 #include "vtkSphereSource.h"
5 #include "vtkRenderer.h"
6 #include "vtkTextActor3D.h"
9 #include "vtkProperty.h"
10 #include "vtkPolyDataMapper.h"
11 #include "vtkRenderWindow.h"
12 #include <vtkTextProperty.h>
14 #include <wx/button.h>
16 #include <wx/filedlg.h>
17 #include <wx/msgdlg.h>
19 #include "WidgetShowNPoints.h"
22 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
28 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
30 mmodelShowNPoints = new ModelShowNPoints();
33 this->renderer = NULL;
34 wxPanel *panel = this;
35 wxSizer *sizer = NULL;
37 if ((mtype==0) || (mtype==3))
40 askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
41 textCtrl = new wxTextCtrl(panel, -1);
42 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
43 wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT
44 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
45 wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
46 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
47 wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
48 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
49 wxButton *btnSavePoints = NULL;
50 wxButton *btnLoadPoints = NULL;
53 btnSavePoints = new wxButton( panel, -1, _T("Save points"));
54 btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
56 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
58 //NTU: Sliders for opacity and radio change
59 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
60 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
61 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
62 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
64 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
65 // sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
67 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
68 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
69 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
70 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
71 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
72 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
73 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
76 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
77 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
80 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
81 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
83 sizer1->Add(askPointLabel); // JPR
84 sizer1->Add(textCtrl);
85 sizer1->Add(btnAddPoint);
86 sizer1->Add(btnInsertPoint);//CFT
87 sizer1->Add(btnSetPositionPoint);
88 sizer1->Add(btnRenamePoint);
89 sizer1->Add(btnErasePoint);
90 sizer1->Add(btnEraseLastPoint);
91 sizer1->Add(btnDeleteAllPoints);
92 sizer1->Add(txtNrPoints);
93 sizer1->Add(txOpacity);
94 sizer1->Add(sdrOpacity,1,wxGROW );
96 sizer1->Add(sdrRadio,1,wxGROW );
99 sizer1->Add(btnSavePoints);
100 sizer1->Add(btnLoadPoints);
108 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
109 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
111 //NTU: Sliders for opacity and radio change
112 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
113 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
114 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
115 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
116 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
117 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
118 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
119 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
121 sizer1->Add(btnSetPositionPoint);
122 sizer1->Add(txtNrPoints);
123 sizer1->Add(txOpacity);
124 sizer1->Add(sdrOpacity,1,wxGROW );
125 sizer1->Add(txRadio);
126 sizer1->Add(sdrRadio,1,wxGROW );
132 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
133 wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point "));
134 wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All "));
135 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
136 textCtrl = new wxTextCtrl(panel, -1);
137 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
138 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
139 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
140 sizer1->Add(askPointLabel);
141 sizer1->Add(btnAddPoint);
142 sizer1->Add(btnDeleteAllPoints);
144 sizer1->Add(textCtrl);
145 sdrOpacity = new wxSlider();
146 sdrRadio = new wxSlider();
147 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
149 } // bbGetInputType 2
153 panel->SetSizer(sizer);
154 panel->SetAutoLayout(true);
159 //------------------------------------------------------------------------
160 WidgetShowNPoints::~WidgetShowNPoints()
164 //------------------------------------------------------------------------
165 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
167 return mmodelShowNPoints;
171 //------------------------------------------------------------------------
172 void WidgetShowNPoints::SetRadio(double radio)
174 GetModelShowNPoints()->SetRadio(radio);
176 sdrRadio->SetValue(radio);
179 //------------------------------------------------------------------------
180 void WidgetShowNPoints::SetColour(std::vector<double> colour)
182 this->mcolour = colour;
185 //------------------------------------------------------------------------
186 void WidgetShowNPoints::SetImage(vtkImageData* image)
188 GetModelShowNPoints()->SetImage(image);
191 //------------------------------------------------------------------------
192 void WidgetShowNPoints::SetOpacity(double opacity)
194 this->mopacity=opacity;
196 sdrOpacity->SetValue(this->mopacity*100.0);
200 //------------------------------------------------------------------------
201 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
203 this->renderer = renderer;
206 //------------------------------------------------------------------------
208 void WidgetShowNPoints::RefreshPoint(int id)
213 // mimage->GetSpacing(spc);
214 // int x = lstPointsX[id];
215 // int y = lstPointsY[id];
216 // int z = lstPointsZ[id];
218 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
219 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
220 std::string label = GetModelShowNPoints()->GetIdLabel(id);
221 double radio = GetModelShowNPoints()->GetRadio();
223 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
224 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
225 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
226 lstSourceSphere[id]->SetRadius( radio );
228 //EED 2017-01-01 Migration VTK7
229 #if VTK_MAJOR_VERSION <= 5
232 lstSourceSphere[id]->Update();
235 lstActorsText[id]->SetInput( label.c_str() );
236 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
239 //------------------------------------------------------------------------
240 void WidgetShowNPoints::RefreshPoints()
242 int id,size=lstActorsSphere.size();
243 for (id=0;id<size;id++)
247 renderer->GetRenderWindow()->Render();
250 //------------------------------------------------------------------------
251 void WidgetShowNPoints::AddVtkPoint()
254 vtkSphereSource *vtksphere = vtkSphereSource::New();
255 vtksphere->SetThetaResolution (20);
256 vtksphere->SetPhiResolution (20);
257 vtksphere->SetRadius( 1 );
258 //NTU: For updating points
259 lstSourceSphere.push_back(vtksphere);
260 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
262 //EED 2017-01-01 Migration VTK7
263 #if VTK_MAJOR_VERSION <= 5
264 sphereMapper->SetInput( vtksphere->GetOutput() );
267 sphereMapper->SetInputData( vtksphere->GetOutput() );
270 vtkActor *sphereActor = vtkActor::New();
271 sphereActor->SetMapper(sphereMapper);
272 sphereActor->SetOrigin(0, 0, 0);
274 lstActorsSphere.push_back(sphereActor);
276 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
280 renderer->AddActor( sphereActor );
282 vtkTextActor3D *textActor = vtkTextActor3D::New();
283 // textActor->SetInput( strLabel.c_str() );
284 renderer->AddActor( textActor );
285 lstActorsText.push_back(textActor);
289 //------------------------------------------------------------------------
290 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
292 GetModelShowNPoints()->AddPoint(x,y,z, label );
294 RefreshPoint(lstActorsSphere.size()-1);
299 //------------------------------------------------------------------------
300 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
304 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
308 AddPoint(x,y,z,label);
315 //------------------------------------------------------------------------
316 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
318 if (this->renderer==NULL)
323 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
326 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
328 renderer->GetRenderWindow()->Render();
329 } else {//mpoint.size
330 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
334 //------------------------------------------------------------------------
335 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
337 if (this->renderer==NULL)
342 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
345 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
347 } else {//mpoint.size
348 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
353 //------------------------------------------------------------------------
354 void WidgetShowNPoints::SetOutputBox()
356 //EED renderer->GetRenderWindow()->Render();
358 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
359 txtNrPoints->SetLabel( strTmp );
363 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
364 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
365 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
366 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
367 // mbbShowNPoints->bbSignalOutputModification();
371 //------------------------------------------------------------------------
372 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
375 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
376 #if wxMAJOR_VERSION <= 2
377 wxFileDialog* FD = new wxFileDialog( 0,
378 _T("Save points .."),
382 wxSAVE | wxOVERWRITE_PROMPT,
385 wxFileDialog* FD = new wxFileDialog( 0,
386 _T("Save points .."),
390 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
396 int result_FD = FD->ShowModal();
398 // This line is need it by windows //EED
399 FD->SetReturnCode( result_FD );
401 if (FD->GetReturnCode()==wxID_OK)
403 std::string filename= (const char*) ( FD->GetPath().mb_str() );
404 GetModelShowNPoints()->SavePoints( filename );
409 //------------------------------------------------------------------------
410 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
413 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
414 #if wxMAJOR_VERSION <= 2
415 wxFileDialog* FD = new wxFileDialog( 0,
416 _T("Load points .."),
420 wxOPEN | wxFILE_MUST_EXIST,
423 wxFileDialog* FD = new wxFileDialog( 0,
424 _T("Load points .."),
428 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
433 int result_FD = FD->ShowModal();
434 // This line is need it by windows //EED
435 FD->SetReturnCode( result_FD );
436 if (FD->GetReturnCode()==wxID_OK)
439 std::string filename= (const char*) ( FD->GetPath().mb_str() );
440 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
441 for (i=0;i<numberPointsRead;i++)
451 //------------------------------------------------------------------------
452 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
454 int id=GetModelShowNPoints()->GetNearestPoint();
455 if((id==-1) && (mtype==1))
464 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
466 renderer->GetRenderWindow()->Render();
471 //------------------------------------------------------------------------
472 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
474 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
477 lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
479 renderer->GetRenderWindow()->Render();
483 //------------------------------------------------------------------------
484 void WidgetShowNPoints::ErasePoint(int id)
486 if (this->renderer!=NULL)
490 renderer->RemoveActor( lstActorsSphere[id] );
491 renderer->RemoveActor( lstActorsText[id] );
492 lstActorsSphere[id]->Delete();
493 lstActorsText[id]->Delete();
494 lstSourceSphere[id]->Delete();
495 lstActorsSphere.erase( lstActorsSphere.begin()+id );
496 lstActorsText.erase( lstActorsText.begin()+id );
497 lstSourceSphere.erase( lstSourceSphere.begin()+id );
498 GetModelShowNPoints()->ErasePoint(id);
503 //------------------------------------------------------------------------
504 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
506 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
508 renderer->GetRenderWindow()->Render();
511 //------------------------------------------------------------------------
512 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
514 ErasePoint(lstActorsSphere.size()-1);
516 renderer->GetRenderWindow()->Render();
519 //------------------------------------------------------------------------
520 void WidgetShowNPoints::DeleteAllPoints()
522 int id,size=lstActorsSphere.size();
523 for (id=size-1;id>=0;id--)
528 renderer->GetRenderWindow()->Render();
531 //------------------------------------------------------------------------
532 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
537 //NTU: Method for updating points opacity and Radio
539 //------------------------------------------------------------------------
540 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
542 //Difference in Radio for text placement
543 // double radio=GetModelShowNPoints()->GetRadio();
544 this->mopacity = sdrOpacity->GetValue()/100.0;
545 GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
546 // radio = sdrRadio->GetValue();
547 //NTU refresh the inputs
550 // mbbShowNPoints->bbSetInputOpacity(this->mopacity);
551 // mbbShowNPoints->bbSetInputRadio( radio );
556 //------------------------------------------------------------------------
557 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
559 GetModelShowNPoints()->SetReferencePoint(point);
562 //------------------------------------------------------------------------
563 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
565 if (this->renderer==NULL)
570 int i,sizeX,sizeY,sizeZ,sizeLabels;
571 sizeX=(int)initLstPointsX.size();
572 sizeY=(int)initLstPointsY.size();
573 sizeZ=(int)initLstPointsZ.size();
574 sizeLabels=(int)initLstLabels.size();
579 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
582 for (i=0;i<sizeX;i++)
584 x = initLstPointsX[i];
585 y = initLstPointsY[i];
586 z = initLstPointsZ[i];
589 label = initLstLabels[i];
593 AddPoint( x,y,z,label );
596 // renderer->GetRenderWindow()->Render();
600 //------------------------------------------------------------------------
601 void WidgetShowNPoints::SetType(int type)
606 //------------------------------------------------------------------------
607 int WidgetShowNPoints::GetType()
613 //------------------------------------------------------------------------
614 double WidgetShowNPoints::GetRadio()
616 return sdrRadio->GetValue();
619 //------------------------------------------------------------------------
620 double WidgetShowNPoints::GetOpacity()