VTK  9.5.20250718
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
32VTK_ABI_NAMESPACE_BEGIN
33class vtkBitArray;
35class vtkColorLegend;
36class vtkLookupTable;
37class vtkStringArray;
38class vtkTable;
39class vtkTooltipItem;
40class vtkVariantArray;
41
42class VTKVIEWSINFOVIS_EXPORT VTK_MARSHALAUTO vtkHeatmapItem : public vtkContextItem
43{
44public:
47 void PrintSelf(ostream& os, vtkIndent indent) override;
48
53 virtual void SetTable(vtkTable* table);
54
59
64
66
73 vtkGetMacro(NameColumn, vtkStdString);
74 vtkSetMacro(NameColumn, vtkStdString);
76
80 void SetOrientation(int orientation);
81
86
92 double GetTextAngleForOrientation(int orientation);
93
95
98 vtkSetVector2Macro(Position, float);
99 void SetPosition(const vtkVector2f& pos);
101
103
106 vtkGetVector2Macro(Position, float);
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
182protected:
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
210
218
224
230
236 std::string GetTooltipText(float x, float y);
237
245
251 bool LineIsVisible(double x0, double y0, double x1, double y1);
252
258
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
277private:
278 vtkHeatmapItem(const vtkHeatmapItem&) = delete;
279 void operator=(const vtkHeatmapItem&) = delete;
280
281 unsigned long HeatmapBuildTime;
282 vtkNew<vtkCategoryLegend> CategoryLegend;
283 vtkNew<vtkColorLegend> ColorLegend;
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
312VTK_ABI_NAMESPACE_END
313#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.
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 ...
vtkStringArray * GetRowNames()
Get the table that this item draws.
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
vtkTable * GetTable()
Get the table that this item draws.
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
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.
static vtkHeatmapItem * New()
virtual void GetBounds(double bounds[4])
Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
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
Allocate and hold a VTK object.
Definition vtkNew.h:167
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition vtkTable.h:169
takes care of drawing 2D axes
An array holding vtkVariants.
int vtkIdType
Definition vtkType.h:332
#define VTK_MARSHALAUTO