]> 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->GetInteractor()->Render();
97 }
98
99 void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * center)
100 {
101   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
102   
103   self->Superclass::SetCenter(center);
104   self->SphereActor->SetPosition(center);
105   self->SphereActor->Modified();
106
107   std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] + 19 << "} " << std::endl;
108 }
109
110 // -------------------------------------------------------------------------
111 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
112 {
113   SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
114   self->Superclass::StartInteraction();
115
116   double * center = self->GetCenter();
117
118   auto radius = self->GetRadius();
119
120   switch (key)
121   {
122   case 122: // Z & z
123   case 90:
124     radius += 0.1;
125    
126     break;
127   case 88:  // X & x
128   case 120:
129     radius -= 0.1;
130    
131     break;
132   case 119: // W & w
133   case 87:
134     center[0] += 1;
135    
136     break;
137   case 83: // S & s
138   case 115:
139     center[0] -= 1;
140    
141     break;
142   case 65: // A & a
143   case 97:
144     center[1] += 1;
145    
146     break;
147   case 100: // D & d
148   case 68:
149     center[1] -= 1;
150    
151     break;
152   case 81: // Q & q
153   case 113:
154     center[2] += 1;
155   
156     break;
157   case 69: // E & e
158   case 101:
159     center[2] -= 1;
160   
161     break;
162
163   default:
164     break;
165   }
166
167
168   self->SetRadius(radius);
169   self->SetCenter(data, center);
170   self->Modified();
171   self->GetInteractor()->Render();
172   self->EndInteraction();
173 }
174
175
176
177
178
179
180
181 // eof - $RCSfile$