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