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()
85 //------------------------------------------------------------------------
86 void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
91 //------------------------------------------------------------------------
92 void WidgetShowNPoints::SetColour(std::vector<double> colour)
94 this->mcolour = colour;
97 //------------------------------------------------------------------------
98 void WidgetShowNPoints::SetOpacity(double opacity)
100 this->mopacity=opacity;
103 //------------------------------------------------------------------------
104 void WidgetShowNPoints::SetImage(vtkImageData *image)
109 //------------------------------------------------------------------------
110 void WidgetShowNPoints::SetRenderer(vtkRenderer *renderer)
112 this->renderer = renderer;
117 //------------------------------------------------------------------------
118 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
120 if (this->renderer!=NULL){
121 if (mpoint.size()==3){
122 lstPointsX.push_back( mpoint[0] );
123 lstPointsY.push_back( mpoint[1] );
124 lstPointsZ.push_back( mpoint[2] );
127 vtkSphereSource *vtksphere = vtkSphereSource::New();
128 vtksphere->SetThetaResolution (20);
129 vtksphere->SetPhiResolution (20);
130 vtksphere->SetRadius( mradio );
131 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
132 sphereMapper->SetInput( vtksphere->GetOutput() );
133 vtkActor *sphereActor = vtkActor::New();
134 sphereActor->SetMapper(sphereMapper);
135 sphereActor->SetOrigin(0, 0, 0);
137 mimage->GetSpacing(spc);
138 sphereActor->SetPosition( spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
139 sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
140 sphereActor->GetProperty()->SetOpacity( mopacity );
142 lstActorsSphere.push_back(sphereActor);
143 renderer->AddActor( sphereActor );
146 vtkTextActor3D *text = vtkTextActor3D::New();
147 text->SetPosition( mradio+spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
148 text->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
149 renderer->AddActor( text );
150 lstActorsText.push_back(text);
152 renderer->GetRenderWindow()->Render();
155 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
156 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
157 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
159 } else {//mpoint.size
160 printf("creaMaracasVisu::ShowNPoints (not match point) \n");
166 //------------------------------------------------------------------------
167 void WidgetShowNPoints::ErasePoint(int id)
169 if (this->renderer!=NULL){
171 renderer->RemoveActor( lstActorsSphere[id] );
172 renderer->RemoveActor( lstActorsText[id] );
173 lstActorsSphere[id]->Delete();
174 lstActorsText[id]->Delete();
175 lstActorsSphere.erase( lstActorsSphere.begin()+id );
176 lstActorsText.erase( lstActorsText.begin()+id );
177 lstPointsX.erase( lstPointsX.begin()+id );
178 lstPointsY.erase( lstPointsY.begin()+id );
179 lstPointsZ.erase( lstPointsZ.begin()+id );
180 renderer->GetRenderWindow()->Render();
182 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
183 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
184 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
189 //------------------------------------------------------------------------
190 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
193 int i, size=(int)(lstActorsSphere.size());
195 mimage->GetSpacing(spc);
197 for ( i=0 ; i<size; i++ )
199 double rx = spc[0]*(mpoint[0] - lstPointsX [i]);
200 double ry = spc[1]*(mpoint[1] - lstPointsY [i]);
201 double rz = spc[2]*(mpoint[2] - lstPointsZ [i]);
202 if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
210 //------------------------------------------------------------------------
211 void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
213 ErasePoint(lstActorsSphere.size()-1);
217 //------------------------------------------------------------------------
218 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
220 int i,size=lstActorsSphere.size();
221 if (this->renderer!=NULL){
224 renderer->RemoveActor( lstActorsSphere[i] );
225 renderer->RemoveActor( lstActorsText[i] );
227 lstActorsSphere.clear();
228 lstActorsText.clear();
232 renderer->GetRenderWindow()->Render();
234 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
235 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
236 mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
244 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
245 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
247 void ShowNPoints::Process()
249 if (mwxwidget!=NULL){
250 mwxwidget->SetRenderer( bbGetInputRenderer() );
251 mwxwidget->SetPoint( bbGetInputIn() );
252 mwxwidget->SetImage( bbGetInputImage() );
253 mwxwidget->SetColour( bbGetInputColour() );
254 mwxwidget->SetOpacity( bbGetInputOpacity() );
255 mwxwidget->SetRadio( bbGetInputRadio() );
257 bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
258 bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
259 bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
264 void ShowNPoints::CreateWidget(wxWindow* parent)
266 mwxwidget = new WidgetShowNPoints( parent , this);
267 mwxwidget->SetPoint( bbGetInputIn() );
269 if (bbGetInputImage()==NULL)
271 printf("Missing Image (ShowNPoints) \n");
274 bbSetOutputWidget( mwxwidget );
277 void ShowNPoints::bbUserSetDefaultValues()
281 bbSetInputRadio(0.5);
282 bbSetInputOpacity(1);
284 std::vector<double> colour;
285 colour.push_back(1.0);
286 colour.push_back(0.0);
287 colour.push_back(0.0);
288 bbSetInputColour(colour);
290 bbSetInputImage(NULL);
291 bbSetInputRenderer(NULL);
294 //-----------------------------------------------------------------
295 void ShowNPoints::bbUserInitializeProcessing()
299 //-----------------------------------------------------------------
300 void ShowNPoints::bbUserFinalizeProcessing()
304 //-----------------------------------------------------------------
307 // EO namespace bbcreaMaracasVisu