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  virtual void PrintSelf(ostream &os, vtkIndent indent);
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 
148 
152  virtual bool Paint(vtkContext2D *painter);
153 
155 
159  vtkGetMacro(RowLabelWidth, float);
160  vtkGetMacro(ColumnLabelWidth, float);
162 
166  enum
167  {
171  DOWN_TO_UP
172  };
173 
177  virtual bool Hit(const vtkContextMouseEvent &mouse);
178 
182  virtual bool MouseMoveEvent(const vtkContextMouseEvent &event);
183 
187  virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &event);
188 
189 protected:
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&) VTK_DELETE_FUNCTION;
286  void operator=(const vtkHeatmapItem&) VTK_DELETE_FUNCTION;
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
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:37
Legend item to display categorical data.
Legend item to display vtkScalarsToColors.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
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 correponding heatmap orientation.
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)
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &event)
Display a legend for a column of data.
vtkSmartPointer< vtkTable > Table
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual bool Hit(const vtkContextMouseEvent &mouse)
Returns true if the transform is interactive, false otherwise.
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.
vtkVector2f GetPositionVector()
vtkStringArray * RowNames
void SetPosition(const vtkVector2f &pos)
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.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &event)
Display a tooltip when the user mouses over a cell in the heatmap.
void GenerateContinuousDataLookupTable()
Setup the default lookup table to use for continuous (not categorical) data.
void MarkRowAsBlank(std::string rowName)
Mark a row as blank, meaning that no cells will be drawn for it.
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...
virtual bool Paint(vtkContext2D *painter)
Paints the table as a heatmap.
a simple class to control print indentation
Definition: vtkIndent.h:40
map scalar values into colors via a lookup table
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:69
takes care of drawing 2D axes
An array holding vtkVariants.
@ orientation
Definition: vtkX3D.h:262
@ string
Definition: vtkX3D.h:490
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287