/*========================================================================= Program: Visualization Toolkit Module: TestCenteredSliderWidget2D.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // // This example tests the vtkSliderWidget with a 2D representation. // First include the required header files for the VTK classes we are using. #include "vtkSmartPointer.h" #include "vtkActor.h" #include "vtkAppendPolyData.h" #include "vtkCenteredSliderWidget.h" #include "vtkClipPolyData.h" #include "vtkCommand.h" #include "vtkConeSource.h" #include "vtkGlyph3D.h" #include "vtkInteractorEventRecorder.h" #include "vtkLODActor.h" #include "vtkPolyDataMapper.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkSliderRepresentation2D.h" #include "vtkSmartPointer.h" #include "vtkSphere.h" #include "vtkSphereSource.h" #include "vtkWidgetEvent.h" #include "vtkWidgetEventTranslator.h" // This does the actual work: updates the probe. // Callback for the interaction class vtkCenteredSlider2DCallback : public vtkCommand { public: static vtkCenteredSlider2DCallback* New() { return new vtkCenteredSlider2DCallback; } void Execute(vtkObject* caller, unsigned long, void*) override { vtkCenteredSliderWidget* sliderWidget = reinterpret_cast(caller); double widgetValue = sliderWidget->GetValue(); this->Glyph->SetScaleFactor(this->Glyph->GetScaleFactor() * widgetValue); } vtkCenteredSlider2DCallback() : Glyph(nullptr) { } vtkGlyph3D* Glyph; }; int TestCenteredSliderWidget2D(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) { // Create a mace out of filters. vtkSmartPointer sphereSource = vtkSmartPointer::New(); vtkSmartPointer cone = vtkSmartPointer::New(); vtkSmartPointer glyph = vtkSmartPointer::New(); glyph->SetInputConnection(sphereSource->GetOutputPort()); glyph->SetSourceConnection(cone->GetOutputPort()); glyph->SetVectorModeToUseNormal(); glyph->SetScaleModeToScaleByVector(); glyph->SetScaleFactor(0.25); // The sphere and spikes are appended into a single polydata. // This just makes things simpler to manage. vtkSmartPointer apd = vtkSmartPointer::New(); apd->AddInputConnection(glyph->GetOutputPort()); apd->AddInputConnection(sphereSource->GetOutputPort()); vtkSmartPointer maceMapper = vtkSmartPointer::New(); maceMapper->SetInputConnection(apd->GetOutputPort()); vtkSmartPointer maceActor = vtkSmartPointer::New(); maceActor->SetMapper(maceMapper); maceActor->VisibilityOn(); maceActor->SetPosition(1, 1, 1); // Create the RenderWindow, Renderer and both Actors vtkSmartPointer ren1 = vtkSmartPointer::New(); vtkSmartPointer renWin = vtkSmartPointer::New(); renWin->AddRenderer(ren1); vtkSmartPointer iren = vtkSmartPointer::New(); iren->SetRenderWindow(renWin); // VTK widgets consist of two parts: the widget part that handles event // processing; and the widget representation that defines how the widget // appears in the scene (i.e., matters pertaining to geometry). vtkSmartPointer sliderRep = vtkSmartPointer::New(); sliderRep->SetMinimumValue(0.7); sliderRep->SetMaximumValue(1.3); sliderRep->SetValue(1.0); sliderRep->SetTitleText("Spike Size"); sliderRep->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay(); sliderRep->GetPoint1Coordinate()->SetValue(0.2, 0.1); sliderRep->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay(); sliderRep->GetPoint2Coordinate()->SetValue(0.8, 0.1); sliderRep->SetSliderLength(0.02); sliderRep->SetSliderWidth(0.03); sliderRep->SetEndCapLength(0.03); sliderRep->SetEndCapWidth(0.03); sliderRep->SetTubeWidth(0.005); vtkSmartPointer sliderWidget = vtkSmartPointer::New(); sliderWidget->SetInteractor(iren); sliderWidget->SetRepresentation(sliderRep); vtkSmartPointer callback = vtkSmartPointer::New(); callback->Glyph = glyph; sliderWidget->AddObserver(vtkCommand::InteractionEvent, callback); ren1->AddActor(maceActor); // Add the actors to the renderer, set the background and size ren1->SetBackground(0.1, 0.2, 0.4); renWin->SetSize(300, 300); // record events vtkSmartPointer recorder = vtkSmartPointer::New(); recorder->SetInteractor(iren); recorder->SetFileName("c:/record.log"); // recorder->Record(); // recorder->ReadFromInputStringOn(); // recorder->SetInputString(eventLog); // render the image iren->Initialize(); renWin->Render(); // recorder->Play(); // Remove the observers so we can go interactive. Without this the "-I" // testing option fails. recorder->Off(); iren->Start(); return EXIT_SUCCESS; }