]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuShowNPoints.cxx
b33daa47a187c337002ca084e8fcf6f5cf680a34
[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 //------------------------------------------------------------------------
168 void WidgetShowNPoints::SetRadio(double radio)
169 {
170         this->mradio=radio;
171         //NTU: For Slider
172         sdrRadio->SetValue(this->mradio);
173 }
174
175 //------------------------------------------------------------------------
176 std::vector<int> WidgetShowNPoints::GetLstPointsX()
177 {
178         return lstPointsX;
179 }
180
181 //------------------------------------------------------------------------
182 std::vector<int> WidgetShowNPoints::GetLstPointsY()
183 {
184         return lstPointsY;
185 }
186
187 //------------------------------------------------------------------------
188 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
189 {
190         return lstPointsZ;
191 }
192
193 //------------------------------------------------------------------------
194         std::vector<std::string> WidgetShowNPoints::GetLstLabels()
195 {
196         return lstLabels;
197 }
198
199 //------------------------------------------------------------------------
200 void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
201 {
202         mpoint = ppoint;
203 }
204
205 //------------------------------------------------------------------------
206 void WidgetShowNPoints::SetColour(std::vector<double> colour)
207 {
208         this->mcolour = colour;
209 }
210
211 //------------------------------------------------------------------------
212 void WidgetShowNPoints::SetOpacity(double opacity)
213 {
214         this->mopacity=opacity;
215         //NTU: For Slider
216         sdrOpacity->SetValue(this->mopacity*100.0);
217 }
218
219 //------------------------------------------------------------------------
220 void WidgetShowNPoints::SetImage(vtkImageData *image)
221 {
222         this->mimage=image;
223 }
224
225 //------------------------------------------------------------------------
226 void  WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
227 {
228         this->renderer  = renderer;
229 }
230
231 //------------------------------------------------------------------------
232
233 std::string WidgetShowNPoints::CleanSpaces(std::string ss)
234 {
235         int i;
236         while( (i=ss.find(32))>=0 )
237         {
238                 ss.replace(i,1,"_");
239         }
240         return ss;
241 }
242
243         
244 //------------------------------------------------------------------------
245         
246 void WidgetShowNPoints::RefreshPoint(int id)
247 {
248         int x = lstPointsX[id];
249         int y = lstPointsY[id];
250         int z = lstPointsZ[id];
251         
252         double spc[3];
253         mimage->GetSpacing(spc);
254         
255         lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
256         lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
257         lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
258         
259         lstActorsText[id]->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
260 }
261         
262         
263 //------------------------------------------------------------------------
264 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
265 {
266         lstPointsX.push_back( x );
267         lstPointsY.push_back( y );
268         lstPointsZ.push_back( z );
269
270         std::string strLabel = CleanSpaces(  label );
271
272         lstLabels.push_back( strLabel );
273
274         // Sphere
275         vtkSphereSource *vtksphere              = vtkSphereSource::New();
276         vtksphere->SetThetaResolution (20);
277         vtksphere->SetPhiResolution (20);
278         vtksphere->SetRadius( mradio  );
279
280         //NTU: For updating points
281
282         lstSourceSphere.push_back(vtksphere);
283
284         vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
285         sphereMapper->SetInput( vtksphere->GetOutput() );
286         vtkActor *sphereActor   = vtkActor::New();
287         sphereActor->SetMapper(sphereMapper);
288         sphereActor->SetOrigin(0, 0, 0);
289
290 /*EED Borrame
291         double spc[3];
292         if(mimage==NULL){
293                 wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
294                 dialog.ShowModal();
295                 return;
296         }
297         mimage->GetSpacing(spc);
298         sphereActor->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
299         sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
300         sphereActor->GetProperty()->SetOpacity( mopacity );
301 */
302
303         lstActorsSphere.push_back(sphereActor);
304         if(renderer==NULL){
305                 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
306                 dialog.ShowModal();             
307                 return;
308         }
309         renderer->AddActor( sphereActor );
310
311         // Actor
312         vtkTextActor3D *textActor = vtkTextActor3D::New();
313 /* EED Borrame  
314         textActor->SetPosition(  mradio+spc[0]*x , spc[1]*y , spc[2]*z );
315 */ 
316         textActor->SetInput( strLabel.c_str()  );
317         renderer->AddActor( textActor );
318         lstActorsText.push_back(textActor);
319
320         RefreshPoint(lstPointsX.size()-1);
321 }
322
323 //------------------------------------------------------------------------
324 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
325 {
326         if(mimage==NULL){
327                 wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
328                 dialog.ShowModal();
329                 return;
330         }
331         
332         if (this->renderer!=NULL){
333                 if (mpoint.size()==3){
334                         AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
335                         SetOutputBox();
336                 } else {//mpoint.size
337                         printf("creaMaracasVisu::ShowNPoints (not match point) \n");
338                 }
339         } // renderer
340 }
341
342 //------------------------------------------------------------------------
343         void WidgetShowNPoints::SetOutputBox()
344         {
345                 renderer->GetRenderWindow()->Render();
346                 wxString strTmp;
347                 strTmp.Printf(_T("Nbr of points: %d"), (int)(lstPointsX.size()) );
348                 txtNrPoints->SetLabel(  strTmp );
349
350                 //--BBTK
351                 mbbShowNPoints->bbSetOutputlstPointsX( lstPointsX );
352                 mbbShowNPoints->bbSetOutputlstPointsY( lstPointsY );
353                 mbbShowNPoints->bbSetOutputlstPointsZ( lstPointsZ );
354                 mbbShowNPoints->bbSetOutputlstLabels( lstLabels );
355                 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
356                 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
357                 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
358                 mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));
359         }
360
361 //------------------------------------------------------------------------
362         void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
363         {
364                 wxFileDialog* FD = new wxFileDialog( 0,
365                                             _T("Save points .."),
366                                             _T(""),
367                                             _T(""),
368                                             _T("(*.xls)|*.xls"),
369                                             wxSAVE | wxOVERWRITE_PROMPT,
370                                             wxDefaultPosition);
371                 //EED
372
373                 int result_FD = FD->ShowModal();
374                 std::string tmpLabel;
375                 
376                 // This line is need it by windows //EED
377                 FD->SetReturnCode( result_FD );
378
379                 if (FD->GetReturnCode()==wxID_OK)
380                 {
381                         FILE *ff;
382                         std::string filename= (const char*) ( FD->GetPath().mb_str() );
383                         ff = fopen( filename.c_str() , "w+" );
384                         if (ff!=NULL)
385                         {
386                                 int i , size = (int) (lstActorsSphere.size());
387                                 fprintf(ff,"NumberOfPoints %d \n",size);
388                                 fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
389                                 int x, y, z;
390                                 double value;
391                                 for (i=0; i<size; i++)
392                                 {
393                                         x=lstPointsX[i];
394                                         y=lstPointsY[i];
395                                         z=lstPointsZ[i];
396                                         value= mimage->GetScalarComponentAsDouble(x,y,z,0);
397                                         if (lstLabels[i]!="") 
398                                         {
399                                                 tmpLabel=lstLabels[i];
400                                         } else{
401                                             tmpLabel="<_VOID_>";
402                                         }
403                                         fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value  , tmpLabel.c_str());
404                                 } // for
405                                 fclose(ff);
406                         } else {   // else ff
407                                 printf("WidgetShowNPoints::OnSavePoints  ...Error... creating file");
408                         } //ff
409                 }       // dialog box
410         }
411
412 //------------------------------------------------------------------------
413         void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
414         {
415                 wxFileDialog* FD = new wxFileDialog( 0,
416                                              _T("Load points .."),
417                                              _T(""),
418                                              _T(""),
419                                              _T("(*.xls)|*.xls"),
420                                              wxOPEN | wxFILE_MUST_EXIST,
421                                              wxDefaultPosition);
422                 //EED
423
424                 int result_FD = FD->ShowModal();
425
426                 // This line is need it by windows //EED
427                 FD->SetReturnCode( result_FD );
428
429                 if (FD->GetReturnCode()==wxID_OK)
430                 {
431                         FILE *ff;
432                         std::string filename= (const char*) ( FD->GetPath().mb_str() );
433                         ff = fopen( filename.c_str() , "r+" );
434                         if (ff!=NULL)
435                         {
436                                 int i,size;
437                                 char chartmp[256];
438                                 fscanf(ff," %s %d",chartmp,&size);
439                                 fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp );
440
441                                 float value;
442                                 int x,y,z;
443                                 for (i=0; i<size; i++)
444                                 {
445                                         fscanf(ff,"%d%d%d%f%s",&x,&y,&z,&value,chartmp );  // x,y,z,value,label
446                                         if (strcmp(chartmp,"<_VOID_>")==0) { strcpy(chartmp,""); }
447                                         AddPoint(x,y,z, chartmp );
448                                 }
449                                 SetOutputBox();
450                                 fclose(ff);
451                         } else {   // else ff
452                                 printf("WidgetShowNPoints::OnLoadPoints  ...Error... reading file");
453                         } //ff
454                 }       // dialog box
455
456
457         }
458
459 //------------------------------------------------------------------------
460
461         int WidgetShowNPoints::GetNearestPoint()
462         {
463                 int id=-1;
464                 int i, size=(int)(lstActorsSphere.size());
465                 double radioMin=10000000;
466                 
467                 if(mimage ==NULL){                      
468                         wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
469                         diag->ShowModal();
470                         return -1;
471                 }else{
472                         
473                         for ( i=0  ; i<size; i++ )
474                         {
475                                 double rx =  mpoint[0] - lstPointsX [i];
476                                 double ry =  mpoint[1] - lstPointsY [i];
477                                 double rz =  mpoint[2] - lstPointsZ [i];
478                                 double radio = rx*rx + ry*ry + rz*rz;
479                                 if ( radio <= radioMin)
480                                 {
481                                         radioMin=radio;
482                                         id=i;
483                                 }       // if
484                         } // for
485                         
486                         return id;
487                 }
488         }
489
490         
491         //------------------------------------------------------------------------
492         void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
493         {
494                 int id=GetNearestPoint();
495                 if((id==-1) && (mbbShowNPoints->bbGetInputType()==1))
496                 {
497                         id=0;
498                         AddPoint(0,0,0,"");
499                         SetOutputBox();
500                 }
501                 
502                 
503                 if (id>=0)
504                 {
505                         printf("WidgetShowNPoints::OnSetPoint \n");
506                         lstPointsX[id] = mpoint[0];
507                         lstPointsY[id] = mpoint[1];
508                         lstPointsZ[id] = mpoint[2];             
509                         RefreshPoint(id);
510                         /*EED Borrame
511                          this->lstActorsSphere[id]->SetPosition( spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
512                          this->lstActorsText[id]->SetPosition(  spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
513                          */ 
514                 } // if id
515                 SetOutputBox();
516         }
517         
518         
519         //------------------------------------------------------------------------
520         
521         int WidgetShowNPoints::IdInsidePoint()
522         {
523                 int id=-1;
524                 int i, size=(int)(lstActorsSphere.size());
525                 double spc[3];
526
527                 if(mimage ==NULL){                      
528                         wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
529                         diag->ShowModal();
530                         return -1;
531                 }else{
532
533                         mimage->GetSpacing(spc);
534
535                         for ( i=0  ; i<size; i++ )
536                         {
537                                 double rx =  spc[0]*(mpoint[0] - lstPointsX [i]);
538                                 double ry =  spc[1]*(mpoint[1] - lstPointsY [i]);
539                                 double rz =  spc[2]*(mpoint[2] - lstPointsZ [i]);
540                                 if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
541                                 {
542                                         id=i;
543                                 }       // if
544                         } // for
545
546                         return id;
547                 }
548         }
549
550 //------------------------------------------------------------------------
551         void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
552         {
553                 int id=IdInsidePoint();
554                 if (id>=0)
555                 {
556                         std::string strLabel = CleanSpaces(  (const char*) ( textCtrl->GetValue().mb_str() ) );
557                         lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ;
558                         lstActorsText[id]->SetInput(  lstLabels[id].c_str() );
559                         SetOutputBox();
560                 }
561         }
562
563 //------------------------------------------------------------------------
564         void WidgetShowNPoints::ErasePoint(int id)
565         {
566                 if (this->renderer!=NULL){
567                         if (id>=0){
568                                 renderer->RemoveActor( lstActorsSphere[id] );
569                                 renderer->RemoveActor( lstActorsText[id] );
570                                  lstActorsSphere[id]->Delete();
571                                  lstActorsText[id]->Delete();
572                                  lstSourceSphere[id]->Delete();
573                                 lstActorsSphere.erase( lstActorsSphere.begin()+id );
574                                 lstActorsText.erase( lstActorsText.begin()+id );
575                                 lstSourceSphere.erase( lstSourceSphere.begin()+id );
576
577                                 lstPointsX.erase( lstPointsX.begin()+id );
578                                 lstPointsY.erase( lstPointsY.begin()+id );
579                                 lstPointsZ.erase( lstPointsZ.begin()+id );
580                                 lstLabels.erase( lstLabels.begin()+id );
581
582                                 SetOutputBox();
583
584                         } // if id
585                 } // if renderer
586         }
587
588 //------------------------------------------------------------------------
589         void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
590         {
591                 ErasePoint( IdInsidePoint() );
592         }
593
594 //------------------------------------------------------------------------
595         void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
596         {
597                 ErasePoint(lstActorsSphere.size()-1);
598         }
599
600 //------------------------------------------------------------------------
601 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
602 {
603         int id,size=lstActorsSphere.size();
604         for (id=size-1;id>=0;id--)
605         {
606                 ErasePoint(id);
607         }
608 }
609
610 //NTU: Method for updating points opacity and Radio
611
612 //------------------------------------------------------------------------
613 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
614 {
615         //Difference in Radio for text placement
616         int difradio = sdrRadio->GetValue() - this->mradio;
617         
618         this->mopacity = sdrOpacity->GetValue()/100.0;
619         this->mradio = sdrRadio->GetValue();
620         
621         //NTU refresh the inputs
622         mbbShowNPoints->bbSetInputOpacity(this->mopacity);
623         mbbShowNPoints->bbSetInputRadio(this->mradio);
624
625         int size = (int) this->lstActorsSphere.size();
626         int i;
627         for(i = 0; i < size; i ++)
628         {
629                 this->lstSourceSphere[i]->SetRadius(mradio);
630                 this->lstActorsSphere[i]->GetProperty()->SetOpacity(mopacity);
631                 this->lstActorsText[i]->GetTextProperty()->SetOpacity(mopacity);
632                 this->lstActorsText[i]->SetPosition(this->lstActorsText[i]->GetPosition()[0]+difradio,this->lstActorsText[i]->GetPosition()[1], this->lstActorsText[i]->GetPosition()[2]);
633         }
634
635         //NTU: For updating
636 //EED   SetOutputBox();
637         renderer->GetRenderWindow()->Render();
638
639 }
640
641 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
642 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
643
644 //-----------------------------------------------------------------
645 void ShowNPoints::Process()
646 {
647         if (mwxwidget!=NULL)
648         {
649                 mwxwidget->SetRenderer( bbGetInputRenderer() );
650                 mwxwidget->SetPoint( bbGetInputIn() );
651                 mwxwidget->SetImage( bbGetInputImage() );
652                 mwxwidget->SetColour( bbGetInputColour() );
653                 mwxwidget->SetOpacity( bbGetInputOpacity() );
654                 mwxwidget->SetRadio( bbGetInputRadio() );
655
656                 bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
657                 bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
658                 bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
659                 bbSetOutputlstLabels( mwxwidget->GetLstLabels() );
660
661         } // mwxwidget
662 }
663
664 //-----------------------------------------------------------------
665 void ShowNPoints::CreateWidget(wxWindow* parent)
666 {
667         mwxwidget = new WidgetShowNPoints( parent, this);
668     bbSetOutputWidget( mwxwidget );
669 }
670
671 //-----------------------------------------------------------------
672 void ShowNPoints::bbUserSetDefaultValues()
673 {
674         mwxwidget = NULL;
675
676         bbSetInputRadio(10);
677         bbSetInputOpacity(1);
678
679         std::vector<double> colour;
680         colour.push_back(1.0);
681         colour.push_back(0.0);
682         colour.push_back(0.0);
683         bbSetInputColour(colour);
684
685         bbSetInputImage(NULL);
686         bbSetInputType(0);
687         bbSetInputRenderer(NULL);
688 }
689
690 //-----------------------------------------------------------------
691         void ShowNPoints::bbUserInitializeProcessing()
692         {
693         }
694
695 //-----------------------------------------------------------------
696         void ShowNPoints::bbUserFinalizeProcessing()
697         {
698         }
699
700 //-----------------------------------------------------------------
701
702 }
703 // EO namespace bbcreaMaracasVisu