3 #include "vtkSphereSource.h"
4 #include "vtkRenderer.h"
5 #include "vtkTextActor3D.h"
10 #include <wx/checkbox.h>
12 #include <wx/filedlg.h>
13 #include <wx/msgdlg.h>
14 #include <wx/notebook.h>
16 #include "WidgetShowNPoints.h"
19 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
25 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
27 printf("EED WidgetShowNPoints::WidgetShowNPoints Start \n");
29 // mmodelShowNPoints = new ModelShowNPoints();
31 ModelShowNPoints* modelShowNPoints = new ModelShowNPoints();
32 lstModelShowNPoints.push_back( modelShowNPoints );
33 lstViewShowNPoints.push_back( new ViewShowNPoints( modelShowNPoints ) );
37 wxPanel* panelParent = this;
38 wxSizer* sizer = NULL;
39 wxSizer* MNPsizer = NULL;
41 wxNotebook* bookSetPoints = NULL;
42 wxNotebook* bookGroupManager = NULL;
43 wxPanel* panel = NULL;
44 wxPanel* panel2 = NULL;
46 bookSetPoints = new wxNotebook(panelParent,
51 panel = new wxPanel(bookSetPoints);
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 wxCheckBox *chkBox = 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);
160 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
161 sizer1->Add(askPointLabel); // JPR
162 sizer1->Add(textCtrl);
163 sizer1->Add(btnAddPoint);
164 sizer1->Add(btnInsertPoint);//CFT
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();
600 //------------------------------------------------------------------------
601 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
603 int id=GetModelShowNPoints()->GetNearestPoint();
604 if((id==-1) && (mtype==1))
613 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
616 //renderer->GetRenderWindow()->Render();
617 GetViewShowNPoints()->RefreshPoint(id);
618 GetViewShowNPoints()->Render();
623 //------------------------------------------------------------------------
624 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
626 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
630 //lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
631 //renderer->GetRenderWindow()->Render();
632 GetViewShowNPoints()->lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
633 GetViewShowNPoints()->Render();
638 //------------------------------------------------------------------------
639 void WidgetShowNPoints::ErasePoint(int id)
642 //if (this->renderer!=NULL)
643 if (GetViewShowNPoints()->renderer!=NULL)
648 //renderer->RemoveActor( lstActorsSphere[id] );
649 //renderer->RemoveActor( lstActorsText[id] );
650 //lstActorsSphere[id]->Delete();
651 //lstActorsText[id]->Delete();
652 //lstSourceSphere[id]->Delete();
653 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
654 //lstActorsText.erase( lstActorsText.begin()+id );
655 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
656 GetViewShowNPoints()->ErasePoint(id);
657 GetModelShowNPoints()->ErasePoint(id);
662 //------------------------------------------------------------------------
663 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
665 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
668 //renderer->GetRenderWindow()->Render();
669 GetViewShowNPoints()->Render();
672 //------------------------------------------------------------------------
673 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
676 //ErasePoint( lstActorsSphere.size()-1 );
677 //renderer->GetRenderWindow()->Render();
678 int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
680 GetViewShowNPoints()->Render();
684 //------------------------------------------------------------------------
685 void WidgetShowNPoints::DeleteAllPoints()
688 //int id,size=lstActorsSphere.size();
689 int id,size=GetViewShowNPoints()->lstActorsSphere.size();
690 for (id=size-1;id>=0;id--)
696 //renderer->GetRenderWindow()->Render();
697 GetViewShowNPoints()->Render();
700 //------------------------------------------------------------------------
701 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
706 //NTU: Method for updating points opacity and Radio
708 //------------------------------------------------------------------------
709 void WidgetShowNPoints::UpdatePoints_()
712 //this->mopacity = sdrOpacity->GetValue()/100.0;
713 //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
716 double opacity = sdrOpacity->GetValue()/100.0;
717 double radio = sdrRadio->GetValue();
718 int i,size = lstViewShowNPoints.size();
719 for (i=0 ; i<size ; i++)
721 lstViewShowNPoints[i]->mopacity = opacity;
722 lstModelShowNPoints[i]->SetRadio( radio ) ;
724 // GetViewShowNPoints()->RefreshPoints();
727 //------------------------------------------------------------------------
728 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
730 RefreshColourCollection();
733 //------------------------------------------------------------------------
734 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
736 GetModelShowNPoints()->SetReferencePoint(point);
737 int i,size=lstModelShowNPoints.size();
740 lstModelShowNPoints[i]->SetReferencePoint(point); // All collection
744 //------------------------------------------------------------------------
745 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
748 //if (this->renderer==NULL)
749 if (GetViewShowNPoints()->renderer==NULL)
753 int i,sizeX,sizeY,sizeZ,sizeLabels;
754 sizeX = (int)initLstPointsX.size();
755 sizeY = (int)initLstPointsY.size();
756 sizeZ = (int)initLstPointsZ.size();
757 sizeLabels = (int)initLstLabels.size();
760 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
762 for (i=0;i<sizeX;i++)
764 x = initLstPointsX[i];
765 y = initLstPointsY[i];
766 z = initLstPointsZ[i];
769 label = initLstLabels[i];
773 AddPoint( x,y,z,label );
776 // renderer->GetRenderWindow()->Render();
780 //------------------------------------------------------------------------
781 void WidgetShowNPoints::SetType(int type)
786 //------------------------------------------------------------------------
787 int WidgetShowNPoints::GetType()
793 //------------------------------------------------------------------------
794 double WidgetShowNPoints::GetRadio()
796 return sdrRadio->GetValue();
798 //------------------------------------------------------------------------
799 double WidgetShowNPoints::GetOpacity()
801 return sdrOpacity->GetValue()/100;
804 //------------------------------------------------------------------------
805 void WidgetShowNPoints::InsertCollection()
807 ModelShowNPoints* model = new ModelShowNPoints();
808 ViewShowNPoints* view = new ViewShowNPoints( model );
809 model->SetImage( lstModelShowNPoints[0]->GetImage() );
810 view->mopacity = lstViewShowNPoints[0]->mopacity;
811 view->renderer = lstViewShowNPoints[0]->renderer;
812 lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
813 lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
814 RefreshCollectionText();
817 //------------------------------------------------------------------------
818 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
821 RefreshColourCollection();
824 //------------------------------------------------------------------------
825 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
829 RefreshColourCollection();
832 //------------------------------------------------------------------------
833 void WidgetShowNPoints::DeleteCollection_()
835 if ( lstModelShowNPoints.size()>1 )
837 DeleteAllPoints(); // Actual Collection
838 lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
839 lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
840 if ( mActualCollection>=lstModelShowNPoints.size() )
845 DeleteAllPoints(); // Actual Collection
849 //------------------------------------------------------------------------
850 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
853 RefreshCollectionText();
854 RefreshColourCollection();
857 //------------------------------------------------------------------------
858 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
861 if ( mActualCollection <0 )
865 RefreshCollectionText();
866 RefreshColourCollection();
869 //------------------------------------------------------------------------
870 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
873 if ( mActualCollection >=lstModelShowNPoints.size() )
875 mActualCollection = lstModelShowNPoints.size()-1;
877 RefreshCollectionText();
878 RefreshColourCollection();
881 //------------------------------------------------------------------------
882 void WidgetShowNPoints::RefreshColourCollection()
885 std::vector<double> colourAll;
886 colourAll.push_back(1);
887 colourAll.push_back(0);
888 colourAll.push_back(0);
889 std::vector<double> colourActual;
890 colourActual.push_back(1);
891 colourActual.push_back(1);
892 colourActual.push_back(0);
893 SetColour( colourAll ); // For all collections
894 int i,size=lstViewShowNPoints.size();
897 lstViewShowNPoints[i] -> mcolour = colourAll; // All collection
898 lstViewShowNPoints[i]->RefreshEachPoint();
900 lstViewShowNPoints[mActualCollection] -> mcolour = colourActual; // Actual collection
901 lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
902 lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
905 //------------------------------------------------------------------------
906 void WidgetShowNPoints::RefreshCollectionText()
909 strTmp.Printf(_T("%d / %d "), (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
910 txtNrCollections->SetLabel( strTmp );
914 //------------------------------------------------------------------------
915 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
917 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
918 #if wxMAJOR_VERSION <= 2
919 wxFileDialog* FD = new wxFileDialog( 0,
920 _T("Save groups of points .."),
924 wxSAVE | wxOVERWRITE_PROMPT,
927 wxFileDialog* FD = new wxFileDialog( 0,
928 _T("Save groups of points .."),
932 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
936 int result_FD = FD->ShowModal();
937 // This line is need it by windows //EED
938 FD->SetReturnCode( result_FD );
939 if (FD->GetReturnCode()==wxID_OK)
941 std::string filename= (const char*) ( FD->GetPath().mb_str() );
944 ff = fopen( filename.c_str() , "w+" );
947 int i,size=lstModelShowNPoints.size();
948 fprintf(ff,"NumberOfGroups %d \n",size);
952 lstModelShowNPoints[i]->SavePoints_(ff);
957 printf("WidgetShowNPoints::Save Groups Points ...Error... creating file \n");
965 //------------------------------------------------------------------------
966 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
968 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
969 #if wxMAJOR_VERSION <= 2
970 wxFileDialog* FD = new wxFileDialog( 0,
971 _T("Load groups of points .."),
975 wxOPEN | wxFILE_MUST_EXIST,
978 wxFileDialog* FD = new wxFileDialog( 0,
979 _T("Load groups of points .."),
983 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
986 bool okEraseFirstGrout=false;
988 int result_FD = FD->ShowModal();
989 // This line is need it by windows //EED
990 FD->SetReturnCode( result_FD );
991 if (FD->GetReturnCode()==wxID_OK)
993 if (lstModelShowNPoints.size()==1)
995 if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGrout=true; }
997 std::string filename= (const char*) ( FD->GetPath().mb_str() );
998 FILE *ff = fopen( filename.c_str() , "r+" );
1002 int iGroup,sizeGroups;
1003 int iPoint,numberPointsRead;
1005 fscanf(ff," %s %d",chartmp,&sizeGroups);
1006 for (iGroup=0;iGroup<sizeGroups;iGroup++)
1008 mActualCollection = lstModelShowNPoints.size();
1011 int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1012 for (i=0;i<numberPointsRead;i++)
1016 GetViewShowNPoints()->AddVtkPoint();
1022 printf("WidgetShowNPoints::Load Group of Points ...Error... reading file");
1024 if (okEraseFirstGrout==true)
1026 mActualCollection=0;
1027 DeleteCollection_();
1028 mActualCollection = lstModelShowNPoints.size()-1;
1030 RefreshCollectionText();
1031 RefreshColourCollection();
1036 //------------------------------------------------------------------------
1037 std::vector<int> WidgetShowNPoints::GetLstPointsX()
1041 return GetModelShowNPoints()->GetLstPointsX();
1043 std::vector<int> lst;
1045 int iG,sG=lstModelShowNPoints.size();
1046 for (iG=0 ; iG<sG ; iG++)
1048 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1050 for (iP=0 ; iP<s ; iP++)
1052 lst.push_back( lstTmp[iP] );
1059 //------------------------------------------------------------------------
1060 std::vector<int> WidgetShowNPoints::GetLstPointsY()
1064 return GetModelShowNPoints()->GetLstPointsY();
1066 std::vector<int> lst;
1068 int iG,sG=lstModelShowNPoints.size();
1069 for (iG=0 ; iG<sG ; iG++)
1071 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1073 for (iP=0 ; iP<s ; iP++)
1075 lst.push_back( lstTmp[iP] );
1082 //------------------------------------------------------------------------
1083 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
1087 return GetModelShowNPoints()->GetLstPointsZ();
1089 std::vector<int> lst;
1091 int iG,sG=lstModelShowNPoints.size();
1092 for (iG=0 ; iG<sG ; iG++)
1094 std::vector<int> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1096 for (iP=0 ; iP<s ; iP++)
1098 lst.push_back( lstTmp[iP] );
1106 //------------------------------------------------------------------------
1107 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1111 return GetModelShowNPoints()->GetLstLabels();
1113 std::vector< std::string > lst;
1115 int iG,sG=lstModelShowNPoints.size();
1116 for (iG=0 ; iG<sG ; iG++)
1118 std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1120 for (iP=0 ; iP<s ; iP++)
1122 lst.push_back( lstTmp[iP] );
1129 //------------------------------------------------------------------------
1130 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1132 std::vector<int> lstIndexs;
1135 lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1137 int iG,sG=lstModelShowNPoints.size();
1138 for (iG=0 ; iG<sG ; iG++)
1140 lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );