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;
45 bookSetPoints = new wxNotebook(panelParent,
50 panel = new wxPanel(bookSetPoints);
56 bookGroupManager = new wxNotebook(panelParent, //bbGetWxParent(),
61 panel2 = new wxPanel(bookGroupManager);
62 txtNrCollections = new wxStaticText(panel2,-1, _T("1 / 1 "));
63 wxButton *btnBackCollection = new wxButton( panel2, -1, _T("<"));
64 wxButton *btnNextCollection = new wxButton( panel2, -1, _T(">"));
65 wxButton *btnInsertCollectionBefore = new wxButton( panel2, -1, _T("Insert Group Before"));
66 wxButton *btnInsertCollectionAfter = new wxButton( panel2, -1, _T("Insert Group After"));
67 wxButton *btnDeleteCollection = new wxButton( panel2, -1, _T("Delete Group "));
68 wxButton *btnSaveCollection = new wxButton( panel2, -1, _T("Save Groups"));
69 wxButton *btnLoadCollection = new wxButton( panel2, -1, _T("Load Groups"));
71 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
72 wxFlexGridSizer *sizer2 = new wxFlexGridSizer(2);
73 wxStaticText* txOpacity = new wxStaticText(panel2, -1, wxString(_T(" Points Opacity ")));
74 sdrOpacity = new wxSlider(panel2, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
75 wxStaticText* txRadio = new wxStaticText(panel2, -1, wxString(_T(" Points Radius ")));
76 sdrRadio = new wxSlider(panel2, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
78 Connect(btnBackCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection );
79 Connect(btnNextCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection );
80 Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore );
81 Connect(btnInsertCollectionAfter->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter );
82 Connect(btnDeleteCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection );
83 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints );
84 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints );
85 Connect(btnSaveCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnSaveCollections );
86 Connect(btnLoadCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnLoadCollections );
89 sizer2->Add( btnBackCollection );
90 sizer2->Add( btnNextCollection );
92 sizer1->Add( txtNrCollections );
93 sizer1->Add( sizer2 );
94 sizer1->Add( btnInsertCollectionBefore );
95 sizer1->Add( btnInsertCollectionAfter );
96 sizer1->Add( btnDeleteCollection );
98 sizer1->Add( txOpacity );
99 sizer1->Add( sdrOpacity );
100 sizer1->Add( txRadio );
101 sizer1->Add( sdrRadio );
103 sizer1->Add( btnSaveCollection );
104 sizer1->Add( btnLoadCollection );
106 panel2->SetSizer( MNPsizer );
107 panel2->SetAutoLayout(true);
109 bookGroupManager->AddPage(panel2 , _T("Groupts") );
112 if ( (mtype==0) || (mtype==3) || (mtype==4) )
115 askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
116 textCtrl = new wxTextCtrl(panel, -1);
117 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
118 wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT
119 wxButton *btnSetPositionPoint= new wxButton( panel, -1, _T("Set nearest point"));
120 cbTrackPoint = new wxCheckBox(panel,-1, _T("Track Point") );
121 wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
122 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
123 wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
124 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
125 wxButton *btnSavePoints = NULL;
126 wxButton *btnLoadPoints = NULL;
129 btnSavePoints = new wxButton( panel, -1, _T("Save points"));
130 btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
131 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
132 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
134 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
136 wxStaticText* txOpacity;
137 wxStaticText* txRadio;
138 if ( (mtype==0) || (mtype==3) )
140 //NTU: Sliders for opacity and radio change
141 txOpacity = new wxStaticText(panel, -1, wxString(_T(" Points Opacity ")));
142 sdrOpacity = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
143 txRadio = new wxStaticText(panel, -1, wxString(_T(" Points Radius ")));
144 sdrRadio = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
146 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
147 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
150 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
151 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
152 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
153 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
154 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
155 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
156 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
157 Connect(cbTrackPoint->GetId() , wxEVT_CHECKBOX , (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint);
160 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
161 sizer1->Add(askPointLabel); // JPR
162 sizer1->Add(textCtrl);
163 sizer1->Add(btnAddPoint);
164 sizer1->Add(btnInsertPoint);//CFT
165 sizer1->Add(cbTrackPoint);
166 sizer1->Add(btnSetPositionPoint);
167 sizer1->Add(btnRenamePoint);
168 sizer1->Add(btnErasePoint);
169 sizer1->Add(btnEraseLastPoint);
170 sizer1->Add(btnDeleteAllPoints);
171 sizer1->Add(txtNrPoints);
173 if ( (mtype==0) || (mtype==3) )
175 sizer1->Add(txOpacity);
176 sizer1->Add(sdrOpacity,1,wxGROW );
177 sizer1->Add(txRadio);
178 sizer1->Add(sdrRadio,1,wxGROW );
182 sizer1->Add(btnSavePoints);
183 sizer1->Add(btnLoadPoints);
191 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
192 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
194 //NTU: Sliders for opacity and radio change
195 wxStaticText* txOpacity = new wxStaticText(panel, -1, wxString(_T(" Points Opacity ")));
196 sdrOpacity = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
197 wxStaticText* txRadio = new wxStaticText(panel, -1, wxString(_T(" Points Radio ")));
198 sdrRadio = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
199 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
200 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
201 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
203 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
204 sizer1->Add(btnSetPositionPoint);
205 sizer1->Add(txtNrPoints);
206 sizer1->Add(txOpacity);
207 sizer1->Add(sdrOpacity,1,wxGROW );
208 sizer1->Add(txRadio);
209 sizer1->Add(sdrRadio,1,wxGROW );
215 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
216 wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point "));
217 wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All "));
218 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
219 textCtrl = new wxTextCtrl(panel, -1);
220 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
221 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
222 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
223 sizer1->Add(askPointLabel);
224 sizer1->Add(btnAddPoint);
225 sizer1->Add(btnDeleteAllPoints);
227 sizer1->Add(textCtrl);
228 // sdrOpacity = new wxSlider();
229 // sdrRadio = new wxSlider();
230 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
232 } // bbGetInputType 2
235 panel->SetSizer(sizer);
236 panel->SetAutoLayout(true);
238 bookSetPoints->AddPage(panel , _T("Points") );
240 if ((mtype >= 0) && (mtype <= 3) )
244 wxFlexGridSizer *sizerParent = new wxFlexGridSizer(1);
245 sizerParent->Add( bookSetPoints );
246 panelParent->SetSizer( sizerParent );
247 panelParent->SetAutoLayout(true);
248 panelParent->Layout();
250 } // if mtype 0 1 2 3
254 if ((sizer!=NULL) && (MNPsizer!=NULL))
256 wxFlexGridSizer *sizerG = new wxFlexGridSizer(2);
257 sizerG->Add(bookGroupManager);
258 sizerG->Add(bookSetPoints);
259 panelParent->SetSizer(sizerG);
260 panelParent->SetAutoLayout(true);
261 panelParent->Layout();
266 //------------------------------------------------------------------------
267 WidgetShowNPoints::~WidgetShowNPoints()
271 //------------------------------------------------------------------------
272 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
275 // return mmodelShowNPoints;
276 return lstModelShowNPoints[ mActualCollection ];
280 //------------------------------------------------------------------------
281 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
283 return lstViewShowNPoints[ mActualCollection ];
287 //------------------------------------------------------------------------
288 void WidgetShowNPoints::SetRadio(double radio)
291 // GetModelShowNPoints()->SetRadio(radio);
292 int i,size = lstModelShowNPoints.size();
295 lstModelShowNPoints[i]->SetRadio( radio );
298 sdrRadio->SetValue(radio);
301 //------------------------------------------------------------------------
302 void WidgetShowNPoints::SetColour(std::vector<double> colour)
305 //this->mcolour = colour;
306 int i,size = lstViewShowNPoints.size();
307 for (i=0 ; i<size ; i++)
309 lstViewShowNPoints[i]->mcolour = colour;
313 //------------------------------------------------------------------------
314 void WidgetShowNPoints::SetImage(vtkImageData* image)
317 //GetModelShowNPoints()->SetImage(image);
318 int i,size = lstModelShowNPoints.size();
319 for (i=0 ; i<size ; i++)
321 lstModelShowNPoints[i]->SetImage(image);
325 //------------------------------------------------------------------------
326 void WidgetShowNPoints::SetOpacity(double opacity)
329 //this->mopacity=opacity;
330 int i,size = lstViewShowNPoints.size();
331 for (i=0 ; i<size ; i++)
333 lstViewShowNPoints[i]->mopacity = opacity;
336 sdrOpacity->SetValue( opacity*100.0 );
340 //------------------------------------------------------------------------
341 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
344 //this->renderer = renderer;
345 int i,size = lstViewShowNPoints.size();
346 for (i=0 ; i<size ; i++)
348 lstViewShowNPoints[i]->renderer = renderer;
353 //------------------------------------------------------------------------
355 void WidgetShowNPoints::RefreshPoint(int id)
359 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
360 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
361 std::string label = GetModelShowNPoints()->GetIdLabel(id);
362 double radio = GetModelShowNPoints()->GetRadio();
363 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
364 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
365 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
366 lstSourceSphere[id]->SetRadius( radio );
367 //EED 2017-01-01 Migration VTK7
368 #if VTK_MAJOR_VERSION <= 5
371 lstSourceSphere[id]->Update();
373 lstActorsText[id]->SetInput( label.c_str() );
374 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
377 //------------------------------------------------------------------------
378 void WidgetShowNPoints::RefreshPoints()
380 int id,size=lstActorsSphere.size();
381 for (id=0;id<size;id++)
385 renderer->GetRenderWindow()->Render();
388 //------------------------------------------------------------------------
389 void WidgetShowNPoints::AddVtkPoint()
392 vtkSphereSource *vtksphere = vtkSphereSource::New();
393 vtksphere->SetThetaResolution (20);
394 vtksphere->SetPhiResolution (20);
395 vtksphere->SetRadius( 1 );
396 //NTU: For updating points
397 lstSourceSphere.push_back(vtksphere);
398 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
400 //EED 2017-01-01 Migration VTK7
401 #if VTK_MAJOR_VERSION <= 5
402 sphereMapper->SetInput( vtksphere->GetOutput() );
405 sphereMapper->SetInputData( vtksphere->GetOutput() );
408 vtkActor *sphereActor = vtkActor::New();
409 sphereActor->SetMapper(sphereMapper);
410 sphereActor->SetOrigin(0, 0, 0);
412 lstActorsSphere.push_back(sphereActor);
414 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
418 renderer->AddActor( sphereActor );
420 vtkTextActor3D *textActor = vtkTextActor3D::New();
421 // textActor->SetInput( strLabel.c_str() );
422 renderer->AddActor( textActor );
423 lstActorsText.push_back(textActor);
428 //------------------------------------------------------------------------
429 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
431 GetModelShowNPoints()->AddPoint(x,y,z, label );
434 //RefreshPoint(lstActorsSphere.size()-1);
435 GetViewShowNPoints()->AddPoint();
438 //------------------------------------------------------------------------
439 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
442 //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
446 // AddPoint(x,y,z,label);
449 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
451 GetViewShowNPoints()->AddVtkPoint();
453 AddPoint(x,y,z,label);
455 GetViewShowNPoints()->RefreshPoints();
459 //------------------------------------------------------------------------
460 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
463 //if (this->renderer==NULL)
464 if (GetViewShowNPoints()->renderer==NULL)
469 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
472 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
475 //renderer->GetRenderWindow()->Render();
476 GetViewShowNPoints()->Render();
477 } else {//mpoint.size
478 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
482 //------------------------------------------------------------------------
483 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
486 //if (this->renderer==NULL)
487 if (GetViewShowNPoints()->renderer==NULL)
492 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
495 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
497 } else {//mpoint.size
498 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
503 //------------------------------------------------------------------------
504 void WidgetShowNPoints::SetOutputBox()
506 //EED renderer->GetRenderWindow()->Render();
508 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
509 txtNrPoints->SetLabel( strTmp );
513 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
514 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
515 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
516 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
517 // mbbShowNPoints->bbSignalOutputModification();
521 //------------------------------------------------------------------------
522 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
525 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
526 #if wxMAJOR_VERSION <= 2
527 wxFileDialog* FD = new wxFileDialog( 0,
528 _T("Save points .."),
532 wxSAVE | wxOVERWRITE_PROMPT,
535 wxFileDialog* FD = new wxFileDialog( 0,
536 _T("Save points .."),
540 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
544 int result_FD = FD->ShowModal();
545 // This line is need it by windows //EED
546 FD->SetReturnCode( result_FD );
547 if (FD->GetReturnCode()==wxID_OK)
549 std::string filename= (const char*) ( FD->GetPath().mb_str() );
550 GetModelShowNPoints()->SavePoints( filename );
555 //------------------------------------------------------------------------
556 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
559 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
560 #if wxMAJOR_VERSION <= 2
561 wxFileDialog* FD = new wxFileDialog( 0,
562 _T("Load points .."),
566 wxOPEN | wxFILE_MUST_EXIST,
569 wxFileDialog* FD = new wxFileDialog( 0,
570 _T("Load points .."),
574 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
579 int result_FD = FD->ShowModal();
580 // This line is need it by windows //EED
581 FD->SetReturnCode( result_FD );
582 if (FD->GetReturnCode()==wxID_OK)
585 std::string filename= (const char*) ( FD->GetPath().mb_str() );
586 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
587 for (i=0;i<numberPointsRead;i++)
591 GetViewShowNPoints()->AddVtkPoint();
596 GetViewShowNPoints()->RefreshPoints();
601 //------------------------------------------------------------------------
602 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
604 int id=GetModelShowNPoints()->GetNearestPoint();
605 if((id==-1) && (mtype==1))
614 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
617 //renderer->GetRenderWindow()->Render();
618 GetViewShowNPoints()->RefreshPoint(id);
619 GetViewShowNPoints()->Render();
624 //------------------------------------------------------------------------
625 void WidgetShowNPoints::OnTrackPoint(wxCommandEvent& event)
628 // trackPointFlag = cbTrackPoint->GetValue();
629 if ( cbTrackPoint->GetValue() == true )
631 idTrack = GetModelShowNPoints()->IdInsidePoint();
632 } // if trackPointFlag
635 //------------------------------------------------------------------------
636 void WidgetShowNPoints::TrackPoint( )
638 if ( cbTrackPoint->GetValue() == true )
640 int id = GetModelShowNPoints()->IdInsidePoint();
648 GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
649 GetViewShowNPoints()->RefreshPoint(idTrack);
650 GetViewShowNPoints()->Render();
652 } // if trackPointFlag
655 //------------------------------------------------------------------------
656 void WidgetShowNPoints::StopTrackPoint( )
658 cbTrackPoint->SetValue(false);
663 //------------------------------------------------------------------------
664 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
666 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
670 //lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
671 //renderer->GetRenderWindow()->Render();
672 GetViewShowNPoints()->lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
673 GetViewShowNPoints()->Render();
678 //------------------------------------------------------------------------
679 void WidgetShowNPoints::ErasePoint(int id)
682 //if (this->renderer!=NULL)
683 if (GetViewShowNPoints()->renderer!=NULL)
688 //renderer->RemoveActor( lstActorsSphere[id] );
689 //renderer->RemoveActor( lstActorsText[id] );
690 //lstActorsSphere[id]->Delete();
691 //lstActorsText[id]->Delete();
692 //lstSourceSphere[id]->Delete();
693 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
694 //lstActorsText.erase( lstActorsText.begin()+id );
695 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
696 GetViewShowNPoints()->ErasePoint(id);
697 GetModelShowNPoints()->ErasePoint(id);
702 //------------------------------------------------------------------------
703 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
705 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
708 //renderer->GetRenderWindow()->Render();
709 GetViewShowNPoints()->Render();
713 //------------------------------------------------------------------------
714 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
717 //ErasePoint( lstActorsSphere.size()-1 );
718 //renderer->GetRenderWindow()->Render();
719 int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
721 GetViewShowNPoints()->Render();
726 //------------------------------------------------------------------------
727 void WidgetShowNPoints::DeleteAllPoints()
730 //int id,size=lstActorsSphere.size();
731 int id,size=GetViewShowNPoints()->lstActorsSphere.size();
732 for (id=size-1;id>=0;id--)
738 //renderer->GetRenderWindow()->Render();
739 GetViewShowNPoints()->Render();
742 //------------------------------------------------------------------------
743 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
748 //NTU: Method for updating points opacity and Radio
750 //------------------------------------------------------------------------
751 void WidgetShowNPoints::UpdatePoints_()
754 //this->mopacity = sdrOpacity->GetValue()/100.0;
755 //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
758 double opacity = sdrOpacity->GetValue()/100.0;
759 double radio = sdrRadio->GetValue();
760 int i,size = lstViewShowNPoints.size();
761 for (i=0 ; i<size ; i++)
763 lstViewShowNPoints[i]->mopacity = opacity;
764 lstModelShowNPoints[i]->SetRadio( radio ) ;
766 // GetViewShowNPoints()->RefreshPoints();
769 //------------------------------------------------------------------------
770 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
772 RefreshColourCollection();
775 //------------------------------------------------------------------------
776 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
778 GetModelShowNPoints()->SetReferencePoint(point);
779 int i,size=lstModelShowNPoints.size();
782 lstModelShowNPoints[i]->SetReferencePoint(point); // All collection
786 //------------------------------------------------------------------------
787 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
790 //if (this->renderer==NULL)
791 if (GetViewShowNPoints()->renderer==NULL)
795 int i,sizeX,sizeY,sizeZ,sizeLabels;
796 sizeX = (int)initLstPointsX.size();
797 sizeY = (int)initLstPointsY.size();
798 sizeZ = (int)initLstPointsZ.size();
799 sizeLabels = (int)initLstLabels.size();
802 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
804 for (i=0;i<sizeX;i++)
806 x = initLstPointsX[i];
807 y = initLstPointsY[i];
808 z = initLstPointsZ[i];
811 label = initLstLabels[i];
815 AddPoint( x,y,z,label );
818 // renderer->GetRenderWindow()->Render();
822 //------------------------------------------------------------------------
823 void WidgetShowNPoints::SetType(int type)
828 //------------------------------------------------------------------------
829 int WidgetShowNPoints::GetType()
835 //------------------------------------------------------------------------
836 double WidgetShowNPoints::GetRadio()
838 return sdrRadio->GetValue();
840 //------------------------------------------------------------------------
841 double WidgetShowNPoints::GetOpacity()
843 return sdrOpacity->GetValue()/100;
846 //------------------------------------------------------------------------
847 void WidgetShowNPoints::InsertCollection()
849 ModelShowNPoints* model = new ModelShowNPoints();
850 ViewShowNPoints* view = new ViewShowNPoints( model );
851 model->SetImage( lstModelShowNPoints[0]->GetImage() );
852 view->mopacity = lstViewShowNPoints[0]->mopacity;
853 view->renderer = lstViewShowNPoints[0]->renderer;
854 lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
855 lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
856 RefreshCollectionText();
859 //------------------------------------------------------------------------
860 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
863 RefreshColourCollection();
867 //------------------------------------------------------------------------
868 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
872 RefreshColourCollection();
876 //------------------------------------------------------------------------
877 void WidgetShowNPoints::DeleteCollection_()
879 if ( lstModelShowNPoints.size()>1 )
881 DeleteAllPoints(); // Actual Collection
882 lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
883 lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
884 if ( mActualCollection>=lstModelShowNPoints.size() )
889 DeleteAllPoints(); // Actual Collection
893 //------------------------------------------------------------------------
894 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
897 RefreshCollectionText();
898 RefreshColourCollection();
902 //------------------------------------------------------------------------
903 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
906 if ( mActualCollection <0 )
910 RefreshCollectionText();
911 RefreshColourCollection();
915 //------------------------------------------------------------------------
916 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
919 if ( mActualCollection >=lstModelShowNPoints.size() )
921 mActualCollection = lstModelShowNPoints.size()-1;
923 RefreshCollectionText();
924 RefreshColourCollection();
928 //------------------------------------------------------------------------
929 void WidgetShowNPoints::DetectCollectionActive()
932 int i,size=lstModelShowNPoints.size();
935 id = lstModelShowNPoints[i]->IdInsidePoint();
941 RefreshCollectionText();
942 RefreshColourCollection();
945 //------------------------------------------------------------------------
946 void WidgetShowNPoints::RefreshColourCollection()
949 std::vector<double> colourAll;
950 colourAll.push_back(1);
951 colourAll.push_back(0);
952 colourAll.push_back(0);
953 std::vector<double> colourActual;
954 colourActual.push_back(1);
955 colourActual.push_back(1);
956 colourActual.push_back(0);
957 SetColour( colourAll ); // For all collections
958 int i,size=lstViewShowNPoints.size();
961 lstViewShowNPoints[i] -> mcolour = colourAll; // All collection
962 lstViewShowNPoints[i]->RefreshEachPoint();
964 lstViewShowNPoints[mActualCollection] -> mcolour = colourActual; // Actual collection
965 lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
966 lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
969 //------------------------------------------------------------------------
970 void WidgetShowNPoints::RefreshCollectionText()
973 strTmp.Printf(_T("%d / %d "), (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
974 txtNrCollections->SetLabel( strTmp );
978 //------------------------------------------------------------------------
979 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
981 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
982 #if wxMAJOR_VERSION <= 2
983 wxFileDialog* FD = new wxFileDialog( 0,
984 _T("Save groups of points .."),
988 wxSAVE | wxOVERWRITE_PROMPT,
991 wxFileDialog* FD = new wxFileDialog( 0,
992 _T("Save groups of points .."),
996 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
1000 int result_FD = FD->ShowModal();
1001 // This line is need it by windows //EED
1002 FD->SetReturnCode( result_FD );
1003 if (FD->GetReturnCode()==wxID_OK)
1005 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1008 ff = fopen( filename.c_str() , "w+" );
1011 int i,size=lstModelShowNPoints.size();
1012 fprintf(ff,"NumberOfGroups %d \n",size);
1014 for (i=0;i<size;i++)
1016 lstModelShowNPoints[i]->SavePoints_(ff);
1021 printf("WidgetShowNPoints::Save Groups Points ...Error... creating file \n");
1030 //------------------------------------------------------------------------
1031 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
1033 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1034 #if wxMAJOR_VERSION <= 2
1035 wxFileDialog* FD = new wxFileDialog( 0,
1036 _T("Load groups of points .."),
1039 _T("(*.xls)|*.xls"),
1040 wxOPEN | wxFILE_MUST_EXIST,
1043 wxFileDialog* FD = new wxFileDialog( 0,
1044 _T("Load groups of points .."),
1047 _T("(*.xls)|*.xls"),
1048 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1051 bool okEraseFirstGrout=false;
1053 int result_FD = FD->ShowModal();
1054 // This line is need it by windows //EED
1055 FD->SetReturnCode( result_FD );
1056 if (FD->GetReturnCode()==wxID_OK)
1058 if (lstModelShowNPoints.size()==1)
1060 if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGrout=true; }
1062 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1063 FILE *ff = fopen( filename.c_str() , "r+" );
1067 int iGroup,sizeGroups;
1068 int iPoint,numberPointsRead;
1070 fscanf(ff," %s %d",chartmp,&sizeGroups);
1071 for (iGroup=0;iGroup<sizeGroups;iGroup++)
1073 mActualCollection = lstModelShowNPoints.size();
1076 int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1077 for (i=0;i<numberPointsRead;i++)
1081 GetViewShowNPoints()->AddVtkPoint();
1087 printf("WidgetShowNPoints::Load Group of Points ...Error... reading file");
1089 if (okEraseFirstGrout==true)
1091 mActualCollection=0;
1092 DeleteCollection_();
1093 mActualCollection = lstModelShowNPoints.size()-1;
1095 RefreshCollectionText();
1096 RefreshColourCollection();
1102 //------------------------------------------------------------------------
1103 std::vector<int> WidgetShowNPoints::GetLstPointsX()
1107 return GetModelShowNPoints()->GetLstPointsX();
1109 std::vector<int> lst;
1111 int iG,sG=lstModelShowNPoints.size();
1112 for (iG=0 ; iG<sG ; iG++)
1114 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1116 for (iP=0 ; iP<s ; iP++)
1118 lst.push_back( lstTmp[iP] );
1125 //------------------------------------------------------------------------
1126 std::vector<int> WidgetShowNPoints::GetLstPointsY()
1130 return GetModelShowNPoints()->GetLstPointsY();
1132 std::vector<int> lst;
1134 int iG,sG=lstModelShowNPoints.size();
1135 for (iG=0 ; iG<sG ; iG++)
1137 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1139 for (iP=0 ; iP<s ; iP++)
1141 lst.push_back( lstTmp[iP] );
1148 //------------------------------------------------------------------------
1149 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
1153 return GetModelShowNPoints()->GetLstPointsZ();
1155 std::vector<int> lst;
1157 int iG,sG=lstModelShowNPoints.size();
1158 for (iG=0 ; iG<sG ; iG++)
1160 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1162 for (iP=0 ; iP<s ; iP++)
1164 lst.push_back( lstTmp[iP] );
1172 //------------------------------------------------------------------------
1173 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1177 return GetModelShowNPoints()->GetLstLabels();
1179 std::vector< std::string > lst;
1181 int iG,sG=lstModelShowNPoints.size();
1182 for (iG=0 ; iG<sG ; iG++)
1184 std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1186 for (iP=0 ; iP<s ; iP++)
1188 lst.push_back( lstTmp[iP] );
1195 //------------------------------------------------------------------------
1196 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1198 std::vector<int> lstIndexs;
1201 lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1203 int iG,sG=lstModelShowNPoints.size();
1204 for (iG=0 ; iG<sG ; iG++)
1206 lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );