VTK  9.7.1
vtkHeatmapItem.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
17 #ifndef vtkHeatmapItem_h
18 #define vtkHeatmapItem_h
19 
20 #include "vtkContextItem.h"
21 #include "vtkViewsInfovisModule.h" // For export macro
22 
23 #include "vtkNew.h" // For vtkNew ivars
24 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
25 #include "vtkStdString.h" // For get/set ivars
26 #include "vtkVector.h" // For vtkVector2f ivar
27 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
28 #include <map> // For column ranges
29 #include <set> // For blank row support
30 #include <vector> // For row mapping
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class vtkBitArray;
34 class vtkCategoryLegend;
35 class vtkColorLegend;
36 class vtkLookupTable;
37 class vtkStringArray;
38 class vtkTable;
39 class vtkTooltipItem;
40 class vtkVariantArray;
41 
42 class VTKVIEWSINFOVIS_EXPORT VTK_MARSHALAUTO vtkHeatmapItem : public vtkContextItem
43 {
44 public:
45  static vtkHeatmapItem* New();
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
53  virtual void SetTable(vtkTable* table);
54 
58  vtkTable* GetTable();
59 
63  vtkStringArray* GetRowNames();
64 
66 
73  vtkGetMacro(NameColumn, vtkStdString);
74  vtkSetMacro(NameColumn, vtkStdString);
76 
80  void SetOrientation(int orientation);
81 
85  int GetOrientation();
86 
92  double GetTextAngleForOrientation(int orientation);
93 
95 
98  vtkSetVector2Macro(Position, float);
99  void SetPosition(const vtkVector2f& pos);
101 
103 
106  vtkGetVector2Macro(Position, float);
107  vtkVector2f GetPositionVector();
109 
111 
115  vtkGetMacro(CellHeight, double);
116  vtkSetMacro(CellHeight, double);
118 
120 
124  vtkGetMacro(CellWidth, double);
125  vtkSetMacro(CellWidth, double);
127 
131  virtual void GetBounds(double bounds[4]);
132 
137  void MarkRowAsBlank(const std::string& rowName);
138 
142  bool Paint(vtkContext2D* painter) override;
143 
145 
149  vtkGetMacro(RowLabelWidth, float);
150  vtkGetMacro(ColumnLabelWidth, float);
152 
156  enum
157  {
161  DOWN_TO_UP
162  };
163 
167  bool Hit(const vtkContextMouseEvent& mouse) override;
168 
172  bool MouseMoveEvent(const vtkContextMouseEvent& event) override;
173 
177  bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
178 
179  vtkGetObjectMacro(CategoryLegend, vtkCategoryLegend);
180  vtkGetObjectMacro(ColorLegend, vtkColorLegend);
181 
182 protected:
183  vtkHeatmapItem();
184  ~vtkHeatmapItem() override;
185 
187  float* Position;
188 
193  virtual void RebuildBuffers();
194 
198  virtual void PaintBuffers(vtkContext2D* painter);
199 
204  virtual bool IsDirty();
205 
209  void InitializeLookupTables();
210 
217  void AccumulateProminentCategoricalDataValues(vtkIdType column);
218 
223  void GenerateContinuousDataLookupTable();
224 
229  void GenerateCategoricalDataLookupTable();
230 
236  std::string GetTooltipText(float x, float y);
237 
244  void UpdateVisibleSceneExtent(vtkContext2D* painter);
245 
251  bool LineIsVisible(double x0, double y0, double x1, double y1);
252 
257  void ComputeBounds();
258 
263  void ComputeLabelWidth(vtkContext2D* painter);
264 
265  // Setup the position, size, and orientation of this heatmap's color
266  // legend based on the heatmap's current orientation.
267  void PositionColorLegend(int orientation);
268 
269  // Setup the position, size, and orientation of this heatmap's
270  // legends based on the heatmap's current orientation.
271  void PositionLegends(int orientation);
272 
276 
277 private:
278  vtkHeatmapItem(const vtkHeatmapItem&) = delete;
279  void operator=(const vtkHeatmapItem&) = delete;
280 
281  unsigned long HeatmapBuildTime;
282  vtkNew<vtkCategoryLegend> CategoryLegend;
283  vtkNew<vtkColorLegend> ColorLegend;
284  vtkNew<vtkTooltipItem> Tooltip;
285  vtkNew<vtkLookupTable> ContinuousDataLookupTable;
286  vtkNew<vtkLookupTable> CategoricalDataLookupTable;
287  vtkNew<vtkLookupTable> ColorLegendLookupTable;
288  vtkNew<vtkStringArray> CategoricalDataValues;
289  vtkNew<vtkVariantArray> CategoryLegendValues;
290  double CellWidth;
291  double CellHeight;
292 
293  std::map<vtkIdType, std::pair<double, double>> ColumnRanges;
294  std::vector<vtkIdType> SceneRowToTableRowMap;
295  std::vector<vtkIdType> SceneColumnToTableColumnMap;
296  std::set<std::string> BlankRows;
297 
298  double MinX;
299  double MinY;
300  double MaxX;
301  double MaxY;
302  double SceneBottomLeft[3];
303  double SceneTopRight[3];
304  float RowLabelWidth;
305  float ColumnLabelWidth;
306 
307  vtkBitArray* CollapsedRowsArray;
308  vtkBitArray* CollapsedColumnsArray;
309  bool LegendPositionSet;
310 };
311 
312 VTK_ABI_NAMESPACE_END
313 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
void GetBounds(T a, double bds[6])
An array holding vtkVariants.
base class for items that are part of a vtkContextScene.
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
map scalar values into colors via a lookup table
Legend item to display vtkScalarsToColors.
a vtkAbstractArray subclass for strings
A 2D graphics item for rendering a heatmap.
int vtkIdType
Definition: vtkType.h:363
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkVector2f PositionVector
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkStringArray * RowNames
Legend item to display categorical data.
vtkSmartPointer< vtkTable > Table
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:32
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse)
Mouse move event.
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
vtkStdString NameColumn
#define VTK_MARSHALAUTO
takes care of drawing 2D axes
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.