#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->SetAxis(0); 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::SetAxis(int axis) { this->m_axis = axis; } void cpExtensions::Interaction::SphereWidget::SetAxis(void* data, int axis) { SphereWidget* self = reinterpret_cast(data); self->SetAxis(axis); } int cpExtensions::Interaction::SphereWidget::GetAxis() { return this->m_axis; } int cpExtensions::Interaction::SphereWidget::GetAxis(void* data) { SphereWidget* self = reinterpret_cast(data); return self->GetAxis(); } double* cpExtensions::Interaction::SphereWidget::GetPosition() { return this->SphereActor->GetPosition(); } double* cpExtensions::Interaction::SphereWidget::GetPosition(void* data) { SphereWidget* self = reinterpret_cast(data); return self->GetPosition(); } void cpExtensions::Interaction::SphereWidget::SetCenter(double * center) { //this->Superclass::SetCenter(center); this->SphereActor->SetPosition(center); this->SphereActor->Modified(); this->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(); self->Modified(); self->GetInteractor()->Render(); std::cout << "sphere: {" << center[0] << " , " << center[1] << " , " << center[2] << "} " << std::endl; } // ------------------------------------------------------------------------- void cpExtensions::Interaction::SphereWidget::_KeyPress(void* data, const char& key) { SphereWidget* self = reinterpret_cast(data); self->Superclass::StartInteraction(); double * center = self->SphereActor->GetPosition(); auto radius = self->GetRadius(); auto axis = self->GetAxis(); 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: if (axis == 0) { center[2] += 1; } else if (axis == 1) { center[2] += 1; } else { center[1] -= 1; } break; case 83: // S & s case 115: if (axis == 0) { center[2] -= 1; } else if (axis == 1) { center[2] -= 1; } else { center[1] += 1; } break; case 65: // A & a case 97: if (axis == 0) { center[1] -= 1; } else if (axis == 1) { center[0] -= 1; } else { center[0] += 1; } break; case 100: // D & d case 68: if (axis == 0) { center[1] += 1; } else if (axis == 1) { center[0] += 1; } else { center[0] -= 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$