VTK: Views/Infovis/vtkDendrogramItem.h Source File

| VTK 9.3.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
38 VTK_ABI_NAMESPACE_BEGIN
39 class vtkColorLegend;
40 class vtkDoubleArray;
41 class vtkGraphLayout;
42 class vtkLookupTable;
43 class vtkPruneTreeFilter;
44 class vtkTree;
45
46 class VTKVIEWSINFOVIS_EXPORT vtkDendrogramItem : public vtkContextItem
47 {
48 public:
49 static vtkDendrogramItem* New();
50 vtkTypeMacro(vtkDendrogramItem, vtkContextItem);
51 void PrintSelf(ostream& os, vtkIndent indent) override;
52
58 virtual void SetTree(vtkTree* tree);
59
63 vtkTree* GetTree();
64
71 void CollapseToNumberOfLeafNodes(unsigned int n);
72
76 vtkTree* GetPrunedTree();
77
83 void SetColorArray(const char* arrayName);
84
86
92 vtkSetMacro(ExtendLeafNodes, bool);
93 vtkGetMacro(ExtendLeafNodes, bool);
94 vtkBooleanMacro(ExtendLeafNodes, bool);
96
101 void SetOrientation(int orientation);
102
106 int GetOrientation();
107
113 double GetAngleForOrientation(int orientation);
114
120 double GetTextAngleForOrientation(int orientation);
121
123
127 vtkSetMacro(DrawLabels, bool);
128 vtkGetMacro(DrawLabels, bool);
129 vtkBooleanMacro(DrawLabels, bool);
131
133
136 vtkSetVector2Macro(Position, float);
137 void SetPosition(const vtkVector2f& pos);
139
141
144 vtkGetVector2Macro(Position, float);
145 vtkVector2f GetPositionVector();
147
149
153 vtkGetMacro(LeafSpacing, double);
154 vtkSetMacro(LeafSpacing, double);
156
162 void PrepareToPaint(vtkContext2D* painter);
163
169 virtual void GetBounds(double bounds[4]);
170
174 void ComputeLabelWidth(vtkContext2D* painter);
175
179 float GetLabelWidth();
180
186 bool GetPositionOfVertex(const std::string& vertexName, double position[2]);
187
191 bool Paint(vtkContext2D* painter) override;
192
194
197 vtkGetMacro(LineWidth, float);
198 vtkSetMacro(LineWidth, float);
200
202
206 vtkSetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
207 vtkGetMacro(DisplayNumberOfCollapsedLeafNodes, bool);
208 vtkBooleanMacro(DisplayNumberOfCollapsedLeafNodes, bool);
210
212
218 vtkGetMacro(DistanceArrayName, vtkStdString);
219 vtkSetMacro(DistanceArrayName, vtkStdString);
221
223
229 vtkGetMacro(VertexNameArrayName, vtkStdString);
230 vtkSetMacro(VertexNameArrayName, vtkStdString);
232
233 // this struct & class allow us to generate a priority queue of vertices.
234 struct WeightedVertex
235 {
236 vtkIdType ID;
237 double weight;
238 };
239 class CompareWeightedVertices
240 {
241 public:
242 // Returns true if v2 is higher priority than v1
243 bool operator()(WeightedVertex& v1, WeightedVertex& v2)
244 {
245 if (v1.weight <= v2.weight)
246 {
247 return false;
248 }
249 return true;
250 }
251 };
252
256 enum
257 {
258 LEFT_TO_RIGHT,
259 UP_TO_DOWN,
260 RIGHT_TO_LEFT,
261 DOWN_TO_UP
262 };
263
267 bool Hit(const vtkContextMouseEvent& mouse) override;
268
273 bool MouseDoubleClickEvent(const vtkContextMouseEvent& event) override;
274
275 protected:
276 vtkDendrogramItem();
277 ~vtkDendrogramItem() override;
278
279 vtkVector2f PositionVector;
280 float* Position;
281
286 virtual void RebuildBuffers();
287
291 virtual void PaintBuffers(vtkContext2D* painter);
292
297 virtual bool IsDirty();
298
303 void ComputeMultipliers();
304
308 void ComputeBounds();
309
313 void CountLeafNodes();
314
318 int CountLeafNodes(vtkIdType vertex);
319
323 vtkIdType GetClosestVertex(double x, double y);
324
328 void CollapseSubTree(vtkIdType vertex);
329
333 void ExpandSubTree(vtkIdType vertex);
334
338 vtkIdType GetOriginalId(vtkIdType vertex);
339
344 vtkIdType GetPrunedIdForOriginalId(vtkIdType originalId);
345
351 vtkIdType GetClickedCollapsedSubTree(double x, double y);
352
359 void UpdateVisibleSceneExtent(vtkContext2D* painter);
360
366 bool LineIsVisible(double x0, double y0, double x1, double y1);
367
371 void SetOrientation(vtkTree* tree, int orientation);
372
373 // Setup the position, size, and orientation of this dendrogram's color
374 // legend based on the dendrogram's current orientation.
375 void PositionColorLegend();
376
377 vtkSmartPointer<vtkTree> Tree;
378 vtkSmartPointer<vtkTree> LayoutTree;
379
380 private:
381 vtkDendrogramItem(const vtkDendrogramItem&) = delete;
382 void operator=(const vtkDendrogramItem&) = delete;
383
384 vtkSmartPointer<vtkTree> PrunedTree;
385 vtkMTimeType DendrogramBuildTime;
386 vtkNew<vtkGraphLayout> Layout;
387 vtkNew<vtkPruneTreeFilter> PruneFilter;
388 vtkNew<vtkLookupTable> TriangleLookupTable;
389 vtkNew<vtkLookupTable> TreeLookupTable;
390 vtkNew<vtkColorLegend> ColorLegend;
391 vtkDoubleArray* ColorArray;
392 double MultiplierX;
393 double MultiplierY;
394 int NumberOfLeafNodes;
395 double LeafSpacing;
396
397 double MinX;
398 double MinY;
399 double MaxX;
400 double MaxY;
401 double SceneBottomLeft[3];
402 double SceneTopRight[3];
403 float LabelWidth;
404 float LineWidth;
405 bool ColorTree;
406 bool ExtendLeafNodes;
407 bool DrawLabels;
408 bool DisplayNumberOfCollapsedLeafNodes;
409 bool LegendPositionSet;
410 vtkStdString DistanceArrayName;
411 vtkStdString VertexNameArrayName;
412 };
413
414 VTK_ABI_NAMESPACE_END
415 #endif
vtkColorLegend
Legend item to display vtkScalarsToColors.
Definition: vtkColorLegend.h:37
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:59
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:35
vtkContextMouseEvent
data structure to represent mouse events.
Definition: vtkContextMouseEvent.h:39
vtkDendrogramItem::CompareWeightedVertices
Definition: vtkDendrogramItem.h:240
vtkDendrogramItem::CompareWeightedVertices::operator()
bool operator()(WeightedVertex &v1, WeightedVertex &v2)
Definition: vtkDendrogramItem.h:243
vtkDendrogramItem
A 2D graphics item for rendering a tree as a dendrogram.
Definition: vtkDendrogramItem.h:47
vtkDendrogramItem::GetTextAngleForOrientation
double GetTextAngleForOrientation(int orientation)
Get the angle that vertex labels should be rotated for the corresponding tree orientation.
vtkDendrogramItem::CollapseToNumberOfLeafNodes
void CollapseToNumberOfLeafNodes(unsigned int n)
Collapse subtrees until there are only n leaf nodes left in the tree.
vtkDendrogramItem::ComputeLabelWidth
void ComputeLabelWidth(vtkContext2D *painter)
Compute the width of the longest leaf node label.
vtkDendrogramItem::CountLeafNodes
void CountLeafNodes()
Count the number of leaf nodes in the tree.
vtkDendrogramItem::SetPosition
void SetPosition(const vtkVector2f &pos)
Set the position of the dendrogram.
vtkDendrogramItem::ExpandSubTree
void ExpandSubTree(vtkIdType vertex)
Expand the previously collapsed subtree rooted at vertex.
vtkDendrogramItem::SetColorArray
void SetColorArray(const char *arrayName)
Indicate which array within the Tree's VertexData should be used to color the tree.
vtkDendrogramItem::GetPrunedTree
vtkTree * GetPrunedTree()
Get the collapsed tree.
vtkDendrogramItem::CollapseSubTree
void CollapseSubTree(vtkIdType vertex)
Collapse the subtree rooted at vertex.
vtkDendrogramItem::GetPositionOfVertex
bool GetPositionOfVertex(const std::string &vertexName, double position[2])
Find the position of the vertex with the specified name.
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::RIGHT_TO_LEFT
@ RIGHT_TO_LEFT
Definition: vtkDendrogramItem.h:260
vtkDendrogramItem::UP_TO_DOWN
@ UP_TO_DOWN
Definition: vtkDendrogramItem.h:259
vtkDendrogramItem::LEFT_TO_RIGHT
@ LEFT_TO_RIGHT
Definition: vtkDendrogramItem.h:258
vtkDendrogramItem::PositionColorLegend
void PositionColorLegend()
vtkDendrogramItem::Hit
bool Hit(const vtkContextMouseEvent &mouse) override
Returns true if the transform is interactive, false otherwise.
vtkDendrogramItem::New
static vtkDendrogramItem * New()
vtkDendrogramItem::SetTree
virtual void SetTree(vtkTree *tree)
Set the tree that this item draws.
vtkDendrogramItem::PrepareToPaint
void PrepareToPaint(vtkContext2D *painter)
This function calls RebuildBuffers() if necessary.
vtkDendrogramItem::MouseDoubleClickEvent
bool MouseDoubleClickEvent(const vtkContextMouseEvent &event) override
Collapse or expand a subtree when the user double clicks on an internal node.
vtkDendrogramItem::GetAngleForOrientation
double GetAngleForOrientation(int orientation)
Get the rotation angle (in degrees) that corresponds to the given tree orientation.
vtkDendrogramItem::ComputeBounds
void ComputeBounds()
Compute the bounds of our tree in pixel coordinates.
vtkDendrogramItem::PaintBuffers
virtual void PaintBuffers(vtkContext2D *painter)
This function does the bulk of the actual work in rendering our dendrogram.
vtkDendrogramItem::SetOrientation
void SetOrientation(vtkTree *tree, int orientation)
Internal function.
vtkDendrogramItem::GetTree
vtkTree * GetTree()
Get the tree that this item draws.
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::GetPositionVector
vtkVector2f GetPositionVector()
Get position of the dendrogram.
vtkDendrogramItem::Paint
bool Paint(vtkContext2D *painter) override
Paints the input tree as a dendrogram.
vtkDendrogramItem::Tree
vtkSmartPointer< vtkTree > Tree
Definition: vtkDendrogramItem.h:377
vtkDendrogramItem::~vtkDendrogramItem
~vtkDendrogramItem() override
vtkDendrogramItem::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDendrogramItem::CountLeafNodes
int CountLeafNodes(vtkIdType vertex)
Count the number of leaf nodes that descend from a given vertex.
vtkDendrogramItem::ComputeMultipliers
void ComputeMultipliers()
Compute how to scale our data so that text labels will fit within the bounds determined by the spacin...
vtkDendrogramItem::vtkDendrogramItem
vtkDendrogramItem()
vtkDendrogramItem::GetOrientation
int GetOrientation()
Get the current tree orientation.
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::GetOriginalId
vtkIdType GetOriginalId(vtkIdType vertex)
Look up the original ID of a vertex in the pruned tree.
vtkDendrogramItem::GetClosestVertex
vtkIdType GetClosestVertex(double x, double y)
Get the tree vertex closest to the specified coordinates.
vtkDendrogramItem::LayoutTree
vtkSmartPointer< vtkTree > LayoutTree
Definition: vtkDendrogramItem.h:378
vtkDendrogramItem::PositionVector
vtkVector2f PositionVector
Definition: vtkDendrogramItem.h:279
vtkDendrogramItem::SetOrientation
void SetOrientation(int orientation)
Set which way the tree should face within the visualization.
vtkDendrogramItem::GetLabelWidth
float GetLabelWidth()
Get the width of the longest leaf node label.
vtkDendrogramItem::IsDirty
virtual bool IsDirty()
This function returns a bool indicating whether or not we need to rebuild our cached data before pain...
vtkDendrogramItem::UpdateVisibleSceneExtent
void UpdateVisibleSceneExtent(vtkContext2D *painter)
Calculate the extent of the data that is visible within the window.
vtkDendrogramItem::GetBounds
virtual void GetBounds(double bounds[4])
Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
vtkDendrogramItem::Position
float * Position
Definition: vtkDendrogramItem.h:280
vtkDendrogramItem::RebuildBuffers
virtual void RebuildBuffers()
Generate some data needed for painting.
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:40
vtkGraphLayout
layout a graph in 2 or 3 dimensions
Definition: vtkGraphLayout.h:45
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkLookupTable
map scalar values into colors via a lookup table
Definition: vtkLookupTable.h:73
vtkNew< vtkGraphLayout >
vtkPruneTreeFilter
prune a subtree out of a vtkTree
Definition: vtkPruneTreeFilter.h:27
vtkSmartPointer< vtkTree >
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
vtkTree
A rooted tree data structure.
Definition: vtkTree.h:55
vtkVector2f
Definition: vtkVector.h:463
vtkParticleTracerBaseNamespace::Position
struct Position_t Position
Definition: vtkParticleTracerBase.h:55
vtkX3D::orientation
@ orientation
Definition: vtkX3D.h:262
vtkX3D::position
@ position
Definition: vtkX3D.h:261
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkDendrogramItem::WeightedVertex
Definition: vtkDendrogramItem.h:235
vtkDendrogramItem::WeightedVertex::weight
double weight
Definition: vtkDendrogramItem.h:237
vtkDendrogramItem::WeightedVertex::ID
vtkIdType ID
Definition: vtkDendrogramItem.h:236
vtkContextItem.h
vtkNew.h
vtkSmartPointer.h
vtkStdString.h
vtkIdType
int vtkIdType
Definition: vtkType.h:315
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
vtkVector.h