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::
42 this->SetTranslation(0);
45 this->SetPhiResolution(10);
46 this->SetThetaResolution(20);
48 this->SetRepresentationToWireframe();
51 // -------------------------------------------------------------------------
52 cpExtensions::Interaction::SphereWidget::
57 // -------------------------------------------------------------------------
58 void cpExtensions::Interaction::SphereWidget::
60 void* data, const TBaseStyle::ButtonID& button,
61 int* idx, double* pos, bool alt, bool ctr, bool sft
64 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
65 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::SetCenter(double * center)
93 this->Superclass::SetCenter(center);
94 this->SphereActor->SetPosition(center);
95 this->SphereActor->Modified();
97 this->GetInteractor()->Render();
100 void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * center)
102 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
104 self->Superclass::SetCenter(center);
105 self->SphereActor->SetPosition(center);
106 self->SphereActor->Modified();
108 self->GetInteractor()->Render();
110 std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] << "} " << std::endl;
113 // -------------------------------------------------------------------------
114 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
116 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
117 self->Superclass::StartInteraction();
119 double * center = self->GetCenter();
121 auto radius = self->GetRadius();
171 self->SetRadius(radius);
172 self->SetCenter(data, center);
174 self->GetInteractor()->Render();
175 self->EndInteraction();