From KitwarePublic
Jump to: navigation, search



3D widget for manipulating a sphere
This 3D widget defines a sphere that can be interactively placed in a scene.
The vtkSphereWidget has several methods that can be used in conjunction with other VTK objects. The Set/GetThetaResolution() and Set/GetPhiResolution() methods control the number of subdivisions of the sphere in the theta and phi directions; the GetPolyData() method can be used to get the polygonal representation and can be used for things like seeding streamlines. The GetSphere() method returns a sphere implicit function that can be used for cutting and clipping. Typical usage of the widget is to make use of the StartInteractionEvent, InteractionEvent, and EndInteractionEvent events. The InteractionEvent is called on mouse motion; the other two events are called on button down and button up (any mouse button).
Some additional features of this class include the ability to control the properties of the widget. You can set the properties of the selected and unselected representations of the sphere.

Classes Used

  • vtkSphereWidget
  • vtkSphereRepresentation
  • vtkActor
  • vtkCellPicker
  • vtkPolyDataMapper
  • vtkProperty
  • vtkSphereSource

Class Diagram

3DWidgets class arch sphere.jpg

Using the widget (example code)

vtkSphereWidget * sphereWidget = vtkSphereWidget::New();
vtkSphereRepresentation * sphereRep = sphereWidget->GetRepresentation();

Basic event handling is automatically generated so no need to set up a callback/event translator unless you need to change the way the events are handled. In such a case use GetEventTranslator() which returns a pointer to the vtkWidgetEventTranslator in use. Thereafter, you can set event handling directly to this translator.

Anything affecting the widgets representation can be accessed using the sphereRep as shown above, such as PlaceWidget(double bounds[6]).

To set a representation other than the default vtkSphereRepresentation, instead of calling sphereWidget->GetRepresentation(), which instantiates the default representation if none exists, use SetRepresentation(vtkSphereRepresentation *r) to pass an instance of a representation inheriting from vtkSphereRepresentation.

KWWidgets: [Welcome | Site Map]