]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuShowNPoints.cxx
25debba998835ec2288161ba90eb76b10d9a49d3
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuShowNPoints.cxx
1 #include "bbmaracasvisuShowNPoints.h"
2 #include "bbcreaMaracasVisuPackage.h"
3
4 #include "vtkProperty.h"
5 #include "vtkSphereSource.h"
6 #include "vtkPolyDataMapper.h"
7 #include "vtkRenderWindow.h"
8 #include "vtkTextActor3D.h"
9 #include <vtkTextProperty.h>
10
11 namespace bbcreaMaracasVisu
12 {
13
14 //----------------------------------------------------------------------
15   WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent,  bbcreaMaracasVisu::ShowNPoints *box)
16     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
17   {
18     mbbShowNPoints                                      = box;
19     this->renderer                                      = NULL;
20     wxPanel     *panel                                  = this;
21     wxSizer *sizer                                      = NULL;
22
23         if (mbbShowNPoints->bbGetInputType()==0)
24         {
25                 // Widget interface
26                 askPointLabel                                   = new wxStaticText(panel, -1, _T("Point label :")); // JPR
27                 textCtrl                                                = new wxTextCtrl(panel, -1);
28                 wxButton *btnAddPoint                   = new wxButton( panel, -1, _T("Add Point"));
29                 wxButton *btnSetPositionPoint   = new wxButton( panel, -1, _T("Set nearest point"));
30                 wxButton *btnRenamePoint                = new wxButton( panel, -1, _T("Rename point"));
31                 wxButton *btnEraseLastPoint             = new wxButton( panel, -1, _T("Erase Last point"));
32                 wxButton *btnErasePoint                 = new wxButton( panel, -1, _T("Erase point"));
33                 wxButton *btnDeleteAllPoints    = new wxButton( panel, -1, _T("Delete all points"));
34                 wxButton *btnSavePoints                 = new wxButton( panel, -1, _T("Save points"));
35                 wxButton *btnLoadPoints                 = new wxButton( panel, -1, _T("Load points"));
36                 txtNrPoints                                             = new wxStaticText(panel,-1, _T(" "));
37
38                 //NTU: Sliders for opacity and radio change
39                 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T("  Points Opacity  ")));
40                 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
41                 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T("  Points Radio  ")));
42                 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
43
44                 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
45                 //    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
46
47                 Connect(btnAddPoint->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
48                 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
49                 Connect(btnRenamePoint->GetId()         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
50                 Connect(btnEraseLastPoint->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
51                 Connect(btnErasePoint->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
52                 Connect(btnDeleteAllPoints->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
53                 Connect(btnSavePoints->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
54                 Connect(btnLoadPoints->GetId()          , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
55
56                 //NTU: Slider events
57                 Connect(sdrOpacity->GetId()                     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
58                 Connect(sdrRadio->GetId()                       , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
59
60                 sizer1->Add(askPointLabel); // JPR
61                 sizer1->Add(textCtrl);
62                 sizer1->Add(btnAddPoint);
63                 sizer1->Add(btnSetPositionPoint);
64                 sizer1->Add(btnRenamePoint);
65                 sizer1->Add(btnErasePoint);
66                 sizer1->Add(btnEraseLastPoint);
67                 sizer1->Add(btnDeleteAllPoints);
68                 sizer1->Add(txtNrPoints);
69                 sizer1->Add(txOpacity);
70                 sizer1->Add(sdrOpacity,1,wxGROW );
71                 sizer1->Add(txRadio);
72                 sizer1->Add(sdrRadio,1,wxGROW );
73                 sizer1->Add(btnSavePoints);
74                 sizer1->Add(btnLoadPoints);
75                 sizer = sizer1;
76         }
77
78           if (mbbShowNPoints->bbGetInputType()==1)
79           {
80                   // Widget interface
81                   wxButton *btnSetPositionPoint         = new wxButton( panel, -1, _T("Set nearest point"));
82                   txtNrPoints                                           = new wxStaticText(panel,-1, _T(" "));
83
84                   //NTU: Sliders for opacity and radio change
85                   wxStaticText* txOpacity               = new wxStaticText(this, -1, wxString(_T("  Points Opacity  ")));
86                   sdrOpacity                                    = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
87                   wxStaticText* txRadio                 = new wxStaticText(this, -1, wxString(_T("  Points Radio  ")));
88                   sdrRadio                                              = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
89                   wxFlexGridSizer *sizer1               = new wxFlexGridSizer(1);
90                   Connect(btnSetPositionPoint->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
91                   Connect(sdrOpacity->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
92                   Connect(sdrRadio->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
93
94                   sizer1->Add(btnSetPositionPoint);
95                   sizer1->Add(txtNrPoints);
96                   sizer1->Add(txOpacity);
97                   sizer1->Add(sdrOpacity,1,wxGROW );
98                   sizer1->Add(txRadio);
99                   sizer1->Add(sdrRadio,1,wxGROW );
100                   sizer = sizer1;
101           }
102     
103         if (mbbShowNPoints->bbGetInputType() == 2) {
104             askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
105             
106             wxButton *btnAddPoint = new wxButton(panel, -1,        _T("      Add  Point      "));
107             wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T("      Delete All      "));
108             wxStaticText* spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
109             textCtrl = new wxTextCtrl(panel, -1);
110             
111             wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
112
113             Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
114             Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
115             
116             sizer1->Add(askPointLabel); 
117             sizer1->Add(btnAddPoint);
118             sizer1->Add(btnDeleteAllPoints);
119             sizer1->Add(spacer);
120             sizer1->Add(textCtrl);
121             
122             sdrOpacity = new wxSlider();
123             sdrRadio = new wxSlider();
124             
125             txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));  
126             
127             sizer = sizer1;
128         } 
129           if (sizer!=NULL)
130           {
131                   panel->SetSizer(sizer);
132                   panel->SetAutoLayout(true);
133                   panel->Layout();
134           }
135 }
136
137 //------------------------------------------------------------------------
138 WidgetShowNPoints::~WidgetShowNPoints()
139 {
140 }
141
142 void WidgetShowNPoints::SetRadio(double radio)
143 {
144         this->mradio=radio;
145         //NTU: For Slider
146         sdrRadio->SetValue(this->mradio);
147 }
148
149 //------------------------------------------------------------------------
150 std::vector<int> WidgetShowNPoints::GetLstPointsX()
151 {
152         return lstPointsX;
153 }
154
155 //------------------------------------------------------------------------
156 std::vector<int> WidgetShowNPoints::GetLstPointsY()
157 {
158         return lstPointsY;
159 }
160
161 //------------------------------------------------------------------------
162 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
163 {
164         return lstPointsZ;
165 }
166
167 //------------------------------------------------------------------------
168         std::vector<std::string> WidgetShowNPoints::GetLstLabels()
169 {
170         return lstLabels;
171 }
172
173 //------------------------------------------------------------------------
174 void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
175 {
176         mpoint = ppoint;
177 }
178
179 //------------------------------------------------------------------------
180 void WidgetShowNPoints::SetColour(std::vector<double> colour)
181 {
182         this->mcolour = colour;
183 }
184
185 //------------------------------------------------------------------------
186 void WidgetShowNPoints::SetOpacity(double opacity)
187 {
188         this->mopacity=opacity;
189         //NTU: For Slider
190         sdrOpacity->SetValue(this->mopacity/100.0);
191 }
192
193 //------------------------------------------------------------------------
194 void WidgetShowNPoints::SetImage(vtkImageData *image)
195 {
196         this->mimage=image;
197 }
198
199 //------------------------------------------------------------------------
200 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
201 {
202         this->renderer  = renderer;
203 }
204
205 //------------------------------------------------------------------------
206
207 std::string WidgetShowNPoints::CleanSpaces(std::string ss)
208 {
209         int i;
210         while( (i=ss.find(32))>=0 )
211         {
212                 ss.replace(i,1,"_");
213         }
214         return ss;
215 }
216
217         
218 //------------------------------------------------------------------------
219         
220 void WidgetShowNPoints::RefreshPoint(int id)
221 {
222         int x = lstPointsX[id];
223         int y = lstPointsY[id];
224         int z = lstPointsZ[id];
225         
226         double spc[3];
227         mimage->GetSpacing(spc);
228         
229         lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
230         lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
231         lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
232         
233         lstActorsText[id]->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
234 }
235         
236         
237 //------------------------------------------------------------------------
238 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
239 {
240         lstPointsX.push_back( x );
241         lstPointsY.push_back( y );
242         lstPointsZ.push_back( z );
243
244         std::string strLabel = CleanSpaces(  label );
245
246         lstLabels.push_back( strLabel );
247
248         // Sphere
249         vtkSphereSource *vtksphere              = vtkSphereSource::New();
250         vtksphere->SetThetaResolution (20);
251         vtksphere->SetPhiResolution (20);
252         vtksphere->SetRadius( mradio  );
253
254         //NTU: For updating points
255
256         lstSourceSphere.push_back(vtksphere);
257
258         vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
259         sphereMapper->SetInput( vtksphere->GetOutput() );
260         vtkActor *sphereActor   = vtkActor::New();
261         sphereActor->SetMapper(sphereMapper);
262         sphereActor->SetOrigin(0, 0, 0);
263
264 /*EED Borrame
265         double spc[3];
266         if(mimage==NULL){
267                 wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
268                 dialog.ShowModal();
269                 return;
270         }
271         mimage->GetSpacing(spc);
272         sphereActor->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
273         sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
274         sphereActor->GetProperty()->SetOpacity( mopacity );
275 */
276
277         lstActorsSphere.push_back(sphereActor);
278         if(renderer==NULL){
279                 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
280                 dialog.ShowModal();             
281                 return;
282         }
283         renderer->AddActor( sphereActor );
284
285         // Actor
286         vtkTextActor3D *textActor = vtkTextActor3D::New();
287 /* EED Borrame  
288         textActor->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
289 */ 
290         textActor->SetInput( strLabel.c_str()  );
291         renderer->AddActor( textActor );
292         lstActorsText.push_back(textActor);
293
294         RefreshPoint(lstPointsX.size()-1);
295         SetOutputBox();
296 }
297
298 //------------------------------------------------------------------------
299 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
300 {
301         if(mimage==NULL){
302                 wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
303                 dialog.ShowModal();
304                 return;
305         }
306         
307         if (this->renderer!=NULL){
308                 if (mpoint.size()==3){
309                         AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
310                 } else {//mpoint.size
311                         printf("creaMaracasVisu::ShowNPoints (not match point) \n");
312                 }
313         } // renderer
314 }
315
316 //------------------------------------------------------------------------
317         void WidgetShowNPoints::SetOutputBox()
318         {
319                 renderer->GetRenderWindow()->Render();
320                 wxString strTmp;
321                 strTmp.Printf(_T("Nbr of points: %d"), (int)(lstPointsX.size()) );
322                 txtNrPoints->SetLabel(  strTmp );
323
324                 //--BBTK
325                 mbbShowNPoints->bbSetOutputlstPointsX( lstPointsX );
326                 mbbShowNPoints->bbSetOutputlstPointsY( lstPointsY );
327                 mbbShowNPoints->bbSetOutputlstPointsZ( lstPointsZ );
328                 mbbShowNPoints->bbSetOutputlstLabels( lstLabels );
329                 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
330                 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
331                 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
332                 mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));
333         }
334
335 //------------------------------------------------------------------------
336         void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
337         {
338                 wxFileDialog* FD = new wxFileDialog( 0,
339                                             _T("Save points .."),
340                                             _T(""),
341                                             _T(""),
342                                             _T("(*.xls)|*.xls"),
343                                             wxSAVE | wxOVERWRITE_PROMPT,
344                                             wxDefaultPosition);
345                 //EED
346
347                 int result_FD = FD->ShowModal();
348                 std::string tmpLabel;
349                 
350                 // This line is need it by windows //EED
351                 FD->SetReturnCode( result_FD );
352
353                 if (FD->GetReturnCode()==wxID_OK)
354                 {
355                         FILE *ff;
356                         std::string filename= (const char*) ( FD->GetPath().mb_str() );
357                         ff = fopen( filename.c_str() , "w+" );
358                         if (ff!=NULL)
359                         {
360                                 int i , size = (int) (lstActorsSphere.size());
361                                 fprintf(ff,"NumberOfPoints %d \n",size);
362                                 fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
363                                 int x, y, z;
364                                 double value;
365                                 for (i=0; i<size; i++)
366                                 {
367                                         x=lstPointsX[i];
368                                         y=lstPointsY[i];
369                                         z=lstPointsZ[i];
370                                         value= mimage->GetScalarComponentAsDouble(x,y,z,0);
371                                         if (lstLabels[i]!="") 
372                                         {
373                                                 tmpLabel=lstLabels[i];
374                                         } else{
375                                             tmpLabel="<_VOID_>";
376                                         }
377                                         fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value  , tmpLabel.c_str());
378                                 } // for
379                                 fclose(ff);
380                         } else {   // else ff
381                                 printf("WidgetShowNPoints::OnSavePoints  ...Error... creating file");
382                         } //ff
383                 }       // dialog box
384         }
385
386 //------------------------------------------------------------------------
387         void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
388         {
389                 wxFileDialog* FD = new wxFileDialog( 0,
390                                              _T("Load points .."),
391                                              _T(""),
392                                              _T(""),
393                                              _T("(*.xls)|*.xls"),
394                                              wxOPEN | wxFILE_MUST_EXIST,
395                                              wxDefaultPosition);
396                 //EED
397
398                 int result_FD = FD->ShowModal();
399
400                 // This line is need it by windows //EED
401                 FD->SetReturnCode( result_FD );
402
403                 if (FD->GetReturnCode()==wxID_OK)
404                 {
405                         FILE *ff;
406                         std::string filename= (const char*) ( FD->GetPath().mb_str() );
407                         ff = fopen( filename.c_str() , "r+" );
408                         if (ff!=NULL)
409                         {
410                                 int i,size;
411                                 char chartmp[256];
412                                 fscanf(ff," %s %d",chartmp,&size);
413                                 fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp );
414
415                                 float value;
416                                 int x,y,z;
417                                 for (i=0; i<size; i++)
418                                 {
419                                         fscanf(ff,"%d%d%d%f%s",&x,&y,&z,&value,chartmp );  // x,y,z,value,label
420                                         if (strcmp(chartmp,"<_VOID_>")==0) { strcpy(chartmp,""); }
421                                         AddPoint(x,y,z, chartmp );
422                                 }
423                                 fclose(ff);
424                         } else {   // else ff
425                                 printf("WidgetShowNPoints::OnLoadPoints  ...Error... reading file");
426                         } //ff
427                 }       // dialog box
428
429
430         }
431
432 //------------------------------------------------------------------------
433
434         int WidgetShowNPoints::GetNearestPoint()
435         {
436                 int id=-1;
437                 int i, size=(int)(lstActorsSphere.size());
438                 double radioMin=10000000;
439                 
440                 if(mimage ==NULL){                      
441                         wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
442                         diag->ShowModal();
443                         return -1;
444                 }else{
445                         
446                         for ( i=0  ; i<size; i++ )
447                         {
448                                 double rx =  mpoint[0] - lstPointsX [i];
449                                 double ry =  mpoint[1] - lstPointsY [i];
450                                 double rz =  mpoint[2] - lstPointsZ [i];
451                                 double radio = rx*rx + ry*ry + rz*rz;
452                                 if ( radio <= radioMin)
453                                 {
454                                         radioMin=radio;
455                                         id=i;
456                                 }       // if
457                         } // for
458                         
459                         return id;
460                 }
461         }
462
463         
464         //------------------------------------------------------------------------
465         void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
466         {
467                 int id=GetNearestPoint();
468                 if((id==-1) && (mbbShowNPoints->bbGetInputType()==1))
469                 {
470                         id=0;
471                         AddPoint(0,0,0,"");
472                 }
473                 
474                 
475                 if (id>=0)
476                 {
477                         printf("WidgetShowNPoints::OnSetPoint \n");
478                         lstPointsX[id] = mpoint[0];
479                         lstPointsY[id] = mpoint[1];
480                         lstPointsZ[id] = mpoint[2];             
481                         RefreshPoint(id);
482                         /*EED Borrame
483                          this->lstActorsSphere[id]->SetPosition( spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
484                          this->lstActorsText[id]->SetPosition(  spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
485                          */ 
486                 } // if id
487                 SetOutputBox();
488         }
489         
490         
491         //------------------------------------------------------------------------
492         
493         int WidgetShowNPoints::IdInsidePoint()
494         {
495                 int id=-1;
496                 int i, size=(int)(lstActorsSphere.size());
497                 double spc[3];
498
499                 if(mimage ==NULL){                      
500                         wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
501                         diag->ShowModal();
502                         return -1;
503                 }else{
504
505                         mimage->GetSpacing(spc);
506
507                         for ( i=0  ; i<size; i++ )
508                         {
509                                 double rx =  spc[0]*(mpoint[0] - lstPointsX [i]);
510                                 double ry =  spc[1]*(mpoint[1] - lstPointsY [i]);
511                                 double rz =  spc[2]*(mpoint[2] - lstPointsZ [i]);
512                                 if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
513                                 {
514                                         id=i;
515                                 }       // if
516                         } // for
517
518                         return id;
519                 }
520         }
521
522 //------------------------------------------------------------------------
523         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
524         {
525                 int id=IdInsidePoint();
526                 if (id>=0)
527                 {
528                         std::string strLabel = CleanSpaces(  (const char*) ( textCtrl->GetValue().mb_str() ) );
529                         lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ;
530                         lstActorsText[id]->SetInput(  lstLabels[id].c_str() );
531                         SetOutputBox();
532                 }
533         }
534
535 //------------------------------------------------------------------------
536         void WidgetShowNPoints::ErasePoint(int id)
537         {
538                 if (this->renderer!=NULL){
539                         if (id>=0){
540                                 renderer->RemoveActor( lstActorsSphere[id] );
541                                 renderer->RemoveActor( lstActorsText[id] );
542                                  lstActorsSphere[id]->Delete();
543                                  lstActorsText[id]->Delete();
544                                  lstSourceSphere[id]->Delete();
545                                 lstActorsSphere.erase( lstActorsSphere.begin()+id );
546                                 lstActorsText.erase( lstActorsText.begin()+id );
547                                 lstSourceSphere.erase( lstSourceSphere.begin()+id );
548
549                                 lstPointsX.erase( lstPointsX.begin()+id );
550                                 lstPointsY.erase( lstPointsY.begin()+id );
551                                 lstPointsZ.erase( lstPointsZ.begin()+id );
552                                 lstLabels.erase( lstLabels.begin()+id );
553
554                                 SetOutputBox();
555
556                         } // if id
557                 } // if renderer
558         }
559
560 //------------------------------------------------------------------------
561         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
562         {
563                 ErasePoint( IdInsidePoint() );
564         }
565
566 //------------------------------------------------------------------------
567         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
568         {
569                 ErasePoint(lstActorsSphere.size()-1);
570         }
571
572 //------------------------------------------------------------------------
573 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
574 {
575         int id,size=lstActorsSphere.size();
576         for (id=size-1;id>=0;id--)
577         {
578                 ErasePoint(id);
579         }
580 }
581
582 //NTU: Method for updating points opacity and Radio
583
584 //------------------------------------------------------------------------
585 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
586 {
587         //Difference in Radio for text placement
588         int difradio = sdrRadio->GetValue() - this->mradio;
589         
590         this->mopacity = sdrOpacity->GetValue()/100.0;
591         this->mradio = sdrRadio->GetValue();
592         
593         //NTU refresh the inputs
594         mbbShowNPoints->bbSetInputOpacity(this->mopacity);
595         mbbShowNPoints->bbSetInputRadio(this->mradio);
596
597         int size = (int) this->lstActorsSphere.size();
598         int i;
599         for(i = 0; i < size; i ++)
600         {
601                 this->lstSourceSphere[i]->SetRadius(mradio);
602                 this->lstActorsSphere[i]->GetProperty()->SetOpacity(mopacity);
603                 this->lstActorsText[i]->GetTextProperty()->SetOpacity(mopacity);
604                 this->lstActorsText[i]->SetPosition(this->lstActorsText[i]->GetPosition()[0]+difradio,this->lstActorsText[i]->GetPosition()[1], this->lstActorsText[i]->GetPosition()[2]);
605         }
606
607         //NTU: For updating
608         SetOutputBox();
609 }
610
611 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
612 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
613
614 void ShowNPoints::Process()
615 {
616         if (mwxwidget!=NULL)
617         {
618                 mwxwidget->SetRenderer( bbGetInputRenderer() );
619                 mwxwidget->SetPoint( bbGetInputIn() );
620                 mwxwidget->SetImage( bbGetInputImage() );
621                 mwxwidget->SetColour( bbGetInputColour() );
622                 mwxwidget->SetOpacity( bbGetInputOpacity() );
623                 mwxwidget->SetRadio( bbGetInputRadio() );
624
625                 bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
626                 bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
627                 bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
628                 bbSetOutputlstLabels( mwxwidget->GetLstLabels() );
629         } // mwxwidget
630 }
631
632 void ShowNPoints::CreateWidget(wxWindow* parent)
633 {
634         mwxwidget = new WidgetShowNPoints( parent, this);
635     bbSetOutputWidget( mwxwidget );
636 }
637
638 void ShowNPoints::bbUserSetDefaultValues()
639 {
640         mwxwidget = NULL;
641
642         bbSetInputRadio(1);
643         bbSetInputOpacity(1);
644
645         std::vector<double> colour;
646         colour.push_back(1.0);
647         colour.push_back(0.0);
648         colour.push_back(0.0);
649         bbSetInputColour(colour);
650
651         bbSetInputImage(NULL);
652         bbSetInputType(0);
653         bbSetInputRenderer(NULL);
654 }
655
656 //-----------------------------------------------------------------
657         void ShowNPoints::bbUserInitializeProcessing()
658         {
659         }
660
661 //-----------------------------------------------------------------
662         void ShowNPoints::bbUserFinalizeProcessing()
663         {
664         }
665
666 //-----------------------------------------------------------------
667
668 }
669 // EO namespace bbcreaMaracasVisu