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 "vtkContextItem.h"
43 #include "vtkViewsInfovisModule.h" // For export macro
44 
45 #include "vtkNew.h" // For vtkNew ivars
46 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
47 #include "vtkStdString.h" // For SetGet 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:
60  static vtkDendrogramItem *New();
62  void PrintSelf(ostream &os, vtkIndent indent) override;
63 
69  virtual void SetTree(vtkTree *tree);
70 
74  vtkTree * GetTree();
75 
82  void CollapseToNumberOfLeafNodes(unsigned int n);
83 
87  vtkTree * GetPrunedTree();
88 
94  void SetColorArray(const char *arrayName);
95 
97 
103  vtkSetMacro(ExtendLeafNodes, bool);
104  vtkGetMacro(ExtendLeafNodes, bool);
105  vtkBooleanMacro(ExtendLeafNodes, bool);
107 
112  void SetOrientation(int orientation);
113 
117  int GetOrientation();
118 
124  double GetAngleForOrientation(int orientation);
125 
131  double GetTextAngleForOrientation(int orientation);
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);
156  vtkVector2f GetPositionVector();
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 
185  void ComputeLabelWidth(vtkContext2D *painter);
186 
190  float GetLabelWidth();
191 
197  bool GetPositionOfVertex(const std::string& vertexName, double position[2]);
198 
202  bool Paint(vtkContext2D *painter) override;
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  bool Hit(const vtkContextMouseEvent &mouse) override;
279 
284  bool MouseDoubleClickEvent( const vtkContextMouseEvent &event) override;
285 
286 protected:
288  ~vtkDendrogramItem() override;
289 
291  float* Position;
292 
297  virtual void RebuildBuffers();
298 
302  virtual void PaintBuffers(vtkContext2D *painter);
303 
308  virtual bool IsDirty();
309 
314  void ComputeMultipliers();
315 
319  void ComputeBounds();
320 
324  void CountLeafNodes();
325 
329  int CountLeafNodes(vtkIdType vertex);
330 
334  vtkIdType GetClosestVertex(double x, double y);
335 
339  void CollapseSubTree(vtkIdType vertex);
340 
344  void ExpandSubTree(vtkIdType vertex);
345 
349  vtkIdType GetOriginalId(vtkIdType vertex);
350 
355  vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId);
356 
362  vtkIdType GetClickedCollapsedSubTree(double x, double y);
363 
370  void UpdateVisibleSceneExtent(vtkContext2D *painter);
371 
377  bool LineIsVisible(double x0, double y0, double x1, double y1);
378 
382  void SetOrientation(vtkTree *tree, int orientation);
383 
384  // Setup the position, size, and orientation of this dendrogram's color
385  // legend based on the dendrogram's current orientation.
386  void PositionColorLegend();
387 
390 
391 private:
392  vtkDendrogramItem(const vtkDendrogramItem&) = delete;
393  void operator=(const vtkDendrogramItem&) = delete;
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
vtkStdString.h
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:40
vtkIdType
int vtkIdType
Definition: vtkType.h:349
vtkDendrogramItem::WeightedVertex::weight
double weight
Definition: vtkDendrogramItem.h:248
vtkDendrogramItem::WeightedVertex
Definition: vtkDendrogramItem.h:245
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkDendrogramItem::LEFT_TO_RIGHT
Definition: vtkDendrogramItem.h:269
vtkSmartPointer< vtkTree >
vtkVector.h
vtkDendrogramItem::Position
float * Position
Definition: vtkDendrogramItem.h:291
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
vtkContextItem.h
vtkDendrogramItem::CompareWeightedVertices
Definition: vtkDendrogramItem.h:250
vtkTree
A rooted tree data structure.
Definition: vtkTree.h:60
vtkX3D::position
Definition: vtkX3D.h:261
vtkDendrogramItem::PositionVector
vtkVector2f PositionVector
Definition: vtkDendrogramItem.h:290
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkDendrogramItem::WeightedVertex::ID
vtkIdType ID
Definition: vtkDendrogramItem.h:247
vtkAbstractContextItem::Hit
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
vtkDendrogramItem::LayoutTree
vtkSmartPointer< vtkTree > LayoutTree
Definition: vtkDendrogramItem.h:389
vtkSmartPointer.h
vtkNew< vtkGraphLayout >
vtkContextItem::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDendrogramItem::Tree
vtkSmartPointer< vtkTree > Tree
Definition: vtkDendrogramItem.h:388
vtkPruneTreeFilter
prune a subtree out of a vtkTree
Definition: vtkPruneTreeFilter.h:41
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:74
vtkDendrogramItem::RIGHT_TO_LEFT
Definition: vtkDendrogramItem.h:271
vtkX3D::string
Definition: vtkX3D.h:490
vtkColorLegend
Legend item to display vtkScalarsToColors.
Definition: vtkColorLegend.h:38
vtkDendrogramItem::UP_TO_DOWN
Definition: vtkDendrogramItem.h:270
vtkX3D::orientation
Definition: vtkX3D.h:262
vtkNew.h
vtkAbstractContextItem::Paint
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
vtkDendrogramItem
A 2D graphics item for rendering a tree as a dendrogram.
Definition: vtkDendrogramItem.h:57
vtkAbstractContextItem::MouseDoubleClickEvent
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
Mouse button double click event.
vtkDendrogramItem::CompareWeightedVertices::operator()
bool operator()(WeightedVertex &v1, WeightedVertex &v2)
Definition: vtkDendrogramItem.h:254
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:41
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkVector2f
Definition: vtkVector.h:422
vtkGraphLayout
layout a graph in 2 or 3 dimensions
Definition: vtkGraphLayout.h:50
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:304