VTK
vtkDendrogramItem.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDendrogramItem.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 =========================================================================*/
39 #ifndef vtkDendrogramItem_h
40 #define vtkDendrogramItem_h
41 
42 #include "vtkViewsInfovisModule.h" // For export macro
43 #include "vtkContextItem.h"
44 
45 #include "vtkNew.h" // For vtkNew ivars
46 #include "vtkStdString.h" // For SetGet ivars
47 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
48 #include "vtkVector.h" // For vtkVector2f ivar
49 
50 class vtkColorLegend;
51 class vtkDoubleArray;
52 class vtkGraphLayout;
53 class vtkLookupTable;
54 class vtkPruneTreeFilter;
55 class vtkTree;
56 
57 class VTKVIEWSINFOVIS_EXPORT vtkDendrogramItem : public vtkContextItem
58 {
59 public:
62  virtual void PrintSelf(ostream &os, vtkIndent indent);
63 
69  virtual void SetTree(vtkTree *tree);
70 
75 
82  void CollapseToNumberOfLeafNodes(unsigned int n);
83 
88 
94  void SetColorArray(const char *arrayName);
95 
97 
103  vtkSetMacro(ExtendLeafNodes, bool);
104  vtkGetMacro(ExtendLeafNodes, bool);
105  vtkBooleanMacro(ExtendLeafNodes, bool);
107 
113 
118 
125 
132 
134 
138  vtkSetMacro(DrawLabels, bool);
139  vtkGetMacro(DrawLabels, bool);
140  vtkBooleanMacro(DrawLabels, bool);
142 
144 
147  vtkSetVector2Macro(Position, float);
148  void SetPosition(const vtkVector2f &pos);
150 
152 
155  vtkGetVector2Macro(Position, float);
158 
160 
164  vtkGetMacro(LeafSpacing, double);
165  vtkSetMacro(LeafSpacing, double);
167 
173  void PrepareToPaint(vtkContext2D *painter);
174 
180  virtual void GetBounds(double bounds[4]);
181 
186 
190  float GetLabelWidth();
191 
197  bool GetPositionOfVertex(std::string vertexName, double position[2]);
198 
202  virtual bool Paint(vtkContext2D *painter);
203 
205 
208  vtkGetMacro(LineWidth, float);
209  vtkSetMacro(LineWidth, float);
211 
213 
217  vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
218  vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
219  vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
221 
223 
229  vtkGetMacro(DistanceArrayName, vtkStdString);
230  vtkSetMacro(DistanceArrayName, vtkStdString);
232 
234 
240  vtkGetMacro(VertexNameArrayName, vtkStdString);
241  vtkSetMacro(VertexNameArrayName, vtkStdString);
243 
244  // this struct & class allow us to generate a priority queue of vertices.
246  {
248  double weight;
249  };
251  {
252  public:
253  // Returns true if v2 is higher priority than v1
255  {
256  if (v1.weight < v2.weight)
257  {
258  return false;
259  }
260  return true;
261  }
262  };
263 
267  enum
268  {
272  DOWN_TO_UP
273  };
274 
278  virtual bool Hit(const vtkContextMouseEvent &mouse);
279 
284  virtual bool MouseDoubleClickEvent( const vtkContextMouseEvent &event);
285 
286 protected:
289 
291  float* Position;
292 
297  virtual void RebuildBuffers();
298 
302  virtual void PaintBuffers(vtkContext2D *painter);
303 
308  virtual bool IsDirty();
309 
315 
320 
325 
330 
334  vtkIdType GetClosestVertex(double x, double y);
335 
340 
344  void ExpandSubTree(vtkIdType vertex);
345 
350 
356 
363 
371 
377  bool LineIsVisible(double x0, double y0, double x1, double y1);
378 
383 
384  // Setup the position, size, and orientation of this dendrogram's color
385  // legend based on the dendrogram's current orientation.
387 
390 
391 private:
392  vtkDendrogramItem(const vtkDendrogramItem&) VTK_DELETE_FUNCTION;
393  void operator=(const vtkDendrogramItem&) VTK_DELETE_FUNCTION;
394 
395  vtkSmartPointer<vtkTree> PrunedTree;
396  vtkMTimeType DendrogramBuildTime;
397  vtkNew<vtkGraphLayout> Layout;
398  vtkNew<vtkPruneTreeFilter> PruneFilter;
399  vtkNew<vtkLookupTable> TriangleLookupTable;
400  vtkNew<vtkLookupTable> TreeLookupTable;
401  vtkNew<vtkColorLegend> ColorLegend;
402  vtkDoubleArray* ColorArray;
403  double MultiplierX;
404  double MultiplierY;
405  int NumberOfLeafNodes;
406  double LeafSpacing;
407 
408  double MinX;
409  double MinY;
410  double MaxX;
411  double MaxY;
412  double SceneBottomLeft[3];
413  double SceneTopRight[3];
414  float LabelWidth;
415  float LineWidth;
416  bool ColorTree;
417  bool ExtendLeafNodes;
418  bool DrawLabels;
419  bool DisplayNumberOfCollapsedLeafNodes;
420  bool LegendPositionSet;
421  vtkStdString DistanceArrayName;
422  vtkStdString VertexNameArrayName;
423 };
424 
425 #endif
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.
bool operator()(WeightedVertex &v1, WeightedVertex &v2)
A 2D graphics item for rendering a tree as a dendrogram.
double GetTextAngleForOrientation(int orientation)
Get the angle that vertex labels should be rotated for the correponding tree orientation.
void CollapseToNumberOfLeafNodes(unsigned int n)
Collapse subtrees until there are only n leaf nodes left in the tree.
void ComputeLabelWidth(vtkContext2D *painter)
Compute the width of the longest leaf node label.
void CountLeafNodes()
Count the number of leaf nodes in the tree.
void SetPosition(const vtkVector2f &pos)
void ExpandSubTree(vtkIdType vertex)
Expand the previously collapsed subtree rooted at vertex.
bool GetPositionOfVertex(std::string vertexName, double position[2])
Find the position of the vertex with the specified name.
void SetColorArray(const char *arrayName)
Indicate which array within the Tree's VertexData should be used to color the tree.
vtkTree * GetPrunedTree()
Get the collapsed tree.
void CollapseSubTree(vtkIdType vertex)
Collapse the subtree rooted at vertex.
vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId)
Look up the ID of a vertex in the pruned tree from a vertex ID of the input tree.
void PositionColorLegend()
static vtkDendrogramItem * New()
virtual void SetTree(vtkTree *tree)
Set the tree that this item draws.
void PrepareToPaint(vtkContext2D *painter)
This function calls RebuildBuffers() if necessary.
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &event)
Collapse or expand a subtree when the user double clicks on an internal node.
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
double GetAngleForOrientation(int orientation)
Get the rotation angle (in degrees) that corresponds to the given tree orientation.
virtual bool Paint(vtkContext2D *painter)
Paints the input tree as a dendrogram.
void ComputeBounds()
Compute the bounds of our tree in pixel coordinates.
virtual void PaintBuffers(vtkContext2D *painter)
This function does the bulk of the actual work in rendering our dendrogram.
void SetOrientation(vtkTree *tree, int orientation)
Internal function.
vtkTree * GetTree()
Get the tree that this item draws.
vtkIdType GetClickedCollapsedSubTree(double x, double y)
Check if the click at (x, y) should be considered as a click on a collapsed subtree.
vtkVector2f GetPositionVector()
virtual bool Hit(const vtkContextMouseEvent &mouse)
Returns true if the transform is interactive, false otherwise.
vtkSmartPointer< vtkTree > Tree
int CountLeafNodes(vtkIdType vertex)
Count the number of leaf nodes that descend from a given vertex.
void ComputeMultipliers()
Compute how to scale our data so that text labels will fit within the bounds determined by the spacin...
int GetOrientation()
Get the current tree orientation.
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...
vtkIdType GetOriginalId(vtkIdType vertex)
Look up the original ID of a vertex in the pruned tree.
vtkIdType GetClosestVertex(double x, double y)
Get the tree vertex closest to the specified coordinates.
vtkSmartPointer< vtkTree > LayoutTree
vtkVector2f PositionVector
void SetOrientation(int orientation)
Set which way the tree should face within the visualization.
float GetLabelWidth()
Get the width of the longest leaf node label.
virtual bool IsDirty()
This function returns a bool indicating whether or not we need to rebuild our cached data before pain...
void UpdateVisibleSceneExtent(vtkContext2D *painter)
Calculate the extent of the data that is visible within the window.
virtual void GetBounds(double bounds[4])
Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
virtual void RebuildBuffers()
Generate some data needed for painting.
dynamic, self-adjusting array of double
layout a graph in 2 or 3 dimensions
a simple class to control print indentation
Definition: vtkIndent.h:40
map scalar values into colors via a lookup table
prune a subtree out of a vtkTree
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
A rooted tree data structure.
Definition: vtkTree.h:61
@ orientation
Definition: vtkX3D.h:262
@ position
Definition: vtkX3D.h:261
@ string
Definition: vtkX3D.h:490
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248