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;
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 = new wxButton( panel, -1, _T("Save points"));
50 wxButton *btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
51 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
53 //NTU: Sliders for opacity and radio change
54 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
55 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
56 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
57 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
59 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
60 // sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
62 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
63 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
64 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
65 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
66 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
67 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
68 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
69 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
70 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
73 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
74 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
76 sizer1->Add(askPointLabel); // JPR
77 sizer1->Add(textCtrl);
78 sizer1->Add(btnAddPoint);
79 sizer1->Add(btnInsertPoint);//CFT
80 sizer1->Add(btnSetPositionPoint);
81 sizer1->Add(btnRenamePoint);
82 sizer1->Add(btnErasePoint);
83 sizer1->Add(btnEraseLastPoint);
84 sizer1->Add(btnDeleteAllPoints);
85 sizer1->Add(txtNrPoints);
86 sizer1->Add(txOpacity);
87 sizer1->Add(sdrOpacity,1,wxGROW );
89 sizer1->Add(sdrRadio,1,wxGROW );
90 sizer1->Add(btnSavePoints);
91 sizer1->Add(btnLoadPoints);
98 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
99 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
101 //NTU: Sliders for opacity and radio change
102 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
103 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
104 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
105 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
106 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
107 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
108 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
109 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
111 sizer1->Add(btnSetPositionPoint);
112 sizer1->Add(txtNrPoints);
113 sizer1->Add(txOpacity);
114 sizer1->Add(sdrOpacity,1,wxGROW );
115 sizer1->Add(txRadio);
116 sizer1->Add(sdrRadio,1,wxGROW );
122 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
123 wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point "));
124 wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All "));
125 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
126 textCtrl = new wxTextCtrl(panel, -1);
127 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
128 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
129 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
130 sizer1->Add(askPointLabel);
131 sizer1->Add(btnAddPoint);
132 sizer1->Add(btnDeleteAllPoints);
134 sizer1->Add(textCtrl);
135 sdrOpacity = new wxSlider();
136 sdrRadio = new wxSlider();
137 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
139 } // bbGetInputType 2
143 panel->SetSizer(sizer);
144 panel->SetAutoLayout(true);
149 //------------------------------------------------------------------------
150 WidgetShowNPoints::~WidgetShowNPoints()
154 //------------------------------------------------------------------------
155 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
157 return mmodelShowNPoints;
161 //------------------------------------------------------------------------
162 void WidgetShowNPoints::SetRadio(double radio)
164 GetModelShowNPoints()->SetRadio(radio);
166 sdrRadio->SetValue(radio);
169 //------------------------------------------------------------------------
170 void WidgetShowNPoints::SetColour(std::vector<double> colour)
172 this->mcolour = colour;
175 //------------------------------------------------------------------------
176 void WidgetShowNPoints::SetImage(vtkImageData* image)
178 GetModelShowNPoints()->SetImage(image);
181 //------------------------------------------------------------------------
182 void WidgetShowNPoints::SetOpacity(double opacity)
184 this->mopacity=opacity;
186 sdrOpacity->SetValue(this->mopacity*100.0);
190 //------------------------------------------------------------------------
191 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
193 this->renderer = renderer;
196 //------------------------------------------------------------------------
198 void WidgetShowNPoints::RefreshPoint(int id)
203 // mimage->GetSpacing(spc);
204 // int x = lstPointsX[id];
205 // int y = lstPointsY[id];
206 // int z = lstPointsZ[id];
208 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
209 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
210 std::string label = GetModelShowNPoints()->GetIdLabel(id);
211 double radio = GetModelShowNPoints()->GetRadio();
213 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
214 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
215 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
216 lstSourceSphere[id]->SetRadius( radio );
218 //EED 2017-01-01 Migration VTK7
219 #if VTK_MAJOR_VERSION <= 5
222 lstSourceSphere[id]->Update();
225 lstActorsText[id]->SetInput( label.c_str() );
226 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
229 //------------------------------------------------------------------------
230 void WidgetShowNPoints::RefreshPoints()
232 int id,size=lstActorsSphere.size();
233 for (id=0;id<size;id++)
237 renderer->GetRenderWindow()->Render();
240 //------------------------------------------------------------------------
241 void WidgetShowNPoints::AddVtkPoint()
244 vtkSphereSource *vtksphere = vtkSphereSource::New();
245 vtksphere->SetThetaResolution (20);
246 vtksphere->SetPhiResolution (20);
247 vtksphere->SetRadius( 1 );
248 //NTU: For updating points
249 lstSourceSphere.push_back(vtksphere);
250 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
252 //EED 2017-01-01 Migration VTK7
253 #if VTK_MAJOR_VERSION <= 5
254 sphereMapper->SetInput( vtksphere->GetOutput() );
257 sphereMapper->SetInputData( vtksphere->GetOutput() );
260 vtkActor *sphereActor = vtkActor::New();
261 sphereActor->SetMapper(sphereMapper);
262 sphereActor->SetOrigin(0, 0, 0);
264 lstActorsSphere.push_back(sphereActor);
266 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
270 renderer->AddActor( sphereActor );
272 vtkTextActor3D *textActor = vtkTextActor3D::New();
273 // textActor->SetInput( strLabel.c_str() );
274 renderer->AddActor( textActor );
275 lstActorsText.push_back(textActor);
279 //------------------------------------------------------------------------
280 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
282 GetModelShowNPoints()->AddPoint(x,y,z, label );
284 RefreshPoint(lstActorsSphere.size()-1);
289 //------------------------------------------------------------------------
290 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
294 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
298 AddPoint(x,y,z,label);
305 //------------------------------------------------------------------------
306 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
308 if (this->renderer==NULL)
313 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
316 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
318 renderer->GetRenderWindow()->Render();
319 } else {//mpoint.size
320 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
324 //------------------------------------------------------------------------
325 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
327 if (this->renderer==NULL)
332 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
335 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
337 } else {//mpoint.size
338 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
343 //------------------------------------------------------------------------
344 void WidgetShowNPoints::SetOutputBox()
346 //EED renderer->GetRenderWindow()->Render();
348 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
349 txtNrPoints->SetLabel( strTmp );
353 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
354 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
355 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
356 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
357 // mbbShowNPoints->bbSignalOutputModification();
361 //------------------------------------------------------------------------
362 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
364 wxFileDialog* FD = new wxFileDialog( 0,
365 _T("Save points .."),
369 wxSAVE | wxOVERWRITE_PROMPT,
373 int result_FD = FD->ShowModal();
375 // This line is need it by windows //EED
376 FD->SetReturnCode( result_FD );
378 if (FD->GetReturnCode()==wxID_OK)
380 std::string filename= (const char*) ( FD->GetPath().mb_str() );
381 GetModelShowNPoints()->SavePoints( filename );
386 //------------------------------------------------------------------------
387 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
389 wxFileDialog* FD = new wxFileDialog( 0,
390 _T("Load points .."),
394 wxOPEN | wxFILE_MUST_EXIST,
398 int result_FD = FD->ShowModal();
399 // This line is need it by windows //EED
400 FD->SetReturnCode( result_FD );
401 if (FD->GetReturnCode()==wxID_OK)
404 std::string filename= (const char*) ( FD->GetPath().mb_str() );
405 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
406 for (i=0;i<numberPointsRead;i++)
416 //------------------------------------------------------------------------
417 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
419 int id=GetModelShowNPoints()->GetNearestPoint();
420 if((id==-1) && (mtype==1))
429 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
431 renderer->GetRenderWindow()->Render();
436 //------------------------------------------------------------------------
437 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
439 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
442 lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
444 renderer->GetRenderWindow()->Render();
448 //------------------------------------------------------------------------
449 void WidgetShowNPoints::ErasePoint(int id)
451 if (this->renderer!=NULL)
455 renderer->RemoveActor( lstActorsSphere[id] );
456 renderer->RemoveActor( lstActorsText[id] );
457 lstActorsSphere[id]->Delete();
458 lstActorsText[id]->Delete();
459 lstSourceSphere[id]->Delete();
460 lstActorsSphere.erase( lstActorsSphere.begin()+id );
461 lstActorsText.erase( lstActorsText.begin()+id );
462 lstSourceSphere.erase( lstSourceSphere.begin()+id );
463 GetModelShowNPoints()->ErasePoint(id);
468 //------------------------------------------------------------------------
469 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
471 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
473 renderer->GetRenderWindow()->Render();
476 //------------------------------------------------------------------------
477 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
479 ErasePoint(lstActorsSphere.size()-1);
481 renderer->GetRenderWindow()->Render();
484 //------------------------------------------------------------------------
485 void WidgetShowNPoints::DeleteAllPoints()
487 int id,size=lstActorsSphere.size();
488 for (id=size-1;id>=0;id--)
493 renderer->GetRenderWindow()->Render();
496 //------------------------------------------------------------------------
497 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
502 //NTU: Method for updating points opacity and Radio
504 //------------------------------------------------------------------------
505 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
507 //Difference in Radio for text placement
508 // double radio=GetModelShowNPoints()->GetRadio();
509 this->mopacity = sdrOpacity->GetValue()/100.0;
510 GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
511 // radio = sdrRadio->GetValue();
512 //NTU refresh the inputs
515 // mbbShowNPoints->bbSetInputOpacity(this->mopacity);
516 // mbbShowNPoints->bbSetInputRadio( radio );
521 //------------------------------------------------------------------------
522 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
524 GetModelShowNPoints()->SetReferencePoint(point);
527 //------------------------------------------------------------------------
528 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
530 if (this->renderer==NULL)
535 int i,sizeX,sizeY,sizeZ,sizeLabels;
536 sizeX=(int)initLstPointsX.size();
537 sizeY=(int)initLstPointsY.size();
538 sizeZ=(int)initLstPointsZ.size();
539 sizeLabels=(int)initLstLabels.size();
544 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
547 for (i=0;i<sizeX;i++)
549 x = initLstPointsX[i];
550 y = initLstPointsY[i];
551 z = initLstPointsZ[i];
554 label = initLstLabels[i];
558 AddPoint( x,y,z,label );
561 // renderer->GetRenderWindow()->Render();
565 //------------------------------------------------------------------------
566 void WidgetShowNPoints::SetType(int type)
571 //------------------------------------------------------------------------
572 int WidgetShowNPoints::GetType()
578 //------------------------------------------------------------------------
579 double WidgetShowNPoints::GetRadio()
581 return sdrRadio->GetValue();
584 //------------------------------------------------------------------------
585 double WidgetShowNPoints::GetOpacity()