VTK  9.7.1
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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
38 
39 VTK_ABI_NAMESPACE_BEGIN
40 class vtkColorLegend;
41 class vtkDoubleArray;
42 class vtkGraphLayout;
43 class vtkLookupTable;
44 class vtkPruneTreeFilter;
45 class vtkTree;
46 
47 class VTKVIEWSINFOVIS_EXPORT VTK_MARSHALAUTO vtkDendrogramItem : public vtkContextItem
48 {
49 public:
50  static vtkDendrogramItem* New();
52  void PrintSelf(ostream& os, vtkIndent indent) override;
53 
59  virtual void SetTree(vtkTree* tree);
60 
64  vtkTree* GetTree();
65 
72  void CollapseToNumberOfLeafNodes(unsigned int n);
73 
77  vtkTree* GetPrunedTree();
78 
84  void SetColorArray(const char* arrayName);
85 
87 
93  vtkSetMacro(ExtendLeafNodes, bool);
94  vtkGetMacro(ExtendLeafNodes, bool);
95  vtkBooleanMacro(ExtendLeafNodes, bool);
97 
102  void SetOrientation(int orientation);
103 
107  int GetOrientation();
108 
114  double GetAngleForOrientation(int orientation);
115 
121  double GetTextAngleForOrientation(int orientation);
122 
124 
128  vtkSetMacro(DrawLabels, bool);
129  vtkGetMacro(DrawLabels, bool);
130  vtkBooleanMacro(DrawLabels, bool);
132 
134 
137  vtkSetVector2Macro(Position, float);
138  void SetPosition(const vtkVector2f& pos);
140 
142 
145  vtkGetVector2Macro(Position, float);
146  vtkVector2f GetPositionVector();
148 
150 
154  vtkGetMacro(LeafSpacing, double);
155  vtkSetMacro(LeafSpacing, double);
157 
163  void PrepareToPaint(vtkContext2D* painter);
164 
170  virtual void GetBounds(double bounds[4]);
171 
175  void ComputeLabelWidth(vtkContext2D* painter);
176 
180  float GetLabelWidth();
181 
187  bool GetPositionOfVertex(const std::string& vertexName, double position[2]);
188 
192  bool Paint(vtkContext2D* painter) override;
193 
195 
198  vtkGetMacro(LineWidth, float);
199  vtkSetMacro(LineWidth, float);
201 
203 
207  vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
208  vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
209  vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
211 
213 
219  vtkGetMacro(DistanceArrayName, vtkStdString);
220  vtkSetMacro(DistanceArrayName, vtkStdString);
222 
224 
230  vtkGetMacro(VertexNameArrayName, vtkStdString);
231  vtkSetMacro(VertexNameArrayName, vtkStdString);
233 
234  // this struct & class allow us to generate a priority queue of vertices.
236  {
238  double weight;
239  };
241  {
242  public:
243  // Returns true if v2 is higher priority than v1
245  {
246  if (v1.weight <= v2.weight)
247  {
248  return false;
249  }
250  return true;
251  }
252  };
253 
257  enum
258  {
262  DOWN_TO_UP
263  };
264 
268  bool Hit(const vtkContextMouseEvent& mouse) override;
269 
274  bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
275 
276 protected:
278  ~vtkDendrogramItem() override;
279 
281  float* Position;
282 
287  virtual void RebuildBuffers();
288 
292  virtual void PaintBuffers(vtkContext2D* painter);
293 
298  virtual bool IsDirty();
299 
304  void ComputeMultipliers();
305 
309  void ComputeBounds();
310 
314  void CountLeafNodes();
315 
319  int CountLeafNodes(vtkIdType vertex);
320 
324  vtkIdType GetClosestVertex(double x, double y);
325 
329  void CollapseSubTree(vtkIdType vertex);
330 
334  void ExpandSubTree(vtkIdType vertex);
335 
339  vtkIdType GetOriginalId(vtkIdType vertex);
340 
345  vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId);
346 
352  vtkIdType GetClickedCollapsedSubTree(double x, double y);
353 
360  void UpdateVisibleSceneExtent(vtkContext2D* painter);
361 
367  bool LineIsVisible(double x0, double y0, double x1, double y1);
368 
372  void SetOrientation(vtkTree* tree, int orientation);
373 
374  // Setup the position, size, and orientation of this dendrogram's color
375  // legend based on the dendrogram's current orientation.
376  void PositionColorLegend();
377 
380 
381 private:
382  vtkDendrogramItem(const vtkDendrogramItem&) = delete;
383  void operator=(const vtkDendrogramItem&) = delete;
384 
385  vtkSmartPointer<vtkTree> PrunedTree;
386  vtkMTimeType DendrogramBuildTime;
387  vtkNew<vtkGraphLayout> Layout;
388  vtkNew<vtkPruneTreeFilter> PruneFilter;
389  vtkNew<vtkLookupTable> TriangleLookupTable;
390  vtkNew<vtkLookupTable> TreeLookupTable;
391  vtkNew<vtkColorLegend> ColorLegend;
392  vtkDoubleArray* ColorArray;
393  double MultiplierX;
394  double MultiplierY;
395  int NumberOfLeafNodes;
396  double LeafSpacing;
397 
398  double MinX;
399  double MinY;
400  double MaxX;
401  double MaxY;
402  double SceneBottomLeft[3];
403  double SceneTopRight[3];
404  float LabelWidth;
405  float LineWidth;
406  bool ColorTree;
407  bool ExtendLeafNodes;
408  bool DrawLabels;
409  bool DisplayNumberOfCollapsedLeafNodes;
410  bool LegendPositionSet;
411  vtkStdString DistanceArrayName;
412  vtkStdString VertexNameArrayName;
413 };
414 
415 VTK_ABI_NAMESPACE_END
416 #endif
vtkSmartPointer< vtkTree > LayoutTree
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
void GetBounds(T a, double bds[6])
A 2D graphics item for rendering a tree as a dendrogram.
vtkSmartPointer< vtkTree > Tree
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
base class for items that are part of a vtkContextScene.
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
map scalar values into colors via a lookup table
Legend item to display vtkScalarsToColors.
int vtkIdType
Definition: vtkType.h:363
dynamic, self-adjusting array of double
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:28
layout a graph in 2 or 3 dimensions
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool operator()(WeightedVertex &v1, WeightedVertex &v2)
vtkVector2f PositionVector
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
prune a subtree out of a vtkTree
#define VTK_MARSHALAUTO
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
A rooted tree data structure.
Definition: vtkTree.h:46
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.