VTK  9.0.20210615
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
vtkStdString.h
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:35
vtkDendrogramItem::PositionColorLegend
void PositionColorLegend()
vtkDendrogramItem::LEFT_TO_RIGHT
@ LEFT_TO_RIGHT
Definition: vtkDendrogramItem.h:266
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkDendrogramItem::WeightedVertex::weight
double weight
Definition: vtkDendrogramItem.h:245
vtkDendrogramItem::ComputeLabelWidth
void ComputeLabelWidth(vtkContext2D *painter)
Compute the width of the longest leaf node label.
vtkDendrogramItem::~vtkDendrogramItem
~vtkDendrogramItem() override
vtkDendrogramItem::WeightedVertex
Definition: vtkDendrogramItem.h:243
vtkDendrogramItem::ComputeBounds
void ComputeBounds()
Compute the bounds of our tree in pixel coordinates.
vtkDendrogramItem::LineIsVisible
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...
vtkDendrogramItem::RIGHT_TO_LEFT
@ RIGHT_TO_LEFT
Definition: vtkDendrogramItem.h:268
vtkSmartPointer< vtkTree >
vtkVector.h
vtkDendrogramItem::CollapseToNumberOfLeafNodes
void CollapseToNumberOfLeafNodes(unsigned int n)
Collapse subtrees until there are only n leaf nodes left in the tree.
vtkDendrogramItem::Position
float * Position
Definition: vtkDendrogramItem.h:288
vtkDendrogramItem::GetTextAngleForOrientation
double GetTextAngleForOrientation(int orientation)
Get the angle that vertex labels should be rotated for the corresponding tree orientation.
vtkDendrogramItem::GetPositionOfVertex
bool GetPositionOfVertex(const std::string &vertexName, double position[2])
Find the position of the vertex with the specified name.
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:54
vtkDendrogramItem::Hit
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the transform is interactive, false otherwise.
vtkContextItem.h
vtkDendrogramItem::PaintBuffers
virtual void PaintBuffers(vtkContext2D *painter)
This function does the bulk of the actual work in rendering our dendrogram.
vtkDendrogramItem::GetClickedCollapsedSubTree
vtkIdType GetClickedCollapsedSubTree(double x, double y)
Check if the click at (x, y) should be considered as a click on a collapsed subtree.
vtkDendrogramItem::GetLabelWidth
float GetLabelWidth()
Get the width of the longest leaf node label.
vtkDendrogramItem::SetOrientation
void SetOrientation(int orientation)
Set which way the tree should face within the visualization.
vtkDendrogramItem::CompareWeightedVertices
Definition: vtkDendrogramItem.h:248
vtkDendrogramItem::CollapseSubTree
void CollapseSubTree(vtkIdType vertex)
Collapse the subtree rooted at vertex.
vtkDendrogramItem::UpdateVisibleSceneExtent
void UpdateVisibleSceneExtent(vtkContext2D *painter)
Calculate the extent of the data that is visible within the window.
vtkDendrogramItem::PrepareToPaint
void PrepareToPaint(vtkContext2D *painter)
This function calls RebuildBuffers() if necessary.
vtkTree
A rooted tree data structure.
Definition: vtkTree.h:55
vtkDendrogramItem::IsDirty
virtual bool IsDirty()
This function returns a bool indicating whether or not we need to rebuild our cached data before pain...
vtkDendrogramItem::GetClosestVertex
vtkIdType GetClosestVertex(double x, double y)
Get the tree vertex closest to the specified coordinates.
vtkDendrogramItem::GetOriginalId
vtkIdType GetOriginalId(vtkIdType vertex)
Look up the original ID of a vertex in the pruned tree.
vtkDendrogramItem::GetTree
vtkTree * GetTree()
Get the tree that this item draws.
vtkX3D::position
@ position
Definition: vtkX3D.h:267
vtkDendrogramItem::GetBounds
virtual void GetBounds(double bounds[4])
Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
vtkDendrogramItem::SetTree
virtual void SetTree(vtkTree *tree)
Set the tree that this item draws.
vtkDendrogramItem::PositionVector
vtkVector2f PositionVector
Definition: vtkDendrogramItem.h:287
vtkDendrogramItem::New
static vtkDendrogramItem * New()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkDendrogramItem::WeightedVertex::ID
vtkIdType ID
Definition: vtkDendrogramItem.h:244
vtkDendrogramItem::LayoutTree
vtkSmartPointer< vtkTree > LayoutTree
Definition: vtkDendrogramItem.h:386
vtkSmartPointer.h
vtkDendrogramItem::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDendrogramItem::UP_TO_DOWN
@ UP_TO_DOWN
Definition: vtkDendrogramItem.h:267
vtkNew< vtkGraphLayout >
vtkDendrogramItem::GetOrientation
int GetOrientation()
Get the current tree orientation.
vtkDendrogramItem::Tree
vtkSmartPointer< vtkTree > Tree
Definition: vtkDendrogramItem.h:385
vtkDendrogramItem::CountLeafNodes
int CountLeafNodes(vtkIdType vertex)
Count the number of leaf nodes that descend from a given vertex.
vtkDendrogramItem::GetPrunedIdForOriginalId
vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId)
Look up the ID of a vertex in the pruned tree from a vertex ID of the input tree.
vtkDendrogramItem::GetAngleForOrientation
double GetAngleForOrientation(int orientation)
Get the rotation angle (in degrees) that corresponds to the given tree orientation.
vtkDendrogramItem::GetPositionVector
vtkVector2f GetPositionVector()
Get position of the dendrogram.
vtkPruneTreeFilter
prune a subtree out of a vtkTree
Definition: vtkPruneTreeFilter.h:39
vtkDendrogramItem::SetPosition
void SetPosition(const vtkVector2f &pos)
Set the position of the dendrogram.
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:34
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:69
vtkDendrogramItem::SetOrientation
void SetOrientation(vtkTree *tree, int orientation)
Internal function.
vtkDendrogramItem::vtkDendrogramItem
vtkDendrogramItem()
vtkDendrogramItem::GetPrunedTree
vtkTree * GetPrunedTree()
Get the collapsed tree.
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkDendrogramItem::RebuildBuffers
virtual void RebuildBuffers()
Generate some data needed for painting.
vtkColorLegend
Legend item to display vtkScalarsToColors.
Definition: vtkColorLegend.h:39
vtkDendrogramItem::CountLeafNodes
void CountLeafNodes()
Count the number of leaf nodes in the tree.
vtkDendrogramItem::MouseDoubleClickEvent
bool MouseDoubleClickEvent(const vtkContextMouseEvent &event) override
Collapse or expand a subtree when the user double clicks on an internal node.
vtkParticleTracerBaseNamespace::Position
struct Position_t Position
Definition: vtkParticleTracerBase.h:63
vtkX3D::orientation
@ orientation
Definition: vtkX3D.h:268
vtkNew.h
vtkDendrogramItem
A 2D graphics item for rendering a tree as a dendrogram.
Definition: vtkDendrogramItem.h:55
vtkDendrogramItem::CompareWeightedVertices::operator()
bool operator()(WeightedVertex &v1, WeightedVertex &v2)
Definition: vtkDendrogramItem.h:251
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:36
vtkDendrogramItem::Paint
bool Paint(vtkContext2D *painter) override
Paints the input tree as a dendrogram.
vtkDendrogramItem::ComputeMultipliers
void ComputeMultipliers()
Compute how to scale our data so that text labels will fit within the bounds determined by the spacin...
vtkDendrogramItem::ExpandSubTree
void ExpandSubTree(vtkIdType vertex)
Expand the previously collapsed subtree rooted at vertex.
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
vtkDendrogramItem::SetColorArray
void SetColorArray(const char *arrayName)
Indicate which array within the Tree's VertexData should be used to color the tree.
vtkVector2f
Definition: vtkVector.h:432
vtkGraphLayout
layout a graph in 2 or 3 dimensions
Definition: vtkGraphLayout.h:45
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287