VTK  9.1.0
vtkSphereRepresentation.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSphereRepresentation.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
85#ifndef vtkSphereRepresentation_h
86#define vtkSphereRepresentation_h
87
88#include "vtkInteractionWidgetsModule.h" // For export macro
89#include "vtkSphereSource.h" // Needed for fast access to the sphere source
91
92class vtkActor;
94class vtkSphere;
95class vtkSphereSource;
96class vtkCellPicker;
97class vtkProperty;
98class vtkPolyData;
99class vtkPoints;
101class vtkTransform;
102class vtkDoubleArray;
103class vtkMatrix4x4;
104class vtkTextMapper;
105class vtkActor2D;
106class vtkTextProperty;
107class vtkLineSource;
108class vtkCursor3D;
109
110#define VTK_SPHERE_OFF 0
111#define VTK_SPHERE_WIREFRAME 1
112#define VTK_SPHERE_SURFACE 2
113
114class VTKINTERACTIONWIDGETS_EXPORT vtkSphereRepresentation : public vtkWidgetRepresentation
115{
116public:
121
123
127 void PrintSelf(ostream& os, vtkIndent indent) override;
129
130 // Used to manage the state of the widget
131 enum
132 {
133 Outside = 0,
137 Scaling
138 };
139
141
145 vtkSetClampMacro(Representation, int, VTK_SPHERE_OFF, VTK_SPHERE_SURFACE);
146 vtkGetMacro(Representation, int);
147 void SetRepresentationToOff() { this->SetRepresentation(VTK_SPHERE_OFF); }
148 void SetRepresentationToWireframe() { this->SetRepresentation(VTK_SPHERE_WIREFRAME); }
149 void SetRepresentationToSurface() { this->SetRepresentation(VTK_SPHERE_SURFACE); }
151
155 void SetThetaResolution(int r) { this->SphereSource->SetThetaResolution(r); }
156 int GetThetaResolution() { return this->SphereSource->GetThetaResolution(); }
157
161 void SetPhiResolution(int r) { this->SphereSource->SetPhiResolution(r); }
162 int GetPhiResolution() { return this->SphereSource->GetPhiResolution(); }
163
169 void SetCenter(double c[3]);
170 void SetCenter(double x, double y, double z)
171 {
172 double c[3];
173 c[0] = x;
174 c[1] = y;
175 c[2] = z;
176 this->SetCenter(c);
177 }
178 double* GetCenter() VTK_SIZEHINT(3) { return this->SphereSource->GetCenter(); }
179 void GetCenter(double xyz[3]) { this->SphereSource->GetCenter(xyz); }
180
185 void SetRadius(double r);
186 double GetRadius() { return this->SphereSource->GetRadius(); }
187
189
195 vtkSetMacro(HandleVisibility, vtkTypeBool);
196 vtkGetMacro(HandleVisibility, vtkTypeBool);
197 vtkBooleanMacro(HandleVisibility, vtkTypeBool);
199
201
205 void SetHandlePosition(double handle[3]);
206 void SetHandlePosition(double x, double y, double z)
207 {
208 double p[3];
209 p[0] = x;
210 p[1] = y;
211 p[2] = z;
212 this->SetHandlePosition(p);
213 }
214 vtkGetVector3Macro(HandlePosition, double);
216
218
223 void SetHandleDirection(double dir[3]);
224 void SetHandleDirection(double dx, double dy, double dz)
225 {
226 double d[3];
227 d[0] = dx;
228 d[1] = dy;
229 d[2] = dz;
230 this->SetHandleDirection(d);
231 }
232 vtkGetVector3Macro(HandleDirection, double);
234
236
243 vtkSetMacro(HandleText, vtkTypeBool);
244 vtkGetMacro(HandleText, vtkTypeBool);
245 vtkBooleanMacro(HandleText, vtkTypeBool);
247
249
253 vtkSetMacro(RadialLine, vtkTypeBool);
254 vtkGetMacro(RadialLine, vtkTypeBool);
255 vtkBooleanMacro(RadialLine, vtkTypeBool);
257
259
263 vtkSetMacro(CenterCursor, bool);
264 vtkGetMacro(CenterCursor, bool);
265 vtkBooleanMacro(CenterCursor, bool);
267
276
283 void GetSphere(vtkSphere* sphere);
284
286
290 vtkGetObjectMacro(SphereProperty, vtkProperty);
291 vtkGetObjectMacro(SelectedSphereProperty, vtkProperty);
293
295
300 vtkGetObjectMacro(HandleProperty, vtkProperty);
301 vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
303
305
309 vtkGetObjectMacro(HandleTextProperty, vtkTextProperty);
311
313
317 vtkGetObjectMacro(RadialLineProperty, vtkProperty);
319
329 void SetInteractionState(int state);
330
332
337 void PlaceWidget(double bounds[6]) override;
338 virtual void PlaceWidget(double center[3], double handlePosition[3]);
339 void BuildRepresentation() override;
340 int ComputeInteractionState(int X, int Y, int modify = 0) override;
341 void StartWidgetInteraction(double e[2]) override;
342 void WidgetInteraction(double e[2]) override;
343 double* GetBounds() override;
345
347
356
357 /*
358 * Register internal Pickers within PickingManager
359 */
360 void RegisterPickers() override;
361
363
367 vtkGetMacro(TranslationAxis, int);
368 vtkSetClampMacro(TranslationAxis, int, -1, 2);
370
372
375 void SetXTranslationAxisOn() { this->TranslationAxis = Axis::XAxis; }
376 void SetYTranslationAxisOn() { this->TranslationAxis = Axis::YAxis; }
377 void SetZTranslationAxisOn() { this->TranslationAxis = Axis::ZAxis; }
378 void SetTranslationAxisOff() { this->TranslationAxis = Axis::NONE; }
380
382
385 bool IsTranslationConstrained() { return this->TranslationAxis != Axis::NONE; }
387
388protected:
391
392 // Manage how the representation appears
393 double LastEventPosition[3];
394
396
397 // the sphere
401 void HighlightSphere(int highlight);
402
403 // The representation of the sphere
405
406 // Do the picking
409 double LastPickPosition[3];
410
411 // Methods to manipulate the sphere widget
412 void Translate(const double* p1, const double* p2);
413 void Scale(const double* p1, const double* p2, int X, int Y);
414 void PlaceHandle(const double* center, double radius);
415 virtual void SizeHandles();
416
417 // Method to adapt the center cursor bounds
418 // so it always have the same pixel size on screen
420
421 // Properties used to control the appearance of selected objects and
422 // the manipulator in general.
428
429 // Managing the handle
435 double HandleDirection[3];
436 double HandlePosition[3];
437
438 // Manage the handle label
443
444 // Manage the radial line segment
450
451 // Managing the center cursor
456
457private:
459 void operator=(const vtkSphereRepresentation&) = delete;
460};
461
462#endif
a actor that draws 2D data
Definition: vtkActor2D.h:149
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:155
ray-cast cell picker for all kinds of Prop3Ds
Definition: vtkCellPicker.h:96
generate a 3D cursor representation
Definition: vtkCursor3D.h:56
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:113
create a line defined by two end points
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
represent and manipulate 3D points
Definition: vtkPoints.h:143
Superclass for algorithms that produce only polydata as output.
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:195
represent surface properties of a geometric object
Definition: vtkProperty.h:171
a class defining the representation for the vtkSphereWidget2
void SetHandleDirection(double dx, double dy, double dz)
Set/Get the direction vector of the handle relative to the center of the sphere.
void SetPhiResolution(int r)
Set/Get the resolution of the sphere in the phi direction.
void SetRepresentationToWireframe()
Set the representation (i.e., appearance) of the sphere.
void BuildRepresentation() override
These are methods that satisfy vtkWidgetRepresentation's API.
void GetPolyData(vtkPolyData *pd)
Grab the polydata (including points) that defines the sphere.
vtkPolyDataMapper * HandleMapper
void SetXTranslationAxisOn()
Toggles constraint translation axis on/off.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type information and to print out the contents of the class.
vtkPolyDataMapper * CenterMapper
void SetHandleDirection(double dir[3])
Set/Get the direction vector of the handle relative to the center of the sphere.
bool IsTranslationConstrained()
Returns true if ContrainedAxis.
void SetZTranslationAxisOn()
Toggles constraint translation axis on/off.
void SetCenter(double x, double y, double z)
int ComputeInteractionState(int X, int Y, int modify=0) override
These are methods that satisfy vtkWidgetRepresentation's API.
static vtkSphereRepresentation * New()
Instantiate the class.
double * GetBounds() override
These are methods that satisfy vtkWidgetRepresentation's API.
void SetTranslationAxisOff()
Toggles constraint translation axis on/off.
void SetRepresentationToOff()
Set the representation (i.e., appearance) of the sphere.
virtual void PlaceWidget(double center[3], double handlePosition[3])
These are methods that satisfy vtkWidgetRepresentation's API.
void SetCenter(double c[3])
Set/Get the center position of the sphere.
void PlaceHandle(const double *center, double radius)
vtkPolyDataMapper * RadialLineMapper
int RenderOpaqueGeometry(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetThetaResolution(int r)
Set/Get the resolution of the sphere in the theta direction.
void SetInteractionState(int state)
The interaction state may be set from a widget (e.g., vtkSphereWidget2) or other object.
void GetSphere(vtkSphere *sphere)
Get the spherical implicit function defined by this widget.
vtkTextProperty * HandleTextProperty
void HighlightSphere(int highlight)
void SetRadius(double r)
Set/Get the radius of sphere.
void PlaceWidget(double bounds[6]) override
These are methods that satisfy vtkWidgetRepresentation's API.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetYTranslationAxisOn()
Toggles constraint translation axis on/off.
void WidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
~vtkSphereRepresentation() override
void SetHandlePosition(double x, double y, double z)
Set/Get the position of the handle.
void RegisterPickers() override
Register internal Pickers in the Picking Manager.
vtkPolyDataMapper * SphereMapper
int RenderOverlay(vtkViewport *) override
Methods supporting, and required by, the rendering process.
void SetRepresentationToSurface()
Set the representation (i.e., appearance) of the sphere.
void SetHandlePosition(double handle[3])
Set/Get the position of the handle.
virtual void SizeHandles()
void ReleaseGraphicsResources(vtkWindow *) override
Methods supporting, and required by, the rendering process.
void Scale(const double *p1, const double *p2, int X, int Y)
void StartWidgetInteraction(double e[2]) override
These are methods that satisfy vtkWidgetRepresentation's API.
virtual void AdaptCenterCursorBounds()
vtkTypeBool HasTranslucentPolygonalGeometry() override
Methods supporting, and required by, the rendering process.
void Translate(const double *p1, const double *p2)
create a polygonal sphere centered at the origin
implicit function for a sphere
Definition: vtkSphere.h:141
2D text annotation
represent text properties.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
abstract specification for Viewports
Definition: vtkViewport.h:47
abstract class defines interface between the widget and widget representation classes
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_SPHERE_SURFACE
#define VTK_SPHERE_OFF
#define VTK_SPHERE_WIREFRAME
#define VTK_SIZEHINT(...)