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 lstActorsText[id]->SetInput( label.c_str() );
229 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
232 //------------------------------------------------------------------------
233 void WidgetShowNPoints::RefreshPoints()
235 int id,size=lstActorsSphere.size();
236 for (id=0;id<size;id++)
240 renderer->GetRenderWindow()->Render();
243 //------------------------------------------------------------------------
244 void WidgetShowNPoints::AddVtkPoint()
247 vtkSphereSource *vtksphere = vtkSphereSource::New();
248 vtksphere->SetThetaResolution (20);
249 vtksphere->SetPhiResolution (20);
250 vtksphere->SetRadius( 1 );
251 //NTU: For updating points
252 lstSourceSphere.push_back(vtksphere);
253 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
254 sphereMapper->SetInput( vtksphere->GetOutput() );
255 vtkActor *sphereActor = vtkActor::New();
256 sphereActor->SetMapper(sphereMapper);
257 sphereActor->SetOrigin(0, 0, 0);
259 lstActorsSphere.push_back(sphereActor);
261 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
265 renderer->AddActor( sphereActor );
267 vtkTextActor3D *textActor = vtkTextActor3D::New();
268 // textActor->SetInput( strLabel.c_str() );
269 renderer->AddActor( textActor );
270 lstActorsText.push_back(textActor);
274 //------------------------------------------------------------------------
275 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
277 GetModelShowNPoints()->AddPoint(x,y,z, label );
279 RefreshPoint(lstActorsSphere.size()-1);
284 //------------------------------------------------------------------------
285 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
289 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
293 AddPoint(x,y,z,label);
300 //------------------------------------------------------------------------
301 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
303 if (this->renderer==NULL)
308 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
311 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
313 renderer->GetRenderWindow()->Render();
314 } else {//mpoint.size
315 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
319 //------------------------------------------------------------------------
320 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
322 if (this->renderer==NULL)
327 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
330 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
332 } else {//mpoint.size
333 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
338 //------------------------------------------------------------------------
339 void WidgetShowNPoints::SetOutputBox()
341 //EED renderer->GetRenderWindow()->Render();
343 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
344 txtNrPoints->SetLabel( strTmp );
348 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
349 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
350 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
351 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
352 // mbbShowNPoints->bbSignalOutputModification();
356 //------------------------------------------------------------------------
357 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
359 wxFileDialog* FD = new wxFileDialog( 0,
360 _T("Save points .."),
364 wxSAVE | wxOVERWRITE_PROMPT,
368 int result_FD = FD->ShowModal();
370 // This line is need it by windows //EED
371 FD->SetReturnCode( result_FD );
373 if (FD->GetReturnCode()==wxID_OK)
375 std::string filename= (const char*) ( FD->GetPath().mb_str() );
376 GetModelShowNPoints()->SavePoints( filename );
381 //------------------------------------------------------------------------
382 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
384 wxFileDialog* FD = new wxFileDialog( 0,
385 _T("Load points .."),
389 wxOPEN | wxFILE_MUST_EXIST,
393 int result_FD = FD->ShowModal();
394 // This line is need it by windows //EED
395 FD->SetReturnCode( result_FD );
396 if (FD->GetReturnCode()==wxID_OK)
399 std::string filename= (const char*) ( FD->GetPath().mb_str() );
400 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
401 for (i=0;i<numberPointsRead;i++)
411 //------------------------------------------------------------------------
412 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
414 int id=GetModelShowNPoints()->GetNearestPoint();
415 if((id==-1) && (mtype==1))
424 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
426 renderer->GetRenderWindow()->Render();
431 //------------------------------------------------------------------------
432 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
434 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
437 lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
439 renderer->GetRenderWindow()->Render();
443 //------------------------------------------------------------------------
444 void WidgetShowNPoints::ErasePoint(int id)
446 if (this->renderer!=NULL)
450 renderer->RemoveActor( lstActorsSphere[id] );
451 renderer->RemoveActor( lstActorsText[id] );
452 lstActorsSphere[id]->Delete();
453 lstActorsText[id]->Delete();
454 lstSourceSphere[id]->Delete();
455 lstActorsSphere.erase( lstActorsSphere.begin()+id );
456 lstActorsText.erase( lstActorsText.begin()+id );
457 lstSourceSphere.erase( lstSourceSphere.begin()+id );
458 GetModelShowNPoints()->ErasePoint(id);
463 //------------------------------------------------------------------------
464 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
466 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
468 renderer->GetRenderWindow()->Render();
471 //------------------------------------------------------------------------
472 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
474 ErasePoint(lstActorsSphere.size()-1);
476 renderer->GetRenderWindow()->Render();
479 //------------------------------------------------------------------------
480 void WidgetShowNPoints::DeleteAllPoints()
482 int id,size=lstActorsSphere.size();
483 for (id=size-1;id>=0;id--)
488 renderer->GetRenderWindow()->Render();
491 //------------------------------------------------------------------------
492 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
497 //NTU: Method for updating points opacity and Radio
499 //------------------------------------------------------------------------
500 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
502 //Difference in Radio for text placement
503 // double radio=GetModelShowNPoints()->GetRadio();
504 this->mopacity = sdrOpacity->GetValue()/100.0;
505 GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
506 // radio = sdrRadio->GetValue();
507 //NTU refresh the inputs
510 // mbbShowNPoints->bbSetInputOpacity(this->mopacity);
511 // mbbShowNPoints->bbSetInputRadio( radio );
516 //------------------------------------------------------------------------
517 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
519 GetModelShowNPoints()->SetReferencePoint(point);
522 //------------------------------------------------------------------------
523 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
525 if (this->renderer==NULL)
530 int i,sizeX,sizeY,sizeZ,sizeLabels;
531 sizeX=(int)initLstPointsX.size();
532 sizeY=(int)initLstPointsY.size();
533 sizeZ=(int)initLstPointsZ.size();
534 sizeLabels=(int)initLstLabels.size();
539 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
542 for (i=0;i<sizeX;i++)
544 x = initLstPointsX[i];
545 y = initLstPointsY[i];
546 z = initLstPointsZ[i];
549 label = initLstLabels[i];
553 AddPoint( x,y,z,label );
556 // renderer->GetRenderWindow()->Render();
560 //------------------------------------------------------------------------
561 void WidgetShowNPoints::SetType(int type)
566 //------------------------------------------------------------------------
567 int WidgetShowNPoints::GetType()
573 //------------------------------------------------------------------------
574 double WidgetShowNPoints::GetRadio()
576 return sdrRadio->GetValue();
579 //------------------------------------------------------------------------
580 double WidgetShowNPoints::GetOpacity()