#include #include #include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpExtensions::Interaction::SphereWidget:: Self* cpExtensions::Interaction::SphereWidget:: New() { return(new Self); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::SphereWidget:: SetInteractor(vtkRenderWindowInteractor* rwi) { this->Superclass::SetInteractor(rwi); TBaseStyle* s = dynamic_cast(rwi->GetInteractorStyle()); if (s != NULL) { s->AddKeyCommand(Self::_KeyPress, this); s->AddMouseMoveCommand(Self::_MouseMove, this); } // fi } // ------------------------------------------------------------------------- cpExtensions::Interaction::SphereWidget:: SphereWidget() : Superclass() { this->SetTranslation(0); this->SetRadius(7); this->SetPhiResolution(10); this->SetThetaResolution(20); this->SetRepresentationToWireframe(); } // ------------------------------------------------------------------------- cpExtensions::Interaction::SphereWidget:: ~SphereWidget() { } // ------------------------------------------------------------------------- void cpExtensions::Interaction::SphereWidget:: _Click( void* data, const TBaseStyle::ButtonID& button, int* idx, double* pos, bool alt, bool ctr, bool sft ) { SphereWidget* self = reinterpret_cast(data); self->Superclass::EndInteraction(); } // ------------------------------------------------------------------------- void cpExtensions::Interaction::SphereWidget:: _DoubleClick( void* data, const TBaseStyle::ButtonID& button, int* idx, double* pos, bool alt, bool ctr, bool sft ) { } // ------------------------------------------------------------------------- void cpExtensions::Interaction::SphereWidget:: _MouseMove( void* data, const TBaseStyle::ButtonID& button, int* idx, double* pos, bool alt, bool ctr, bool sft ) { /*SphereWidget* self = reinterpret_cast(data); self->Superclass::StartInteraction();*/ } void cpExtensions::Interaction::SphereWidget::SetCenter(double * center) { this->Superclass::SetCenter(center); this->SphereActor->SetPosition(center); this->SphereActor->Modified(); this->GetInteractor()->Render(); } void cpExtensions::Interaction::SphereWidget::SetCenter(void* data, double * center) { SphereWidget* self = reinterpret_cast(data); self->Superclass::SetCenter(center); self->SphereActor->SetPosition(center); self->SphereActor->Modified(); std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] + 19 << "} " << std::endl; } // ------------------------------------------------------------------------- void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key) { SphereWidget* self = reinterpret_cast(data); self->Superclass::StartInteraction(); double * center = self->GetCenter(); auto radius = self->GetRadius(); switch (key) { case 122: // Z & z case 90: radius += 0.1; break; case 88: // X & x case 120: radius -= 0.1; break; case 119: // W & w case 87: center[0] += 1; break; case 83: // S & s case 115: center[0] -= 1; break; case 65: // A & a case 97: center[1] += 1; break; case 100: // D & d case 68: center[1] -= 1; break; case 81: // Q & q case 113: center[2] += 1; break; case 69: // E & e case 101: center[2] -= 1; break; default: break; } self->SetRadius(radius); self->SetCenter(data, center); self->Modified(); self->GetInteractor()->Render(); self->EndInteraction(); } // eof - $RCSfile$