]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuShowNPoints.cxx
BUG 1610
[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 }
296
297 //------------------------------------------------------------------------
298 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
299 {
300         if(mimage==NULL){
301                 wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
302                 dialog.ShowModal();
303                 return;
304         }
305         
306         if (this->renderer!=NULL){
307                 if (mpoint.size()==3){
308                         AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
309                         SetOutputBox();
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                                 SetOutputBox();
424                                 fclose(ff);
425                         } else {   // else ff
426                                 printf("WidgetShowNPoints::OnLoadPoints  ...Error... reading file");
427                         } //ff
428                 }       // dialog box
429
430
431         }
432
433 //------------------------------------------------------------------------
434
435         int WidgetShowNPoints::GetNearestPoint()
436         {
437                 int id=-1;
438                 int i, size=(int)(lstActorsSphere.size());
439                 double radioMin=10000000;
440                 
441                 if(mimage ==NULL){                      
442                         wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
443                         diag->ShowModal();
444                         return -1;
445                 }else{
446                         
447                         for ( i=0  ; i<size; i++ )
448                         {
449                                 double rx =  mpoint[0] - lstPointsX [i];
450                                 double ry =  mpoint[1] - lstPointsY [i];
451                                 double rz =  mpoint[2] - lstPointsZ [i];
452                                 double radio = rx*rx + ry*ry + rz*rz;
453                                 if ( radio <= radioMin)
454                                 {
455                                         radioMin=radio;
456                                         id=i;
457                                 }       // if
458                         } // for
459                         
460                         return id;
461                 }
462         }
463
464         
465         //------------------------------------------------------------------------
466         void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
467         {
468                 int id=GetNearestPoint();
469                 if((id==-1) && (mbbShowNPoints->bbGetInputType()==1))
470                 {
471                         id=0;
472                         AddPoint(0,0,0,"");
473                         SetOutputBox();
474                 }
475                 
476                 
477                 if (id>=0)
478                 {
479                         printf("WidgetShowNPoints::OnSetPoint \n");
480                         lstPointsX[id] = mpoint[0];
481                         lstPointsY[id] = mpoint[1];
482                         lstPointsZ[id] = mpoint[2];             
483                         RefreshPoint(id);
484                         /*EED Borrame
485                          this->lstActorsSphere[id]->SetPosition( spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
486                          this->lstActorsText[id]->SetPosition(  spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
487                          */ 
488                 } // if id
489                 SetOutputBox();
490         }
491         
492         
493         //------------------------------------------------------------------------
494         
495         int WidgetShowNPoints::IdInsidePoint()
496         {
497                 int id=-1;
498                 int i, size=(int)(lstActorsSphere.size());
499                 double spc[3];
500
501                 if(mimage ==NULL){                      
502                         wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
503                         diag->ShowModal();
504                         return -1;
505                 }else{
506
507                         mimage->GetSpacing(spc);
508
509                         for ( i=0  ; i<size; i++ )
510                         {
511                                 double rx =  spc[0]*(mpoint[0] - lstPointsX [i]);
512                                 double ry =  spc[1]*(mpoint[1] - lstPointsY [i]);
513                                 double rz =  spc[2]*(mpoint[2] - lstPointsZ [i]);
514                                 if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
515                                 {
516                                         id=i;
517                                 }       // if
518                         } // for
519
520                         return id;
521                 }
522         }
523
524 //------------------------------------------------------------------------
525         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
526         {
527                 int id=IdInsidePoint();
528                 if (id>=0)
529                 {
530                         std::string strLabel = CleanSpaces(  (const char*) ( textCtrl->GetValue().mb_str() ) );
531                         lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ;
532                         lstActorsText[id]->SetInput(  lstLabels[id].c_str() );
533                         SetOutputBox();
534                 }
535         }
536
537 //------------------------------------------------------------------------
538         void WidgetShowNPoints::ErasePoint(int id)
539         {
540                 if (this->renderer!=NULL){
541                         if (id>=0){
542                                 renderer->RemoveActor( lstActorsSphere[id] );
543                                 renderer->RemoveActor( lstActorsText[id] );
544                                  lstActorsSphere[id]->Delete();
545                                  lstActorsText[id]->Delete();
546                                  lstSourceSphere[id]->Delete();
547                                 lstActorsSphere.erase( lstActorsSphere.begin()+id );
548                                 lstActorsText.erase( lstActorsText.begin()+id );
549                                 lstSourceSphere.erase( lstSourceSphere.begin()+id );
550
551                                 lstPointsX.erase( lstPointsX.begin()+id );
552                                 lstPointsY.erase( lstPointsY.begin()+id );
553                                 lstPointsZ.erase( lstPointsZ.begin()+id );
554                                 lstLabels.erase( lstLabels.begin()+id );
555
556                                 SetOutputBox();
557
558                         } // if id
559                 } // if renderer
560         }
561
562 //------------------------------------------------------------------------
563         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
564         {
565                 ErasePoint( IdInsidePoint() );
566         }
567
568 //------------------------------------------------------------------------
569         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
570         {
571                 ErasePoint(lstActorsSphere.size()-1);
572         }
573
574 //------------------------------------------------------------------------
575 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
576 {
577         int id,size=lstActorsSphere.size();
578         for (id=size-1;id>=0;id--)
579         {
580                 ErasePoint(id);
581         }
582 }
583
584 //NTU: Method for updating points opacity and Radio
585
586 //------------------------------------------------------------------------
587 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
588 {
589         //Difference in Radio for text placement
590         int difradio = sdrRadio->GetValue() - this->mradio;
591         
592         this->mopacity = sdrOpacity->GetValue()/100.0;
593         this->mradio = sdrRadio->GetValue();
594         
595         //NTU refresh the inputs
596         mbbShowNPoints->bbSetInputOpacity(this->mopacity);
597         mbbShowNPoints->bbSetInputRadio(this->mradio);
598
599         int size = (int) this->lstActorsSphere.size();
600         int i;
601         for(i = 0; i < size; i ++)
602         {
603                 this->lstSourceSphere[i]->SetRadius(mradio);
604                 this->lstActorsSphere[i]->GetProperty()->SetOpacity(mopacity);
605                 this->lstActorsText[i]->GetTextProperty()->SetOpacity(mopacity);
606                 this->lstActorsText[i]->SetPosition(this->lstActorsText[i]->GetPosition()[0]+difradio,this->lstActorsText[i]->GetPosition()[1], this->lstActorsText[i]->GetPosition()[2]);
607         }
608
609         //NTU: For updating
610         SetOutputBox();
611 }
612
613 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
614 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
615
616 void ShowNPoints::Process()
617 {
618         if (mwxwidget!=NULL)
619         {
620                 mwxwidget->SetRenderer( bbGetInputRenderer() );
621                 mwxwidget->SetPoint( bbGetInputIn() );
622                 mwxwidget->SetImage( bbGetInputImage() );
623                 mwxwidget->SetColour( bbGetInputColour() );
624                 mwxwidget->SetOpacity( bbGetInputOpacity() );
625                 mwxwidget->SetRadio( bbGetInputRadio() );
626
627                 bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
628                 bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
629                 bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
630                 bbSetOutputlstLabels( mwxwidget->GetLstLabels() );
631         } // mwxwidget
632 }
633
634 void ShowNPoints::CreateWidget(wxWindow* parent)
635 {
636         mwxwidget = new WidgetShowNPoints( parent, this);
637     bbSetOutputWidget( mwxwidget );
638 }
639
640 void ShowNPoints::bbUserSetDefaultValues()
641 {
642         mwxwidget = NULL;
643
644         bbSetInputRadio(1);
645         bbSetInputOpacity(1);
646
647         std::vector<double> colour;
648         colour.push_back(1.0);
649         colour.push_back(0.0);
650         colour.push_back(0.0);
651         bbSetInputColour(colour);
652
653         bbSetInputImage(NULL);
654         bbSetInputType(0);
655         bbSetInputRenderer(NULL);
656 }
657
658 //-----------------------------------------------------------------
659         void ShowNPoints::bbUserInitializeProcessing()
660         {
661         }
662
663 //-----------------------------------------------------------------
664         void ShowNPoints::bbUserFinalizeProcessing()
665         {
666         }
667
668 //-----------------------------------------------------------------
669
670 }
671 // EO namespace bbcreaMaracasVisu