1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "bbmaracasvisuShowNPoints.h"
27 #include "bbcreaMaracasVisuPackage.h"
29 #include "vtkProperty.h"
30 #include "vtkSphereSource.h"
31 #include "vtkPolyDataMapper.h"
32 #include "vtkRenderWindow.h"
33 #include "vtkTextActor3D.h"
34 #include <vtkTextProperty.h>
36 namespace bbcreaMaracasVisu
39 //----------------------------------------------------------------------
40 ModelShowNPoints::ModelShowNPoints()
43 //----------------------------------------------------------------------
45 ModelShowNPoints::~ModelShowNPoints()
49 //------------------------------------------------------------------------
50 void ModelShowNPoints::SetRadio(double radio)
56 //------------------------------------------------------------------------
57 double ModelShowNPoints::GetRadio()
63 //------------------------------------------------------------------------
64 std::vector<int> ModelShowNPoints::GetLstPointsX()
69 //------------------------------------------------------------------------
70 std::vector<int> ModelShowNPoints::GetLstPointsY()
75 //------------------------------------------------------------------------
76 std::vector<int> ModelShowNPoints::GetLstPointsZ()
81 //------------------------------------------------------------------------
82 std::vector<std::string> ModelShowNPoints::GetLstLabels()
87 //------------------------------------------------------------------------
88 void ModelShowNPoints::SetReferencePoint(std::vector<int> ppoint)
90 mReferencePoint = ppoint;
93 //------------------------------------------------------------------------
94 std::vector<int> ModelShowNPoints::GetReferencePoint()
96 return mReferencePoint;
99 //------------------------------------------------------------------------
100 void ModelShowNPoints::SetImage(vtkImageData *image)
106 //------------------------------------------------------------------------
107 std::string ModelShowNPoints::CleanSpaces(std::string ss)
110 while( (i=ss.find(32))>=0 )
117 //------------------------------------------------------------------------
118 void ModelShowNPoints::GetIdPoint(int id, int *x, int *y, int *z)
125 //------------------------------------------------------------------------
126 std::string ModelShowNPoints::GetIdLabel(int id)
128 return lstLabels[id];
131 //------------------------------------------------------------------------
132 vtkImageData *ModelShowNPoints::GetImage()
137 //------------------------------------------------------------------------
138 void ModelShowNPoints::AddPoint(int x, int y, int z, std::string label)
140 lstPointsX.push_back( x );
141 lstPointsY.push_back( y );
142 lstPointsZ.push_back( z );
143 std::string strLabel = CleanSpaces( label );
144 lstLabels.push_back( strLabel );
147 //------------------------------------------------------------------------
148 double ModelShowNPoints::Distance(double dX0, double dY0, double dZ0, double dX1, double dY1, double dZ1)//CFT
150 return sqrt((dX1 - dX0)*(dX1 - dX0) + (dY1 - dY0)*(dY1 - dY0) + (dZ1 - dZ0)*(dZ1 - dZ0));
153 //------------------------------------------------------------------------
154 int ModelShowNPoints::InsertPoint(int x, int y, int z, std::string label)
156 if(lstPointsX.size()>1)
158 std::vector<int> dTotal;
162 //Calcule distance for each pair of points
163 for(int i = 0; i<(int)lstPointsX.size()-1 ; i++)
165 a = Distance(x, y, z, lstPointsX[i], lstPointsY[i], lstPointsZ[i]);
166 b = Distance(x, y, z, lstPointsX[i+1], lstPointsY[i+1], lstPointsZ[i+1]);
168 dTotal.push_back (res);
170 //Gets the smallest distance
171 int smallTMP = dTotal[0];
172 for (int j = 0; j < (int) dTotal.size(); j++)
174 if(dTotal[j]<smallTMP)
181 std::vector<int>::iterator it;
182 //Insert the point in the list of points
183 it = lstPointsX.begin();
184 lstPointsX.insert( it+pos, x );
185 it = lstPointsY.begin();
186 lstPointsY.insert( it+pos, y );
187 it = lstPointsZ.begin();
188 lstPointsZ.insert( it+pos, z );
190 std::string strLabel = CleanSpaces( label );
192 std::vector<std::string>::iterator itS;
193 itS = lstLabels.begin();
194 //Insert Label in list of labels
195 lstLabels.insert( itS+pos, strLabel );
204 //------------------------------------------------------------------------
205 void ModelShowNPoints::SavePoints(std::string filename)
207 std::string tmpLabel;
209 ff = fopen( filename.c_str() , "w+" );
212 int i , size = (int) (lstPointsX.size());
213 fprintf(ff,"NumberOfPoints %d \n",size);
214 fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
217 for (i=0; i<size; i++)
222 value= mimage->GetScalarComponentAsDouble(x,y,z,0);
223 if (lstLabels[i]!="")
225 tmpLabel=lstLabels[i];
229 fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value , tmpLabel.c_str());
233 printf("ModelShowNPoints::SavePoints ...Error... creating file");
237 //------------------------------------------------------------------------
238 int ModelShowNPoints::ReadPoints(std::string filename)
243 ff = fopen( filename.c_str() , "r+" );
246 fscanf(ff," %s %d",chartmp,&size);
247 fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp );
251 for (i=0; i<size; i++)
253 fscanf(ff,"%d%d%d%f%s",&x,&y,&z,&value,chartmp ); // x,y,z,value,label
254 if (strcmp(chartmp,"<_VOID_>")==0) { strcpy(chartmp,""); }
255 AddPoint(x,y,z, chartmp );
259 printf("ModelShowNPoints::LoadPoints ...Error... reading file");
264 //------------------------------------------------------------------------
265 int ModelShowNPoints::GetNearestPoint()
268 int i, size=(int)(lstPointsX.size());
269 double radioMin=10000000;
270 for ( i=0 ; i<size; i++ )
272 double rx = mReferencePoint[0] - lstPointsX [i];
273 double ry = mReferencePoint[1] - lstPointsY [i];
274 double rz = mReferencePoint[2] - lstPointsZ [i];
275 double radio = rx*rx + ry*ry + rz*rz;
276 if ( radio <= radioMin)
285 //------------------------------------------------------------------------
286 int ModelShowNPoints::GetLstPointsSize()
288 return lstPointsX.size();
291 //------------------------------------------------------------------------
292 void ModelShowNPoints::SetPointId_mReferencePoint(int id)
294 lstPointsX[id] = mReferencePoint[0];
295 lstPointsY[id] = mReferencePoint[1];
296 lstPointsZ[id] = mReferencePoint[2];
300 //------------------------------------------------------------------------
301 int ModelShowNPoints::IdInsidePoint()
304 int i, size=(int)(lstPointsX.size());
308 printf("WidgetShowNPoints::IdInsidePoint image not set\n");
311 mimage->GetSpacing(spc);
312 for ( i=0 ; i<size; i++ )
314 double rx = spc[0]*(mReferencePoint[0] - lstPointsX [i]);
315 double ry = spc[1]*(mReferencePoint[1] - lstPointsY [i]);
316 double rz = spc[2]*(mReferencePoint[2] - lstPointsZ [i]);
317 if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
326 //------------------------------------------------------------------------
327 int ModelShowNPoints::RenamePoint(std::string label)
329 int id=IdInsidePoint();
332 std::string strLabel = CleanSpaces( label );
333 lstLabels[id] = strLabel;
338 //----------------------------------------------------------------------
339 void ModelShowNPoints::ErasePoint(int id)
341 lstPointsX.erase( lstPointsX.begin()+id );
342 lstPointsY.erase( lstPointsY.begin()+id );
343 lstPointsZ.erase( lstPointsZ.begin()+id );
344 lstLabels.erase( lstLabels.begin()+id );
349 //----------------------------------------------------------------------
350 //----------------------------------------------------------------------
351 //----------------------------------------------------------------------
352 //----------------------------------------------------------------------
353 //----------------------------------------------------------------------
354 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, bbcreaMaracasVisu::ShowNPoints *box)
355 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
357 mmodelShowNPoints = new ModelShowNPoints();
358 mbbShowNPoints = box;
359 this->renderer = NULL;
360 wxPanel *panel = this;
361 wxSizer *sizer = NULL;
363 if (mbbShowNPoints->bbGetInputType()==0)
366 askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
367 textCtrl = new wxTextCtrl(panel, -1);
368 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
369 wxButton *btnInsertPoint = new wxButton( panel, -1, _T("Insert Point"));//CFT
370 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
371 wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
372 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
373 wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
374 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
375 wxButton *btnSavePoints = new wxButton( panel, -1, _T("Save points"));
376 wxButton *btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
377 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
379 //NTU: Sliders for opacity and radio change
380 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
381 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
382 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
383 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
385 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
386 // sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
388 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
389 Connect(btnInsertPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnInsertPoint);//CFT
390 Connect(btnSetPositionPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
391 Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
392 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
393 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
394 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
395 Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
396 Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
399 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
400 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
402 sizer1->Add(askPointLabel); // JPR
403 sizer1->Add(textCtrl);
404 sizer1->Add(btnAddPoint);
405 sizer1->Add(btnInsertPoint);//CFT
406 sizer1->Add(btnSetPositionPoint);
407 sizer1->Add(btnRenamePoint);
408 sizer1->Add(btnErasePoint);
409 sizer1->Add(btnEraseLastPoint);
410 sizer1->Add(btnDeleteAllPoints);
411 sizer1->Add(txtNrPoints);
412 sizer1->Add(txOpacity);
413 sizer1->Add(sdrOpacity,1,wxGROW );
414 sizer1->Add(txRadio);
415 sizer1->Add(sdrRadio,1,wxGROW );
416 sizer1->Add(btnSavePoints);
417 sizer1->Add(btnLoadPoints);
421 if (mbbShowNPoints->bbGetInputType()==1)
424 wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
425 txtNrPoints = new wxStaticText(panel,-1, _T(" "));
427 //NTU: Sliders for opacity and radio change
428 wxStaticText* txOpacity = new wxStaticText(this, -1, wxString(_T(" Points Opacity ")));
429 sdrOpacity = new wxSlider(this, -1, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
430 wxStaticText* txRadio = new wxStaticText(this, -1, wxString(_T(" Points Radio ")));
431 sdrRadio = new wxSlider(this, -1, 0, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
432 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
433 Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
434 Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
435 Connect(sdrRadio->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
437 sizer1->Add(btnSetPositionPoint);
438 sizer1->Add(txtNrPoints);
439 sizer1->Add(txOpacity);
440 sizer1->Add(sdrOpacity,1,wxGROW );
441 sizer1->Add(txRadio);
442 sizer1->Add(sdrRadio,1,wxGROW );
446 if (mbbShowNPoints->bbGetInputType() == 2)
448 askPointLabel = new wxStaticText(panel, -1, _T("\nPOINT CONTROLS:")); // JPR
449 wxButton *btnAddPoint = new wxButton(panel, -1, _T(" Add Point "));
450 wxButton *btnDeleteAllPoints = new wxButton(panel, -1, _T(" Delete All "));
451 wxStaticText *spacer = new wxStaticText(panel, -1, _T("\n")); // JPR
452 textCtrl = new wxTextCtrl(panel, -1);
453 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
454 Connect(btnAddPoint->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnAddPoint);
455 Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) & WidgetShowNPoints::OnDeleteAllPoints);
456 sizer1->Add(askPointLabel);
457 sizer1->Add(btnAddPoint);
458 sizer1->Add(btnDeleteAllPoints);
460 sizer1->Add(textCtrl);
461 sdrOpacity = new wxSlider();
462 sdrRadio = new wxSlider();
463 txtNrPoints = new wxStaticText(panel, -1, _T("\n\n\n"));
465 } // bbGetInputType 2
469 panel->SetSizer(sizer);
470 panel->SetAutoLayout(true);
475 //------------------------------------------------------------------------
476 WidgetShowNPoints::~WidgetShowNPoints()
480 //------------------------------------------------------------------------
481 ModelShowNPoints* WidgetShowNPoints::GetModelShowNPoints()
483 return mmodelShowNPoints;
487 //------------------------------------------------------------------------
488 void WidgetShowNPoints::SetRadio(double radio)
490 GetModelShowNPoints()->SetRadio(radio);
492 sdrRadio->SetValue(radio);
495 //------------------------------------------------------------------------
496 void WidgetShowNPoints::SetColour(std::vector<double> colour)
498 this->mcolour = colour;
501 //------------------------------------------------------------------------
502 void WidgetShowNPoints::SetImage(vtkImageData* image)
504 GetModelShowNPoints()->SetImage(image);
507 //------------------------------------------------------------------------
508 void WidgetShowNPoints::SetOpacity(double opacity)
510 this->mopacity=opacity;
512 sdrOpacity->SetValue(this->mopacity*100.0);
516 //------------------------------------------------------------------------
517 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
519 this->renderer = renderer;
522 //------------------------------------------------------------------------
524 void WidgetShowNPoints::RefreshPoint(int id)
529 // mimage->GetSpacing(spc);
530 // int x = lstPointsX[id];
531 // int y = lstPointsY[id];
532 // int z = lstPointsZ[id];
534 GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
535 GetModelShowNPoints()->GetImage()->GetSpacing(spc);
536 std::string label = GetModelShowNPoints()->GetIdLabel(id);
537 double radio = GetModelShowNPoints()->GetRadio();
539 lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
540 lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
541 lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
542 lstSourceSphere[id]->SetRadius( radio );
544 lstActorsText[id]->SetInput( label.c_str() );
545 lstActorsText[id]->SetPosition( radio+spc[0]*x , spc[1]*y , spc[2]*z );
548 //------------------------------------------------------------------------
549 void WidgetShowNPoints::RefreshPoints()
551 int id,size=lstActorsSphere.size();
552 for (id=0;id<size;id++)
556 renderer->GetRenderWindow()->Render();
559 //------------------------------------------------------------------------
560 void WidgetShowNPoints::AddVtkPoint()
563 vtkSphereSource *vtksphere = vtkSphereSource::New();
564 vtksphere->SetThetaResolution (20);
565 vtksphere->SetPhiResolution (20);
566 vtksphere->SetRadius( 1 );
567 //NTU: For updating points
568 lstSourceSphere.push_back(vtksphere);
569 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
570 sphereMapper->SetInput( vtksphere->GetOutput() );
571 vtkActor *sphereActor = vtkActor::New();
572 sphereActor->SetMapper(sphereMapper);
573 sphereActor->SetOrigin(0, 0, 0);
575 lstActorsSphere.push_back(sphereActor);
577 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
581 renderer->AddActor( sphereActor );
583 vtkTextActor3D *textActor = vtkTextActor3D::New();
584 // textActor->SetInput( strLabel.c_str() );
585 renderer->AddActor( textActor );
586 lstActorsText.push_back(textActor);
590 //------------------------------------------------------------------------
591 void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
593 GetModelShowNPoints()->AddPoint(x,y,z, label );
595 RefreshPoint(lstActorsSphere.size()-1);
600 //------------------------------------------------------------------------
601 void WidgetShowNPoints::InsertPoint(int x, int y, int z, std::string label)//CFT
606 if ( GetModelShowNPoints()->InsertPoint(x,y,z,label) != -1 )
610 vtkSphereSource *vtksphere = vtkSphereSource::New();
611 vtksphere->SetThetaResolution (20);
612 vtksphere->SetPhiResolution (20);
613 vtksphere->SetRadius( mradio );
615 //NTU: For updating points
616 std::vector<vtkSphereSource*>::iterator itSS;
617 itSS = lstSourceSphere.begin();
618 lstSourceSphere.insert( itSS+pos, vtksphere);
620 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
621 sphereMapper->SetInput( vtksphere->GetOutput() );
622 vtkActor *sphereActor = vtkActor::New();
623 sphereActor->SetMapper(sphereMapper);
624 sphereActor->SetOrigin(0, 0, 0);
626 std::vector<vtkActor*>::iterator itAS;
627 itAS = lstActorsSphere.begin();
628 lstActorsSphere.insert( itAS+pos, sphereActor);
630 wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
634 renderer->AddActor( sphereActor );
637 vtkTextActor3D *textActor = vtkTextActor3D::New();
639 textActor->SetInput( strLabel.c_str() );
640 renderer->AddActor( textActor );
641 std::vector<vtkTextActor3D*>::iterator itTA;
642 itTA = lstActorsText.begin();
643 lstActorsText.insert( itTA+pos , textActor);
648 AddPoint(x,y,z,label);
655 //------------------------------------------------------------------------
656 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
658 if (this->renderer==NULL)
663 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
666 AddPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
668 renderer->GetRenderWindow()->Render();
669 } else {//mpoint.size
670 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
674 //------------------------------------------------------------------------
675 void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
677 if (this->renderer==NULL)
682 std::vector<int> point = GetModelShowNPoints()->GetReferencePoint();
685 InsertPoint(point[0],point[1],point[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
687 } else {//mpoint.size
688 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
693 //------------------------------------------------------------------------
694 void WidgetShowNPoints::SetOutputBox()
696 //EED renderer->GetRenderWindow()->Render();
698 strTmp.Printf(_T("Nbr of points: %d"), GetModelShowNPoints()->GetLstPointsSize() );
699 txtNrPoints->SetLabel( strTmp );
701 mbbShowNPoints->bbSetOutputlstPointsX( GetModelShowNPoints()->GetLstPointsX() );
702 mbbShowNPoints->bbSetOutputlstPointsY( GetModelShowNPoints()->GetLstPointsY() );
703 mbbShowNPoints->bbSetOutputlstPointsZ( GetModelShowNPoints()->GetLstPointsZ() );
704 mbbShowNPoints->bbSetOutputlstLabels( GetModelShowNPoints()->GetLstLabels() );
705 mbbShowNPoints->bbSignalOutputModification();
709 //------------------------------------------------------------------------
710 void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
712 wxFileDialog* FD = new wxFileDialog( 0,
713 _T("Save points .."),
717 wxSAVE | wxOVERWRITE_PROMPT,
721 int result_FD = FD->ShowModal();
723 // This line is need it by windows //EED
724 FD->SetReturnCode( result_FD );
726 if (FD->GetReturnCode()==wxID_OK)
728 std::string filename= (const char*) ( FD->GetPath().mb_str() );
729 GetModelShowNPoints()->SavePoints( filename );
734 //------------------------------------------------------------------------
735 void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
737 wxFileDialog* FD = new wxFileDialog( 0,
738 _T("Load points .."),
742 wxOPEN | wxFILE_MUST_EXIST,
746 int result_FD = FD->ShowModal();
747 // This line is need it by windows //EED
748 FD->SetReturnCode( result_FD );
749 if (FD->GetReturnCode()==wxID_OK)
752 std::string filename= (const char*) ( FD->GetPath().mb_str() );
753 int numberPointsRead = GetModelShowNPoints()->ReadPoints( filename );
754 for (i=0;i<numberPointsRead;i++)
764 //------------------------------------------------------------------------
765 void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
767 int id=GetModelShowNPoints()->GetNearestPoint();
768 if((id==-1) && (mbbShowNPoints->bbGetInputType()==1))
777 GetModelShowNPoints()->SetPointId_mReferencePoint(id);
779 renderer->GetRenderWindow()->Render();
784 //------------------------------------------------------------------------
785 void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
787 int id = GetModelShowNPoints()->RenamePoint( (const char*) ( textCtrl->GetValue().mb_str() ) );
790 lstActorsText[id]->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
792 renderer->GetRenderWindow()->Render();
796 //------------------------------------------------------------------------
797 void WidgetShowNPoints::ErasePoint(int id)
799 if (this->renderer!=NULL)
803 renderer->RemoveActor( lstActorsSphere[id] );
804 renderer->RemoveActor( lstActorsText[id] );
805 lstActorsSphere[id]->Delete();
806 lstActorsText[id]->Delete();
807 lstSourceSphere[id]->Delete();
808 lstActorsSphere.erase( lstActorsSphere.begin()+id );
809 lstActorsText.erase( lstActorsText.begin()+id );
810 lstSourceSphere.erase( lstSourceSphere.begin()+id );
811 GetModelShowNPoints()->ErasePoint(id);
816 //------------------------------------------------------------------------
817 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
819 ErasePoint( GetModelShowNPoints()->IdInsidePoint() );
821 renderer->GetRenderWindow()->Render();
824 //------------------------------------------------------------------------
825 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
827 ErasePoint(lstActorsSphere.size()-1);
829 renderer->GetRenderWindow()->Render();
832 //------------------------------------------------------------------------
833 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
835 int id,size=lstActorsSphere.size();
836 for (id=size-1;id>=0;id--)
841 renderer->GetRenderWindow()->Render();
844 //NTU: Method for updating points opacity and Radio
846 //------------------------------------------------------------------------
847 void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
849 //Difference in Radio for text placement
850 double radio=GetModelShowNPoints()->GetRadio();
851 this->mopacity = sdrOpacity->GetValue()/100.0;
852 GetModelShowNPoints()->SetRadio( sdrRadio->GetValue() ) ;
853 radio = sdrRadio->GetValue();
854 //NTU refresh the inputs
855 mbbShowNPoints->bbSetInputOpacity(this->mopacity);
856 mbbShowNPoints->bbSetInputRadio( radio );
861 //------------------------------------------------------------------------
862 void WidgetShowNPoints::SetReferencePoint(std::vector<int> point)
864 GetModelShowNPoints()->SetReferencePoint(point);
867 //------------------------------------------------------------------------
868 void WidgetShowNPoints::SetInitLstPoints( std::vector<int> initLstPointsX, std::vector<int> initLstPointsY, std::vector<int> initLstPointsZ, std::vector<std::string> initLstLabels )
870 if (this->renderer==NULL)
875 int i,sizeX,sizeY,sizeZ,sizeLabels;
876 sizeX=(int)initLstPointsX.size();
877 sizeY=(int)initLstPointsY.size();
878 sizeZ=(int)initLstPointsZ.size();
879 sizeLabels=(int)initLstLabels.size();
884 if ( (sizeX==sizeY) && (sizeX==sizeZ) )
887 for (i=0;i<sizeX;i++)
889 x = initLstPointsX[i];
890 y = initLstPointsY[i];
891 z = initLstPointsZ[i];
894 label = initLstLabels[i];
898 AddPoint( x,y,z,label );
901 // renderer->GetRenderWindow()->Render();
909 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
910 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
912 //-----------------------------------------------------------------
913 void ShowNPoints::Process()
917 mwxwidget->SetRenderer( bbGetInputRenderer() );
918 mwxwidget->SetReferencePoint( bbGetInputIn() );
919 mwxwidget->SetImage( bbGetInputImage() );
920 mwxwidget->SetColour( bbGetInputColour() );
921 mwxwidget->SetOpacity( bbGetInputOpacity() );
922 mwxwidget->SetRadio( bbGetInputRadio() );
927 mwxwidget->SetInitLstPoints( bbGetInputInitLstPointsX() , bbGetInputInitLstPointsY() , bbGetInputInitLstPointsZ() , bbGetInputInitLstLabels() );
930 bbSetOutputlstPointsX( mwxwidget->GetModelShowNPoints()->GetLstPointsX() );
931 bbSetOutputlstPointsY( mwxwidget->GetModelShowNPoints()->GetLstPointsY() );
932 bbSetOutputlstPointsZ( mwxwidget->GetModelShowNPoints()->GetLstPointsZ() );
933 bbSetOutputlstLabels( mwxwidget->GetModelShowNPoints()->GetLstLabels() );
937 //-----------------------------------------------------------------
938 void ShowNPoints::CreateWidget(wxWindow* parent)
940 mwxwidget = new WidgetShowNPoints( parent, this);
941 bbSetOutputWidget( mwxwidget );
944 //-----------------------------------------------------------------
945 void ShowNPoints::bbUserSetDefaultValues()
951 bbSetInputOpacity(1);
953 std::vector<double> colour;
954 colour.push_back(1.0);
955 colour.push_back(0.0);
956 colour.push_back(0.0);
957 bbSetInputColour(colour);
959 bbSetInputImage(NULL);
961 bbSetInputRenderer(NULL);
964 //-----------------------------------------------------------------
965 void ShowNPoints::bbUserInitializeProcessing()
969 //-----------------------------------------------------------------
970 void ShowNPoints::bbUserFinalizeProcessing()
974 //-----------------------------------------------------------------
977 // EO namespace bbcreaMaracasVisu