1 #include "bbmaracasvisuShowNPoints.h"
2 #include "bbcreaMaracasVisuPackage.h"
4 #include "vtkProperty.h"
5 #include "vtkSphereSource.h"
6 #include "vtkPolyDataMapper.h"
7 #include "vtkRenderWindow.h"
8 #include "vtkTextActor3D.h"
10 namespace bbcreaMaracasVisu
14 //----------------------------------------------------------------------
15 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, bbcreaMaracasVisu::ShowNPoints *box)
16 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
19 this->renderer = NULL;
20 wxPanel *panel = this;
21 wxSizer *sizer = NULL;
25 textCtrl = new wxTextCtrl(panel, -1);
26 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
27 wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
28 wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
29 wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
32 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
33 // sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
35 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
36 Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
37 Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
38 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
40 sizer1->Add(textCtrl);
41 sizer1->Add(btnAddPoint);
42 sizer1->Add(btnErasePoint);
43 sizer1->Add(btnEraseLastPoint);
44 sizer1->Add(btnDeleteAllPoints);
47 panel -> SetSizer(sizer);
48 panel -> SetAutoLayout(true);
54 //------------------------------------------------------------------------
55 WidgetShowNPoints::~WidgetShowNPoints()
59 void WidgetShowNPoints::SetRadio(double radio)
64 //------------------------------------------------------------------------
65 std::vector<int> WidgetShowNPoints::GetLstPointsX()
70 //------------------------------------------------------------------------
71 std::vector<int> WidgetShowNPoints::GetLstPointsY()
76 //------------------------------------------------------------------------
77 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
82 //------------------------------------------------------------------------
83 std::vector<std::string> WidgetShowNPoints::GetLstLabels()
91 //------------------------------------------------------------------------
92 void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
97 //------------------------------------------------------------------------
98 void WidgetShowNPoints::SetColour(std::vector<double> colour)
100 this->mcolour = colour;
103 //------------------------------------------------------------------------
104 void WidgetShowNPoints::SetOpacity(double opacity)
106 this->mopacity=opacity;
109 //------------------------------------------------------------------------
110 void WidgetShowNPoints::SetImage(vtkImageData *image)
115 //------------------------------------------------------------------------
116 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
118 this->renderer = renderer;
123 //------------------------------------------------------------------------
124 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
126 if (this->renderer!=NULL){
127 if (mpoint.size()==3){
128 lstPointsX.push_back( mpoint[0] );
129 lstPointsY.push_back( mpoint[1] );
130 lstPointsZ.push_back( mpoint[2] );
131 lstLabels.push_back( (const char*) ( textCtrl->GetValue().mb_str() ) );
134 vtkSphereSource *vtksphere = vtkSphereSource::New();
135 vtksphere->SetThetaResolution (20);
136 vtksphere->SetPhiResolution (20);
137 vtksphere->SetRadius( mradio );
138 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
139 sphereMapper->SetInput( vtksphere->GetOutput() );
140 vtkActor *sphereActor = vtkActor::New();
141 sphereActor->SetMapper(sphereMapper);
142 sphereActor->SetOrigin(0, 0, 0);
144 mimage->GetSpacing(spc);
145 sphereActor->SetPosition( spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
146 sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
147 sphereActor->GetProperty()->SetOpacity( mopacity );
149 lstActorsSphere.push_back(sphereActor);
150 renderer->AddActor( sphereActor );
153 vtkTextActor3D *textActor = vtkTextActor3D::New();
154 textActor->SetPosition( mradio+spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
155 textActor->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
156 renderer->AddActor( textActor );
157 lstActorsText.push_back(textActor);
159 renderer->GetRenderWindow()->Render();
163 } else {//mpoint.size
164 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
169 void WidgetShowNPoints::SetOutputBox()
172 mbbShowNPoints->bbSetOutputlstPointsX( GetLstPointsX() );
173 mbbShowNPoints->bbSetOutputlstPointsY( GetLstPointsY() );
174 mbbShowNPoints->bbSetOutputlstPointsZ( GetLstPointsZ() );
175 mbbShowNPoints->bbSetOutputlstLabels( GetLstLabels() );
176 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
177 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
178 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
179 mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));
182 //------------------------------------------------------------------------
183 void WidgetShowNPoints::ErasePoint(int id)
185 if (this->renderer!=NULL){
187 renderer->RemoveActor( lstActorsSphere[id] );
188 renderer->RemoveActor( lstActorsText[id] );
189 lstActorsSphere[id]->Delete();
190 lstActorsText[id]->Delete();
191 lstActorsSphere.erase( lstActorsSphere.begin()+id );
192 lstActorsText.erase( lstActorsText.begin()+id );
194 lstPointsX.erase( lstPointsX.begin()+id );
195 lstPointsY.erase( lstPointsY.begin()+id );
196 lstPointsZ.erase( lstPointsZ.begin()+id );
197 lstLabels.erase( lstLabels.begin()+id );
199 renderer->GetRenderWindow()->Render();
206 //------------------------------------------------------------------------
207 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
210 int i, size=(int)(lstActorsSphere.size());
212 mimage->GetSpacing(spc);
214 for ( i=0 ; i<size; i++ )
216 double rx = spc[0]*(mpoint[0] - lstPointsX [i]);
217 double ry = spc[1]*(mpoint[1] - lstPointsY [i]);
218 double rz = spc[2]*(mpoint[2] - lstPointsZ [i]);
219 if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
227 //------------------------------------------------------------------------
228 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
230 ErasePoint(lstActorsSphere.size()-1);
234 //------------------------------------------------------------------------
235 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
237 int id,size=lstActorsSphere.size();
238 for (id=size-1;id>=0;id--)
247 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
248 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
250 void ShowNPoints::Process()
252 if (mwxwidget!=NULL){
253 mwxwidget->SetRenderer( bbGetInputRenderer() );
254 mwxwidget->SetPoint( bbGetInputIn() );
255 mwxwidget->SetImage( bbGetInputImage() );
256 mwxwidget->SetColour( bbGetInputColour() );
257 mwxwidget->SetOpacity( bbGetInputOpacity() );
258 mwxwidget->SetRadio( bbGetInputRadio() );
260 bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
261 bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
262 bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
263 bbSetOutputlstLabels( mwxwidget->GetLstLabels() );
268 void ShowNPoints::CreateWidget(wxWindow* parent)
270 mwxwidget = new WidgetShowNPoints( parent , this);
271 mwxwidget->SetPoint( bbGetInputIn() );
273 if (bbGetInputImage()==NULL)
275 printf("Missing Image (ShowNPoints) \n");
278 bbSetOutputWidget( mwxwidget );
281 void ShowNPoints::bbUserSetDefaultValues()
285 bbSetInputRadio(0.5);
286 bbSetInputOpacity(1);
288 std::vector<double> colour;
289 colour.push_back(1.0);
290 colour.push_back(0.0);
291 colour.push_back(0.0);
292 bbSetInputColour(colour);
294 bbSetInputImage(NULL);
295 bbSetInputRenderer(NULL);
298 //-----------------------------------------------------------------
299 void ShowNPoints::bbUserInitializeProcessing()
303 //-----------------------------------------------------------------
304 void ShowNPoints::bbUserFinalizeProcessing()
308 //-----------------------------------------------------------------
311 // EO namespace bbcreaMaracasVisu