VTK  9.3.20240418
vtkDendrogramItem.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
27 #ifndef vtkDendrogramItem_h
28 #define vtkDendrogramItem_h
29 
30 #include "vtkContextItem.h"
31 #include "vtkViewsInfovisModule.h" // For export macro
32 
33 #include "vtkNew.h" // For vtkNew ivars
34 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
35 #include "vtkStdString.h" // For SetGet ivars
36 #include "vtkVector.h" // For vtkVector2f ivar
37 
38 VTK_ABI_NAMESPACE_BEGIN
39 class vtkColorLegend;
40 class vtkDoubleArray;
41 class vtkGraphLayout;
42 class vtkLookupTable;
43 class vtkPruneTreeFilter;
44 class vtkTree;
45 
46 class VTKVIEWSINFOVIS_EXPORT vtkDendrogramItem : public vtkContextItem
47 {
48 public:
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
58  virtual void SetTree(vtkTree* tree);
59 
64 
71  void CollapseToNumberOfLeafNodes(unsigned int n);
72 
77 
83  void SetColorArray(const char* arrayName);
84 
86 
92  vtkSetMacro(ExtendLeafNodes, bool);
93  vtkGetMacro(ExtendLeafNodes, bool);
94  vtkBooleanMacro(ExtendLeafNodes, bool);
96 
102 
107 
114 
121 
123 
127  vtkSetMacro(DrawLabels, bool);
128  vtkGetMacro(DrawLabels, bool);
129  vtkBooleanMacro(DrawLabels, bool);
131 
133 
136  vtkSetVector2Macro(Position, float);
137  void SetPosition(const vtkVector2f& pos);
139 
141 
144  vtkGetVector2Macro(Position, float);
147 
149 
153  vtkGetMacro(LeafSpacing, double);
154  vtkSetMacro(LeafSpacing, double);
156 
162  void PrepareToPaint(vtkContext2D* painter);
163 
169  virtual void GetBounds(double bounds[4]);
170 
175 
179  float GetLabelWidth();
180 
186  bool GetPositionOfVertex(const std::string& vertexName, double position[2]);
187 
191  bool Paint(vtkContext2D* painter) override;
192 
194 
197  vtkGetMacro(LineWidth, float);
198  vtkSetMacro(LineWidth, float);
200 
202 
206  vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
207  vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
208  vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
210 
212 
218  vtkGetMacro(DistanceArrayName, vtkStdString);
219  vtkSetMacro(DistanceArrayName, vtkStdString);
221 
223 
229  vtkGetMacro(VertexNameArrayName, vtkStdString);
230  vtkSetMacro(VertexNameArrayName, vtkStdString);
232 
233  // this struct & class allow us to generate a priority queue of vertices.
235  {
237  double weight;
238  };
240  {
241  public:
242  // Returns true if v2 is higher priority than v1
244  {
245  if (v1.weight <= v2.weight)
246  {
247  return false;
248  }
249  return true;
250  }
251  };
252 
256  enum
257  {
261  DOWN_TO_UP
262  };
263 
267  bool Hit(const vtkContextMouseEvent& mouse) override;
268 
273  bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
274 
275 protected:
277  ~vtkDendrogramItem() override;
278 
280  float* Position;
281 
286  virtual void RebuildBuffers();
287 
291  virtual void PaintBuffers(vtkContext2D* painter);
292 
297  virtual bool IsDirty();
298 
304 
309 
314 
319 
323  vtkIdType GetClosestVertex(double x, double y);
324 
329 
333  void ExpandSubTree(vtkIdType vertex);
334 
339 
345 
352 
360 
366  bool LineIsVisible(double x0, double y0, double x1, double y1);
367 
372 
373  // Setup the position, size, and orientation of this dendrogram's color
374  // legend based on the dendrogram's current orientation.
376 
379 
380 private:
381  vtkDendrogramItem(const vtkDendrogramItem&) = delete;
382  void operator=(const vtkDendrogramItem&) = delete;
383 
384  vtkSmartPointer<vtkTree> PrunedTree;
385  vtkMTimeType DendrogramBuildTime;
386  vtkNew<vtkGraphLayout> Layout;
387  vtkNew<vtkPruneTreeFilter> PruneFilter;
388  vtkNew<vtkLookupTable> TriangleLookupTable;
389  vtkNew<vtkLookupTable> TreeLookupTable;
390  vtkNew<vtkColorLegend> ColorLegend;
391  vtkDoubleArray* ColorArray;
392  double MultiplierX;
393  double MultiplierY;
394  int NumberOfLeafNodes;
395  double LeafSpacing;
396 
397  double MinX;
398  double MinY;
399  double MaxX;
400  double MaxY;
401  double SceneBottomLeft[3];
402  double SceneTopRight[3];
403  float LabelWidth;
404  float LineWidth;
405  bool ColorTree;
406  bool ExtendLeafNodes;
407  bool DrawLabels;
408  bool DisplayNumberOfCollapsedLeafNodes;
409  bool LegendPositionSet;
410  vtkStdString DistanceArrayName;
411  vtkStdString VertexNameArrayName;
412 };
413 
414 VTK_ABI_NAMESPACE_END
415 #endif
Legend item to display vtkScalarsToColors.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:69
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)
Set the position of the dendrogram.
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()
Get position of the dendrogram.
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:108
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:78
A rooted tree data structure.
Definition: vtkTree.h:145
@ orientation
Definition: vtkX3D.h:262
@ position
Definition: vtkX3D.h:261
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270