vtkTransferFunctionBoxItem.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef vtkTransferFunctionBoxItem_h
4 #define vtkTransferFunctionBoxItem_h
5 
6 #include "vtkControlPointsItem.h"
7 
8 #include "vtkRemotingViewsModule.h" // needed for export macro
9 
10 // STL includes
11 #include <memory> // needed for unique_ptr
12 
13 // Forward declarations
14 class vtkImageData;
15 class vtkTransferFunctionBoxItemInternals;
17 
19 {
20 public:
23  void PrintSelf(ostream& os, vtkIndent indent) override;
24 
25  // Events fires by this class (and subclasses).
26  // \li BoxAddEvent is fired when this box item is added to a chart.
27  // \li BoxEditEvent is fired when this box item is edited, either by dragging the whole box or
28  // editing the corner points.
29  enum
30  {
31  BoxAddEvent = vtkCommand::UserEvent + 100,
34  BoxDeleteEvent
35  };
36 
40  const vtkRectd& GetBox();
41 
45  void SetBox(double x, double y, double width, double height);
46 
50  vtkSmartPointer<vtkImageData> GetTexture() const;
51 
53  /*
54  * Override to rescale box corners when the valid bounds have changed.
55  */
56  void SetValidBounds(double x0, double x1, double y0, double y1) override;
57 
59 
62  vtkSetMacro(Selected, bool);
63  vtkGetMacro(Selected, bool);
64  vtkBooleanMacro(Selected, bool);
66 
68 
71  virtual void SetBoxColor(double r, double g, double b, double a);
72  virtual void SetBoxColor(const double c[4]) { this->SetBoxColor(c[0], c[1], c[2], c[3]); }
73  double* GetBoxColor() VTK_SIZEHINT(4);
74  virtual void GetBoxColor(double& r, double& g, double& b, double& a);
75  virtual void GetBoxColor(double c[4]) { this->GetBoxColor(c[0], c[1], c[2], c[3]); }
77 
79 
82  void SetTransferFunctionBox(vtkPVTransferFunction2DBox* b);
83  vtkPVTransferFunction2DBox* GetTransferFunctionBox();
85 
87 
91  vtkSetMacro(ID, int);
92  vtkGetMacro(ID, int);
94 
95 protected:
97  ~vtkTransferFunctionBoxItem() override;
98 
99  vtkIdType AddPoint(double x, double y);
100  vtkIdType AddPoint(double* pos) override;
101 
113  {
114  BOTTOM_LEFT = 0,
118  BOTTOM_LEFT_LOOP
119  };
120 
124  vtkIdType RemovePoint(double* pos) override;
125 
126  vtkIdType GetNumberOfPoints() const override;
127 
128  void GetControlPoint(vtkIdType index, double* point) const override;
129 
131 
132  void SetControlPoint(vtkIdType index, double* point) override;
133 
134  void emitEvent(unsigned long event, void* params = nullptr) override;
135 
136  void MovePoint(vtkIdType pointId, double deltaX, double deltaY);
137 
138  void DragBox(double deltaX, double deltaY);
139 
140  void DragCorner(vtkIdType cornerId, const double* delta);
141 
142  bool Paint(vtkContext2D* painter) override;
143 
148  bool Hit(const vtkContextMouseEvent& mouse) override;
149 
151 
158  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
159  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
160  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
161  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
162  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
163  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
165 
169  virtual void SelectBox();
170 
171 private:
180  void ClampToValidPosition(double pos[2]);
181 
186  void UpdateBoxPoints();
187 
192  bool ArePointsCrossing(vtkIdType pointA, const double* deltaA, vtkIdType pointB);
193 
199  bool BoxIsWithinBounds(double deltaX, double deltaY);
200 
211  vtkIdType FindBoxPoint(double* _pos);
212 
213  // Helper members
214  std::unique_ptr<vtkTransferFunctionBoxItemInternals> Internals;
215 
216  bool Initialized = false;
217  bool Selected = false;
218  int ID = -1;
219 };
220 
221 #endif // vtkTransferFunctionBoxItem_h
virtual void GetControlPoint(vtkIdType index, double *point) const=0
virtual bool Hit(const vtkContextMouseEvent &mouse)
#define VTKREMOTINGVIEWS_EXPORT
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
virtual vtkMTimeType GetControlPointsMTime()=0
virtual void SetValidBounds(double, double, double, double)
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key)
int vtkIdType
virtual void GetBoxColor(double c[4])
Set/Get the color to be used for this box.
vtkTypeUInt64 vtkMTimeType
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
vtkIdType MovePoint(vtkIdType point, const vtkVector2f &translation)
virtual bool KeyPressEvent(const vtkContextKeyEvent &key)
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual bool Paint(vtkContext2D *painter)
virtual void SetBoxColor(const double c[4])
Set/Get the color to be used for this box.
virtual vtkIdType RemovePoint(double *pos)=0
virtual void SetControlPoint(vtkIdType index, double *point)=0
virtual vtkIdType AddPoint(double *newPos)=0
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
static vtkObject * New()
virtual void emitEvent(unsigned long event, void *params=0)=0
BoxCorners
Box corners are ordered as follows: 3 --— 2 | | (4) 0 --— 1.
Shape that represents an individual control node in a 2D transfer function.
virtual vtkIdType GetNumberOfPoints() const=0