VTK  9.0.20201026
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:
57  static vtkDendrogramItem* New();
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
66  virtual void SetTree(vtkTree* tree);
67 
71  vtkTree* GetTree();
72 
79  void CollapseToNumberOfLeafNodes(unsigned int n);
80 
84  vtkTree* GetPrunedTree();
85 
91  void SetColorArray(const char* arrayName);
92 
94 
100  vtkSetMacro(ExtendLeafNodes, bool);
101  vtkGetMacro(ExtendLeafNodes, bool);
102  vtkBooleanMacro(ExtendLeafNodes, bool);
104 
109  void SetOrientation(int orientation);
110 
114  int GetOrientation();
115 
121  double GetAngleForOrientation(int orientation);
122 
128  double GetTextAngleForOrientation(int orientation);
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);
153  vtkVector2f GetPositionVector();
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 
182  void ComputeLabelWidth(vtkContext2D* painter);
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 
311  void ComputeMultipliers();
312 
316  void ComputeBounds();
317 
321  void CountLeafNodes();
322 
326  int CountLeafNodes(vtkIdType vertex);
327 
331  vtkIdType GetClosestVertex(double x, double y);
332 
336  void CollapseSubTree(vtkIdType vertex);
337 
341  void ExpandSubTree(vtkIdType vertex);
342 
346  vtkIdType GetOriginalId(vtkIdType vertex);
347 
352  vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId);
353 
359  vtkIdType GetClickedCollapsedSubTree(double x, double y);
360 
367  void UpdateVisibleSceneExtent(vtkContext2D* painter);
368 
374  bool LineIsVisible(double x0, double y0, double x1, double y1);
375 
379  void SetOrientation(vtkTree* tree, int orientation);
380 
381  // Setup the position, size, and orientation of this dendrogram's color
382  // legend based on the dendrogram's current orientation.
383  void PositionColorLegend();
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:34
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkDendrogramItem::WeightedVertex::weight
double weight
Definition: vtkDendrogramItem.h:245
vtkDendrogramItem::WeightedVertex
Definition: vtkDendrogramItem.h:242
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkSmartPointer< vtkTree >
vtkVector.h
vtkDendrogramItem::Position
float * Position
Definition: vtkDendrogramItem.h:288
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
vtkContextItem.h
vtkDendrogramItem::LEFT_TO_RIGHT
Definition: vtkDendrogramItem.h:266
vtkDendrogramItem::CompareWeightedVertices
Definition: vtkDendrogramItem.h:247
vtkTree
A rooted tree data structure.
Definition: vtkTree.h:54
vtkX3D::position
Definition: vtkX3D.h:267
vtkDendrogramItem::PositionVector
vtkVector2f PositionVector
Definition: vtkDendrogramItem.h:287
vtkBlockSortHelper::GetBounds
void GetBounds(T a, double bds[6])
Definition: vtkBlockSortHelper.h:37
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkDendrogramItem::WeightedVertex::ID
vtkIdType ID
Definition: vtkDendrogramItem.h:244
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:386
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:385
vtkPruneTreeFilter
prune a subtree out of a vtkTree
Definition: vtkPruneTreeFilter.h:38
vtkDendrogramItem::RIGHT_TO_LEFT
Definition: vtkDendrogramItem.h:268
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:31
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:68
vtkX3D::string
Definition: vtkX3D.h:496
vtkColorLegend
Legend item to display vtkScalarsToColors.
Definition: vtkColorLegend.h:38
vtkParticleTracerBaseNamespace::Position
struct Position_t Position
Definition: vtkParticleTracerBase.h:63
vtkX3D::orientation
Definition: vtkX3D.h:268
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:54
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:251
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:35
vtkDendrogramItem::UP_TO_DOWN
Definition: vtkDendrogramItem.h:267
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkVector2f
Definition: vtkVector.h:432
vtkGraphLayout
layout a graph in 2 or 3 dimensions
Definition: vtkGraphLayout.h:44
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:285