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