3 #include "vtkSphereSource.h"
4 #include "vtkRenderer.h"
5 #include "vtkTextActor3D.h"
11 #include <wx/filedlg.h>
12 #include <wx/msgdlg.h>
13 #include <wx/notebook.h>
15 #include "WidgetShowNPoints.h"
18 //----------------------------------------------------------------------
19 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
24 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
26 printf("EED WidgetShowNPoints::WidgetShowNPoints Start \n");
28 // mmodelShowNPoints = new ModelShowNPoints();
30 ModelShowNPoints* modelShowNPoints = new ModelShowNPoints();
31 lstModelShowNPoints.push_back( modelShowNPoints );
32 lstViewShowNPoints.push_back( new ViewShowNPoints( modelShowNPoints ) );
36 wxPanel* panelParent = this;
37 wxSizer* sizer = NULL;
38 wxSizer* MNPsizer = NULL;
40 wxNotebook* bookSetPoints = NULL;
41 wxNotebook* bookGroupManager = NULL;
42 wxPanel* panel = NULL;
43 wxPanel* panel2 = NULL;
44 txtNrCollections = NULL;
46 bookSetPoints = new wxNotebook(panelParent,
51 panel = new wxPanel(bookSetPoints);
52 txtNrCollections = NULL;
57 bookGroupManager = new wxNotebook(panelParent, //bbGetWxParent(),
62 panel2 = new wxPanel(bookGroupManager);
63 txtNrCollections = new wxStaticText(panel2,-1, _T("1 / 1 "));
64 wxButton *btnBackCollection = new wxButton( panel2, -1, _T("<"));
65 wxButton *btnNextCollection = new wxButton( panel2, -1, _T(">"));
66 wxButton *btnInsertCollectionBefore = new wxButton( panel2, -1, _T("Insert Group Before"));
67 wxButton *btnInsertCollectionAfter = new wxButton( panel2, -1, _T("Insert Group After"));
68 wxButton *btnDeleteCollection = new wxButton( panel2, -1, _T("Delete Group "));
69 wxButton *btnSaveCollection = new wxButton( panel2, -1, _T("Save Groups"));
70 wxButton *btnLoadCollection = new wxButton( panel2, -1, _T("Load Groups"));
72 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
73 wxFlexGridSizer *sizer2 = new wxFlexGridSizer(2);
74 wxStaticText* txOpacity = new wxStaticText(panel2, -1, wxString(_T(" Points Opacity ")));
75 sdrOpacity = new wxSlider(panel2, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
76 wxStaticText* txRadio = new wxStaticText(panel2, -1, wxString(_T(" Points Radius ")));
77 sdrRadio = new wxSlider(panel2, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
79 Connect(btnBackCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection );
80 Connect(btnNextCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection );
81 Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore );
82 Connect(btnInsertCollectionAfter->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter );
83 Connect(btnDeleteCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection );
84 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints );
85 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints );
86 Connect(btnSaveCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnSaveCollections );
87 Connect(btnLoadCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnLoadCollections );
90 sizer2->Add( btnBackCollection );
91 sizer2->Add( btnNextCollection );
93 sizer1->Add( txtNrCollections );
94 sizer1->Add( sizer2 );
95 sizer1->Add( btnInsertCollectionBefore );
96 sizer1->Add( btnInsertCollectionAfter );
97 sizer1->Add( btnDeleteCollection );
99 sizer1->Add( txOpacity );
100 sizer1->Add( sdrOpacity );
101 sizer1->Add( txRadio );
102 sizer1->Add( sdrRadio );
104 sizer1->Add( btnSaveCollection );
105 sizer1->Add( btnLoadCollection );
107 panel2->SetSizer( MNPsizer );
108 panel2->SetAutoLayout(true);
110 bookGroupManager->AddPage(panel2 , _T("Groupts") );
113 if ( (mtype==0) || (mtype==3) || (mtype==4) )
116 askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
117 textCtrl = new wxTextCtrl(panel, -1);
118 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
119 wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT
120 wxButton *btnSetPositionPoint= new wxButton( panel, -1, _T("Set nearest point"));
121 cbTrackPoint = new wxCheckBox(panel,-1, _T("Track Point") );
122 wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
123 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
124 wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
125 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
126 wxButton *btnSavePoints = NULL;
127 wxButton *btnLoadPoints = NULL;
130 btnSavePoints = new wxButton( panel, -1, _T("Save points"));
131 btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
132 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
133 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
135 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
137 wxStaticText* txOpacity;
138 wxStaticText* txRadio;
139 if ( (mtype==0) || (mtype==3) )
141 //NTU: Sliders for opacity and radio change
142 txOpacity = new wxStaticText(panel, -1, wxString(_T(" Points Opacity ")));
143 sdrOpacity = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
144 txRadio = new wxStaticText(panel, -1, wxString(_T(" Points Radius ")));
145 sdrRadio = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
147 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
148 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
151 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
152 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
153 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
154 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
155 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
156 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
157 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
158 Connect(cbTrackPoint->GetId() , wxEVT_CHECKBOX , (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint);
161 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
162 sizer1->Add(askPointLabel); // JPR
163 sizer1->Add(textCtrl);
164 sizer1->Add(btnAddPoint);
165 sizer1->Add(btnInsertPoint);//CFT
166 sizer1->Add(cbTrackPoint);
167 sizer1->Add(btnSetPositionPoint);
168 sizer1->Add(btnRenamePoint);
169 sizer1->Add(btnErasePoint);
170 sizer1->Add(btnEraseLastPoint);
171 sizer1->Add(btnDeleteAllPoints);
172 sizer1->Add(txtNrPoints);
174 if ( (mtype==0) || (mtype==3) )
176 sizer1->Add(txOpacity);
177 sizer1->Add(sdrOpacity,1,wxGROW );
178 sizer1->Add(txRadio);
179 sizer1->Add(sdrRadio,1,wxGROW );
183 sizer1->Add(btnSavePoints);
184 sizer1->Add(btnLoadPoints);
192 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
193 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
195 //NTU: Sliders for opacity and radio change
196 wxStaticText* txOpacity = new wxStaticText(panel, -1, wxString(_T(" Points Opacity ")));
197 sdrOpacity = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
198 wxStaticText* txRadio = new wxStaticText(panel, -1, wxString(_T(" Points Radio ")));
199 sdrRadio = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
200 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
201 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
202 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
204 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
205 sizer1->Add(btnSetPositionPoint);
206 sizer1->Add(txtNrPoints);
207 sizer1->Add(txOpacity);
208 sizer1->Add(sdrOpacity,1,wxGROW );
209 sizer1->Add(txRadio);
210 sizer1->Add(sdrRadio,1,wxGROW );
216 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
217 wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point "));
218 wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All "));
219 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
220 textCtrl = new wxTextCtrl(panel, -1);
221 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
222 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
223 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
224 sizer1->Add(askPointLabel);
225 sizer1->Add(btnAddPoint);
226 sizer1->Add(btnDeleteAllPoints);
228 sizer1->Add(textCtrl);
229 // sdrOpacity = new wxSlider();
230 // sdrRadio = new wxSlider();
231 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
233 } // bbGetInputType 2
236 panel->SetSizer(sizer);
237 panel->SetAutoLayout(true);
239 bookSetPoints->AddPage(panel , _T("Points") );
241 if ((mtype >= 0) && (mtype <= 3) )
245 wxFlexGridSizer *sizerParent = new wxFlexGridSizer(1);
246 sizerParent->Add( bookSetPoints );
247 panelParent->SetSizer( sizerParent );
248 panelParent->SetAutoLayout(true);
249 panelParent->Layout();
251 } // if mtype 0 1 2 3
255 if ((sizer!=NULL) && (MNPsizer!=NULL))
257 wxFlexGridSizer *sizerG = new wxFlexGridSizer(2);
258 sizerG->Add(bookGroupManager);
259 sizerG->Add(bookSetPoints);
260 panelParent->SetSizer(sizerG);
261 panelParent->SetAutoLayout(true);
262 panelParent->Layout();
267 //------------------------------------------------------------------------
268 WidgetShowNPoints::~WidgetShowNPoints()
272 //------------------------------------------------------------------------
273 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
276 // return mmodelShowNPoints;
277 return lstModelShowNPoints[ mActualCollection ];
281 //------------------------------------------------------------------------
282 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
284 return lstViewShowNPoints[ mActualCollection ];
288 //------------------------------------------------------------------------
289 void WidgetShowNPoints::SetRadio(double radio)
292 // GetModelShowNPoints()->SetRadio(radio);
293 int i,size = lstModelShowNPoints.size();
296 lstModelShowNPoints[i]->SetRadio( radio );
299 sdrRadio->SetValue(radio);
302 //------------------------------------------------------------------------
303 void WidgetShowNPoints::SetColour(std::vector<double> colour)
306 //this->mcolour = colour;
307 int i,size = lstViewShowNPoints.size();
308 for (i=0 ; i<size ; i++)
310 lstViewShowNPoints[i]->mcolour = colour;
314 //------------------------------------------------------------------------
315 void WidgetShowNPoints::SetImage(vtkImageData* image)
318 //GetModelShowNPoints()->SetImage(image);
319 int i,size = lstModelShowNPoints.size();
320 for (i=0 ; i<size ; i++)
322 lstModelShowNPoints[i]->SetImage(image);
326 //------------------------------------------------------------------------
327 void WidgetShowNPoints::SetOpacity(double opacity)
330 //this->mopacity=opacity;
331 int i,size = lstViewShowNPoints.size();
332 for (i=0 ; i<size ; i++)
334 lstViewShowNPoints[i]->mopacity = opacity;
337 sdrOpacity->SetValue( opacity*100.0 );
341 //------------------------------------------------------------------------
342 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
345 //this->renderer = renderer;
346 int i,size = lstViewShowNPoints.size();
347 for (i=0 ; i<size ; i++)
349 lstViewShowNPoints[i]->renderer = renderer;
354 //------------------------------------------------------------------------
356 void WidgetShowNPoints::RefreshPoint(int id)
360 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
361 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
362 std::string label = GetModelShowNPoints()->GetIdLabel(id);
363 double radio = GetModelShowNPoints()->GetRadio();
364 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
365 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
366 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
367 lstSourceSphere[id]->SetRadius( radio );
368 //EED 2017-01-01 Migration VTK7
369 #if VTK_MAJOR_VERSION <= 5
372 lstSourceSphere[id]->Update();
374 lstActorsText[id]->SetInput( label.c_str() );
375 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
378 //------------------------------------------------------------------------
379 void WidgetShowNPoints::RefreshPoints()
381 int id,size=lstActorsSphere.size();
382 for (id=0;id<size;id++)
386 renderer->GetRenderWindow()->Render();
389 //------------------------------------------------------------------------
390 void WidgetShowNPoints::AddVtkPoint()
393 vtkSphereSource *vtksphere = vtkSphereSource::New();
394 vtksphere->SetThetaResolution (20);
395 vtksphere->SetPhiResolution (20);
396 vtksphere->SetRadius( 1 );
397 //NTU: For updating points
398 lstSourceSphere.push_back(vtksphere);
399 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
401 //EED 2017-01-01 Migration VTK7
402 #if VTK_MAJOR_VERSION <= 5
403 sphereMapper->SetInput( vtksphere->GetOutput() );
406 sphereMapper->SetInputData( vtksphere->GetOutput() );
409 vtkActor *sphereActor = vtkActor::New();
410 sphereActor->SetMapper(sphereMapper);
411 sphereActor->SetOrigin(0, 0, 0);
413 lstActorsSphere.push_back(sphereActor);
415 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
419 renderer->AddActor( sphereActor );
421 vtkTextActor3D *textActor = vtkTextActor3D::New();
422 // textActor->SetInput( strLabel.c_str() );
423 renderer->AddActor( textActor );
424 lstActorsText.push_back(textActor);
429 //------------------------------------------------------------------------
430 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
432 GetModelShowNPoints()->AddPoint(x,y,z, label );
435 //RefreshPoint(lstActorsSphere.size()-1);
436 GetViewShowNPoints()->AddPoint();
439 //------------------------------------------------------------------------
440 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
443 //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
447 // AddPoint(x,y,z,label);
450 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
452 GetViewShowNPoints()->AddVtkPoint();
454 AddPoint(x,y,z,label);
456 GetViewShowNPoints()->RefreshPoints();
459 //------------------------------------------------------------------------
460 void WidgetShowNPoints::OnInsertPoint_()
463 //if (this->renderer==NULL)
464 if (GetViewShowNPoints()->renderer==NULL)
469 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
472 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
474 } else {//mpoint.size
475 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
481 //------------------------------------------------------------------------
482 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
485 //if (this->renderer==NULL)
486 if (GetViewShowNPoints()->renderer==NULL)
491 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
494 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
497 //renderer->GetRenderWindow()->Render();
498 GetViewShowNPoints()->Render();
499 } else {//mpoint.size
500 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
504 //------------------------------------------------------------------------
505 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
511 //------------------------------------------------------------------------
512 void WidgetShowNPoints::SetOutputBox()
514 //EED renderer->GetRenderWindow()->Render();
516 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
517 txtNrPoints->SetLabel( strTmp );
521 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
522 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
523 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
524 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
525 // mbbShowNPoints->bbSignalOutputModification();
529 //------------------------------------------------------------------------
530 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
533 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
534 #if wxMAJOR_VERSION <= 2
535 wxFileDialog* FD = new wxFileDialog( 0,
536 _T("Save points .."),
540 wxSAVE | wxOVERWRITE_PROMPT,
543 wxFileDialog* FD = new wxFileDialog( 0,
544 _T("Save points .."),
548 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
552 int result_FD = FD->ShowModal();
553 // This line is need it by windows //EED
554 FD->SetReturnCode( result_FD );
555 if (FD->GetReturnCode()==wxID_OK)
557 std::string filename= (const char*) ( FD->GetPath().mb_str() );
558 GetModelShowNPoints()->SavePoints( filename );
563 //------------------------------------------------------------------------
564 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
567 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
568 #if wxMAJOR_VERSION <= 2
569 wxFileDialog* FD = new wxFileDialog( 0,
570 _T("Load points .."),
574 wxOPEN | wxFILE_MUST_EXIST,
577 wxFileDialog* FD = new wxFileDialog( 0,
578 _T("Load points .."),
582 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
587 int result_FD = FD->ShowModal();
588 // This line is need it by windows //EED
589 FD->SetReturnCode( result_FD );
590 if (FD->GetReturnCode()==wxID_OK)
593 std::string filename= (const char*) ( FD->GetPath().mb_str() );
594 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
595 for (i=0;i<numberPointsRead;i++)
599 GetViewShowNPoints()->AddVtkPoint();
604 GetViewShowNPoints()->RefreshPoints();
608 //------------------------------------------------------------------------
609 void WidgetShowNPoints::OnSetPoint_()
611 int id=GetModelShowNPoints()->GetNearestPoint();
612 if((id==-1) && (mtype==1))
620 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
623 //renderer->GetRenderWindow()->Render();
624 GetViewShowNPoints()->RefreshPoint(id);
625 GetViewShowNPoints()->Render();
630 //------------------------------------------------------------------------
631 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
636 //------------------------------------------------------------------------
637 void WidgetShowNPoints::TrackingPoint( )
639 if ( cbTrackPoint->GetValue() == true )
641 int id = GetModelShowNPoints()->IdInsidePoint();
649 GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
650 GetViewShowNPoints()->RefreshPoint(idTrack);
651 GetViewShowNPoints()->Render();
653 } // if trackPointFlag
656 //------------------------------------------------------------------------
657 void WidgetShowNPoints::OnTrackPoint_tool()
659 cbTrackPoint->SetValue( !cbTrackPoint->GetValue() );
663 //------------------------------------------------------------------------
664 void WidgetShowNPoints::OnTrackPoint_()
667 if ( cbTrackPoint->GetValue() == true )
669 idTrack = GetModelShowNPoints()->IdInsidePoint();
670 } // if trackPointFlag
673 //------------------------------------------------------------------------
674 void WidgetShowNPoints::OnTrackPoint(wxCommandEvent& event)
679 //------------------------------------------------------------------------
680 void WidgetShowNPoints::StopTrackPoint( )
682 cbTrackPoint->SetValue(false);
686 //------------------------------------------------------------------------
687 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
689 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
693 //lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
694 //renderer->GetRenderWindow()->Render();
695 GetViewShowNPoints()->lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
696 GetViewShowNPoints()->Render();
701 //------------------------------------------------------------------------
702 void WidgetShowNPoints::ErasePoint(int id)
705 //if (this->renderer!=NULL)
706 if (GetViewShowNPoints()->renderer!=NULL)
711 //renderer->RemoveActor( lstActorsSphere[id] );
712 //renderer->RemoveActor( lstActorsText[id] );
713 //lstActorsSphere[id]->Delete();
714 //lstActorsText[id]->Delete();
715 //lstSourceSphere[id]->Delete();
716 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
717 //lstActorsText.erase( lstActorsText.begin()+id );
718 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
719 GetViewShowNPoints()->ErasePoint(id);
720 GetModelShowNPoints()->ErasePoint(id);
725 //------------------------------------------------------------------------
726 void WidgetShowNPoints::OnErasePoint_()
728 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
731 //renderer->GetRenderWindow()->Render();
732 GetViewShowNPoints()->Render();
736 //------------------------------------------------------------------------
737 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
742 //------------------------------------------------------------------------
743 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
746 //ErasePoint( lstActorsSphere.size()-1 );
747 //renderer->GetRenderWindow()->Render();
748 int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
750 GetViewShowNPoints()->Render();
755 //------------------------------------------------------------------------
756 void WidgetShowNPoints::DeleteAllPoints()
759 //int id,size=lstActorsSphere.size();
760 int id,size=GetViewShowNPoints()->lstActorsSphere.size();
761 for (id=size-1;id>=0;id--)
767 //renderer->GetRenderWindow()->Render();
768 GetViewShowNPoints()->Render();
772 //------------------------------------------------------------------------
773 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
778 //NTU: Method for updating points opacity and Radio
780 //------------------------------------------------------------------------
781 void WidgetShowNPoints::UpdatePoints_()
784 //this->mopacity = sdrOpacity->GetValue()/100.0;
785 //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
788 double opacity = sdrOpacity->GetValue()/100.0;
789 double radio = sdrRadio->GetValue();
790 int i,size = lstViewShowNPoints.size();
791 for (i=0 ; i<size ; i++)
793 lstViewShowNPoints[i]->mopacity = opacity;
794 lstModelShowNPoints[i]->SetRadio( radio ) ;
796 // GetViewShowNPoints()->RefreshPoints();
799 //------------------------------------------------------------------------
800 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
802 RefreshColourCollection();
805 //------------------------------------------------------------------------
806 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
808 GetModelShowNPoints()->SetReferencePoint(point);
809 int i,size=lstModelShowNPoints.size();
812 lstModelShowNPoints[i]->SetReferencePoint(point); // All collection
816 //------------------------------------------------------------------------
817 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
820 //if (this->renderer==NULL)
821 if (GetViewShowNPoints()->renderer==NULL)
825 int i,sizeX,sizeY,sizeZ,sizeLabels;
826 sizeX = (int)initLstPointsX.size();
827 sizeY = (int)initLstPointsY.size();
828 sizeZ = (int)initLstPointsZ.size();
829 sizeLabels = (int)initLstLabels.size();
832 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
834 for (i=0;i<sizeX;i++)
836 x = initLstPointsX[i];
837 y = initLstPointsY[i];
838 z = initLstPointsZ[i];
841 label = initLstLabels[i];
845 AddPoint( x,y,z,label );
848 // renderer->GetRenderWindow()->Render();
852 //------------------------------------------------------------------------
853 void WidgetShowNPoints::SetType(int type)
858 //------------------------------------------------------------------------
859 int WidgetShowNPoints::GetType()
865 //------------------------------------------------------------------------
866 double WidgetShowNPoints::GetRadio()
868 return sdrRadio->GetValue();
870 //------------------------------------------------------------------------
871 double WidgetShowNPoints::GetOpacity()
873 return sdrOpacity->GetValue()/100;
876 //------------------------------------------------------------------------
877 void WidgetShowNPoints::InsertCollection()
879 ModelShowNPoints* model = new ModelShowNPoints();
880 ViewShowNPoints* view = new ViewShowNPoints( model );
881 model->SetImage( lstModelShowNPoints[0]->GetImage() );
882 view->mopacity = lstViewShowNPoints[0]->mopacity;
883 view->renderer = lstViewShowNPoints[0]->renderer;
884 lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
885 lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
886 RefreshCollectionText();
889 //------------------------------------------------------------------------
890 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
893 RefreshColourCollection();
897 //------------------------------------------------------------------------
898 void WidgetShowNPoints::OnInsertCollectionAfter_()
902 RefreshColourCollection();
906 //------------------------------------------------------------------------
907 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
909 OnInsertCollectionAfter_();
912 //------------------------------------------------------------------------
913 void WidgetShowNPoints::DeleteCollection_()
915 if ( lstModelShowNPoints.size()>1 )
917 DeleteAllPoints(); // Actual Collection
918 lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
919 lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
920 if ( mActualCollection>=lstModelShowNPoints.size() )
925 DeleteAllPoints(); // Actual Collection
929 //------------------------------------------------------------------------
930 void WidgetShowNPoints::OnDeleteCollection_()
933 RefreshCollectionText();
934 RefreshColourCollection();
938 //------------------------------------------------------------------------
939 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
941 OnDeleteCollection_();
944 //------------------------------------------------------------------------
945 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
948 if ( mActualCollection <0 )
952 RefreshCollectionText();
953 RefreshColourCollection();
957 //------------------------------------------------------------------------
958 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
961 if ( mActualCollection >=lstModelShowNPoints.size() )
963 mActualCollection = lstModelShowNPoints.size()-1;
965 RefreshCollectionText();
966 RefreshColourCollection();
970 //------------------------------------------------------------------------
971 void WidgetShowNPoints::DetectCollectionActive()
974 int i,size=lstModelShowNPoints.size();
977 id = lstModelShowNPoints[i]->IdInsidePoint();
983 RefreshCollectionText();
984 RefreshColourCollection();
987 //------------------------------------------------------------------------
988 void WidgetShowNPoints::RefreshColourCollection()
991 std::vector<double> colourAll;
992 colourAll.push_back(1);
993 colourAll.push_back(0);
994 colourAll.push_back(0);
995 std::vector<double> colourActual;
996 colourActual.push_back(1);
997 colourActual.push_back(1);
998 colourActual.push_back(0);
999 SetColour( colourAll ); // For all collections
1000 int i,size=lstViewShowNPoints.size();
1001 for (i=0;i<size;i++)
1003 lstViewShowNPoints[i] -> mcolour = colourAll; // All collection
1004 lstViewShowNPoints[i]->RefreshEachPoint();
1006 lstViewShowNPoints[mActualCollection] -> mcolour = colourActual; // Actual collection
1007 lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
1008 lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
1011 //------------------------------------------------------------------------
1012 void WidgetShowNPoints::RefreshCollectionText()
1014 if ((mtype==4) && (txtNrCollections!=NULL)) // Just for Collection interface
1017 strTmp.Printf(_T("%d / %d "), (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
1018 txtNrCollections->SetLabel( strTmp );
1023 //------------------------------------------------------------------------
1024 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
1026 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1027 #if wxMAJOR_VERSION <= 2
1028 wxFileDialog* FD = new wxFileDialog( 0,
1029 _T("Save groups of points .."),
1032 _T("(*.xls)|*.xls"),
1033 wxSAVE | wxOVERWRITE_PROMPT,
1036 wxFileDialog* FD = new wxFileDialog( 0,
1037 _T("Save groups of points .."),
1040 _T("(*.xls)|*.xls"),
1041 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
1045 int result_FD = FD->ShowModal();
1046 // This line is need it by windows //EED
1047 FD->SetReturnCode( result_FD );
1048 if (FD->GetReturnCode()==wxID_OK)
1050 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1053 ff = fopen( filename.c_str() , "w+" );
1056 int i,size=lstModelShowNPoints.size();
1057 fprintf(ff,"NumberOfGroups %d \n",size);
1059 for (i=0;i<size;i++)
1061 lstModelShowNPoints[i]->SavePoints_(ff);
1066 printf("WidgetShowNPoints::Save Groups Points ...Error... creating file \n");
1075 //------------------------------------------------------------------------
1076 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
1078 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1079 #if wxMAJOR_VERSION <= 2
1080 wxFileDialog* FD = new wxFileDialog( 0,
1081 _T("Load groups of points .."),
1084 _T("(*.xls)|*.xls"),
1085 wxOPEN | wxFILE_MUST_EXIST,
1088 wxFileDialog* FD = new wxFileDialog( 0,
1089 _T("Load groups of points .."),
1092 _T("(*.xls)|*.xls"),
1093 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1096 bool okEraseFirstGrout=false;
1098 int result_FD = FD->ShowModal();
1099 // This line is need it by windows //EED
1100 FD->SetReturnCode( result_FD );
1101 if (FD->GetReturnCode()==wxID_OK)
1103 if (lstModelShowNPoints.size()==1)
1105 if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGrout=true; }
1107 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1108 FILE *ff = fopen( filename.c_str() , "r+" );
1112 int iGroup,sizeGroups;
1113 int iPoint,numberPointsRead;
1115 fscanf(ff," %s %d",chartmp,&sizeGroups);
1116 for (iGroup=0;iGroup<sizeGroups;iGroup++)
1118 mActualCollection = lstModelShowNPoints.size();
1121 int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1122 for (i=0;i<numberPointsRead;i++)
1126 GetViewShowNPoints()->AddVtkPoint();
1132 printf("WidgetShowNPoints::Load Group of Points ...Error... reading file");
1134 if (okEraseFirstGrout==true)
1136 mActualCollection=0;
1137 DeleteCollection_();
1138 mActualCollection = lstModelShowNPoints.size()-1;
1140 RefreshCollectionText();
1141 RefreshColourCollection();
1147 //------------------------------------------------------------------------
1148 std::vector<int> WidgetShowNPoints::GetLstPointsX()
1152 return GetModelShowNPoints()->GetLstPointsX();
1154 std::vector<int> lst;
1156 int iG,sG=lstModelShowNPoints.size();
1157 for (iG=0 ; iG<sG ; iG++)
1159 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1161 for (iP=0 ; iP<s ; iP++)
1163 lst.push_back( lstTmp[iP] );
1170 //------------------------------------------------------------------------
1171 std::vector<int> WidgetShowNPoints::GetLstPointsY()
1175 return GetModelShowNPoints()->GetLstPointsY();
1177 std::vector<int> lst;
1179 int iG,sG=lstModelShowNPoints.size();
1180 for (iG=0 ; iG<sG ; iG++)
1182 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1184 for (iP=0 ; iP<s ; iP++)
1186 lst.push_back( lstTmp[iP] );
1193 //------------------------------------------------------------------------
1194 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
1198 return GetModelShowNPoints()->GetLstPointsZ();
1200 std::vector<int> lst;
1202 int iG,sG=lstModelShowNPoints.size();
1203 for (iG=0 ; iG<sG ; iG++)
1205 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1207 for (iP=0 ; iP<s ; iP++)
1209 lst.push_back( lstTmp[iP] );
1217 //------------------------------------------------------------------------
1218 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1222 return GetModelShowNPoints()->GetLstLabels();
1224 std::vector< std::string > lst;
1226 int iG,sG=lstModelShowNPoints.size();
1227 for (iG=0 ; iG<sG ; iG++)
1229 std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1231 for (iP=0 ; iP<s ; iP++)
1233 lst.push_back( lstTmp[iP] );
1240 //------------------------------------------------------------------------
1241 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1243 std::vector<int> lstIndexs;
1246 lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1248 int iG,sG=lstModelShowNPoints.size();
1249 for (iG=0 ; iG<sG ; iG++)
1251 lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );
1257 //------------------------------------------------------------------------
1258 int WidgetShowNPoints::GetLstModelShowNPointsSize()
1260 return lstModelShowNPoints.size();