]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuShowNPoints.cxx
Compilation with bbtk 0.9.1
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuShowNPoints.cxx
1 #include "bbmaracasvisuShowNPoints.h"
2 #include "bbcreaMaracasVisuPackage.h"
3
4 #include "vtkProperty.h"
5 #include "vtkSphereSource.h"
6 #include "vtkPolyDataMapper.h"
7 #include "vtkRenderWindow.h"
8
9 namespace bbcreaMaracasVisu
10 {
11
12
13 //----------------------------------------------------------------------
14         WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, vtkRenderer *renderer, ShowNPoints *box)
15     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
16   {
17     mbbShowNPoints                              = box;
18     this->renderer                              = renderer;
19         wxPanel *panel                          = this;
20     wxSizer *sizer                              = NULL;
21         
22
23         // Widget interface
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"));
27
28
29         wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1); 
30 //    sizer1->Add(new wxStaticText(panel,-1,_T("  ")));
31
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);
35
36     sizer1->Add(btnAddPoint);
37     sizer1->Add(btnEraseLstPoint);
38     sizer1->Add(btnDeleteAllPoints);
39
40         sizer = sizer1;
41         panel   ->      SetSizer(sizer);
42     panel       ->      SetAutoLayout(true);
43     panel       ->      Layout();  
44         
45 }
46
47
48 //------------------------------------------------------------------------
49 WidgetShowNPoints::~WidgetShowNPoints()
50 {
51 }
52
53 void WidgetShowNPoints::SetRadio(double radio)
54 {
55         mradio=radio;
56 }
57
58 //------------------------------------------------------------------------
59 std::vector<int> WidgetShowNPoints::GetLstPointsX()
60 {
61         return lstPointsX;
62 }
63
64 //------------------------------------------------------------------------
65 std::vector<int> WidgetShowNPoints::GetLstPointsY()
66 {
67         return lstPointsY;
68 }
69
70 //------------------------------------------------------------------------
71 std::vector<int> WidgetShowNPoints::GetLstPointsZ()
72 {
73         return lstPointsZ;
74 }
75
76
77
78
79 //------------------------------------------------------------------------
80 void WidgetShowNPoints::SetPoint(std::vector<int> ppoint)
81 {
82         mpoint = ppoint;
83 }
84
85 //------------------------------------------------------------------------
86 void WidgetShowNPoints::SetColour(std::vector<double> colour)
87 {
88         this->mcolour = colour;
89 }
90
91 //------------------------------------------------------------------------
92 void WidgetShowNPoints::SetOpacity(double opacity)
93 {
94         this->mopacity=opacity;
95 }
96
97 //------------------------------------------------------------------------
98 void WidgetShowNPoints::SetImage(vtkImageData *image)
99 {
100         this->mimage=image;
101 }
102
103
104
105 //------------------------------------------------------------------------
106 void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
107 {
108 //      printf("EED %p WidgetShowNPoints::OnAddPoint %d,%d,%d \n", this,mpoint[0],mpoint[1],mpoint[2] );
109
110         if (mpoint.size()==3){
111                 lstPointsX.push_back( mpoint[0] );
112                 lstPointsY.push_back( mpoint[1] );
113                 lstPointsZ.push_back( mpoint[2] );
114
115                 // Sphere
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);
125                 double spc[3];
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 );
130
131                 lstActors.push_back(sphereActor);
132                 renderer->AddActor( sphereActor );
133
134                 renderer->GetRenderWindow()->Render();
135
136                 //--BBTK
137                 mbbShowNPoints->bbSignalOutputModification(std::string("Point"));    
138
139         }
140 }
141
142 //------------------------------------------------------------------------
143 void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
144 {
145         int id = lstActors.size()-1;
146         if (id>=0){
147                 renderer->RemoveActor( lstActors[id] );
148                 lstActors.erase( lstActors.begin()+id );
149                 lstPointsX.erase( lstPointsX.begin()+id );
150                 lstPointsY.erase( lstPointsY.begin()+id );
151                 lstPointsZ.erase( lstPointsZ.begin()+id );
152                 renderer->GetRenderWindow()->Render();
153         //--BBTK
154                 mbbShowNPoints->bbSignalOutputModification(std::string("Point"));    
155         }
156
157 }
158
159 //------------------------------------------------------------------------
160 void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
161 {
162         int i,size=lstActors.size();
163         for (i=0;i<size;i++)
164         {
165                 renderer->RemoveActor( lstActors[i] );
166         }
167         lstActors.clear();
168         lstPointsX.clear();
169         lstPointsY.clear();
170         lstPointsZ.clear();
171         renderer->GetRenderWindow()->Render();
172         //--BBTK
173         mbbShowNPoints->bbSignalOutputModification(std::string("Point"));    
174 }
175
176
177
178
179
180 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints)
181 BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints,bbtk::WxBlackBox);
182
183 void ShowNPoints::Process()
184 {
185         mwxwidget->SetPoint( bbGetInputIn() );   
186         mwxwidget->SetImage( bbGetInputImage() );   
187         mwxwidget->SetColour( bbGetInputColour() );   
188         mwxwidget->SetOpacity( bbGetInputOpacity() );   
189         mwxwidget->SetRadio( bbGetInputRadio() );   
190
191         bbSetOutputlstPointsX( mwxwidget->GetLstPointsX() );
192         bbSetOutputlstPointsY( mwxwidget->GetLstPointsY() );
193         bbSetOutputlstPointsZ( mwxwidget->GetLstPointsZ() );
194 }
195
196
197 void ShowNPoints::CreateWidget(wxWindow* parent)
198 {
199         mwxwidget = new WidgetShowNPoints( parent , bbGetInputRenderer(), this);
200         mwxwidget->SetPoint( bbGetInputIn() );
201
202         if (bbGetInputImage()==NULL)
203         {
204                 printf("Missing Image  (ShowNPoints) \n");
205         }
206
207    bbSetOutputWidget( mwxwidget ); 
208    Process();  
209 }
210
211 void ShowNPoints::bbUserConstructor()
212 {
213         std::vector<double> colour;
214         colour.push_back(1.0);
215         colour.push_back(0.0);
216         colour.push_back(0.0);
217         bbSetInputColour(colour);
218         bbSetInputOpacity(1);
219         bbSetInputImage(NULL);
220         bbSetInputRadio(0.5);
221 }
222
223
224 void ShowNPoints::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
225 {
226 }
227
228 void ShowNPoints::bbUserDestructor()
229 {
230 }
231
232 }
233 // EO namespace bbcreaMaracasVisu
234
235