1 #include <cpExtensions/Interaction/SphereWidget.h>
3 #include <vtkCallbackCommand.h>
4 #include <vtkCommand.h>
5 #include <vtkRenderWindowInteractor.h>
6 #include <vtkSeedRepresentation.h>
7 #include <vtkWidgetEventTranslator.h>
8 #include <vtkWidgetRepresentation.h>
10 #include <vtkSphereRepresentation.h>
11 #include <vtkSmartPointer.h>
12 #include <vtkSphere.h>
13 #include <vtkProperty.h>
15 // -------------------------------------------------------------------------
16 cpExtensions::Interaction::SphereWidget::
17 Self* cpExtensions::Interaction::SphereWidget::
23 // -------------------------------------------------------------------------
24 void cpExtensions::Interaction::SphereWidget::
25 SetInteractor(vtkRenderWindowInteractor* rwi)
27 this->Superclass::SetInteractor(rwi);
28 TBaseStyle* s = dynamic_cast<TBaseStyle*>(rwi->GetInteractorStyle());
31 s->AddKeyCommand(Self::_KeyPress, this);
32 s->AddMouseMoveCommand(Self::_MouseMove, this);
37 // -------------------------------------------------------------------------
38 cpExtensions::Interaction::SphereWidget::
44 this->SetTranslation(0);
47 this->SetPhiResolution(10);
48 this->SetThetaResolution(20);
50 this->SetRepresentationToWireframe();
53 // -------------------------------------------------------------------------
54 cpExtensions::Interaction::SphereWidget::
59 // -------------------------------------------------------------------------
60 void cpExtensions::Interaction::SphereWidget::
62 void* data, const TBaseStyle::ButtonID& button,
63 int* idx, double* pos, bool alt, bool ctr, bool sft
66 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
67 self->Superclass::EndInteraction();
70 // -------------------------------------------------------------------------
71 void cpExtensions::Interaction::SphereWidget::
73 void* data, const TBaseStyle::ButtonID& button,
74 int* idx, double* pos, bool alt, bool ctr, bool sft
80 // -------------------------------------------------------------------------
81 void cpExtensions::Interaction::SphereWidget::
83 void* data, const TBaseStyle::ButtonID& button,
84 int* idx, double* pos, bool alt, bool ctr, bool sft
87 /*SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
88 self->Superclass::StartInteraction();*/
91 void cpExtensions::Interaction::SphereWidget::SetAxis(int axis)
97 void cpExtensions::Interaction::SphereWidget::SetAxis(void* data, int axis)
99 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
103 int cpExtensions::Interaction::SphereWidget::GetAxis()
108 int cpExtensions::Interaction::SphereWidget::GetAxis(void* data)
110 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
111 return self->GetAxis();
114 double* cpExtensions::Interaction::SphereWidget::GetPosition()
116 return this->SphereActor->GetPosition();
119 double* cpExtensions::Interaction::SphereWidget::GetPosition(void* data)
121 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
122 return self->GetPosition();
125 void cpExtensions::Interaction::SphereWidget::SetCenter(double * center)
127 //this->Superclass::SetCenter(center);
128 this->SphereActor->SetPosition(center);
129 this->SphereActor->Modified();
131 this->GetInteractor()->Render();
134 void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * center)
136 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
138 //self->Superclass::SetCenter(center);
139 self->SphereActor->SetPosition(center);
140 self->SphereActor->Modified();
142 self->GetInteractor()->Render();
144 std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] << "} " << std::endl;
147 // -------------------------------------------------------------------------
148 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
150 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
151 self->Superclass::StartInteraction();
153 double * center = self->SphereActor->GetPosition();
155 auto radius = self->GetRadius();
157 auto axis = self->GetAxis();
176 } else if (axis == 1)
250 self->SetRadius(radius);
251 self->SetCenter(data, center);
253 self->GetInteractor()->Render();
254 self->EndInteraction();