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 
52  /*
53  * Override to rescale box corners when the valid bounds have changed.
54  */
55  void SetValidBounds(double x0, double x1, double y0, double y1) override;
56 
58 
61  vtkSetMacro(Selected, bool);
62  vtkGetMacro(Selected, bool);
63  vtkBooleanMacro(Selected, bool);
65 
67 
70  virtual void SetBoxColor(double r, double g, double b, double a);
71  virtual void SetBoxColor(const double c[4]) { this->SetBoxColor(c[0], c[1], c[2], c[3]); }
72  double* GetBoxColor() VTK_SIZEHINT(4);
73  virtual void GetBoxColor(double& r, double& g, double& b, double& a);
74  virtual void GetBoxColor(double c[4]) { this->GetBoxColor(c[0], c[1], c[2], c[3]); }
76 
78 
81  void SetTransferFunctionBox(vtkPVTransferFunction2DBox* b);
82  vtkPVTransferFunction2DBox* GetTransferFunctionBox();
84 
86 
90  vtkSetMacro(ID, int);
91  vtkGetMacro(ID, int);
93 
94 protected:
96  ~vtkTransferFunctionBoxItem() override;
97 
98  vtkIdType AddPoint(double x, double y);
99  vtkIdType AddPoint(double* pos) override;
100 
112  {
113  BOTTOM_LEFT = 0,
117  BOTTOM_LEFT_LOOP
118  };
119 
123  vtkIdType RemovePoint(double* pos) override;
124 
125  vtkIdType GetNumberOfPoints() const override;
126 
127  void GetControlPoint(vtkIdType index, double* point) const override;
128 
130 
131  void SetControlPoint(vtkIdType index, double* point) override;
132 
133  void emitEvent(unsigned long event, void* params = nullptr) override;
134 
135  void MovePoint(vtkIdType pointId, double deltaX, double deltaY);
136 
137  void DragBox(double deltaX, double deltaY);
138 
139  void DragCorner(vtkIdType cornerId, const double* delta);
140 
141  bool Paint(vtkContext2D* painter) override;
142 
147  bool Hit(const vtkContextMouseEvent& mouse) override;
148 
150 
157  bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
158  bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
159  bool MouseDoubleClickEvent(const vtkContextMouseEvent& mouse) override;
160  bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
161  bool KeyPressEvent(const vtkContextKeyEvent& key) override;
162  bool KeyReleaseEvent(const vtkContextKeyEvent& key) override;
164 
168  virtual void SelectBox();
169 
170 private:
179  void ClampToValidPosition(double pos[2]);
180 
185  void UpdateBoxPoints();
186 
191  bool ArePointsCrossing(vtkIdType pointA, const double* deltaA, vtkIdType pointB);
192 
198  bool BoxIsWithinBounds(double deltaX, double deltaY);
199 
210  vtkIdType FindBoxPoint(double* _pos);
211 
212  // Helper members
213  std::unique_ptr<vtkTransferFunctionBoxItemInternals> Internals;
214 
215  bool Initialized = false;
216  bool Selected = false;
217  int ID = -1;
218 };
219 
220 #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