#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // The callback does the work. // The callback keeps a pointer to the sphere whose resolution is // controlled. After constructing the callback, the program sets the // SphereSource of the callback to // the object to be controlled. class vtkSliderCallback : public vtkCommand { public: static vtkSliderCallback *New() { return new vtkSliderCallback; } void Execute(vtkObject *caller, unsigned long, void*) override { vtkSliderWidget *sliderWidget = reinterpret_cast(caller); int value = static_cast(static_cast(sliderWidget->GetRepresentation())->GetValue()); this->SphereSource->SetPhiResolution(value/2); this->SphereSource->SetThetaResolution(value); } vtkSliderCallback():SphereSource(0) {} vtkSphereSource *SphereSource; }; int main (int, char *[]) { // A sphere vtkSmartPointer sphereSource = vtkSmartPointer::New(); sphereSource->SetCenter(0.0, 0.0, 0.0); sphereSource->SetRadius(4.0); sphereSource->SetPhiResolution(4); sphereSource->SetThetaResolution(8); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection(sphereSource->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); actor->GetProperty()->SetInterpolationToFlat(); // A renderer and render window vtkSmartPointer renderer = vtkSmartPointer::New(); vtkSmartPointer renderWindow = vtkSmartPointer::New(); renderWindow->AddRenderer(renderer); // An interactor vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); renderWindowInteractor->SetRenderWindow(renderWindow); // Add the actors to the scene renderer->AddActor(actor); // Render an image (lights and cameras are created automatically) renderWindow->Render(); vtkSmartPointer sliderRep = vtkSmartPointer::New(); sliderRep->SetMinimumValue(3.0); sliderRep->SetMaximumValue(50.0); sliderRep->SetValue(sphereSource->GetThetaResolution()); sliderRep->SetTitleText("Sphere Resolution"); sliderRep->GetPoint1Coordinate()->SetCoordinateSystemToWorld(); sliderRep->GetPoint1Coordinate()->SetValue(-4,6,0); sliderRep->GetPoint2Coordinate()->SetCoordinateSystemToWorld(); sliderRep->GetPoint2Coordinate()->SetValue(4,6,0); sliderRep->SetSliderLength(0.075); sliderRep->SetSliderWidth(0.05); sliderRep->SetEndCapLength(0.05); vtkSmartPointer sliderWidget = vtkSmartPointer::New(); sliderWidget->SetInteractor(renderWindowInteractor); sliderWidget->SetRepresentation(sliderRep); sliderWidget->SetAnimationModeToAnimate(); sliderWidget->EnabledOn(); vtkSmartPointer callback = vtkSmartPointer::New(); callback->SphereSource = sphereSource; sliderWidget->AddObserver(vtkCommand::InteractionEvent,callback); renderWindowInteractor->Initialize(); renderWindow->Render(); renderWindowInteractor->Start(); return EXIT_SUCCESS; }