3 #include "vtkSphereSource.h"
4 #include "vtkRenderer.h"
5 #include "vtkTextActor3D.h"
11 #include <wx/filedlg.h>
12 #include <wx/msgdlg.h>
14 #include "WidgetShowNPoints.h"
17 //----------------------------------------------------------------------
18 //----------------------------------------------------------------------
19 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
23 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
26 // mmodelShowNPoints = new ModelShowNPoints();
28 ModelShowNPoints* modelShowNPoints = new ModelShowNPoints();
29 lstModelShowNPoints.push_back( modelShowNPoints );
30 lstViewShowNPoints.push_back( new ViewShowNPoints( modelShowNPoints ) );
35 wxPanel *panel = this;
36 wxSizer *sizer = NULL;
38 if ((mtype==0) || (mtype==3))
41 askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
42 textCtrl = new wxTextCtrl(panel, -1);
43 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
44 wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT
45 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
46 wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
47 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
48 wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
49 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
50 wxButton *btnSavePoints = NULL;
51 wxButton *btnLoadPoints = NULL;
54 btnSavePoints = new wxButton( panel, -1, _T("Save points"));
55 btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
57 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
59 //NTU: Sliders for opacity and radio change
60 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
61 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
62 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radius ")));
63 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
65 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
66 // sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
68 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
69 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
70 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
71 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
72 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
73 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
74 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
77 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
78 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
81 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
82 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
84 sizer1->Add(askPointLabel); // JPR
85 sizer1->Add(textCtrl);
86 sizer1->Add(btnAddPoint);
87 sizer1->Add(btnInsertPoint);//CFT
88 sizer1->Add(btnSetPositionPoint);
89 sizer1->Add(btnRenamePoint);
90 sizer1->Add(btnErasePoint);
91 sizer1->Add(btnEraseLastPoint);
92 sizer1->Add(btnDeleteAllPoints);
93 sizer1->Add(txtNrPoints);
94 sizer1->Add(txOpacity);
95 sizer1->Add(sdrOpacity,1,wxGROW );
97 sizer1->Add(sdrRadio,1,wxGROW );
100 sizer1->Add(btnSavePoints);
101 sizer1->Add(btnLoadPoints);
109 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
110 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
112 //NTU: Sliders for opacity and radio change
113 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
114 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
115 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
116 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
117 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
118 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
119 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
120 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
122 sizer1->Add(btnSetPositionPoint);
123 sizer1->Add(txtNrPoints);
124 sizer1->Add(txOpacity);
125 sizer1->Add(sdrOpacity,1,wxGROW );
126 sizer1->Add(txRadio);
127 sizer1->Add(sdrRadio,1,wxGROW );
133 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
134 wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point "));
135 wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All "));
136 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
137 textCtrl = new wxTextCtrl(panel, -1);
138 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
139 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
140 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
141 sizer1->Add(askPointLabel);
142 sizer1->Add(btnAddPoint);
143 sizer1->Add(btnDeleteAllPoints);
145 sizer1->Add(textCtrl);
146 sdrOpacity = new wxSlider();
147 sdrRadio = new wxSlider();
148 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
150 } // bbGetInputType 2
154 panel->SetSizer(sizer);
155 panel->SetAutoLayout(true);
160 //------------------------------------------------------------------------
161 WidgetShowNPoints::~WidgetShowNPoints()
165 //------------------------------------------------------------------------
166 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
169 // return mmodelShowNPoints;
170 return lstModelShowNPoints[ mActualLstPoints ];
174 //------------------------------------------------------------------------
175 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
177 return lstViewShowNPoints[ mActualLstPoints ];
181 //------------------------------------------------------------------------
182 void WidgetShowNPoints::SetRadio(double radio)
185 // GetModelShowNPoints()->SetRadio(radio);
186 int i,size = lstModelShowNPoints.size();
189 lstModelShowNPoints[i]->SetRadio( radio );
192 sdrRadio->SetValue(radio);
195 //------------------------------------------------------------------------
196 void WidgetShowNPoints::SetColour(std::vector<double> colour)
199 //this->mcolour = colour;
200 int i,size = lstViewShowNPoints.size();
201 for (i=0 ; i<size ; i++)
203 lstViewShowNPoints[i]->mcolour = colour;
207 //------------------------------------------------------------------------
208 void WidgetShowNPoints::SetImage(vtkImageData* image)
211 //GetModelShowNPoints()->SetImage(image);
212 int i,size = lstModelShowNPoints.size();
213 for (i=0 ; i<size ; i++)
215 lstModelShowNPoints[i]->SetImage(image);
219 //------------------------------------------------------------------------
220 void WidgetShowNPoints::SetOpacity(double opacity)
223 //this->mopacity=opacity;
224 int i,size = lstViewShowNPoints.size();
225 for (i=0 ; i<size ; i++)
227 lstViewShowNPoints[i]->mopacity = opacity;
230 sdrOpacity->SetValue( opacity*100.0 );
234 //------------------------------------------------------------------------
235 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
238 //this->renderer = renderer;
239 int i,size = lstViewShowNPoints.size();
240 for (i=0 ; i<size ; i++)
242 lstViewShowNPoints[i]->renderer = renderer;
247 //------------------------------------------------------------------------
249 void WidgetShowNPoints::RefreshPoint(int id)
253 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
254 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
255 std::string label = GetModelShowNPoints()->GetIdLabel(id);
256 double radio = GetModelShowNPoints()->GetRadio();
257 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
258 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
259 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
260 lstSourceSphere[id]->SetRadius( radio );
261 //EED 2017-01-01 Migration VTK7
262 #if VTK_MAJOR_VERSION <= 5
265 lstSourceSphere[id]->Update();
267 lstActorsText[id]->SetInput( label.c_str() );
268 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
271 //------------------------------------------------------------------------
272 void WidgetShowNPoints::RefreshPoints()
274 int id,size=lstActorsSphere.size();
275 for (id=0;id<size;id++)
279 renderer->GetRenderWindow()->Render();
282 //------------------------------------------------------------------------
283 void WidgetShowNPoints::AddVtkPoint()
286 vtkSphereSource *vtksphere = vtkSphereSource::New();
287 vtksphere->SetThetaResolution (20);
288 vtksphere->SetPhiResolution (20);
289 vtksphere->SetRadius( 1 );
290 //NTU: For updating points
291 lstSourceSphere.push_back(vtksphere);
292 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
294 //EED 2017-01-01 Migration VTK7
295 #if VTK_MAJOR_VERSION <= 5
296 sphereMapper->SetInput( vtksphere->GetOutput() );
299 sphereMapper->SetInputData( vtksphere->GetOutput() );
302 vtkActor *sphereActor = vtkActor::New();
303 sphereActor->SetMapper(sphereMapper);
304 sphereActor->SetOrigin(0, 0, 0);
306 lstActorsSphere.push_back(sphereActor);
308 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
312 renderer->AddActor( sphereActor );
314 vtkTextActor3D *textActor = vtkTextActor3D::New();
315 // textActor->SetInput( strLabel.c_str() );
316 renderer->AddActor( textActor );
317 lstActorsText.push_back(textActor);
322 //------------------------------------------------------------------------
323 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
325 GetModelShowNPoints()->AddPoint(x,y,z, label );
328 //RefreshPoint(lstActorsSphere.size()-1);
329 GetViewShowNPoints()->AddPoint();
332 //------------------------------------------------------------------------
333 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
336 //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
340 // AddPoint(x,y,z,label);
343 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
345 GetViewShowNPoints()->AddVtkPoint();
347 AddPoint(x,y,z,label);
349 GetViewShowNPoints()->RefreshPoints();
353 //------------------------------------------------------------------------
354 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
357 //if (this->renderer==NULL)
358 if (GetViewShowNPoints()->renderer==NULL)
363 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
366 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
369 //renderer->GetRenderWindow()->Render();
370 GetViewShowNPoints()->Render();
371 } else {//mpoint.size
372 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
376 //------------------------------------------------------------------------
377 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
380 //if (this->renderer==NULL)
381 if (GetViewShowNPoints()->renderer==NULL)
386 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
389 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
391 } else {//mpoint.size
392 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
397 //------------------------------------------------------------------------
398 void WidgetShowNPoints::SetOutputBox()
400 //EED renderer->GetRenderWindow()->Render();
402 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
403 txtNrPoints->SetLabel( strTmp );
407 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
408 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
409 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
410 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
411 // mbbShowNPoints->bbSignalOutputModification();
415 //------------------------------------------------------------------------
416 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
419 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
420 #if wxMAJOR_VERSION <= 2
421 wxFileDialog* FD = new wxFileDialog( 0,
422 _T("Save points .."),
426 wxSAVE | wxOVERWRITE_PROMPT,
429 wxFileDialog* FD = new wxFileDialog( 0,
430 _T("Save points .."),
434 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
438 int result_FD = FD->ShowModal();
439 // This line is need it by windows //EED
440 FD->SetReturnCode( result_FD );
441 if (FD->GetReturnCode()==wxID_OK)
443 std::string filename= (const char*) ( FD->GetPath().mb_str() );
444 GetModelShowNPoints()->SavePoints( filename );
449 //------------------------------------------------------------------------
450 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
453 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
454 #if wxMAJOR_VERSION <= 2
455 wxFileDialog* FD = new wxFileDialog( 0,
456 _T("Load points .."),
460 wxOPEN | wxFILE_MUST_EXIST,
463 wxFileDialog* FD = new wxFileDialog( 0,
464 _T("Load points .."),
468 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
473 int result_FD = FD->ShowModal();
474 // This line is need it by windows //EED
475 FD->SetReturnCode( result_FD );
476 if (FD->GetReturnCode()==wxID_OK)
479 std::string filename= (const char*) ( FD->GetPath().mb_str() );
480 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
481 for (i=0;i<numberPointsRead;i++)
485 GetViewShowNPoints()->AddVtkPoint();
490 GetViewShowNPoints()->RefreshPoints();
494 //------------------------------------------------------------------------
495 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
497 int id=GetModelShowNPoints()->GetNearestPoint();
498 if((id==-1) && (mtype==1))
507 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
510 //renderer->GetRenderWindow()->Render();
511 GetViewShowNPoints()->RefreshPoint(id);
512 GetViewShowNPoints()->Render();
517 //------------------------------------------------------------------------
518 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
520 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
524 //lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
525 //renderer->GetRenderWindow()->Render();
526 GetViewShowNPoints()->lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
527 GetViewShowNPoints()->Render();
532 //------------------------------------------------------------------------
533 void WidgetShowNPoints::ErasePoint(int id)
536 //if (this->renderer!=NULL)
537 if (GetViewShowNPoints()->renderer!=NULL)
542 //renderer->RemoveActor( lstActorsSphere[id] );
543 //renderer->RemoveActor( lstActorsText[id] );
544 //lstActorsSphere[id]->Delete();
545 //lstActorsText[id]->Delete();
546 //lstSourceSphere[id]->Delete();
547 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
548 //lstActorsText.erase( lstActorsText.begin()+id );
549 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
550 GetViewShowNPoints()->ErasePoint(id);
551 GetModelShowNPoints()->ErasePoint(id);
556 //------------------------------------------------------------------------
557 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
559 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
562 //renderer->GetRenderWindow()->Render();
563 GetViewShowNPoints()->Render();
566 //------------------------------------------------------------------------
567 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
570 //ErasePoint( lstActorsSphere.size()-1 );
571 //renderer->GetRenderWindow()->Render();
572 int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
574 GetViewShowNPoints()->Render();
578 //------------------------------------------------------------------------
579 void WidgetShowNPoints::DeleteAllPoints()
582 //int id,size=lstActorsSphere.size();
583 int id,size=GetViewShowNPoints()->lstActorsSphere.size();
584 for (id=size-1;id>=0;id--)
590 //renderer->GetRenderWindow()->Render();
591 GetViewShowNPoints()->Render();
594 //------------------------------------------------------------------------
595 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
600 //NTU: Method for updating points opacity and Radio
602 //------------------------------------------------------------------------
603 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
606 //this->mopacity = sdrOpacity->GetValue()/100.0;
607 //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
610 double opacity = sdrOpacity->GetValue()/100.0;
611 double radio = sdrRadio->GetValue();
612 int i,size = lstViewShowNPoints.size();
613 for (i=0 ; i<size ; i++)
615 lstViewShowNPoints[i]->mopacity = opacity;
616 lstModelShowNPoints[i]->SetRadio( radio ) ;
618 GetViewShowNPoints()->RefreshPoints();
621 //------------------------------------------------------------------------
622 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
624 GetModelShowNPoints()->SetReferencePoint(point);
627 //------------------------------------------------------------------------
628 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
631 //if (this->renderer==NULL)
632 if (GetViewShowNPoints()->renderer==NULL)
636 int i,sizeX,sizeY,sizeZ,sizeLabels;
637 sizeX=(int)initLstPointsX.size();
638 sizeY=(int)initLstPointsY.size();
639 sizeZ=(int)initLstPointsZ.size();
640 sizeLabels=(int)initLstLabels.size();
643 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
645 for (i=0;i<sizeX;i++)
647 x = initLstPointsX[i];
648 y = initLstPointsY[i];
649 z = initLstPointsZ[i];
652 label = initLstLabels[i];
656 AddPoint( x,y,z,label );
659 // renderer->GetRenderWindow()->Render();
663 //------------------------------------------------------------------------
664 void WidgetShowNPoints::SetType(int type)
669 //------------------------------------------------------------------------
670 int WidgetShowNPoints::GetType()
676 //------------------------------------------------------------------------
677 double WidgetShowNPoints::GetRadio()
679 return sdrRadio->GetValue();
681 //------------------------------------------------------------------------
682 double WidgetShowNPoints::GetOpacity()
684 return sdrOpacity->GetValue()/100;