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 <vtkSphereWidget2.h>
12 #include <vtkSmartPointer.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->AddMouseClickCommand(Self::_Click, this);
32 //s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
33 s->AddKeyCommand(Self::_KeyPress, this);
37 // -------------------------------------------------------------------------
38 cpExtensions::Interaction::SphereWidget::
42 vtkSmartPointer<vtkSphereRepresentation> sphereRepresentation =
43 vtkSphereRepresentation::SafeDownCast(this->GetRepresentation());
45 //sphereRepresentation->SetHandleSize(0);
46 sphereRepresentation->SetRadialLine(2);
47 sphereRepresentation->SetRadius(7);
49 sphereRepresentation->SetPhiResolution(10);
50 sphereRepresentation->SetThetaResolution(20);
52 //sphereRepresentation->HandleVisibilityOff();
53 //sphereRepresentation->SetHandleText(0);
54 sphereRepresentation->SetRepresentationToWireframe();
56 // Remove default translations
57 /* vtkWidgetEventTranslator* t = this->GetEventTranslator();
58 t->RemoveTranslation(vtkCommand::LeftButtonPressEvent);
59 t->RemoveTranslation(vtkCommand::MiddleButtonPressEvent);
60 t->RemoveTranslation(vtkCommand::RightButtonPressEvent);*/
63 // -------------------------------------------------------------------------
64 cpExtensions::Interaction::SphereWidget::
69 // -------------------------------------------------------------------------
70 void cpExtensions::Interaction::SphereWidget::
72 void* data, const TBaseStyle::ButtonID& button,
73 int* idx, double* pos, bool alt, bool ctr, bool sft
76 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
77 self->Superclass::StartInteraction();
78 self->InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
79 //if( self->WidgetState == vtkSphereWidget2::MovingSeed )
82 //int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
83 //if( st == vtkSeedRepresentation::NearSeed )
85 // self->WidgetState = vtkSphereWidget2::MovingSeed;
87 // // Invoke an event on ourself for the handles
88 // self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
89 // self->Superclass::StartInteraction( );
90 // self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
91 // self->EventCallbackCommand->SetAbortFlag( 1 );
97 // -------------------------------------------------------------------------
98 void cpExtensions::Interaction::SphereWidget::
100 void* data, const TBaseStyle::ButtonID& button,
101 int* idx, double* pos, bool alt, bool ctr, bool sft
107 // -------------------------------------------------------------------------
108 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
110 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
112 double handlePosition[3];
113 vtkSphereRepresentation* sphereRepresentation =
114 vtkSphereRepresentation::SafeDownCast(self->GetRepresentation());
118 auto center = sphereRepresentation->GetCenter();
119 self->Superclass::StartInteraction();
124 sphereRepresentation->SetRadius(sphereRepresentation->GetRadius() + 0.1);
128 sphereRepresentation->SetRadius(sphereRepresentation->GetRadius() - 0.1);
133 sphereRepresentation->SetCenter(center);
138 sphereRepresentation->SetCenter(center);
143 sphereRepresentation->SetCenter(center);
148 sphereRepresentation->SetCenter(center);
153 sphereRepresentation->SetCenter(center);
158 sphereRepresentation->SetCenter(center);
164 self->SetKeyPressActivation(1);