SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
vtkConeRepresentation.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 #ifndef vtkConeRepresentation_h
11 #define vtkConeRepresentation_h
12 
13 #include "smtk/extension/vtk/widgets/vtkSMTKWidgetsExtModule.h" // For export macro
14 #include "vtkNew.h"
15 #include "vtkVector.h"
16 #include "vtkWidgetRepresentation.h"
17 
18 #include <array>
19 
20 class vtkActor;
21 class vtkPolyDataMapper;
22 class vtkCellPicker;
23 class vtkConeSource;
24 class vtkGlyph3DMapper;
26 class vtkSphereSource;
27 class vtkTubeFilter;
28 class vtkConeFrustum;
29 class vtkProperty;
30 class vtkImageData;
31 class vtkOutlineFilter;
32 class vtkFeatureEdges;
33 class vtkPolyData;
34 class vtkPolyDataAlgorithm;
35 class vtkTransform;
36 class vtkBox;
37 class vtkLookupTable;
38 
39 #define VTK_MAX_CONE_RESOLUTION 2048
40 
54 class VTKSMTKWIDGETSEXT_EXPORT vtkConeRepresentation : public vtkWidgetRepresentation
55 {
56 public:
60  static vtkConeRepresentation* New();
61 
63 
66  vtkTypeMacro(vtkConeRepresentation, vtkWidgetRepresentation);
67  void PrintSelf(ostream& os, vtkIndent indent) override;
69 
71  vtkConeRepresentation& operator=(const vtkConeRepresentation&) = delete;
72 
74 
77  bool SetEndpoint(bool isBottom, double x, double y, double z);
78  bool SetEndpoint(bool isBottom, const vtkVector3d& pt);
79  vtkVector3d GetEndpoint(bool isBottom) const;
80 
81  bool SetBottomEndpoint(double x, double y, double z) { return this->SetEndpoint(true, x, y, z); }
82  bool SetBottomEndpoint(const vtkVector3d& pt) { return this->SetEndpoint(true, pt); }
83  vtkVector3d GetBottomEndpoint() const { return this->GetEndpoint(true); }
84  void SetBottomPoint(double x, double y, double z) { this->SetEndpoint(true, x, y, z); }
85  void SetBottomPoint(double* x) VTK_SIZEHINT(3) { this->SetEndpoint(true, x[0], x[1], x[2]); }
86  double* GetBottomPoint() VTK_SIZEHINT(3);
87 
88  bool SetTopEndpoint(double x, double y, double z) { return this->SetEndpoint(false, x, y, z); }
89  bool SetTopEndpoint(const vtkVector3d& pt) { return this->SetEndpoint(false, pt); }
90  vtkVector3d GetTopEndpoint() const { return this->GetEndpoint(false); }
91  void SetTopPoint(double x, double y, double z) { this->SetEndpoint(false, x, y, z); }
92  void SetTopPoint(double* x) VTK_SIZEHINT(3) { this->SetEndpoint(false, x[0], x[1], x[2]); }
93  double* GetTopPoint() VTK_SIZEHINT(3);
95 
97 
103  bool SetRadius(bool isBottom, double r);
104  double GetRadius(bool isBottom) const;
105 
106  bool SetBottomRadius(double r) { return this->SetRadius(true, r); }
107  double GetBottomRadius() const { return this->GetRadius(true); }
108 
109  bool SetTopRadius(double r) { return this->SetRadius(false, r); }
110  double GetTopRadius() const { return this->GetRadius(false); }
112 
114 
120  bool SetCylindrical(int);
121  vtkGetMacro(Cylindrical, int);
122  vtkBooleanMacro(Cylindrical, int);
124 
126 
133  void SetAlongXAxis(vtkTypeBool);
134  vtkGetMacro(AlongXAxis, vtkTypeBool);
135  vtkBooleanMacro(AlongXAxis, vtkTypeBool);
136  void SetAlongYAxis(vtkTypeBool);
137  vtkGetMacro(AlongYAxis, vtkTypeBool);
138  vtkBooleanMacro(AlongYAxis, vtkTypeBool);
139  void SetAlongZAxis(vtkTypeBool);
140  vtkGetMacro(AlongZAxis, vtkTypeBool);
141  vtkBooleanMacro(AlongZAxis, vtkTypeBool);
143 
145 
151  void SetDrawCone(vtkTypeBool drawCyl);
152  vtkGetMacro(DrawCone, vtkTypeBool);
153  vtkBooleanMacro(DrawCone, vtkTypeBool);
155 
157 
163  vtkSetClampMacro(Resolution, int, 8, VTK_MAX_CONE_RESOLUTION);
164  vtkGetMacro(Resolution, int);
166 
168 
177  vtkSetClampMacro(Tolerance, double, 0.0, VTK_DOUBLE_MAX);
178  vtkGetMacro(Tolerance, double);
180 
182 
187  vtkSetMacro(Tubing, vtkTypeBool);
188  vtkGetMacro(Tubing, vtkTypeBool);
189  vtkBooleanMacro(Tubing, vtkTypeBool);
191 
193 
196  vtkSetMacro(ScaleEnabled, vtkTypeBool);
197  vtkGetMacro(ScaleEnabled, vtkTypeBool);
198  vtkBooleanMacro(ScaleEnabled, vtkTypeBool);
200 
208  void GetCone(vtkImplicitConeFrustum* cone);
209 
214  void UpdatePlacement();
215 
217 
220  vtkGetObjectMacro(HandleProperty, vtkProperty);
221  vtkGetObjectMacro(SelectedHandleProperty, vtkProperty);
223 
225 
229  vtkGetObjectMacro(ConeProperty, vtkProperty);
230  vtkGetObjectMacro(SelectedConeProperty, vtkProperty);
232 
234 
238  vtkGetObjectMacro(EdgeProperty, vtkProperty);
240 
242 
245  int ComputeInteractionState(int X, int Y, int modify = 0) override;
246  void PlaceWidget(double bounds[6]) override;
247  void BuildRepresentation() override;
248  void StartWidgetInteraction(double eventPos[2]) override;
249  void WidgetInteraction(double newEventPos[2]) override;
250  void EndWidgetInteraction(double newEventPos[2]) override;
252 
254 
257  double* GetBounds() override;
258  void GetActors(vtkPropCollection* pc) override;
259  void ReleaseGraphicsResources(vtkWindow*) override;
260  int RenderOpaqueGeometry(vtkViewport*) override;
261  int RenderTranslucentPolygonalGeometry(vtkViewport*) override;
262  vtkTypeBool HasTranslucentPolygonalGeometry() override;
264 
266 
271  vtkSetClampMacro(BumpDistance, double, 0.000001, 1);
272  vtkGetMacro(BumpDistance, double);
274 
282  void BumpCone(int dir, double factor);
283 
290  void PushCone(double distance);
291 
292  // Manage the state of the widget
293  enum _InteractionState
294  {
295  Outside = 0,
296  Moving,
297  PushingBottomFace,
298  PushingTopFace,
299  AdjustingBottomRadius,
300  AdjustingTopRadius,
301  MovingBottomHandle,
302  MovingTopHandle,
303  MovingWhole,
304  RotatingAxis,
305  Scaling,
306  TranslatingCenter
307  };
308 
309  static std::string InteractionStateToString(int);
310 
312 
321  vtkSetClampMacro(InteractionState, int, Outside, TranslatingCenter);
323 
325 
329  virtual void SetRepresentationState(int);
330  vtkGetMacro(RepresentationState, int);
332 
333  /*
334  * Register internal Pickers within PickingManager
335  */
336  void RegisterPickers() override;
337 
339  void SwapTopAndBottom();
340 
341 protected:
343  ~vtkConeRepresentation() override;
344 
347  {
348  ConeFace = 0,
349  BottomFace,
350  TopFace,
351  ConeAxis,
352  BottomCurve,
353  TopCurve,
354  BottomHandle,
355  TopHandle,
356  NumberOfElements
357  };
358 
359  void HighlightElement(ElementType elem, int highlight);
360 
361  void HighlightCone(int highlight);
362  void HighlightAxis(int highlight);
363  void HighlightCap(bool isBottom, int highlight);
364  void HighlightCurve(bool isBottom, int highlight);
365  void HighlightHandle(bool isBottom, int highlight);
366 
367  // Methods to manipulate the cylinder
368  void Rotate(double X, double Y, double* p1, double* p2, double* vpn);
369  void TranslateCone(double* p1, double* p2);
370  void PushCap(bool isBottom, double* p1, double* p2);
371  void AdjustBottomRadius(double X, double Y, double* p1, double* p2);
372  void AdjustTopRadius(double X, double Y, double* p1, double* p2);
373  void TranslateCenter(double* p1, double* p2);
374  void TranslateCenterOnAxis(double* p1, double* p2);
375  void TranslateHandle(bool isBottom, double* p1, double* p2);
376  void Scale(double* p1, double* p2, double X, double Y);
377  void SizeHandles();
378 
379  void CreateDefaultProperties();
380 
381  struct Element
382  {
383  vtkNew<vtkActor> Actor;
384  vtkNew<vtkPolyDataMapper> Mapper;
385  };
386 
387  // Actors and mappers for all visual elements of the representation.
388  std::array<Element, NumberOfElements> Elements;
389 
390  int RepresentationState;
391  // Keep track of event positions
392  double LastEventPosition[3];
393  // Controlling the push operation
394  double BumpDistance{ 0.01 };
395  // Controlling ivars
396  vtkTypeBool AlongXAxis{ 0 };
397  vtkTypeBool AlongYAxis{ 0 };
398  vtkTypeBool AlongZAxis{ 0 };
399  // The actual cylinder which is being manipulated
400  vtkNew<vtkConeFrustum> Cone;
401  // The facet resolution for rendering purposes.
402  int Resolution{ 128 };
403  double Tolerance{ 1e-8 }; // How close are endpoints allowed to be?
404  vtkTypeBool ScaleEnabled{ 1 }; //whether the widget can be scaled
405  vtkTypeBool DrawCone{ 1 };
406  vtkNew<vtkTubeFilter> AxisTuber; // Used to style edges.
407  vtkTypeBool Tubing{ 1 }; //control whether tubing is on
408  int Cylindrical{ 0 }; // control whether the cone is a cylinder (apex at infinity)
409 
410  // Source of endpoint handle geometry
411  vtkNew<vtkSphereSource> Sphere;
412 
413  // Do the picking
414  vtkNew<vtkCellPicker> Picker;
415  vtkNew<vtkCellPicker> CylPicker;
416 
417  // Properties used to control the appearance of selected objects and
418  // the manipulator in general.
419  vtkNew<vtkProperty> HandleProperty;
420  vtkNew<vtkProperty> SelectedHandleProperty;
421  vtkNew<vtkProperty> ConeProperty;
422  vtkNew<vtkProperty> SelectedConeProperty;
423  vtkNew<vtkProperty> EdgeProperty;
424  vtkNew<vtkProperty> SelectedEdgeProperty;
425 
426  // Support GetBounds() method
427  vtkNew<vtkBox> BoundingBox;
428 
429  // Overrides for the point-handle polydata mappers
430  vtkNew<vtkGlyph3DMapper> BottomHandleMapper;
431  vtkNew<vtkGlyph3DMapper> TopHandleMapper;
432 
433  vtkNew<vtkTransform> Transform;
434 };
435 
436 #endif
vtkConeRepresentation
defining the representation for a vtkConeFrustum
Definition: vtkConeRepresentation.h:54
vtkConeFrustum
Generate a polygonal approximation to a cone frustum.
Definition: vtkConeFrustum.h:40
vtkConeRepresentation::Element
Definition: vtkConeRepresentation.h:381
vtkImplicitConeFrustum
Generate an implicit function whose 0-isocontour is a right cone frustum.
Definition: vtkImplicitConeFrustum.h:39
vtkConeRepresentation::ElementType
ElementType
Visual elements of the representation.
Definition: vtkConeRepresentation.h:346