VTK  9.3.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 <map> // For column ranges
28 #include <set> // For blank row support
29 #include <vector> // For row mapping
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkBitArray;
33 class vtkCategoryLegend;
34 class vtkColorLegend;
35 class vtkLookupTable;
36 class vtkStringArray;
37 class vtkTable;
38 class vtkTooltipItem;
39 class vtkVariantArray;
40 
41 class VTKVIEWSINFOVIS_EXPORT vtkHeatmapItem : public vtkContextItem
42 {
43 public:
44  static vtkHeatmapItem* New();
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
52  virtual void SetTable(vtkTable* table);
53 
57  vtkTable* GetTable();
58 
62  vtkStringArray* GetRowNames();
63 
65 
72  vtkGetMacro(NameColumn, vtkStdString);
73  vtkSetMacro(NameColumn, vtkStdString);
75 
79  void SetOrientation(int orientation);
80 
84  int GetOrientation();
85 
91  double GetTextAngleForOrientation(int orientation);
92 
94 
97  vtkSetVector2Macro(Position, float);
98  void SetPosition(const vtkVector2f& pos);
100 
102 
105  vtkGetVector2Macro(Position, float);
106  vtkVector2f GetPositionVector();
108 
110 
114  vtkGetMacro(CellHeight, double);
115  vtkSetMacro(CellHeight, double);
117 
119 
123  vtkGetMacro(CellWidth, double);
124  vtkSetMacro(CellWidth, double);
126 
130  virtual void GetBounds(double bounds[4]);
131 
136  void MarkRowAsBlank(const std::string& rowName);
137 
141  bool Paint(vtkContext2D* painter) override;
142 
144 
148  vtkGetMacro(RowLabelWidth, float);
149  vtkGetMacro(ColumnLabelWidth, float);
151 
155  enum
156  {
160  DOWN_TO_UP
161  };
162 
166  bool Hit(const vtkContextMouseEvent& mouse) override;
167 
171  bool MouseMoveEvent(const vtkContextMouseEvent& event) override;
172 
176  bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
177 
178 protected:
179  vtkHeatmapItem();
180  ~vtkHeatmapItem() override;
181 
183  float* Position;
184 
189  virtual void RebuildBuffers();
190 
194  virtual void PaintBuffers(vtkContext2D* painter);
195 
200  virtual bool IsDirty();
201 
205  void InitializeLookupTables();
206 
213  void AccumulateProminentCategoricalDataValues(vtkIdType column);
214 
219  void GenerateContinuousDataLookupTable();
220 
225  void GenerateCategoricalDataLookupTable();
226 
232  std::string GetTooltipText(float x, float y);
233 
240  void UpdateVisibleSceneExtent(vtkContext2D* painter);
241 
247  bool LineIsVisible(double x0, double y0, double x1, double y1);
248 
253  void ComputeBounds();
254 
259  void ComputeLabelWidth(vtkContext2D* painter);
260 
261  // Setup the position, size, and orientation of this heatmap's color
262  // legend based on the heatmap's current orientation.
263  void PositionColorLegend(int orientation);
264 
265  // Setup the position, size, and orientation of this heatmap's
266  // legends based on the heatmap's current orientation.
267  void PositionLegends(int orientation);
268 
272 
273 private:
274  vtkHeatmapItem(const vtkHeatmapItem&) = delete;
275  void operator=(const vtkHeatmapItem&) = delete;
276 
277  unsigned long HeatmapBuildTime;
278  vtkNew<vtkCategoryLegend> CategoryLegend;
279  vtkNew<vtkColorLegend> ColorLegend;
280  vtkNew<vtkTooltipItem> Tooltip;
281  vtkNew<vtkLookupTable> ContinuousDataLookupTable;
282  vtkNew<vtkLookupTable> CategoricalDataLookupTable;
283  vtkNew<vtkLookupTable> ColorLegendLookupTable;
284  vtkNew<vtkStringArray> CategoricalDataValues;
285  vtkNew<vtkVariantArray> CategoryLegendValues;
286  double CellWidth;
287  double CellHeight;
288 
289  std::map<vtkIdType, std::pair<double, double>> ColumnRanges;
290  std::vector<vtkIdType> SceneRowToTableRowMap;
291  std::vector<vtkIdType> SceneColumnToTableColumnMap;
292  std::set<std::string> BlankRows;
293 
294  double MinX;
295  double MinY;
296  double MaxX;
297  double MaxY;
298  double SceneBottomLeft[3];
299  double SceneTopRight[3];
300  float RowLabelWidth;
301  float ColumnLabelWidth;
302 
303  vtkBitArray* CollapsedRowsArray;
304  vtkBitArray* CollapsedColumnsArray;
305  bool LegendPositionSet;
306 };
307 
308 VTK_ABI_NAMESPACE_END
309 #endif
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
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:315
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:58
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:28
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
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.