]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/SphereWidget.cxx
sphere widget update
[cpPlugins.git] / lib / cpExtensions / Interaction / SphereWidget.cxx
1 #include <cpExtensions/Interaction/SphereWidget.h>
2
3 #include <vtkCallbackCommand.h>
4 #include <vtkCommand.h>
5 #include <vtkRenderWindowInteractor.h>
6 #include <vtkSeedRepresentation.h>
7 #include <vtkWidgetEventTranslator.h>
8 #include <vtkWidgetRepresentation.h>
9 #include <vtkActor.h>
10 #include <vtkSphereRepresentation.h>
11 #include <vtkSmartPointer.h>
12 #include <vtkSphere.h>
13 #include <vtkProperty.h>
14
15 // -------------------------------------------------------------------------
16 cpExtensions::Interaction::SphereWidget::
17 Self* cpExtensions::Interaction::SphereWidget::
18 New()
19 {
20   return(new Self);
21 }
22
23 // -------------------------------------------------------------------------
24 void cpExtensions::Interaction::SphereWidget::
25 SetInteractor(vtkRenderWindowInteractor* rwi)
26 {
27   this->Superclass::SetInteractor(rwi);
28   TBaseStyle* s = dynamic_cast<TBaseStyle*>(rwi->GetInteractorStyle());
29   if (s != NULL)
30   {    
31     s->AddKeyCommand(Self::_KeyPress, this);
32     s->AddMouseMoveCommand(Self::_MouseMove, this);
33
34   } // fi
35 }
36
37 // -------------------------------------------------------------------------
38 cpExtensions::Interaction::SphereWidget::
39 SphereWidget()
40 : Superclass()
41 {
42   this->SetTranslation(0);
43   this->SetRadius(7);
44
45   this->SetPhiResolution(10);
46   this->SetThetaResolution(20);
47
48   this->SetRepresentationToWireframe();
49 }
50
51 // -------------------------------------------------------------------------
52 cpExtensions::Interaction::SphereWidget::
53 ~SphereWidget()
54 {
55 }
56
57 // -------------------------------------------------------------------------
58 void cpExtensions::Interaction::SphereWidget::
59 _Click(
60 void* data, const TBaseStyle::ButtonID& button,
61 int* idx, double* pos, bool alt, bool ctr, bool sft
62 )
63 {
64   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
65   self->Superclass::EndInteraction();
66
67
68 }
69
70 // -------------------------------------------------------------------------
71 void cpExtensions::Interaction::SphereWidget::
72 _DoubleClick(
73 void* data, const TBaseStyle::ButtonID& button,
74 int* idx, double* pos, bool alt, bool ctr, bool sft
75 )
76 {
77
78 }
79
80 // -------------------------------------------------------------------------
81 void cpExtensions::Interaction::SphereWidget::
82 _MouseMove(
83 void* data, const TBaseStyle::ButtonID& button,
84 int* idx, double* pos, bool alt, bool ctr, bool sft
85 )
86 {
87   /*SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
88   self->Superclass::StartInteraction();*/
89 }
90
91 void cpExtensions::Interaction::SphereWidget::SetCenter(double * center)
92 {
93   this->Superclass::SetCenter(center);
94   this->SphereActor->SetPosition(center);
95   this->SphereActor->Modified();
96   this->Modified();
97   this->GetInteractor()->Render();
98 }
99
100 void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * center)
101 {
102   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
103   
104   self->Superclass::SetCenter(center);
105   self->SphereActor->SetPosition(center);
106   self->SphereActor->Modified();
107   self->Modified();
108   self->GetInteractor()->Render();
109
110   std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] << "} " << std::endl;
111 }
112
113 // -------------------------------------------------------------------------
114 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
115 {
116   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
117   self->Superclass::StartInteraction();
118
119   double * center = self->GetCenter();
120
121   auto radius = self->GetRadius();
122
123   switch (key)
124   {
125   case 122: // Z & z
126   case 90:
127     radius += 0.1;
128    
129     break;
130   case 88:  // X & x
131   case 120:
132     radius -= 0.1;
133    
134     break;
135   case 119: // W & w
136   case 87:
137     center[0] += 1;
138    
139     break;
140   case 83: // S & s
141   case 115:
142     center[0] -= 1;
143    
144     break;
145   case 65: // A & a
146   case 97:
147     center[1] += 1;
148    
149     break;
150   case 100: // D & d
151   case 68:
152     center[1] -= 1;
153    
154     break;
155   case 81: // Q & q
156   case 113:
157     center[2] += 1;
158   
159     break;
160   case 69: // E & e
161   case 101:
162     center[2] -= 1;
163   
164     break;
165
166   default:
167     break;
168   }
169
170
171   self->SetRadius(radius);
172   self->SetCenter(data, center);
173   self->Modified();
174   self->GetInteractor()->Render();
175   self->EndInteraction();
176 }
177
178
179
180
181
182
183
184 // eof - $RCSfile$