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 =========================================================================*/
38 #ifndef vtkDendrogramItem_h
39 #define vtkDendrogramItem_h
40 
41 #include "vtkViewsInfovisModule.h" // For export macro
42 #include "vtkContextItem.h"
43 
44 #include "vtkNew.h" // For vtkNew ivars
45 #include "vtkStdString.h" // For SetGet ivars
46 #include "vtkSmartPointer.h" // For vtkSmartPointer ivars
47 #include "vtkVector.h" // For vtkVector2f ivar
48 
49 class vtkColorLegend;
50 class vtkDoubleArray;
51 class vtkGraphLayout;
52 class vtkLookupTable;
53 class vtkPruneTreeFilter;
54 class vtkTree;
55 
57 {
58 public:
59  static vtkDendrogramItem *New();
61  virtual void PrintSelf(ostream &os, vtkIndent indent);
62 
67  virtual void SetTree(vtkTree *tree);
68 
70  vtkTree * GetTree();
71 
76  void CollapseToNumberOfLeafNodes(unsigned int n);
77 
79  vtkTree * GetPrunedTree();
80 
84  void SetColorArray(const char *arrayName);
85 
87 
91  vtkSetMacro(ExtendLeafNodes, bool);
92  vtkGetMacro(ExtendLeafNodes, bool);
93  vtkBooleanMacro(ExtendLeafNodes, bool);
95 
98  void SetOrientation(int orientation);
99 
101  int GetOrientation();
102 
106  double GetAngleForOrientation(int orientation);
107 
111  double GetTextAngleForOrientation(int orientation);
112 
114 
116  vtkSetMacro(DrawLabels, bool);
117  vtkGetMacro(DrawLabels, bool);
118  vtkBooleanMacro(DrawLabels, bool);
120 
122 
123  vtkSetVector2Macro(Position, float);
124  void SetPosition(const vtkVector2f &pos);
126 
128 
129  vtkGetVector2Macro(Position, float);
130  vtkVector2f GetPositionVector();
132 
134 
136  vtkGetMacro(LeafSpacing, double);
137  vtkSetMacro(LeafSpacing, double);
139 
143  void PrepareToPaint(vtkContext2D *painter);
144 
148  virtual void GetBounds(double bounds[4]);
149 
151  void ComputeLabelWidth(vtkContext2D *painter);
152 
154  float GetLabelWidth();
155 
159  bool GetPositionOfVertex(std::string vertexName, double position[2]);
160 
162  virtual bool Paint(vtkContext2D *painter);
163 
165 
167  vtkGetMacro(LineWidth, float);
168  vtkSetMacro(LineWidth, float);
170 
172 
175  vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
176  vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
177  vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
179 
181 
186  vtkGetMacro(DistanceArrayName, vtkStdString);
187  vtkSetMacro(DistanceArrayName, vtkStdString);
189 
191 
195  vtkGetMacro(VertexNameArrayName, vtkStdString);
196  vtkSetMacro(VertexNameArrayName, vtkStdString);
198 
199  // this struct & class allow us to generate a priority queue of vertices.
201  {
203  double weight;
204  };
206  {
207  public:
208  // Returns true if v2 is higher priority than v1
210  {
211  if (v1.weight < v2.weight)
212  {
213  return false;
214  }
215  return true;
216  }
217  };
218 
219  //BTX
221 
222  enum
223  {
227  DOWN_TO_UP
228  };
230 
232  virtual bool Hit(const vtkContextMouseEvent &mouse);
233 
235 
237  virtual bool MouseDoubleClickEvent( const vtkContextMouseEvent &event);
238  //ETX
240 
241 protected:
244 
246  float* Position;
247 
250  virtual void RebuildBuffers();
251 
254  virtual void PaintBuffers(vtkContext2D *painter);
255 
258  virtual bool IsDirty();
259 
262  void ComputeMultipliers();
263 
265  void ComputeBounds();
266 
268  void CountLeafNodes();
269 
271  int CountLeafNodes(vtkIdType vertex);
272 
274  vtkIdType GetClosestVertex(double x, double y);
275 
277  void CollapseSubTree(vtkIdType vertex);
278 
280  void ExpandSubTree(vtkIdType vertex);
281 
283  vtkIdType GetOriginalId(vtkIdType vertex);
284 
287  vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId);
288 
292  vtkIdType GetClickedCollapsedSubTree(double x, double y);
293 
298  void UpdateVisibleSceneExtent(vtkContext2D *painter);
299 
303  bool LineIsVisible(double x0, double y0, double x1, double y1);
304 
306  void SetOrientation(vtkTree *tree, int orientation);
307 
308  // Setup the position, size, and orientation of this dendrogram's color
309  // legend based on the dendrogram's current orientation.
310  void PositionColorLegend();
311 
314 
315 private:
316  vtkDendrogramItem(const vtkDendrogramItem&); // Not implemented
317  void operator=(const vtkDendrogramItem&); // Not implemented
318 
319  vtkSmartPointer<vtkTree> PrunedTree;
320  unsigned long DendrogramBuildTime;
321  vtkNew<vtkGraphLayout> Layout;
322  vtkNew<vtkPruneTreeFilter> PruneFilter;
323  vtkNew<vtkLookupTable> TriangleLookupTable;
324  vtkNew<vtkLookupTable> TreeLookupTable;
325  vtkNew<vtkColorLegend> ColorLegend;
326  vtkDoubleArray* ColorArray;
327  double MultiplierX;
328  double MultiplierY;
329  int NumberOfLeafNodes;
330  double LeafSpacing;
331 
332  double MinX;
333  double MinY;
334  double MaxX;
335  double MaxY;
336  double SceneBottomLeft[3];
337  double SceneTopRight[3];
338  float LabelWidth;
339  float LineWidth;
340  bool ColorTree;
341  bool ExtendLeafNodes;
342  bool DrawLabels;
343  bool DisplayNumberOfCollapsedLeafNodes;
344  bool LegendPositionSet;
345  vtkStdString DistanceArrayName;
346  vtkStdString VertexNameArrayName;
347 };
348 
349 #endif
vtkSmartPointer< vtkTree > LayoutTree
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
A 2D graphics item for rendering a tree as a dendrogram.
vtkSmartPointer< vtkTree > Tree
base class for items that are part of a vtkContextScene.
virtual bool Paint(vtkContext2D *painter)
map scalar values into colors via a lookup table
Legend item to display vtkScalarsToColors.
int vtkIdType
Definition: vtkType.h:275
dynamic, self-adjusting array of double
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:56
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:38
layout a graph in 2 or 3 dimensions
bool operator()(WeightedVertex &v1, WeightedVertex &v2)
vtkVector2f PositionVector
virtual bool Hit(const vtkContextMouseEvent &mouse)
prune a subtree out of a vtkTree
virtual void PrintSelf(ostream &os, vtkIndent indent)
static vtkObject * New()
A rooted tree data structure.
Definition: vtkTree.h:59
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse)
#define VTKVIEWSINFOVIS_EXPORT