VTK  9.0.3
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 =========================================================================*/
36 #ifndef vtkDendrogramItem_h
37 #define vtkDendrogramItem_h
38 
39 #include "vtkContextItem.h"
40 #include "vtkViewsInfovisModule.h" // For export macro
41 
42 #include "vtkNew.h" // For vtkNew ivars
43 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
44 #include "vtkStdString.h" // For SetGet ivars
45 #include "vtkVector.h" // For vtkVector2f ivar
46 
47 class vtkColorLegend;
48 class vtkDoubleArray;
49 class vtkGraphLayout;
50 class vtkLookupTable;
51 class vtkPruneTreeFilter;
52 class vtkTree;
53 
54 class VTKVIEWSINFOVIS_EXPORT vtkDendrogramItem : public vtkContextItem
55 {
56 public:
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
66  virtual void SetTree(vtkTree* tree);
67 
72 
79  void CollapseToNumberOfLeafNodes(unsigned int n);
80 
85 
91  void SetColorArray(const char* arrayName);
92 
94 
100  vtkSetMacro(ExtendLeafNodes, bool);
101  vtkGetMacro(ExtendLeafNodes, bool);
102  vtkBooleanMacro(ExtendLeafNodes, bool);
104 
110 
115 
122 
129 
131 
135  vtkSetMacro(DrawLabels, bool);
136  vtkGetMacro(DrawLabels, bool);
137  vtkBooleanMacro(DrawLabels, bool);
139 
141 
144  vtkSetVector2Macro(Position, float);
145  void SetPosition(const vtkVector2f& pos);
147 
149 
152  vtkGetVector2Macro(Position, float);
155 
157 
161  vtkGetMacro(LeafSpacing, double);
162  vtkSetMacro(LeafSpacing, double);
164 
170  void PrepareToPaint(vtkContext2D* painter);
171 
177  virtual void GetBounds(double bounds[4]);
178 
183 
187  float GetLabelWidth();
188 
194  bool GetPositionOfVertex(const std::string& vertexName, double position[2]);
195 
199  bool Paint(vtkContext2D* painter) override;
200 
202 
205  vtkGetMacro(LineWidth, float);
206  vtkSetMacro(LineWidth, float);
208 
210 
214  vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
215  vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
216  vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
218 
220 
226  vtkGetMacro(DistanceArrayName, vtkStdString);
227  vtkSetMacro(DistanceArrayName, vtkStdString);
229 
231 
237  vtkGetMacro(VertexNameArrayName, vtkStdString);
238  vtkSetMacro(VertexNameArrayName, vtkStdString);
240 
241  // this struct & class allow us to generate a priority queue of vertices.
243  {
245  double weight;
246  };
248  {
249  public:
250  // Returns true if v2 is higher priority than v1
252  {
253  if (v1.weight <= v2.weight)
254  {
255  return false;
256  }
257  return true;
258  }
259  };
260 
264  enum
265  {
269  DOWN_TO_UP
270  };
271 
275  bool Hit(const vtkContextMouseEvent& mouse) override;
276 
281  bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
282 
283 protected:
285  ~vtkDendrogramItem() override;
286 
288  float* Position;
289 
294  virtual void RebuildBuffers();
295 
299  virtual void PaintBuffers(vtkContext2D* painter);
300 
305  virtual bool IsDirty();
306 
312 
317 
322 
327 
331  vtkIdType GetClosestVertex(double x, double y);
332 
337 
341  void ExpandSubTree(vtkIdType vertex);
342 
347 
353 
360 
368 
374  bool LineIsVisible(double x0, double y0, double x1, double y1);
375 
380 
381  // Setup the position, size, and orientation of this dendrogram's color
382  // legend based on the dendrogram's current orientation.
384 
387 
388 private:
389  vtkDendrogramItem(const vtkDendrogramItem&) = delete;
390  void operator=(const vtkDendrogramItem&) = delete;
391 
392  vtkSmartPointer<vtkTree> PrunedTree;
393  vtkMTimeType DendrogramBuildTime;
394  vtkNew<vtkGraphLayout> Layout;
395  vtkNew<vtkPruneTreeFilter> PruneFilter;
396  vtkNew<vtkLookupTable> TriangleLookupTable;
397  vtkNew<vtkLookupTable> TreeLookupTable;
398  vtkNew<vtkColorLegend> ColorLegend;
399  vtkDoubleArray* ColorArray;
400  double MultiplierX;
401  double MultiplierY;
402  int NumberOfLeafNodes;
403  double LeafSpacing;
404 
405  double MinX;
406  double MinY;
407  double MaxX;
408  double MaxY;
409  double SceneBottomLeft[3];
410  double SceneTopRight[3];
411  float LabelWidth;
412  float LineWidth;
413  bool ColorTree;
414  bool ExtendLeafNodes;
415  bool DrawLabels;
416  bool DisplayNumberOfCollapsedLeafNodes;
417  bool LegendPositionSet;
418  vtkStdString DistanceArrayName;
419  vtkStdString VertexNameArrayName;
420 };
421 
422 #endif
Legend item to display vtkScalarsToColors.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:53
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 corresponding 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.
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.
bool GetPositionOfVertex(const std::string &vertexName, double position[2])
Find the position of the vertex with the specified name.
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()
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the transform is interactive, false otherwise.
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.
bool MouseDoubleClickEvent(const vtkContextMouseEvent &event) override
Collapse or expand a subtree when the user double clicks on an internal node.
double GetAngleForOrientation(int orientation)
Get the rotation angle (in degrees) that corresponds to the given tree orientation.
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()
bool Paint(vtkContext2D *painter) override
Paints the input tree as a dendrogram.
vtkSmartPointer< vtkTree > Tree
~vtkDendrogramItem() override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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:34
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:35
A rooted tree data structure.
Definition: vtkTree.h:55
@ orientation
Definition: vtkX3D.h:268
@ position
Definition: vtkX3D.h:267
@ string
Definition: vtkX3D.h:496
int vtkIdType
Definition: vtkType.h:338
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293