VTK  9.0.1
vtkHeatmapItem.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkHeatmapItem.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
26 #ifndef vtkHeatmapItem_h
27 #define vtkHeatmapItem_h
28 
29 #include "vtkContextItem.h"
30 #include "vtkViewsInfovisModule.h" // For export macro
31 
32 #include "vtkNew.h" // For vtkNew ivars
33 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
34 #include "vtkStdString.h" // For get/set ivars
35 #include "vtkVector.h" // For vtkVector2f ivar
36 #include <map> // For column ranges
37 #include <set> // For blank row support
38 #include <vector> // For row mapping
39 
40 class vtkBitArray;
41 class vtkCategoryLegend;
42 class vtkColorLegend;
43 class vtkLookupTable;
44 class vtkStringArray;
45 class vtkTable;
46 class vtkTooltipItem;
47 class vtkVariantArray;
48 
49 class VTKVIEWSINFOVIS_EXPORT vtkHeatmapItem : public vtkContextItem
50 {
51 public:
52  static vtkHeatmapItem* New();
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
60  virtual void SetTable(vtkTable* table);
61 
66 
71 
73 
80  vtkGetMacro(NameColumn, vtkStdString);
81  vtkSetMacro(NameColumn, vtkStdString);
83 
88 
93 
100 
102 
105  vtkSetVector2Macro(Position, float);
106  void SetPosition(const vtkVector2f& pos);
108 
110 
113  vtkGetVector2Macro(Position, float);
116 
118 
122  vtkGetMacro(CellHeight, double);
123  vtkSetMacro(CellHeight, double);
125 
127 
131  vtkGetMacro(CellWidth, double);
132  vtkSetMacro(CellWidth, double);
134 
138  virtual void GetBounds(double bounds[4]);
139 
144  void MarkRowAsBlank(const std::string& rowName);
145 
149  bool Paint(vtkContext2D* painter) override;
150 
152 
156  vtkGetMacro(RowLabelWidth, float);
157  vtkGetMacro(ColumnLabelWidth, float);
159 
163  enum
164  {
168  DOWN_TO_UP
169  };
170 
174  bool Hit(const vtkContextMouseEvent& mouse) override;
175 
179  bool MouseMoveEvent(const vtkContextMouseEvent& event) override;
180 
184  bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
185 
186 protected:
188  ~vtkHeatmapItem() override;
189 
191  float* Position;
192 
197  virtual void RebuildBuffers();
198 
202  virtual void PaintBuffers(vtkContext2D* painter);
203 
208  virtual bool IsDirty();
209 
214 
222 
228 
234 
240  std::string GetTooltipText(float x, float y);
241 
249 
255  bool LineIsVisible(double x0, double y0, double x1, double y1);
256 
262 
268 
269  // Setup the position, size, and orientation of this heatmap's color
270  // legend based on the heatmap's current orientation.
272 
273  // Setup the position, size, and orientation of this heatmap's
274  // legends based on the heatmap's current orientation.
276 
280 
281 private:
282  vtkHeatmapItem(const vtkHeatmapItem&) = delete;
283  void operator=(const vtkHeatmapItem&) = delete;
284 
285  unsigned long HeatmapBuildTime;
286  vtkNew<vtkCategoryLegend> CategoryLegend;
287  vtkNew<vtkColorLegend> ColorLegend;
288  vtkNew<vtkTooltipItem> Tooltip;
289  vtkNew<vtkLookupTable> ContinuousDataLookupTable;
290  vtkNew<vtkLookupTable> CategoricalDataLookupTable;
291  vtkNew<vtkLookupTable> ColorLegendLookupTable;
292  vtkNew<vtkStringArray> CategoricalDataValues;
293  vtkNew<vtkVariantArray> CategoryLegendValues;
294  double CellWidth;
295  double CellHeight;
296 
297  std::map<vtkIdType, std::pair<double, double> > ColumnRanges;
298  std::vector<vtkIdType> SceneRowToTableRowMap;
299  std::vector<vtkIdType> SceneColumnToTableColumnMap;
300  std::set<std::string> BlankRows;
301 
302  double MinX;
303  double MinY;
304  double MaxX;
305  double MaxY;
306  double SceneBottomLeft[3];
307  double SceneTopRight[3];
308  float RowLabelWidth;
309  float ColumnLabelWidth;
310 
311  vtkBitArray* CollapsedRowsArray;
312  vtkBitArray* CollapsedColumnsArray;
313  bool LegendPositionSet;
314 };
315 
316 #endif
vtkHeatmapItem::GetOrientation
int GetOrientation()
Get the current heatmap orientation.
vtkHeatmapItem::MouseDoubleClickEvent
bool MouseDoubleClickEvent(const vtkContextMouseEvent &event) override
Display a legend for a column of data.
vtkStdString.h
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:35
vtkHeatmapItem::GetTooltipText
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 ...
vtkHeatmapItem::MarkRowAsBlank
void MarkRowAsBlank(const std::string &rowName)
Mark a row as blank, meaning that no cells will be drawn for it.
vtkHeatmapItem::NameColumn
vtkStdString NameColumn
Definition: vtkHeatmapItem.h:279
vtkHeatmapItem::PositionLegends
void PositionLegends(int orientation)
vtkHeatmapItem::GenerateContinuousDataLookupTable
void GenerateContinuousDataLookupTable()
Setup the default lookup table to use for continuous (not categorical) data.
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkHeatmapItem::GetRowNames
vtkStringArray * GetRowNames()
Get the table that this item draws.
vtkTable
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:63
vtkHeatmapItem::MouseMoveEvent
bool MouseMoveEvent(const vtkContextMouseEvent &event) override
Display a tooltip when the user mouses over a cell in the heatmap.
vtkHeatmapItem::PositionVector
vtkVector2f PositionVector
Definition: vtkHeatmapItem.h:190
vtkHeatmapItem::New
static vtkHeatmapItem * New()
vtkHeatmapItem::SetTable
virtual void SetTable(vtkTable *table)
Set the table that this item draws.
vtkSmartPointer< vtkTable >
vtkVector.h
vtkHeatmapItem::GenerateCategoricalDataLookupTable
void GenerateCategoricalDataLookupTable()
Setup the default lookup table to use for categorical (not continuous) data.
vtkTooltipItem
takes care of drawing 2D axes
Definition: vtkTooltipItem.h:40
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:50
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:53
vtkContextItem.h
vtkHeatmapItem::ComputeLabelWidth
void ComputeLabelWidth(vtkContext2D *painter)
Compute the width of our longest row label and the width of our longest column label.
vtkHeatmapItem::GetBounds
virtual void GetBounds(double bounds[4])
Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
vtkHeatmapItem::UpdateVisibleSceneExtent
void UpdateVisibleSceneExtent(vtkContext2D *painter)
Calculate the extent of the data that is visible within the window.
vtkHeatmapItem::RIGHT_TO_LEFT
@ RIGHT_TO_LEFT
Definition: vtkHeatmapItem.h:167
vtkHeatmapItem::Hit
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the transform is interactive, false otherwise.
vtkHeatmapItem::Paint
bool Paint(vtkContext2D *painter) override
Paints the table as a heatmap.
vtkHeatmapItem::SetOrientation
void SetOrientation(int orientation)
Set which way the table should face within the visualization.
vtkHeatmapItem::IsDirty
virtual bool IsDirty()
This function returns a bool indicating whether or not we need to rebuild our cached data before pain...
vtkHeatmapItem::RowNames
vtkStringArray * RowNames
Definition: vtkHeatmapItem.h:278
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkHeatmapItem::PaintBuffers
virtual void PaintBuffers(vtkContext2D *painter)
This function does the bulk of the actual work in rendering our heatmap.
vtkSmartPointer.h
vtkNew< vtkCategoryLegend >
vtkHeatmapItem::InitializeLookupTables
void InitializeLookupTables()
Generate a separate vtkLookupTable for each column in the table.
vtkHeatmapItem::GetTextAngleForOrientation
double GetTextAngleForOrientation(int orientation)
Get the angle that row labels should be rotated for the corresponding heatmap orientation.
vtkHeatmapItem::LEFT_TO_RIGHT
@ LEFT_TO_RIGHT
Definition: vtkHeatmapItem.h:165
vtkHeatmapItem::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkHeatmapItem::Position
float * Position
Definition: vtkHeatmapItem.h:191
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:32
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:69
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkColorLegend
Legend item to display vtkScalarsToColors.
Definition: vtkColorLegend.h:39
vtkX3D::orientation
@ orientation
Definition: vtkX3D.h:268
vtkNew.h
vtkHeatmapItem::GetTable
vtkTable * GetTable()
Get the table that this item draws.
vtkHeatmapItem::GetPositionVector
vtkVector2f GetPositionVector()
vtkHeatmapItem::AccumulateProminentCategoricalDataValues
void AccumulateProminentCategoricalDataValues(vtkIdType column)
Helper function.
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:37
vtkCategoryLegend
Legend item to display categorical data.
Definition: vtkCategoryLegend.h:42
vtkHeatmapItem::Table
vtkSmartPointer< vtkTable > Table
Definition: vtkHeatmapItem.h:277
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:34
vtkHeatmapItem
A 2D graphics item for rendering a heatmap.
Definition: vtkHeatmapItem.h:50
vtkHeatmapItem::SetPosition
void SetPosition(const vtkVector2f &pos)
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
vtkHeatmapItem::ComputeBounds
void ComputeBounds()
Compute the extent of the heatmap.
vtkHeatmapItem::UP_TO_DOWN
@ UP_TO_DOWN
Definition: vtkHeatmapItem.h:166
vtkHeatmapItem::RebuildBuffers
virtual void RebuildBuffers()
Generate some data needed for painting.
vtkHeatmapItem::PositionColorLegend
void PositionColorLegend(int orientation)
vtkHeatmapItem::LineIsVisible
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...
vtkHeatmapItem::vtkHeatmapItem
vtkHeatmapItem()
vtkVector2f
Definition: vtkVector.h:433
vtkHeatmapItem::~vtkHeatmapItem
~vtkHeatmapItem() override