VTK
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 =========================================================================*/
29 #ifndef vtkHeatmapItem_h
30 #define vtkHeatmapItem_h
31 
32 #include "vtkViewsInfovisModule.h" // For export macro
33 #include "vtkContextItem.h"
34 
35 #include "vtkNew.h" // For vtkNew ivars
36 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
37 #include "vtkStdString.h" // For get/set ivars
38 #include "vtkVector.h" // For vtkVector2f ivar
39 #include <map> // For column ranges
40 #include <set> // For blank row support
41 #include <vector> // For row mapping
42 
43 class vtkBitArray;
44 class vtkCategoryLegend;
45 class vtkColorLegend;
46 class vtkLookupTable;
47 class vtkStringArray;
48 class vtkTable;
49 class vtkTooltipItem;
50 class vtkVariantArray;
51 
52 class VTKVIEWSINFOVIS_EXPORT vtkHeatmapItem : public vtkContextItem
53 {
54 public:
55  static vtkHeatmapItem *New();
57  void PrintSelf(ostream &os, vtkIndent indent) override;
58 
63  virtual void SetTable(vtkTable *table);
64 
69 
74 
76 
83  vtkGetMacro(NameColumn, vtkStdString);
84  vtkSetMacro(NameColumn, vtkStdString);
86 
91 
96 
103 
105 
108  vtkSetVector2Macro(Position, float);
109  void SetPosition(const vtkVector2f &pos);
111 
113 
116  vtkGetVector2Macro(Position, float);
119 
121 
125  vtkGetMacro(CellHeight, double);
126  vtkSetMacro(CellHeight, double);
128 
130 
134  vtkGetMacro(CellWidth, double);
135  vtkSetMacro(CellWidth, double);
137 
141  virtual void GetBounds(double bounds[4]);
142 
147  void MarkRowAsBlank(const std::string& rowName);
148 
152  bool Paint(vtkContext2D *painter) override;
153 
155 
159  vtkGetMacro(RowLabelWidth, float);
160  vtkGetMacro(ColumnLabelWidth, float);
162 
166  enum
167  {
171  DOWN_TO_UP
172  };
173 
177  bool Hit(const vtkContextMouseEvent &mouse) override;
178 
182  bool MouseMoveEvent(const vtkContextMouseEvent &event) override;
183 
187  bool MouseDoubleClickEvent(const vtkContextMouseEvent &event) override;
188 
189 protected:
191  ~vtkHeatmapItem() override;
192 
194  float* Position;
195 
200  virtual void RebuildBuffers();
201 
205  virtual void PaintBuffers(vtkContext2D *painter);
206 
211  virtual bool IsDirty();
212 
217 
225 
231 
237 
243  std::string GetTooltipText(float x, float y);
244 
252 
258  bool LineIsVisible(double x0, double y0, double x1, double y1);
259 
265 
271 
272  // Setup the position, size, and orientation of this heatmap's color
273  // legend based on the heatmap's current orientation.
275 
276  // Setup the position, size, and orientation of this heatmap's
277  // legends based on the heatmap's current orientation.
279 
283 
284 private:
285  vtkHeatmapItem(const vtkHeatmapItem&) = delete;
286  void operator=(const vtkHeatmapItem&) = delete;
287 
288  unsigned long HeatmapBuildTime;
289  vtkNew<vtkCategoryLegend> CategoryLegend;
290  vtkNew<vtkColorLegend> ColorLegend;
291  vtkNew<vtkTooltipItem> Tooltip;
292  vtkNew<vtkLookupTable> ContinuousDataLookupTable;
293  vtkNew<vtkLookupTable> CategoricalDataLookupTable;
294  vtkNew<vtkLookupTable> ColorLegendLookupTable;
295  vtkNew<vtkStringArray> CategoricalDataValues;
296  vtkNew<vtkVariantArray> CategoryLegendValues;
297  double CellWidth;
298  double CellHeight;
299 
300  std::map< vtkIdType, std::pair< double, double > > ColumnRanges;
301  std::vector< vtkIdType > SceneRowToTableRowMap;
302  std::vector< vtkIdType > SceneColumnToTableColumnMap;
303  std::set<std::string> BlankRows;
304 
305  double MinX;
306  double MinY;
307  double MaxX;
308  double MaxY;
309  double SceneBottomLeft[3];
310  double SceneTopRight[3];
311  float RowLabelWidth;
312  float ColumnLabelWidth;
313 
314  vtkBitArray* CollapsedRowsArray;
315  vtkBitArray* CollapsedColumnsArray;
316  bool LegendPositionSet;
317 };
318 
319 #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:41
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:282
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:347
vtkHeatmapItem::GetRowNames
vtkStringArray * GetRowNames()
Get the table that this item draws.
vtkTable
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:69
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:193
vtkHeatmapItem::UP_TO_DOWN
@ UP_TO_DOWN
Definition: vtkHeatmapItem.h:169
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:47
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:59
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::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:281
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkHeatmapItem::PaintBuffers
virtual void PaintBuffers(vtkContext2D *painter)
This function does the bulk of the actual work in rendering our heatmap.
vtkHeatmapItem::RIGHT_TO_LEFT
@ RIGHT_TO_LEFT
Definition: vtkHeatmapItem.h:170
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::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:194
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:35
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:75
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkColorLegend
Legend item to display vtkScalarsToColors.
Definition: vtkColorLegend.h:39
vtkX3D::orientation
@ orientation
Definition: vtkX3D.h:262
vtkNew.h
vtkHeatmapItem::GetTable
vtkTable * GetTable()
Get the table that this item draws.
vtkHeatmapItem::GetPositionVector
vtkVector2f GetPositionVector()
vtkHeatmapItem::LEFT_TO_RIGHT
@ LEFT_TO_RIGHT
Definition: vtkHeatmapItem.h:168
vtkHeatmapItem::AccumulateProminentCategoricalDataValues
void AccumulateProminentCategoricalDataValues(vtkIdType column)
Helper function.
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:43
vtkCategoryLegend
Legend item to display categorical data.
Definition: vtkCategoryLegend.h:45
vtkHeatmapItem::Table
vtkSmartPointer< vtkTable > Table
Definition: vtkHeatmapItem.h:280
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:37
vtkHeatmapItem
A 2D graphics item for rendering a heatmap.
Definition: vtkHeatmapItem.h:53
vtkHeatmapItem::SetPosition
void SetPosition(const vtkVector2f &pos)
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
vtkHeatmapItem::ComputeBounds
void ComputeBounds()
Compute the extent of the heatmap.
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:419
vtkHeatmapItem::~vtkHeatmapItem
~vtkHeatmapItem() override