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>
14 // -------------------------------------------------------------------------
15 cpExtensions::Interaction::SphereWidget::
16 Self* cpExtensions::Interaction::SphereWidget::
22 // -------------------------------------------------------------------------
23 void cpExtensions::Interaction::SphereWidget::
24 SetInteractor(vtkRenderWindowInteractor* rwi)
26 this->Superclass::SetInteractor(rwi);
27 TBaseStyle* s = dynamic_cast<TBaseStyle*>(rwi->GetInteractorStyle());
30 s->AddMouseClickCommand(Self::_Click, this);
31 //s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
32 s->AddKeyCommand(Self::_KeyPress, this);
36 // -------------------------------------------------------------------------
37 cpExtensions::Interaction::SphereWidget::
41 /*vtkSmartPointer<vtkself> self =
42 vtkself::SafeDownCast(this->GetRepresentation());*/
44 //self->SetHandleSize(0);
45 //self->SetRadialLine(2);
48 this->SetPhiResolution(10);
49 this->SetThetaResolution(20);
51 //self->HandleVisibilityOff();
52 //self->SetHandleText(0);
53 this->SetRepresentationToWireframe();
55 // Remove default translations
56 /* vtkWidgetEventTranslator* t = this->GetEventTranslator();
57 t->RemoveTranslation(vtkCommand::LeftButtonPressEvent);
58 t->RemoveTranslation(vtkCommand::MiddleButtonPressEvent);
59 t->RemoveTranslation(vtkCommand::RightButtonPressEvent);*/
62 // -------------------------------------------------------------------------
63 cpExtensions::Interaction::SphereWidget::
68 // -------------------------------------------------------------------------
69 void cpExtensions::Interaction::SphereWidget::
71 void* data, const TBaseStyle::ButtonID& button,
72 int* idx, double* pos, bool alt, bool ctr, bool sft
75 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
76 self->Superclass::StartInteraction();
77 self->InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
78 //if( self->WidgetState == vtkSphereWidget2::MovingSeed )
81 //int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
82 //if( st == vtkSeedRepresentation::NearSeed )
84 // self->WidgetState = vtkSphereWidget2::MovingSeed;
86 // // Invoke an event on ourself for the handles
87 // self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
88 // self->Superclass::StartInteraction( );
89 // self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
90 // self->EventCallbackCommand->SetAbortFlag( 1 );
96 // -------------------------------------------------------------------------
97 void cpExtensions::Interaction::SphereWidget::
99 void* data, const TBaseStyle::ButtonID& button,
100 int* idx, double* pos, bool alt, bool ctr, bool sft
106 // -------------------------------------------------------------------------
107 void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key)
109 SphereWidget* self = reinterpret_cast<SphereWidget*>(data);
111 double handlePosition[3];
113 vtkself::SafeDownCast(self->GetRepresentation());
115 auto center = self->GetCenter();
116 auto center2 = self->GetCenter();
117 auto radius = self->GetRadius();
119 self->Superclass::StartInteraction();
125 //self->SetRadius(radius);
130 //self->SetRadius(radius);
135 self->Translate(center, center2);
140 self->Translate(center, center2);
145 self->SetCenter(center);
150 self->SetCenter(center);
155 self->SetCenter(center);
160 self->SetCenter(center);
167 self->SetRadius(radius);
168 self->Translate(center, center2);
170 vtkSmartPointer<vtkSphere> sphere = vtkSmartPointer<vtkSphere>::New();
173 self->InvokeEvent(vtkCommand::ModifiedEvent, NULL);
176 self->GetInteractor()->Render();
177 self->ReleaseFocus();