1 #include "bbmaracasvisuShowNPoints.h"
2 #include "bbcreaMaracasVisuPackage.h"
4 #include "vtkProperty.h"
5 #include "vtkSphereSource.h"
6 #include "vtkPolyDataMapper.h"
7 #include "vtkRenderWindow.h"
9 namespace bbcreaMaracasVisu
13 //----------------------------------------------------------------------
14 WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, vtkRenderer *renderer, ShowNPoints *box)
15 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
18 this->renderer = renderer;
19 wxPanel *panel = this;
20 wxSizer *sizer = NULL;
24 wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
25 wxButton *btnEraseLstPoint = new wxButton( panel, -1, _T("Erase Last point"));
26 wxButton *btnDeleteAllPoints= new wxButton( panel, -1, _T("Delete all points"));
29 wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
30 // sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
32 Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
33 Connect(btnEraseLstPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
34 Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
36 sizer1->Add(btnAddPoint);
37 sizer1->Add(btnEraseLstPoint);
38 sizer1->Add(btnDeleteAllPoints);
41 panel -> SetSizer(sizer);
42 panel -> SetAutoLayout(true);
48 //------------------------------------------------------------------------
49 WidgetShowNPoints::~WidgetShowNPoints()
53 void WidgetShowNPoints::SetRadio(double radio)
58 //------------------------------------------------------------------------
59 std::vector<int> WidgetShowNPoints::GetLstPointsX()
64 //------------------------------------------------------------------------
65 std::vector<int> WidgetShowNPoints::GetLstPointsY()
70 //------------------------------------------------------------------------
71 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
79 //------------------------------------------------------------------------
80 void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
85 //------------------------------------------------------------------------
86 void WidgetShowNPoints::SetColour(std::vector<double> colour)
88 this->mcolour = colour;
91 //------------------------------------------------------------------------
92 void WidgetShowNPoints::SetOpacity(double opacity)
94 this->mopacity=opacity;
97 //------------------------------------------------------------------------
98 void WidgetShowNPoints::SetImage(vtkImageData *image)
105 //------------------------------------------------------------------------
106 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
108 // printf("EED %p WidgetShowNPoints::OnAddPoint %d,%d,%d \n", this,mpoint[0],mpoint[1],mpoint[2] );
110 if (mpoint.size()==3){
111 lstPointsX.push_back( mpoint[0] );
112 lstPointsY.push_back( mpoint[1] );
113 lstPointsZ.push_back( mpoint[2] );
116 vtkSphereSource *vtksphere = vtkSphereSource::New();
117 vtksphere->SetThetaResolution (20);
118 vtksphere->SetPhiResolution (20);
119 vtksphere->SetRadius( mradio );
120 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
121 sphereMapper->SetInput( vtksphere->GetOutput() );
122 vtkActor *sphereActor = vtkActor::New();
123 sphereActor->SetMapper(sphereMapper);
124 sphereActor->SetOrigin(0, 0, 0);
126 mimage->GetSpacing(spc);
127 sphereActor->SetPosition( spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
128 sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
129 sphereActor->GetProperty()->SetOpacity( mopacity );
131 lstActors.push_back(sphereActor);
132 renderer->AddActor( sphereActor );
134 renderer->GetRenderWindow()->Render();
137 mbbShowNPoints->bbSetModifiedStatus();
138 mbbShowNPoints->bbSignalOutputModification("Point");
143 //------------------------------------------------------------------------
144 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
146 int id = lstActors.size()-1;
148 renderer->RemoveActor( lstActors[id] );
149 lstActors.erase( lstActors.begin()+id );
150 lstPointsX.erase( lstPointsX.begin()+id );
151 lstPointsY.erase( lstPointsY.begin()+id );
152 lstPointsZ.erase( lstPointsZ.begin()+id );
153 renderer->GetRenderWindow()->Render();
155 mbbShowNPoints->bbSetModifiedStatus();
156 mbbShowNPoints->bbSignalOutputModification("Point");
161 //------------------------------------------------------------------------
162 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
164 int i,size=lstActors.size();
167 renderer->RemoveActor( lstActors[i] );
173 renderer->GetRenderWindow()->Render();
175 mbbShowNPoints->bbSetModifiedStatus();
176 mbbShowNPoints->bbSignalOutputModification("Point");
183 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
184 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
186 void ShowNPoints::Process()
188 mwxwidget->SetPoint( bbGetInputIn() );
189 mwxwidget->SetImage( bbGetInputImage() );
190 mwxwidget->SetColour( bbGetInputColour() );
191 mwxwidget->SetOpacity( bbGetInputOpacity() );
192 mwxwidget->SetRadio( bbGetInputRadio() );
194 bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
195 bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
196 bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
200 void ShowNPoints::CreateWidget()
202 mwxwidget = new WidgetShowNPoints( bbGetWxParent() , bbGetInputRenderer(), this);
203 mwxwidget->SetPoint( bbGetInputIn() );
205 if (bbGetInputImage()==NULL)
207 printf("Missing Image (ShowNPoints) \n");
210 bbSetOutputWidget( mwxwidget );
214 void ShowNPoints::bbUserConstructor()
216 std::vector<double> colour;
217 colour.push_back(1.0);
218 colour.push_back(0.0);
219 colour.push_back(0.0);
220 bbSetInputColour(colour);
221 bbSetInputOpacity(1);
222 bbSetInputImage(NULL);
223 bbSetInputRadio(0.5);
227 void ShowNPoints::bbUserCopyConstructor()
231 void ShowNPoints::bbUserDestructor()
236 // EO namespace bbcreaMaracasVisu