2 #include "vtkSphereSource.h"
3 #include "vtkRenderer.h"
4 #include "vtkTextActor3D.h"
8 #include <wx/filedlg.h>
10 #include <wx/notebook.h>
12 #include "WidgetShowNPoints.h"
14 #include <creaContoursFactory.h>
16 #include <vtkStaticPointLocator.h>
17 #include <vtkPointData.h>
18 #include <vtkDataArray.h>
20 #include <vtkStaticPointLocator.h>
21 #include <vtkPoints.h>
23 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, int type)
29 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
32 aux_mesh_spc.push_back(1);
33 aux_mesh_spc.push_back(1);
34 aux_mesh_spc.push_back(1);
35 aux_mesh_type = 0; // 0:Patch 1:CloseSpline1 2:CloseSpline2
38 // mmodelShowNPoints = new ModelShowNPoints();
42 char * val = getenv( "TEMP" );
45 UndoRedoDir = std::string("");
47 UndoRedoDir = std::string(val)+"\\creatools";
48 std::string cmd1 = "mkdir "+ UndoRedoDir;
49 system( cmd1.c_str() );
50 // Erasing files of more than 1 day old ( -1 )
51 std::string cmd2 = "ForFiles /p \"" + UndoRedoDir + "\" /s /d -1 /c \"cmd /c del @file \"";
52 system( cmd2.c_str() );
54 #elif defined(__GNUC__)
58 UndoRedoDir = "/tmp/creatools";
60 UndoRedoDir = "/tmp/creatools";
63 std::string cmd1 = "mkdir "+ UndoRedoDir;
64 system( cmd1.c_str() );
65 // Erasing files of more than 1 day old ( +1 )
66 std::string cmd= "find "+UndoRedoDir+" -name \"UndoRedo_collection_*.undoredo\" -type f -mtime +1 -delete";
67 system( cmd.c_str() );
74 mActualCollection = 0;
75 ModelShowNPoints* modelShowNPoints = new ModelShowNPoints();
76 lstModelShowNPoints.push_back( modelShowNPoints );
77 lstViewShowNPoints.push_back( new ViewShowNPoints( modelShowNPoints ) );
81 wxPanel* panelParent = this;
82 wxSizer* sizer = NULL;
83 wxSizer* MNPsizer = NULL;
84 wxNotebook* bookSetPoints = NULL;
85 wxNotebook* bookGroupManager = NULL;
86 wxPanel* panel = NULL;
87 wxPanel* panel2 = NULL;
88 txtNrCollections = NULL;
90 bookSetPoints = new wxNotebook(panelParent,
95 panel = new wxPanel(bookSetPoints);
98 sizeButton.Set( 45 , -1 );
100 sizeSlider.Set( 90 , -1 );
105 bookGroupManager = new wxNotebook(panelParent, //bbGetWxParent(),
110 panel2 = new wxPanel(bookGroupManager);
111 txtNrCollections = new wxStaticText(panel2,-1, _T("1 / 1 "));
112 wxButton *btnBackCollection = new wxButton( panel2, -1, _T("<") , wxDefaultPosition, sizeButton );
113 wxButton *btnNextCollection = new wxButton( panel2, -1, _T(">") , wxDefaultPosition, sizeButton );
114 wxButton *btnInsertCollectionBefore = new wxButton( panel2, -1, _T("+<") , wxDefaultPosition, sizeButton );
115 wxButton *btnInsertCollectionAfter = new wxButton( panel2, -1, _T("+>") , wxDefaultPosition, sizeButton );
116 wxButton *btnDeleteCollection = new wxButton( panel2, -1, _T("-") , wxDefaultPosition, sizeButton );
117 wxButton *btnResetCollection = new wxButton( panel2, -1, _T("--") , wxDefaultPosition, sizeButton );
118 wxButton *btnSaveCollection = new wxButton( panel2, -1, _T("Save") , wxDefaultPosition, sizeButton );
119 wxButton *btnLoadCollection = new wxButton( panel2, -1, _T("Load") , wxDefaultPosition, sizeButton );
120 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
121 wxFlexGridSizer *sizer2 = new wxFlexGridSizer(2);
122 wxFlexGridSizer *sizer3 = new wxFlexGridSizer(3);
123 wxFlexGridSizer *sizer4 = new wxFlexGridSizer(3);
124 wxFlexGridSizer *sizer5 = new wxFlexGridSizer(1);
125 wxFlexGridSizer *sizer6 = new wxFlexGridSizer(2);
126 // wxStaticText* txOpacity = new wxStaticText(panel2, -1, wxString(_T("Op:")));
128 btnInsertCollectionBefore -> SetToolTip( _T("+ Add group before") );
129 btnInsertCollectionAfter -> SetToolTip( _T("+> Add group after") );
130 btnDeleteCollection -> SetToolTip( _T("- Erase group") );
131 btnResetCollection -> SetToolTip( _T("-- Reset : Erase all groups") );
133 sdrOpacity = new wxSlider(panel2, -1, 0, 0, 100, wxDefaultPosition, sizeSlider, wxSL_LABELS);
134 // wxStaticText* txRadio = new wxStaticText(panel2, -1, wxString(_T("R:")));
135 sdrRadio = new wxSlider(panel2, -1, 0, 1, 50, wxDefaultPosition, sizeSlider, wxSL_LABELS);
137 sdrRadio -> SetToolTip( _T("Radio") );
138 sdrOpacity -> SetToolTip( _T("Opacity") );
140 Connect(btnBackCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnBackCollection );
141 Connect(btnNextCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnNextCollection );
142 Connect(btnInsertCollectionBefore->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionBefore );
143 Connect(btnInsertCollectionAfter->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnInsertCollectionAfter );
144 Connect(btnDeleteCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteCollection );
145 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints );
146 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED, (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints );
147 Connect(btnSaveCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnSaveCollections );
148 Connect(btnLoadCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnLoadCollections );
149 Connect(btnResetCollection->GetId() , wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnResetCollections );
151 sizer2->Add( btnBackCollection );
152 sizer2->Add( btnNextCollection );
153 sizer3->Add( btnInsertCollectionBefore );
154 sizer3->Add( btnInsertCollectionAfter );
155 sizer4->Add( btnLoadCollection );
156 sizer4->Add( btnSaveCollection );
157 // sizer5->Add( txRadio ,wxGROW );
158 sizer5->Add( sdrRadio ,wxGROW );
159 // sizer5->Add( txOpacity ,wxGROW );
160 sizer5->Add( sdrOpacity ,wxGROW );
161 sizer6->Add( btnDeleteCollection );
162 sizer6->Add( btnResetCollection );
164 sizer1->Add( txtNrCollections );
165 sizer1->Add( sizer2 );
166 sizer1->Add( sizer3 );
167 sizer1->Add( sizer6 );
168 sizer1->Add( sizer4 );
169 sizer1->Add( sizer5 ,wxGROW );
172 panel2->SetSizer( MNPsizer );
173 panel2->SetAutoLayout(true);
175 bookGroupManager->AddPage(panel2 , _T("Groups") );
178 if ( (mtype==0) || (mtype==3) || (mtype==4) )
181 // askPointLabel = new wxStaticText(panel, -1, _T("Label:")); // JPR
182 textCtrl = new wxTextCtrl(panel, -1, wxEmptyString , wxDefaultPosition, sizeButton);
183 wxButton *btnBackPoint = new wxButton( panel, -1, _T("<") , wxDefaultPosition, sizeButton );
184 wxButton *btnNextPoint = new wxButton( panel, -1, _T(">") , wxDefaultPosition, sizeButton );
185 wxButton *btnAddPoint = new wxButton( panel, -1, _T("+") , wxDefaultPosition, sizeButton );
186 wxButton *btnInsertPoint = new wxButton( panel, -1, _T("(+)") , wxDefaultPosition, sizeButton );
187 cbAutoAddPoints = new wxCheckBox(panel,-1, _T("Auto") , wxDefaultPosition, sizeButton );
188 wxButton *btnMovePointUp = new wxButton( panel, -1, _T("<-") , wxDefaultPosition, sizeButton );
189 wxButton *btnMovePointDown = new wxButton( panel, -1, _T("->") , wxDefaultPosition, sizeButton );
191 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set") , wxDefaultPosition, sizeButton );
192 cbTrackPoint = new wxCheckBox(panel,-1, _T("Tra.") , wxDefaultPosition, sizeButton );
193 wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Ren.") , wxDefaultPosition, sizeButton );
194 wxButton *btnErasePoint = new wxButton( panel, -1, _T("-") , wxDefaultPosition, sizeButton );
195 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("- lst") , wxDefaultPosition, sizeButton );
196 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("--") , wxDefaultPosition, sizeButton );
197 wxButton *btnUndo = new wxButton( panel, -1, _T("Undo") , wxDefaultPosition, sizeButton );
198 wxButton *btnRedo = new wxButton( panel, -1, _T("Redo") , wxDefaultPosition, sizeButton );
199 wxButton *btnSavePoints = NULL;
200 wxButton *btnLoadPoints = NULL;
203 btnBackPoint -> SetToolTip( _T("Select befor point") );
204 btnNextPoint -> SetToolTip( _T("Select next point") );
205 cbAutoAddPoints -> SetToolTip( _T("Auto Add point") );
206 btnAddPoint -> SetToolTip( _T("+ Add point") );
207 btnInsertPoint -> SetToolTip( _T("(-) Insert point") );
208 btnMovePointUp -> SetToolTip( _T("Move point Up in the normal direction") );
209 btnMovePointDown -> SetToolTip( _T("Move point Down in the normal direction") );
211 btnErasePoint -> SetToolTip( _T("- Erase point") );
212 btnEraseLastPoint -> SetToolTip( _T("- lst Erase last point") );
213 btnDeleteAllPoints -> SetToolTip( _T("-- Erase all points") );
217 btnSavePoints = new wxButton( panel, -1, _T("Save points"));
218 btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
219 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
220 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
222 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
224 wxStaticText* txOpacity;
225 wxStaticText* txRadio;
226 if ( (mtype==0) || (mtype==3) )
228 //NTU: Sliders for opacity and radio change
229 txOpacity = new wxStaticText(panel, -1, wxString(_T(" Points Opacity ")));
230 sdrOpacity = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
231 txRadio = new wxStaticText(panel, -1, wxString(_T(" Points Radius ")));
232 sdrRadio = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
234 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
235 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
237 Connect(cbAutoAddPoints->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WidgetShowNPoints::OnAutoAddPoints);
238 Connect(btnBackPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnBackPoint);
239 Connect(btnNextPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnNextPoint);
240 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
241 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
242 Connect(btnMovePointUp->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnMovePointUp);
243 Connect(btnMovePointDown->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnMovePointDown);
244 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
245 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
246 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
247 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
248 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
249 Connect(cbTrackPoint->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WidgetShowNPoints::OnTrackPoint);
250 Connect(btnUndo->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnUndo);
251 Connect(btnRedo->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRedo);
252 wxFlexGridSizer *sizer0 = new wxFlexGridSizer(1);
253 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(2);
254 wxFlexGridSizer *sizer2 = new wxFlexGridSizer(3);
255 wxFlexGridSizer *sizer3 = new wxFlexGridSizer(2);
256 wxFlexGridSizer *sizer4 = new wxFlexGridSizer(3);
257 wxFlexGridSizer *sizer5 = new wxFlexGridSizer(2);
258 wxFlexGridSizer *sizer6 = new wxFlexGridSizer(2);
259 wxFlexGridSizer *sizer7 = new wxFlexGridSizer(2);
260 sizer1->Add( textCtrl );
261 sizer1->Add( btnRenamePoint );
262 // sizer2->Add( cbAutoAddPoints );
263 // sizer2->Add( new wxStaticText(panel, -1, _T(" ")) );
264 sizer2->Add( btnAddPoint );
265 sizer2->Add( btnInsertPoint );//CFT
266 sizer2->Add( cbAutoAddPoints );
267 sizer3->Add( btnSetPositionPoint );
268 sizer3->Add( cbTrackPoint );
269 sizer4->Add( btnErasePoint );
270 sizer4->Add( btnEraseLastPoint );
271 sizer4->Add( btnDeleteAllPoints );
272 sizer5->Add( btnUndo );
273 sizer5->Add( btnRedo );
274 sizer6->Add( btnBackPoint );
275 sizer6->Add( btnNextPoint );
276 sizer7->Add( btnMovePointUp );
277 sizer7->Add( btnMovePointDown );
279 // sizer0->Add(askPointLabel); // JPR
280 sizer0->Add(txtNrPoints);
288 if ( (mtype==0) || (mtype==3) )
290 wxFlexGridSizer *sizer5 = new wxFlexGridSizer(1);
291 sizer5->Add(txRadio);
292 sizer5->Add(sdrRadio,1,wxGROW );
293 sizer5->Add(txOpacity);
294 sizer5->Add(sdrOpacity,1,wxGROW );
299 wxFlexGridSizer *sizer6 = new wxFlexGridSizer(2);
300 sizer6->Add(btnSavePoints);
301 sizer6->Add(btnLoadPoints);
310 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
311 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
313 //NTU: Sliders for opacity and radio change
314 wxStaticText* txOpacity = new wxStaticText(panel, -1, wxString(_T(" Points Opacity ")));
315 sdrOpacity = new wxSlider(panel, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
316 wxStaticText* txRadio = new wxStaticText(panel, -1, wxString(_T(" Points Radio ")));
317 sdrRadio = new wxSlider(panel, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
318 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
319 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
320 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
322 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
323 sizer1->Add(btnSetPositionPoint);
324 sizer1->Add(txtNrPoints);
325 sizer1->Add(txRadio);
326 sizer1->Add(sdrRadio,1,wxGROW );
327 sizer1->Add(txOpacity);
328 sizer1->Add(sdrOpacity,1,wxGROW );
334 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
335 wxButton *btnAddPoint = new wxButton(panel , -1, _T(" Add Point "));
336 wxButton *btnDeleteAllPoints = new wxButton(panel , -1, _T(" Delete All "));
337 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
338 textCtrl = new wxTextCtrl(panel, -1);
339 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
340 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
341 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
342 sizer1->Add(askPointLabel);
343 sizer1->Add(btnAddPoint);
344 sizer1->Add(btnDeleteAllPoints);
346 sizer1->Add(textCtrl);
347 // sdrOpacity = new wxSlider();
348 // sdrRadio = new wxSlider();
349 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
351 } // bbGetInputType 2
353 panel->SetSizer(sizer);
354 panel->SetAutoLayout(true);
356 bookSetPoints->AddPage(panel , _T("Points") );
358 if ((mtype >= 0) && (mtype <= 3) )
362 wxFlexGridSizer *sizerParent = new wxFlexGridSizer(1);
363 sizerParent->Add( bookSetPoints );
364 panelParent->SetSizer( sizerParent );
365 panelParent->SetAutoLayout(true);
366 panelParent->Layout();
368 } // if mtype 0 1 2 3
372 if ((sizer!=NULL) && (MNPsizer!=NULL))
374 wxFlexGridSizer *sizerG = new wxFlexGridSizer(2);
375 sizerG->Add(bookGroupManager);
376 sizerG->Add(bookSetPoints);
377 panelParent->SetSizer(sizerG);
378 panelParent->SetAutoLayout(true);
379 panelParent->Layout();
384 //------------------------------------------------------------------------
385 WidgetShowNPoints::~WidgetShowNPoints()
389 //------------------------------------------------------------------------
390 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
393 // return mmodelShowNPoints;
394 return lstModelShowNPoints[ mActualCollection ];
397 //------------------------------------------------------------------------
398 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints(int id)
400 if(id >= 0 && id < lstModelShowNPoints.size())
402 return lstModelShowNPoints[ id ];
407 //------------------------------------------------------------------------
408 ViewShowNPoints* WidgetShowNPoints::GetViewShowNPoints()
410 return lstViewShowNPoints[ mActualCollection ];
414 //------------------------------------------------------------------------
415 void WidgetShowNPoints::SetRadio(double radio)
418 // GetModelShowNPoints()->SetRadio(radio);
419 int i,size = lstModelShowNPoints.size();
422 lstModelShowNPoints[i]->SetRadio( radio );
425 sdrRadio->SetValue(radio);
428 //------------------------------------------------------------------------
429 void WidgetShowNPoints::SetColour(std::vector<double> colour)
432 //this->mcolour = colour;
433 int i,size = lstViewShowNPoints.size();
434 for (i=0 ; i<size ; i++)
436 lstViewShowNPoints[i]->mcolour = colour;
440 //------------------------------------------------------------------------
441 void WidgetShowNPoints::SetImage(vtkImageData* image)
444 //GetModelShowNPoints()->SetImage(image);
445 int i,size = lstModelShowNPoints.size();
446 for (i=0 ; i<size ; i++)
448 lstModelShowNPoints[i]->SetImage(image);
452 //------------------------------------------------------------------------
453 void WidgetShowNPoints::SetOpacity(double opacity)
456 //this->mopacity=opacity;
457 int i,size = lstViewShowNPoints.size();
458 for (i=0 ; i<size ; i++)
460 lstViewShowNPoints[i]->mopacity = opacity;
463 sdrOpacity->SetValue( opacity*100.0 );
467 //------------------------------------------------------------------------
468 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
471 //this->renderer = renderer;
472 int i,size = lstViewShowNPoints.size();
473 for (i=0 ; i<size ; i++)
475 lstViewShowNPoints[i]->renderer = renderer;
480 //------------------------------------------------------------------------
482 void WidgetShowNPoints::RefreshPoint(int id)
486 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
487 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
488 std::string label = GetModelShowNPoints()->GetIdLabel(id);
489 double radio = GetModelShowNPoints()->GetRadio();
490 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
491 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
492 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
493 lstSourceSphere[id]->SetRadius( radio );
494 //EED 2017-01-01 Migration VTK7
495 #if VTK_MAJOR_VERSION <= 5
498 lstSourceSphere[id]->Update();
500 lstActorsText[id]->SetInput( label.c_str() );
501 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
504 //------------------------------------------------------------------------
505 void WidgetShowNPoints::RefreshPoints()
507 int id,size=lstActorsSphere.size();
508 for (id=0;id<size;id++)
512 renderer->GetRenderWindow()->Render();
515 //------------------------------------------------------------------------
516 void WidgetShowNPoints::AddVtkPoint()
519 vtkSphereSource *vtksphere = vtkSphereSource::New();
520 vtksphere->SetThetaResolution (20);
521 vtksphere->SetPhiResolution (20);
522 vtksphere->SetRadius( 1 );
523 //NTU: For updating points
524 lstSourceSphere.push_back(vtksphere);
525 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
527 //EED 2017-01-01 Migration VTK7
528 #if VTK_MAJOR_VERSION <= 5
529 sphereMapper->SetInput( vtksphere->GetOutput() );
532 sphereMapper->SetInputData( vtksphere->GetOutput() );
535 vtkActor *sphereActor = vtkActor::New();
536 sphereActor->SetMapper(sphereMapper);
537 sphereActor->SetOrigin(0, 0, 0);
539 lstActorsSphere.push_back(sphereActor);
541 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
545 renderer->AddActor( sphereActor );
547 vtkTextActor3D *textActor = vtkTextActor3D::New();
548 // textActor->SetInput( strLabel.c_str() );
549 renderer->AddActor( textActor );
550 lstActorsText.push_back(textActor);
555 void WidgetShowNPoints::SetCurrentPoint(int idCurrentPoint )
557 int size = GetModelShowNPoints()->GetLstPointsSize();
558 if (idCurrentPoint<0) { idCurrentPoint = size-1; }
559 if (idCurrentPoint>=size ) { idCurrentPoint = 0; }
560 GetModelShowNPoints()->SetIdCurrentPoint( idCurrentPoint );
561 RefreshCollectionText();
562 RefreshColourCollection();
565 void WidgetShowNPoints::OnBackPoint(wxCommandEvent &event)
567 SetCurrentPoint( GetModelShowNPoints()->GetIdCurrentPoint() - 1 );
570 void WidgetShowNPoints::OnNextPoint(wxCommandEvent &event)
572 SetCurrentPoint( GetModelShowNPoints()->GetIdCurrentPoint() + 1 );
576 //------------------------------------------------------------------------
577 void WidgetShowNPoints::AddPoint(double x, double y, double z, std::string label)
579 GetModelShowNPoints()->AddPoint(x,y,z, label );
582 //RefreshPoint(lstActorsSphere.size()-1);
583 GetViewShowNPoints()->AddPoint();
586 //------------------------------------------------------------------------
587 void WidgetShowNPoints::InsertPoint(double x, double y, double z, std::string label)//CFT
590 //if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
594 // AddPoint(x,y,z,label);
597 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
599 GetViewShowNPoints()->AddVtkPoint();
601 AddPoint(x,y,z,label);
603 GetViewShowNPoints()->RefreshPoints();
606 //------------------------------------------------------------------------
607 void WidgetShowNPoints::OnInsertPoint_()
610 //if (this->renderer==NULL)
614 if (GetViewShowNPoints()->renderer==NULL)
618 std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
621 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
623 } else {//mpoint.size
624 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
626 RefreshCollectionText();
627 RefreshColourCollection();
629 UndoRedo_SaveCollection();
632 //------------------------------------------------------------------------
633 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
638 //------------------------------------------------------------------------
639 void WidgetShowNPoints::OnAddPoint__()
642 //if (this->renderer==NULL)
643 if (GetViewShowNPoints()->renderer==NULL)
647 std::vector<double> point = GetModelShowNPoints()->GetReferencePoint();
650 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
653 //renderer->GetRenderWindow()->Render();
654 GetViewShowNPoints()->Render();
655 UndoRedo_SaveCollection();
656 } else {//mpoint.size
657 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
661 void WidgetShowNPoints::OnAddPoint_()
668 //------------------------------------------------------------------------
669 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
674 //------------------------------------------------------------------------
675 void WidgetShowNPoints::AutoAddPoints()
677 if ( cbAutoAddPoints->GetValue() == true )
680 RefreshCollectionText();
681 RefreshColourCollection();
682 } // if cbAutoAddPoints
685 //------------------------------------------------------------------------
686 void WidgetShowNPoints::OnAutoAddPoints_tool()
689 cbAutoAddPoints->SetValue( !cbAutoAddPoints->GetValue() );
692 //------------------------------------------------------------------------
693 void WidgetShowNPoints::OnAutoAddPoints_()
698 //------------------------------------------------------------------------
699 void WidgetShowNPoints::OnAutoAddPoints(wxCommandEvent& event)
704 //------------------------------------------------------------------------
705 void WidgetShowNPoints::StopAutoAddPoints( )
707 cbAutoAddPoints->SetValue(false);
710 //------------------------------------------------------------------------
711 void WidgetShowNPoints::SetOutputBox()
713 //EED renderer->GetRenderWindow()->Render();
716 if (GetModelShowNPoints()->GetIdCurrentPoint()<0)
718 strTmp2.Printf(_T(" -- / %d") , GetModelShowNPoints()->GetLstPointsSize() );
720 strTmp.Printf(_T(" %d / %d"), GetModelShowNPoints()->GetIdCurrentPoint()+1 , GetModelShowNPoints()->GetLstPointsSize() );
722 txtNrPoints->SetLabel( strTmp );
726 // mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
727 // mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
728 // mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
729 // mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
730 // mbbShowNPoints->bbSignalOutputModification();
734 //------------------------------------------------------------------------
735 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
738 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
739 #if wxMAJOR_VERSION <= 2
740 wxFileDialog* FD = new wxFileDialog( 0,
741 _T("Save points .."),
745 wxSAVE | wxOVERWRITE_PROMPT,
748 wxFileDialog* FD = new wxFileDialog( 0,
749 _T("Save points .."),
753 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
757 int result_FD = FD->ShowModal();
758 // This line is need it by windows //EED
759 FD->SetReturnCode( result_FD );
760 if (FD->GetReturnCode()==wxID_OK)
762 std::string filename= (const char*) ( FD->GetPath().mb_str() );
763 GetModelShowNPoints()->SavePoints( filename );
768 //------------------------------------------------------------------------
769 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
772 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
773 #if wxMAJOR_VERSION <= 2
774 wxFileDialog* FD = new wxFileDialog( 0,
775 _T("Load points .."),
779 wxOPEN | wxFILE_MUST_EXIST,
782 wxFileDialog* FD = new wxFileDialog( 0,
783 _T("Load points .."),
787 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
792 int result_FD = FD->ShowModal();
793 // This line is need it by windows //EED
794 FD->SetReturnCode( result_FD );
795 if (FD->GetReturnCode()==wxID_OK)
798 std::string filename= (const char*) ( FD->GetPath().mb_str() );
799 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
800 for (i=0;i<numberPointsRead;i++)
804 GetViewShowNPoints()->AddVtkPoint();
809 GetViewShowNPoints()->RefreshPoints();
813 //------------------------------------------------------------------------
814 void WidgetShowNPoints::OnSetPoint_()
819 //int id=GetModelShowNPoints()->GetNearestPoint();
820 int id=GetModelShowNPoints()->GetIdCurrentPoint();
822 if((id==-1) && (mtype==1))
830 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
833 //renderer->GetRenderWindow()->Render();
834 GetViewShowNPoints()->RefreshPoint(id);
835 GetViewShowNPoints()->Render();
837 RefreshCollectionText();
838 RefreshColourCollection();
840 UndoRedo_SaveCollection();
843 //------------------------------------------------------------------------
844 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
849 //------------------------------------------------------------------------
850 void WidgetShowNPoints::MovePoint_(double step)
857 int id=GetModelShowNPoints()->GetIdCurrentPoint();
860 if((GetLstModelShowNPointsSize()>=2) //Check condition
861 && (GetModelShowNPoints()->GetLstPointsSize()>0)
862 && (aux_mesh != NULL)
863 && (aux_mesh_spc.size() == 3))
867 double normal[3];; // point to modify and normal
868 std::vector<double> pN(3); // new point
869 vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New();
870 pointLocator->SetDataSet( aux_mesh );
871 pointLocator->BuildLocator();
873 // int idControlPoint = wsp->GetModelShowNPoints()->GetNearestPoint();
874 int idControlPoint = GetModelShowNPoints()->GetIdCurrentPoint();
876 if(idControlPoint >= 0)
878 GetModelShowNPoints()->GetIdPoint(idControlPoint, &x, &y, &z);
879 p[0] = x * aux_mesh_spc[0];
880 p[1] = y * aux_mesh_spc[1];
881 p[2] = z * aux_mesh_spc[2];
882 long int idMeshPoint = pointLocator->FindClosestPoint(p);
883 aux_mesh->GetPointData()->GetNormals()->GetTuple(idMeshPoint, normal);
884 int direction = step;
885 // pN[0] = p[0] / spc[0] + direction*normal[0];
886 // pN[1] = p[1] / spc[1] + direction*normal[1];
887 // pN[2] = p[2] / spc[2] + direction*normal[2];
888 pN[0] = x + direction*normal[0];
889 pN[1] = y + direction*normal[1];
890 pN[2] = z + direction*normal[2];
892 GetModelShowNPoints()->SetPointById(idControlPoint, pN);
893 // GetViewShowNPoints()->RefreshPoint(idControlPoint);
894 // RefreshCollectionText();
895 // RefreshColourCollection();
897 UndoRedo_SaveCollection();
898 } // if idControlPoint
899 } // if wsp->GetLstModelShowNPointsSiz->size()>=2
902 printf("EED WidgetShowNPoints::MovePoint_ BB \n" );
906 double minX=max,minY=max,minZ=max;
907 double maxX=-max,maxY=-max,maxZ=-max;
908 sizeG = lstModelShowNPoints.size();
909 for (i=0; i<sizeG; i++)
911 std::vector<double> lstX = lstModelShowNPoints[i]->GetLstPointsX();
912 std::vector<double> lstY = lstModelShowNPoints[i]->GetLstPointsY();
913 std::vector<double> lstZ = lstModelShowNPoints[i]->GetLstPointsZ();
915 for (j=0; j<sizeP; j++)
917 if ( lstX[j]<minX ) { minX=lstX[j]; }
918 if ( lstY[j]<minY ) { minY=lstY[j]; }
919 if ( lstZ[j]<minZ ) { minZ=lstZ[j]; }
920 if ( lstX[j]>maxX ) { maxX=lstX[j]; }
921 if ( lstY[j]>maxY ) { maxY=lstY[j]; }
922 if ( lstZ[j]>maxZ ) { maxZ=lstZ[j]; }
926 pc[0]=(minX+maxX) /2 ; pc[1]=(minY+maxY) /2 ; pc[2]=(minZ+maxZ) /2 ;
928 p[0]=GetModelShowNPoints()->GetLstPointsX()[id];
929 p[1]=GetModelShowNPoints()->GetLstPointsY()[id];
930 p[2]=GetModelShowNPoints()->GetLstPointsZ()[id];
935 double mag=sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
937 std::vector<double> point;
948 point.push_back( p[0] + step*v[0] );
949 point.push_back( p[1] + step*v[1] );
950 point.push_back( p[2] + step*v[2] );
951 GetModelShowNPoints()->SetPointById(id,point);
952 UndoRedo_SaveCollection();
958 RefreshCollectionText();
959 RefreshColourCollection();
962 //------------------------------------------------------------------------
963 void WidgetShowNPoints::OnMovePointUp(wxCommandEvent& event)
968 //------------------------------------------------------------------------
969 void WidgetShowNPoints::OnMovePointDown(wxCommandEvent& event)
974 //------------------------------------------------------------------------
975 void WidgetShowNPoints::TrackingPoint( )
977 if ( cbTrackPoint->GetValue() == true )
979 int id = GetModelShowNPoints()->IdInsidePoint();
987 GetModelShowNPoints()->SetPointId_mReferencePoint(idTrack);
989 RefreshCollectionText();
990 RefreshColourCollection();
992 // GetViewShowNPoints()->RefreshPoint(idTrack);
993 // GetViewShowNPoints()->Render();
994 UndoRedo_SaveCollection();
996 } // if trackPointFlag
999 //------------------------------------------------------------------------
1000 void WidgetShowNPoints::OnTrackPoint_tool()
1002 cbTrackPoint->SetValue( !cbTrackPoint->GetValue() );
1006 //------------------------------------------------------------------------
1007 void WidgetShowNPoints::OnTrackPoint_()
1009 StopAutoAddPoints();
1012 if ( cbTrackPoint->GetValue() == true )
1015 // idTrack = GetModelShowNPoints()->IdInsidePoint();
1016 idTrack = GetModelShowNPoints()->GetIdCurrentPoint();
1017 } // if trackPointFlag
1020 //------------------------------------------------------------------------
1021 void WidgetShowNPoints::OnTrackPoint(wxCommandEvent& event)
1026 //------------------------------------------------------------------------
1027 void WidgetShowNPoints::StopTrackPoint( )
1029 cbTrackPoint->SetValue(false);
1033 //------------------------------------------------------------------------
1034 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
1036 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
1040 //lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
1041 //renderer->GetRenderWindow()->Render();
1042 GetViewShowNPoints()->lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
1043 GetViewShowNPoints()->Render();
1045 UndoRedo_SaveCollection();
1049 //------------------------------------------------------------------------
1050 bool WidgetShowNPoints::ErasePoint(int id)
1053 //if (this->renderer!=NULL)
1055 if (GetViewShowNPoints()->renderer!=NULL)
1060 //renderer->RemoveActor( lstActorsSphere[id] );
1061 //renderer->RemoveActor( lstActorsText[id] );
1062 //lstActorsSphere[id]->Delete();
1063 //lstActorsText[id]->Delete();
1064 //lstSourceSphere[id]->Delete();
1065 //lstActorsSphere.erase( lstActorsSphere.begin()+id );
1066 //lstActorsText.erase( lstActorsText.begin()+id );
1067 //lstSourceSphere.erase( lstSourceSphere.begin()+id );
1068 GetViewShowNPoints()->ErasePoint(id);
1069 GetModelShowNPoints()->ErasePoint(id);
1076 //------------------------------------------------------------------------
1077 void WidgetShowNPoints::OnErasePoint_()
1079 StopAutoAddPoints();
1082 //ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
1083 if (ErasePoint( GetModelShowNPoints()->GetIdCurrentPoint() ) == true)
1087 //renderer->GetRenderWindow()->Render();
1088 // GetViewShowNPoints()->Render();
1089 RefreshCollectionText();
1090 RefreshColourCollection();
1092 UndoRedo_SaveCollection();
1096 //------------------------------------------------------------------------
1097 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
1102 //------------------------------------------------------------------------
1103 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
1106 //ErasePoint( lstActorsSphere.size()-1 );
1107 //renderer->GetRenderWindow()->Render();
1108 StopAutoAddPoints();
1111 int id = GetViewShowNPoints()->lstActorsSphere.size()-1;
1114 RefreshCollectionText();
1115 RefreshColourCollection();
1117 UndoRedo_SaveCollection();
1118 GetViewShowNPoints()->Render();
1123 //------------------------------------------------------------------------
1124 void WidgetShowNPoints::DeleteAllPoints_()
1127 //int id,size=lstActorsSphere.size();
1128 int id,size=GetViewShowNPoints()->lstActorsSphere.size();
1129 for (id=size-1;id>=0;id--)
1135 void WidgetShowNPoints::OnDeleteAllPoints_()
1137 StopAutoAddPoints();
1141 UndoRedo_SaveCollection();
1144 //------------------------------------------------------------------------
1145 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
1147 OnDeleteAllPoints_();
1149 GetViewShowNPoints()->Render();
1152 //NTU: Method for updating points opacity and Radio
1154 //------------------------------------------------------------------------
1155 void WidgetShowNPoints::UpdatePoints_()
1158 //this->mopacity = sdrOpacity->GetValue()/100.0;
1159 //GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
1162 double opacity = sdrOpacity->GetValue()/100.0;
1163 double radio = sdrRadio->GetValue();
1164 int i,size = lstViewShowNPoints.size();
1165 for (i=0 ; i<size ; i++)
1167 lstViewShowNPoints[i]->mopacity = opacity;
1168 lstModelShowNPoints[i]->SetRadio( radio ) ;
1170 // GetViewShowNPoints()->RefreshPoints();
1173 //------------------------------------------------------------------------
1174 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
1176 RefreshColourCollection();
1179 //------------------------------------------------------------------------
1180 void WidgetShowNPoints::SetReferencePoint(std::vector<double> point)
1182 GetModelShowNPoints()->SetReferencePoint(point);
1183 int i,size=lstModelShowNPoints.size();
1184 for (i=0;i<size;i++)
1186 lstModelShowNPoints[i]->SetReferencePoint(point); // All collection
1190 //------------------------------------------------------------------------
1191 void WidgetShowNPoints::SetActualCollection( int actual )
1198 if (actual>lstModelShowNPoints.size()-1 )
1200 actual=lstModelShowNPoints.size()-1;
1203 mActualCollection=actual;
1207 //------------------------------------------------------------------------
1208 void WidgetShowNPoints::SetInitLstPoints( std::vector<double> initLstPointsX, std::vector<double> initLstPointsY, std::vector<double> initLstPointsZ, std::vector<std::string> initLstLabels, std::vector<int> initLstIndexs )
1210 if (GetViewShowNPoints()->renderer==NULL)
1216 int i,sizeX,sizeY,sizeZ,sizeTmp,sizeLabels;
1217 int ii,iIndexs,sizeIndexs;
1219 sizeX = (int)initLstPointsX.size();
1220 sizeY = (int)initLstPointsY.size();
1221 sizeZ = (int)initLstPointsZ.size();
1222 sizeLabels = (int)initLstLabels.size();
1223 sizeIndexs = (int)initLstIndexs.size();
1227 initLstIndexs.push_back(sizeX);
1228 sizeIndexs = (int)initLstIndexs.size();
1231 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
1234 for (iIndexs=0;iIndexs<sizeIndexs;iIndexs++ )
1238 InsertCollectionAfter_();
1240 sizeTmp = initLstIndexs[iIndexs];
1241 for (ii=0;ii<sizeTmp;ii++)
1243 x = initLstPointsX[i];
1244 y = initLstPointsY[i];
1245 z = initLstPointsZ[i];
1248 label = initLstLabels[i];
1252 AddPoint( x,y,z,label );
1259 // renderer->GetRenderWindow()->Render();
1268 //if (this->renderer==NULL)
1269 if (GetViewShowNPoints()->renderer==NULL)
1273 int i,sizeX,sizeY,sizeZ,sizeLabels;
1274 sizeX = (int)initLstPointsX.size();
1275 sizeY = (int)initLstPointsY.size();
1276 sizeZ = (int)initLstPointsZ.size();
1277 sizeLabels = (int)initLstLabels.size();
1280 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
1282 for (i=0;i<sizeX;i++)
1284 x = initLstPointsX[i];
1285 y = initLstPointsY[i];
1286 z = initLstPointsZ[i];
1289 label = initLstLabels[i];
1293 AddPoint( x,y,z,label );
1296 // renderer->GetRenderWindow()->Render();
1302 //------------------------------------------------------------------------
1303 void WidgetShowNPoints::SetType(int type)
1308 //------------------------------------------------------------------------
1309 int WidgetShowNPoints::GetType()
1315 //------------------------------------------------------------------------
1316 double WidgetShowNPoints::GetRadio()
1318 return sdrRadio->GetValue();
1320 //------------------------------------------------------------------------
1321 double WidgetShowNPoints::GetOpacity()
1323 return sdrOpacity->GetValue()/100;
1326 //------------------------------------------------------------------------
1327 void WidgetShowNPoints::InsertCollection()
1329 ModelShowNPoints* model = new ModelShowNPoints();
1330 ViewShowNPoints* view = new ViewShowNPoints( model );
1331 view->mopacity = lstViewShowNPoints[0]->mopacity;
1332 view->renderer = lstViewShowNPoints[0]->renderer;
1333 model->SetImage( lstModelShowNPoints[0]->GetImage() );
1334 lstModelShowNPoints.insert( lstModelShowNPoints.begin()+mActualCollection , model );
1335 lstViewShowNPoints.insert( lstViewShowNPoints.begin()+mActualCollection , view );
1338 //------------------------------------------------------------------------
1339 void WidgetShowNPoints::InsertCollectionBefore_()
1342 RefreshCollectionText();
1343 RefreshColourCollection();
1347 //------------------------------------------------------------------------
1348 void WidgetShowNPoints::OnInsertCollectionBefore_()
1350 InsertCollectionBefore_();
1351 CreatePointsIntoNewCollection();
1352 UndoRedo_SaveCollection();
1356 //------------------------------------------------------------------------
1357 void WidgetShowNPoints::OnInsertCollectionBefore(wxCommandEvent &event)
1359 OnInsertCollectionBefore_();
1363 //------------------------------------------------------------------------
1364 void WidgetShowNPoints::InsertCollectionAfter_()
1366 mActualCollection++;
1368 RefreshCollectionText();
1369 RefreshColourCollection();
1374 //------------------------------------------------------------------------
1375 void WidgetShowNPoints::OnInsertCollectionAfter_()
1377 InsertCollectionAfter_();
1378 CreatePointsIntoNewCollection();
1379 UndoRedo_SaveCollection();
1382 //------------------------------------------------------------------------
1383 void WidgetShowNPoints::OnInsertCollectionAfter(wxCommandEvent &event)
1385 OnInsertCollectionAfter_();
1388 //------------------------------------------------------------------------
1389 void WidgetShowNPoints::CreatePointsIntoNewCollection()
1391 int c1 = mActualCollection-1;
1392 int c2 = mActualCollection+1;
1393 int modelSize = lstModelShowNPoints.size();
1394 if (aux_mesh_type==2) // SplineClose2
1396 if (c1==-1) { c1=modelSize-1; }
1397 if (c2==modelSize) { c2=0; }
1398 } // if aux_mesh_type
1400 if ( (c1!=c2) && (c1>=0) && (c1<modelSize) && (c2>=0) && (c2<modelSize) )
1402 std::vector<double> c1LstX = lstModelShowNPoints[c1]->GetLstPointsX();
1403 std::vector<double> c1LstY = lstModelShowNPoints[c1]->GetLstPointsY();
1404 std::vector<double> c1LstZ = lstModelShowNPoints[c1]->GetLstPointsZ();
1405 std::vector<double> c2LstX = lstModelShowNPoints[c2]->GetLstPointsX();
1406 std::vector<double> c2LstY = lstModelShowNPoints[c2]->GetLstPointsY();
1407 std::vector<double> c2LstZ = lstModelShowNPoints[c2]->GetLstPointsZ();
1408 std::vector<double> c1LstXX;
1409 std::vector<double> c1LstYY;
1410 std::vector<double> c1LstZZ;
1411 std::vector<double> c2LstXX;
1412 std::vector<double> c2LstYY;
1413 std::vector<double> c2LstZZ;
1414 creaContoursFactory f;
1415 manualContourModel *m;
1418 int sc; // sizeContour
1420 if ( (c1LstX.size()!=0) && (c2LstX.size()!=0) )
1422 // ----------------- Spline 1 --------------------
1424 size = c1LstX.size();
1425 m = (manualContourModel*)f.getContourModel( 1 ); // Spline
1426 // m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
1427 m->SetNumberOfPointsSpline( sc );
1428 m->SetCloseContour( false );
1429 for (i=0;i<size;i++)
1431 m->AddPoint( c1LstX[i] , c1LstY[i] , c1LstZ[i] );
1436 m->GetSpline_i_Point(i,&x,&y,&z);
1437 c1LstXX.push_back(x);
1438 c1LstYY.push_back(y);
1439 c1LstZZ.push_back(z);
1442 // ----------------- Spline 2 --------------------
1443 size = c2LstX.size();
1444 m = (manualContourModel*)f.getContourModel( 1 ); // Spline
1445 // m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
1446 m->SetNumberOfPointsSpline( sc );
1447 m->SetCloseContour( false );
1448 for (i=0;i<size;i++)
1450 m->AddPoint( c2LstX[i] , c2LstY[i] , c2LstZ[i] );
1455 m->GetSpline_i_Point(i,&x,&y,&z);
1456 c2LstXX.push_back(x);
1457 c2LstYY.push_back(y);
1458 c2LstZZ.push_back(z);
1461 // ----------------- Add new Points --------------------
1462 vtkPoints *points = NULL;
1463 vtkStaticPointLocator *pointLocator = NULL;
1466 points = aux_mesh->GetPoints();
1467 pointLocator = vtkStaticPointLocator::New();
1468 pointLocator->SetDataSet( aux_mesh );
1469 pointLocator->BuildLocator();
1473 if ( c1LstX.size()<c2LstX.size() ) { size=c2LstX.size(); } else { size=c1LstX.size(); }
1474 for (ii=0;ii<size;ii++)
1476 i = (int) ((double)ii/((double)size-1)*(sc-1));
1477 x = (c1LstXX[i]+c2LstXX[i])/2;
1478 y = (c1LstYY[i]+c2LstYY[i])/2;
1479 z = (c1LstZZ[i]+c2LstZZ[i])/2;
1482 p[0] = x * aux_mesh_spc[0];
1483 p[1] = y * aux_mesh_spc[1];
1484 p[2] = z * aux_mesh_spc[2];
1485 points->GetPoint( pointLocator->FindClosestPoint(p) , pM );
1486 x = pM[0] / aux_mesh_spc[0];
1487 y = pM[1] / aux_mesh_spc[1];
1488 z = pM[2] / aux_mesh_spc[2];
1492 if (pointLocator!=NULL) { pointLocator->Delete(); }
1493 RefreshCollectionText();
1494 RefreshColourCollection();
1495 } // if size of c1LstX c2LstX
1499 //------------------------------------------------------------------------
1500 void WidgetShowNPoints::DeleteCollection_()
1502 if ( lstModelShowNPoints.size()>1 )
1504 DeleteAllPoints_(); // Actual Collection
1505 lstModelShowNPoints.erase( lstModelShowNPoints.begin()+mActualCollection );
1506 lstViewShowNPoints.erase( lstViewShowNPoints.begin()+mActualCollection );
1507 if ( mActualCollection>=lstModelShowNPoints.size() )
1509 mActualCollection--;
1512 DeleteAllPoints_(); // Actual Collection
1516 //------------------------------------------------------------------------
1517 void WidgetShowNPoints::OnDeleteCollection_()
1519 DeleteCollection_();
1521 GetViewShowNPoints()->Render();
1522 RefreshCollectionText();
1523 RefreshColourCollection();
1525 UndoRedo_SaveCollection();
1528 //------------------------------------------------------------------------
1529 void WidgetShowNPoints::OnDeleteCollection(wxCommandEvent &event)
1531 OnDeleteCollection_();
1534 //------------------------------------------------------------------------
1535 void WidgetShowNPoints::ResetCollections_()
1537 int i,size=lstModelShowNPoints.size();
1538 for (i=0;i<size;i++)
1540 DeleteCollection_();
1542 GetViewShowNPoints()->Render();
1543 RefreshCollectionText();
1544 RefreshColourCollection();
1549 //------------------------------------------------------------------------
1550 void WidgetShowNPoints::OnResetCollections_()
1552 ResetCollections_();
1553 UndoRedo_SaveCollection();
1557 //------------------------------------------------------------------------
1558 void WidgetShowNPoints::OnResetCollections(wxCommandEvent &event)
1560 OnResetCollections_();
1563 //------------------------------------------------------------------------
1564 void WidgetShowNPoints::OnBackCollection(wxCommandEvent &event)
1566 mActualCollection--;
1567 if ( mActualCollection <0 )
1569 // mActualCollection=0;
1570 mActualCollection = lstModelShowNPoints.size()-1;
1572 RefreshCollectionText();
1573 RefreshColourCollection();
1575 UndoRedo_SaveCollection();
1578 //------------------------------------------------------------------------
1579 void WidgetShowNPoints::OnNextCollection(wxCommandEvent &event)
1581 mActualCollection++;
1582 if ( mActualCollection >=lstModelShowNPoints.size() )
1584 // mActualCollection = lstModelShowNPoints.size()-1;
1585 mActualCollection = 0;
1586 } //if mActualCollection >= size
1587 RefreshCollectionText();
1588 RefreshColourCollection();
1590 UndoRedo_SaveCollection();
1593 //------------------------------------------------------------------------
1594 void WidgetShowNPoints::DetectCollectionActive()
1597 int i,size=lstModelShowNPoints.size();
1598 for (i=0;i<size;i++)
1600 id = lstModelShowNPoints[i]->IdInsidePoint();
1603 mActualCollection=i;
1606 RefreshCollectionText();
1607 RefreshColourCollection();
1610 //------------------------------------------------------------------------
1611 void WidgetShowNPoints::RefreshColourCollection()
1614 std::vector<double> colourAll;
1615 colourAll.push_back(1);
1616 colourAll.push_back(0);
1617 colourAll.push_back(0);
1618 std::vector<double> colourActualGroup;
1619 colourActualGroup.push_back(1);
1620 colourActualGroup.push_back(1);
1621 colourActualGroup.push_back(0);
1623 // For all collections
1624 SetColour( colourAll );
1625 int i,size=lstViewShowNPoints.size();
1626 for (i=0;i<size;i++)
1628 lstViewShowNPoints[i] -> mcolour = colourAll;
1629 lstViewShowNPoints[i] -> ratioRadio = 1;
1630 lstViewShowNPoints[i]->RefreshEachPoint();
1633 // Actual collection
1634 lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
1635 lstViewShowNPoints[mActualCollection] -> ratioRadio = 1.1;
1636 lstViewShowNPoints[mActualCollection] -> RefreshEachPoint();
1639 int curPnt = lstModelShowNPoints[mActualCollection] -> GetIdCurrentPoint();
1640 size=lstModelShowNPoints[mActualCollection]->GetLstPointsSize();
1641 if ((curPnt>=0) && (curPnt<size ) )
1643 std::vector<double> colourActualPoint;
1644 colourActualPoint.push_back(0);
1645 colourActualPoint.push_back(0);
1646 colourActualPoint.push_back(1);
1647 double radio = GetModelShowNPoints()->GetRadio();
1648 lstViewShowNPoints[mActualCollection] -> mcolour = colourActualPoint;
1649 lstViewShowNPoints[mActualCollection]->RefreshPoint( curPnt );
1650 lstViewShowNPoints[mActualCollection] -> mcolour = colourActualGroup;
1652 lstViewShowNPoints[mActualCollection] -> renderer->GetRenderWindow()->Render();
1655 //------------------------------------------------------------------------
1656 void WidgetShowNPoints::RefreshCollectionText()
1658 if ((mtype==4) && (txtNrCollections!=NULL)) // Just for Collection interface
1661 strTmp.Printf(_T("%d / %d "), (int)mActualCollection+1, (int)lstModelShowNPoints.size() );
1662 txtNrCollections->SetLabel( strTmp );
1668 //------------------------------------------------------------------------
1669 void WidgetShowNPoints::OnSaveCollections_( std::string filename )
1672 ff = fopen( filename.c_str() , "w+" );
1675 int i,size = lstModelShowNPoints.size();
1676 fprintf(ff,"NumberOfGroups %d \n",size);
1677 for (i=0 ; i<size ; i++)
1679 lstModelShowNPoints[i]->SavePoints_(ff);
1683 printf("WidgetShowNPoints::Save Groups Points ...Error... creating file \n");
1689 //------------------------------------------------------------------------
1690 void WidgetShowNPoints::OnSaveCollections(wxCommandEvent &event)
1692 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1693 #if wxMAJOR_VERSION <= 2
1694 wxFileDialog* FD = new wxFileDialog( 0,
1695 _T("Save groups of points .."),
1698 _T("(*.xls)|*.xls"),
1699 wxSAVE | wxOVERWRITE_PROMPT,
1702 wxFileDialog* FD = new wxFileDialog( 0,
1703 _T("Save groups of points .."),
1706 _T("(*.xls)|*.xls"),
1707 wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
1711 int result_FD = FD->ShowModal();
1712 // This line is need it by windows //EED
1713 FD->SetReturnCode( result_FD );
1714 if (FD->GetReturnCode()==wxID_OK)
1716 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1717 OnSaveCollections_( filename );
1722 //------------------------------------------------------------------------
1723 void WidgetShowNPoints::OnLoadCollections_( std::string filename )
1725 bool okEraseFirstGroup=false;
1726 if (lstModelShowNPoints.size()==1)
1728 if (GetModelShowNPoints()->GetLstPointsSize()==0) { okEraseFirstGroup=true; }
1730 FILE *ff = fopen( filename.c_str() , "r+" );
1734 int iGroup,sizeGroups;
1735 int iPoint,numberPointsRead;
1737 fscanf(ff," %s %d",chartmp,&sizeGroups);
1738 for (iGroup=0;iGroup<sizeGroups;iGroup++)
1740 mActualCollection = lstModelShowNPoints.size();
1742 int numberPointsRead= lstModelShowNPoints[mActualCollection]->ReadPoints_(ff);
1743 for (i=0;i<numberPointsRead;i++)
1747 GetViewShowNPoints()->AddVtkPoint();
1753 printf("WidgetShowNPoints::Load Group of Points ...Error... reading file");
1755 if (okEraseFirstGroup==true)
1757 mActualCollection=0;
1758 DeleteCollection_();
1759 mActualCollection = lstModelShowNPoints.size()-1;
1761 GetViewShowNPoints()->Render();
1762 RefreshCollectionText();
1763 RefreshColourCollection();
1767 //------------------------------------------------------------------------
1768 void WidgetShowNPoints::OnLoadCollections(wxCommandEvent &event)
1770 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1771 #if wxMAJOR_VERSION <= 2
1772 wxFileDialog* FD = new wxFileDialog( 0,
1773 _T("Load groups of points .."),
1776 _T("(*.xls)|*.xls"),
1777 wxOPEN | wxFILE_MUST_EXIST,
1780 wxFileDialog* FD = new wxFileDialog( 0,
1781 _T("Load groups of points .."),
1784 _T("(*.xls)|*.xls"),
1785 wxFD_OPEN | wxFD_FILE_MUST_EXIST,
1788 int result_FD = FD->ShowModal();
1789 // This line is need it by windows //EED
1790 FD->SetReturnCode( result_FD );
1791 if (FD->GetReturnCode()==wxID_OK)
1793 std::string filename= (const char*) ( FD->GetPath().mb_str() );
1794 OnLoadCollections_( filename );
1795 UndoRedo_SaveCollection();
1799 //------------------------------------------------------------------------
1800 void WidgetShowNPoints::GetCollectionPoint(int idCol,int idPoint, double *pPoint)
1803 lstModelShowNPoints[idCol]->GetIdPoint(idPoint,&x,&y,&z);
1808 //------------------------------------------------------------------------
1809 void WidgetShowNPoints::SetCollectionPoint(int idCol, int idPoint, std::vector<double> modPoint)
1811 if(idCol >= 0 && idCol < lstModelShowNPoints.size())
1813 lstModelShowNPoints[idCol]->SetPointById(idPoint, modPoint);
1814 lstViewShowNPoints[idCol]->RefreshPoint(idPoint);
1817 printf("WidgetShowNPoints::SetCollectionPoint ...Error... Invalid collection, out of range");
1820 //------------------------------------------------------------------------
1821 std::vector<double> WidgetShowNPoints::GetLstPointsX()
1825 return GetModelShowNPoints()->GetLstPointsX();
1827 std::vector<double> lst;
1829 int iG,sG=lstModelShowNPoints.size();
1830 for (iG=0 ; iG<sG ; iG++)
1832 std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsX();
1834 for (iP=0 ; iP<s ; iP++)
1836 lst.push_back( lstTmp[iP] );
1843 //------------------------------------------------------------------------
1844 std::vector<double> WidgetShowNPoints::GetLstPointsY()
1848 return GetModelShowNPoints()->GetLstPointsY();
1850 std::vector<double> lst;
1852 int iG,sG=lstModelShowNPoints.size();
1853 for (iG=0 ; iG<sG ; iG++)
1855 std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsY();
1857 for (iP=0 ; iP<s ; iP++)
1859 lst.push_back( lstTmp[iP] );
1866 //------------------------------------------------------------------------
1867 std::vector<double> WidgetShowNPoints::GetLstPointsZ()
1871 return GetModelShowNPoints()->GetLstPointsZ();
1873 std::vector<double> lst;
1875 int iG,sG=lstModelShowNPoints.size();
1876 for (iG=0 ; iG<sG ; iG++)
1878 std::vector<double> lstTmp = lstModelShowNPoints[iG]->GetLstPointsZ();
1880 for (iP=0 ; iP<s ; iP++)
1882 lst.push_back( lstTmp[iP] );
1890 //------------------------------------------------------------------------
1891 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
1895 return GetModelShowNPoints()->GetLstLabels();
1897 std::vector< std::string > lst;
1899 int iG,sG=lstModelShowNPoints.size();
1900 for (iG=0 ; iG<sG ; iG++)
1902 std::vector< std::string > lstTmp = lstModelShowNPoints[iG]->GetLstLabels();
1904 for (iP=0 ; iP<s ; iP++)
1906 lst.push_back( lstTmp[iP] );
1913 //------------------------------------------------------------------------
1914 std::vector<int> WidgetShowNPoints::GetLstIndexs()
1916 std::vector<int> lstIndexs;
1919 lstIndexs.push_back( GetModelShowNPoints()->GetLstPointsSize() );
1921 int iG,sG=lstModelShowNPoints.size();
1922 for (iG=0 ; iG<sG ; iG++)
1924 lstIndexs.push_back( lstModelShowNPoints[iG]->GetLstPointsSize() );
1929 //------------------------------------------------------------------------
1930 int WidgetShowNPoints::GetLstModelShowNPointsSize()
1932 return lstModelShowNPoints.size();
1935 //------------------------------------------------------------------------
1936 void WidgetShowNPoints::InvertLstPoints_()
1938 int i,size=lstModelShowNPoints.size();
1940 for (i=0 ; i < size ; i++)
1942 lstModelShowNPoints[i]->InversLstPoints();
1946 ModelShowNPoints* tmpModel;
1948 for (i=0 ; i < size2 ; i++)
1950 tmpModel = lstModelShowNPoints[i];
1951 lstModelShowNPoints[i] = lstModelShowNPoints[size-1-i];
1952 lstModelShowNPoints[size-1-i] = tmpModel;
1957 //------------------------------------------------------------------------
1958 void WidgetShowNPoints::OnInvertLstPoints_()
1960 StopAutoAddPoints();
1964 UndoRedo_SaveCollection();
1968 //------------------------------------------------------------------------
1969 std::string WidgetShowNPoints::GetUndoRedoFileName()
1972 sprintf(buff,"%p_%d",this, idUndoRedo);
1973 return UndoRedoDir+"/"+"UndoRedo_collection_" + std::string(buff) + ".undoredo";
1977 //------------------------------------------------------------------------
1978 void WidgetShowNPoints::OnUndo(wxCommandEvent &event)
1980 ResetCollections_();
1981 // if (idUndoRedo==maxUndoRedo+1)
1984 // } // if idUndoRedo+1
1991 OnLoadCollections_( GetUndoRedoFileName() );
1997 //------------------------------------------------------------------------
1998 void WidgetShowNPoints::OnRedo(wxCommandEvent &event)
2000 if (idUndoRedo>maxUndoRedo)
2002 idUndoRedo=maxUndoRedo+1;
2004 ResetCollections_();
2005 OnLoadCollections_( GetUndoRedoFileName() );
2010 //------------------------------------------------------------------------
2011 void WidgetShowNPoints::UndoRedo_SaveCollection()
2013 OnSaveCollections_( GetUndoRedoFileName() );
2014 maxUndoRedo = idUndoRedo;
2018 //------------------------------------------------------------------------
2019 void WidgetShowNPoints::SetAuxMesh(vtkPolyData* mesh, std::vector<double> spc, std::vector<double> params)
2023 if (params.size()==1)
2025 aux_mesh_type = params[0];