VTK  9.3.20240327
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 
58 
63 
65 
72  vtkGetMacro(NameColumn, vtkStdString);
73  vtkSetMacro(NameColumn, vtkStdString);
75 
80 
85 
92 
94 
97  vtkSetVector2Macro(Position, float);
98  void SetPosition(const vtkVector2f& pos);
100 
102 
105  vtkGetVector2Macro(Position, float);
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:
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 
206 
214 
220 
226 
232  std::string GetTooltipText(float x, float y);
233 
241 
247  bool LineIsVisible(double x0, double y0, double x1, double y1);
248 
254 
260 
261  // Setup the position, size, and orientation of this heatmap's color
262  // legend based on the heatmap's current orientation.
264 
265  // Setup the position, size, and orientation of this heatmap's
266  // legends based on the heatmap's current 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
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:29
Legend item to display categorical data.
Legend item to display vtkScalarsToColors.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:69
base class for items that are part of a vtkContextScene.
data structure to represent mouse events.
A 2D graphics item for rendering a heatmap.
int GetOrientation()
Get the current heatmap orientation.
vtkStdString NameColumn
double GetTextAngleForOrientation(int orientation)
Get the angle that row labels should be rotated for the corresponding heatmap orientation.
~vtkHeatmapItem() override
virtual void RebuildBuffers()
Generate some data needed for painting.
bool LineIsVisible(double x0, double y0, double x1, double y1)
Returns true if any part of the line segment defined by endpoints (x0, y0), (x1, y1) falls within the...
void PositionLegends(int orientation)
bool MouseDoubleClickEvent(const vtkContextMouseEvent &event) override
Display a legend for a column of data.
vtkSmartPointer< vtkTable > Table
virtual void SetTable(vtkTable *table)
Set the table that this item draws.
void PositionColorLegend(int orientation)
std::string GetTooltipText(float x, float y)
Get the value for the cell of the heatmap located at scene position (x, y) This function assumes the ...
void SetOrientation(int orientation)
Set which way the table should face within the visualization.
bool MouseMoveEvent(const vtkContextMouseEvent &event) override
Display a tooltip when the user mouses over a cell in the heatmap.
vtkVector2f GetPositionVector()
Get position of the heatmap.
vtkStringArray * RowNames
void SetPosition(const vtkVector2f &pos)
Set the position of the heatmap.
void MarkRowAsBlank(const std::string &rowName)
Mark a row as blank, meaning that no cells will be drawn for it.
void AccumulateProminentCategoricalDataValues(vtkIdType column)
Helper function.
void UpdateVisibleSceneExtent(vtkContext2D *painter)
Calculate the extent of the data that is visible within the window.
vtkVector2f PositionVector
vtkStringArray * GetRowNames()
Get the table that this item draws.
virtual void PaintBuffers(vtkContext2D *painter)
This function does the bulk of the actual work in rendering our heatmap.
void ComputeBounds()
Compute the extent of the heatmap.
vtkTable * GetTable()
Get the table that this item draws.
virtual void GetBounds(double bounds[4])
Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
static vtkHeatmapItem * New()
void InitializeLookupTables()
Generate a separate vtkLookupTable for each column in the table.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the transform is interactive, false otherwise.
void GenerateContinuousDataLookupTable()
Setup the default lookup table to use for continuous (not categorical) data.
bool Paint(vtkContext2D *painter) override
Paints the table as a heatmap.
void GenerateCategoricalDataLookupTable()
Setup the default lookup table to use for categorical (not continuous) data.
void ComputeLabelWidth(vtkContext2D *painter)
Compute the width of our longest row label and the width of our longest column label.
virtual bool IsDirty()
This function returns a bool indicating whether or not we need to rebuild our cached data before pain...
a simple class to control print indentation
Definition: vtkIndent.h:108
map scalar values into colors via a lookup table
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:168
takes care of drawing 2D axes
An array holding vtkVariants.
@ orientation
Definition: vtkX3D.h:262
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:315