1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkRenderedGraphRepresentation.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 =========================================================================*/ 15 /*------------------------------------------------------------------------- 16 Copyright 2008 Sandia Corporation. 17 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 18 the U.S. Government retains certain rights in this software. 19 -------------------------------------------------------------------------*/ 20 /** 21 * @class vtkRenderedGraphRepresentation 22 * 23 * 24 */ 25 26 #ifndef vtkRenderedGraphRepresentation_h 27 #define vtkRenderedGraphRepresentation_h 28 29 #include "vtkViewsInfovisModule.h" // For export macro 30 #include "vtkRenderedRepresentation.h" 31 #include "vtkSmartPointer.h" // for SP ivars 32 33 class vtkActor; 34 class vtkApplyColors; 35 class vtkApplyIcons; 36 class vtkEdgeCenters; 37 class vtkEdgeLayout; 38 class vtkEdgeLayoutStrategy; 39 class vtkGraphLayout; 40 class vtkGraphLayoutStrategy; 41 class vtkGraphToGlyphs; 42 class vtkGraphToPoints; 43 class vtkGraphToPolyData; 44 class vtkIconGlyphFilter; 45 class vtkInformation; 46 class vtkInformationVector; 47 class vtkLookupTable; 48 class vtkPerturbCoincidentVertices; 49 class vtkPointSetToLabelHierarchy; 50 class vtkPolyData; 51 class vtkPolyDataMapper; 52 class vtkPolyDataMapper2D; 53 class vtkRemoveHiddenData; 54 class vtkRenderView; 55 class vtkScalarBarWidget; 56 class vtkScalarsToColors; 57 class vtkTextProperty; 58 class vtkTexturedActor2D; 59 class vtkTransformCoordinateSystems; 60 class vtkVertexDegree; 61 class vtkView; 62 class vtkViewTheme; 63 64 class VTKVIEWSINFOVIS_EXPORT vtkRenderedGraphRepresentation : public vtkRenderedRepresentation 65 { 66 public: 67 static vtkRenderedGraphRepresentation* New(); 68 vtkTypeMacro(vtkRenderedGraphRepresentation, vtkRenderedRepresentation); 69 void PrintSelf(ostream& os, vtkIndent indent) override; 70 71 // ------------------------------------------------------------------------ 72 // Vertex labels 73 74 virtual void SetVertexLabelArrayName(const char* name); 75 virtual const char* GetVertexLabelArrayName(); 76 virtual void SetVertexLabelPriorityArrayName(const char* name); 77 virtual const char* GetVertexLabelPriorityArrayName(); 78 virtual void SetVertexLabelVisibility(bool b); 79 virtual bool GetVertexLabelVisibility(); 80 vtkBooleanMacro(VertexLabelVisibility, bool); 81 virtual void SetVertexLabelTextProperty(vtkTextProperty* p); 82 virtual vtkTextProperty* GetVertexLabelTextProperty(); 83 vtkSetStringMacro(VertexHoverArrayName); 84 vtkGetStringMacro(VertexHoverArrayName); 85 //@{ 86 /** 87 * Whether to hide the display of vertex labels during mouse interaction. Default is off. 88 */ 89 vtkSetMacro(HideVertexLabelsOnInteraction, bool) 90 vtkGetMacro(HideVertexLabelsOnInteraction, bool) 91 vtkBooleanMacro(HideVertexLabelsOnInteraction, bool) 92 //@} 93 94 // ------------------------------------------------------------------------ 95 // Edge labels 96 97 virtual void SetEdgeLabelArrayName(const char* name); 98 virtual const char* GetEdgeLabelArrayName(); 99 virtual void SetEdgeLabelPriorityArrayName(const char* name); 100 virtual const char* GetEdgeLabelPriorityArrayName(); 101 virtual void SetEdgeLabelVisibility(bool b); 102 virtual bool GetEdgeLabelVisibility(); 103 vtkBooleanMacro(EdgeLabelVisibility, bool); 104 virtual void SetEdgeLabelTextProperty(vtkTextProperty* p); 105 virtual vtkTextProperty* GetEdgeLabelTextProperty(); 106 vtkSetStringMacro(EdgeHoverArrayName); 107 vtkGetStringMacro(EdgeHoverArrayName); 108 //@{ 109 /** 110 * Whether to hide the display of edge labels during mouse interaction. Default is off. 111 */ 112 vtkSetMacro(HideEdgeLabelsOnInteraction, bool) 113 vtkGetMacro(HideEdgeLabelsOnInteraction, bool) 114 vtkBooleanMacro(HideEdgeLabelsOnInteraction, bool) 115 //@} 116 117 // ------------------------------------------------------------------------ 118 // Vertex icons 119 120 virtual void SetVertexIconArrayName(const char* name); 121 virtual const char* GetVertexIconArrayName(); 122 virtual void SetVertexIconPriorityArrayName(const char* name); 123 virtual const char* GetVertexIconPriorityArrayName(); 124 virtual void SetVertexIconVisibility(bool b); 125 virtual bool GetVertexIconVisibility(); 126 vtkBooleanMacro(VertexIconVisibility, bool); 127 virtual void AddVertexIconType(const char* name, int type); 128 virtual void ClearVertexIconTypes(); 129 virtual void SetUseVertexIconTypeMap(bool b); 130 virtual bool GetUseVertexIconTypeMap(); 131 vtkBooleanMacro(UseVertexIconTypeMap, bool); 132 virtual void SetVertexIconAlignment(int align); 133 virtual int GetVertexIconAlignment(); 134 virtual void SetVertexSelectedIcon(int icon); 135 virtual int GetVertexSelectedIcon(); 136 virtual void SetVertexDefaultIcon(int icon); 137 virtual int GetVertexDefaultIcon(); 138 139 //@{ 140 /** 141 * Set the mode to one of 142 * <ul> 143 * <li>vtkApplyIcons::SELECTED_ICON - use VertexSelectedIcon 144 * <li>vtkApplyIcons::SELECTED_OFFSET - use VertexSelectedIcon as offset 145 * <li>vtkApplyIcons::ANNOTATION_ICON - use current annotation icon 146 * <li>vtkApplyIcons::IGNORE_SELECTION - ignore selected elements 147 * </ul> 148 * The default is IGNORE_SELECTION. 149 */ 150 virtual void SetVertexIconSelectionMode(int mode); 151 virtual int GetVertexIconSelectionMode(); SetVertexIconSelectionModeToSelectedIcon()152 virtual void SetVertexIconSelectionModeToSelectedIcon() 153 { this->SetVertexIconSelectionMode(0); } SetVertexIconSelectionModeToSelectedOffset()154 virtual void SetVertexIconSelectionModeToSelectedOffset() 155 { this->SetVertexIconSelectionMode(1); } SetVertexIconSelectionModeToAnnotationIcon()156 virtual void SetVertexIconSelectionModeToAnnotationIcon() 157 { this->SetVertexIconSelectionMode(2); } SetVertexIconSelectionModeToIgnoreSelection()158 virtual void SetVertexIconSelectionModeToIgnoreSelection() 159 { this->SetVertexIconSelectionMode(3); } 160 //@} 161 162 // ------------------------------------------------------------------------ 163 // Edge icons 164 165 virtual void SetEdgeIconArrayName(const char* name); 166 virtual const char* GetEdgeIconArrayName(); 167 virtual void SetEdgeIconPriorityArrayName(const char* name); 168 virtual const char* GetEdgeIconPriorityArrayName(); 169 virtual void SetEdgeIconVisibility(bool b); 170 virtual bool GetEdgeIconVisibility(); 171 vtkBooleanMacro(EdgeIconVisibility, bool); 172 virtual void AddEdgeIconType(const char* name, int type); 173 virtual void ClearEdgeIconTypes(); 174 virtual void SetUseEdgeIconTypeMap(bool b); 175 virtual bool GetUseEdgeIconTypeMap(); 176 vtkBooleanMacro(UseEdgeIconTypeMap, bool); 177 virtual void SetEdgeIconAlignment(int align); 178 virtual int GetEdgeIconAlignment(); 179 180 // ------------------------------------------------------------------------ 181 // Vertex colors 182 183 virtual void SetColorVerticesByArray(bool b); 184 virtual bool GetColorVerticesByArray(); 185 vtkBooleanMacro(ColorVerticesByArray, bool); 186 virtual void SetVertexColorArrayName(const char* name); 187 virtual const char* GetVertexColorArrayName(); 188 189 // ------------------------------------------------------------------------ 190 // Edge colors 191 192 virtual void SetColorEdgesByArray(bool b); 193 virtual bool GetColorEdgesByArray(); 194 vtkBooleanMacro(ColorEdgesByArray, bool); 195 virtual void SetEdgeColorArrayName(const char* name); 196 virtual const char* GetEdgeColorArrayName(); 197 198 // ------------------------------------------------------------------------ 199 // Enabled vertices 200 201 virtual void SetEnableVerticesByArray(bool b); 202 virtual bool GetEnableVerticesByArray(); 203 vtkBooleanMacro(EnableVerticesByArray, bool); 204 virtual void SetEnabledVerticesArrayName(const char* name); 205 virtual const char* GetEnabledVerticesArrayName(); 206 207 // ------------------------------------------------------------------------ 208 // Enabled edges 209 210 virtual void SetEnableEdgesByArray(bool b); 211 virtual bool GetEnableEdgesByArray(); 212 vtkBooleanMacro(EnableEdgesByArray, bool); 213 virtual void SetEnabledEdgesArrayName(const char* name); 214 virtual const char* GetEnabledEdgesArrayName(); 215 216 virtual void SetEdgeVisibility(bool b); 217 virtual bool GetEdgeVisibility(); 218 vtkBooleanMacro(EdgeVisibility, bool); 219 220 void SetEdgeSelection(bool b); 221 bool GetEdgeSelection(); 222 223 // ------------------------------------------------------------------------ 224 // Vertex layout strategy 225 226 //@{ 227 /** 228 * Set/get the graph layout strategy. 229 */ 230 virtual void SetLayoutStrategy(vtkGraphLayoutStrategy* strategy); 231 virtual vtkGraphLayoutStrategy* GetLayoutStrategy(); 232 //@} 233 234 //@{ 235 /** 236 * Get/set the layout strategy by name. 237 */ 238 virtual void SetLayoutStrategy(const char* name); 239 vtkGetStringMacro(LayoutStrategyName); 240 //@} 241 242 /** 243 * Set predefined layout strategies. 244 */ SetLayoutStrategyToRandom()245 void SetLayoutStrategyToRandom() 246 { this->SetLayoutStrategy("Random"); } SetLayoutStrategyToForceDirected()247 void SetLayoutStrategyToForceDirected() 248 { this->SetLayoutStrategy("Force Directed"); } SetLayoutStrategyToSimple2D()249 void SetLayoutStrategyToSimple2D() 250 { this->SetLayoutStrategy("Simple 2D"); } SetLayoutStrategyToClustering2D()251 void SetLayoutStrategyToClustering2D() 252 { this->SetLayoutStrategy("Clustering 2D"); } SetLayoutStrategyToCommunity2D()253 void SetLayoutStrategyToCommunity2D() 254 { this->SetLayoutStrategy("Community 2D"); } SetLayoutStrategyToFast2D()255 void SetLayoutStrategyToFast2D() 256 { this->SetLayoutStrategy("Fast 2D"); } SetLayoutStrategyToPassThrough()257 void SetLayoutStrategyToPassThrough() 258 { this->SetLayoutStrategy("Pass Through"); } SetLayoutStrategyToCircular()259 void SetLayoutStrategyToCircular() 260 { this->SetLayoutStrategy("Circular"); } SetLayoutStrategyToTree()261 void SetLayoutStrategyToTree() 262 { this->SetLayoutStrategy("Tree"); } SetLayoutStrategyToCosmicTree()263 void SetLayoutStrategyToCosmicTree() 264 { this->SetLayoutStrategy("Cosmic Tree"); } SetLayoutStrategyToCone()265 void SetLayoutStrategyToCone() 266 { this->SetLayoutStrategy("Cone"); } SetLayoutStrategyToSpanTree()267 void SetLayoutStrategyToSpanTree() 268 { this->SetLayoutStrategy("Span Tree"); } 269 270 /** 271 * Set the layout strategy to use coordinates from arrays. 272 * The x array must be specified. The y and z arrays are optional. 273 */ 274 virtual void SetLayoutStrategyToAssignCoordinates( 275 const char* xarr, const char* yarr = nullptr, const char* zarr = nullptr); 276 277 /** 278 * Set the layout strategy to a tree layout. Radial indicates whether to 279 * do a radial or standard top-down tree layout. The angle parameter is the 280 * angular distance spanned by the tree. Leaf spacing is a 281 * value from 0 to 1 indicating how much of the radial layout should be 282 * allocated to leaf nodes (as opposed to between tree branches). The log spacing value is a 283 * non-negative value where > 1 will create expanding levels, < 1 will create 284 * contracting levels, and = 1 makes all levels the same size. See 285 * vtkTreeLayoutStrategy for more information. 286 */ 287 virtual void SetLayoutStrategyToTree( 288 bool radial, 289 double angle = 90, 290 double leafSpacing = 0.9, 291 double logSpacing = 1.0); 292 293 /** 294 * Set the layout strategy to a cosmic tree layout. nodeSizeArrayName is 295 * the array used to size the circles (default is nullptr, which makes leaf 296 * nodes the same size). sizeLeafNodesOnly only uses the leaf node sizes, 297 * and computes the parent size as the sum of the child sizes (default true). 298 * layoutDepth stops layout at a certain depth (default is 0, which does the 299 * entire tree). layoutRoot is the vertex that will be considered the root 300 * node of the layout (default is -1, which will use the tree's root). 301 * See vtkCosmicTreeLayoutStrategy for more information. 302 */ 303 virtual void SetLayoutStrategyToCosmicTree( 304 const char* nodeSizeArrayName, 305 bool sizeLeafNodesOnly = true, 306 int layoutDepth = 0, 307 vtkIdType layoutRoot = -1); 308 309 // ------------------------------------------------------------------------ 310 // Edge layout strategy 311 312 //@{ 313 /** 314 * Set/get the graph layout strategy. 315 */ 316 virtual void SetEdgeLayoutStrategy(vtkEdgeLayoutStrategy* strategy); 317 virtual vtkEdgeLayoutStrategy* GetEdgeLayoutStrategy(); SetEdgeLayoutStrategyToArcParallel()318 void SetEdgeLayoutStrategyToArcParallel() 319 { this->SetEdgeLayoutStrategy("Arc Parallel"); } SetEdgeLayoutStrategyToPassThrough()320 void SetEdgeLayoutStrategyToPassThrough() 321 { this->SetEdgeLayoutStrategy("Pass Through"); } 322 //@} 323 324 /** 325 * Set the edge layout strategy to a geospatial arced strategy 326 * appropriate for vtkGeoView. 327 */ 328 virtual void SetEdgeLayoutStrategyToGeo(double explodeFactor = 0.2); 329 330 //@{ 331 /** 332 * Set the edge layout strategy by name. 333 */ 334 virtual void SetEdgeLayoutStrategy(const char* name); 335 vtkGetStringMacro(EdgeLayoutStrategyName); 336 //@} 337 338 // ------------------------------------------------------------------------ 339 // Miscellaneous 340 341 /** 342 * Apply a theme to this representation. 343 */ 344 void ApplyViewTheme(vtkViewTheme* theme) override; 345 346 //@{ 347 /** 348 * Set the graph vertex glyph type. 349 */ 350 virtual void SetGlyphType(int type); 351 virtual int GetGlyphType(); 352 //@} 353 354 //@{ 355 /** 356 * Set whether to scale vertex glyphs. 357 */ 358 virtual void SetScaling(bool b); 359 virtual bool GetScaling(); 360 vtkBooleanMacro(Scaling, bool); 361 //@} 362 363 //@{ 364 /** 365 * Set the glyph scaling array name. 366 */ 367 virtual void SetScalingArrayName(const char* name); 368 virtual const char* GetScalingArrayName(); 369 //@} 370 371 //@{ 372 /** 373 * Vertex/edge scalar bar visibility. 374 */ 375 virtual void SetVertexScalarBarVisibility(bool b); 376 virtual bool GetVertexScalarBarVisibility(); 377 virtual void SetEdgeScalarBarVisibility(bool b); 378 virtual bool GetEdgeScalarBarVisibility(); 379 //@} 380 381 //@{ 382 /** 383 * Obtain the scalar bar widget used to draw a legend for the vertices/edges. 384 */ 385 virtual vtkScalarBarWidget* GetVertexScalarBar(); 386 virtual vtkScalarBarWidget* GetEdgeScalarBar(); 387 //@} 388 389 /** 390 * Whether the current graph layout is complete. 391 */ 392 virtual bool IsLayoutComplete(); 393 394 /** 395 * Performs another iteration on the graph layout. 396 */ 397 virtual void UpdateLayout(); 398 399 /** 400 * Compute the bounding box of the selected subgraph. 401 */ 402 void ComputeSelectedGraphBounds( double bounds[6] ); 403 404 protected: 405 vtkRenderedGraphRepresentation(); 406 ~vtkRenderedGraphRepresentation() override; 407 408 //@{ 409 /** 410 * Called by the view to add/remove this representation. 411 */ 412 bool AddToView(vtkView* view) override; 413 bool RemoveFromView(vtkView* view) override; 414 //@} 415 416 void PrepareForRendering(vtkRenderView* view) override; 417 418 vtkSelection* ConvertSelection(vtkView* view, vtkSelection* sel) override; 419 420 vtkUnicodeString GetHoverTextInternal(vtkSelection* sel) override; 421 422 /** 423 * Connect inputs to internal pipeline. 424 */ 425 int RequestData( 426 vtkInformation* request, 427 vtkInformationVector** inputVector, 428 vtkInformationVector* outputVector) override; 429 430 //@{ 431 /** 432 * Internal filter classes. 433 */ 434 vtkSmartPointer<vtkApplyColors> ApplyColors; 435 vtkSmartPointer<vtkVertexDegree> VertexDegree; 436 vtkSmartPointer<vtkPolyData> EmptyPolyData; 437 vtkSmartPointer<vtkEdgeCenters> EdgeCenters; 438 vtkSmartPointer<vtkGraphToPoints> GraphToPoints; 439 vtkSmartPointer<vtkPointSetToLabelHierarchy> VertexLabelHierarchy; 440 vtkSmartPointer<vtkPointSetToLabelHierarchy> EdgeLabelHierarchy; 441 vtkSmartPointer<vtkGraphLayout> Layout; 442 vtkSmartPointer<vtkPerturbCoincidentVertices> Coincident; 443 vtkSmartPointer<vtkEdgeLayout> EdgeLayout; 444 vtkSmartPointer<vtkGraphToPolyData> GraphToPoly; 445 vtkSmartPointer<vtkPolyDataMapper> EdgeMapper; 446 vtkSmartPointer<vtkActor> EdgeActor; 447 vtkSmartPointer<vtkGraphToGlyphs> VertexGlyph; 448 vtkSmartPointer<vtkPolyDataMapper> VertexMapper; 449 vtkSmartPointer<vtkActor> VertexActor; 450 vtkSmartPointer<vtkGraphToGlyphs> OutlineGlyph; 451 vtkSmartPointer<vtkPolyDataMapper> OutlineMapper; 452 vtkSmartPointer<vtkActor> OutlineActor; 453 vtkSmartPointer<vtkScalarBarWidget> VertexScalarBar; 454 vtkSmartPointer<vtkScalarBarWidget> EdgeScalarBar; 455 vtkSmartPointer<vtkRemoveHiddenData> RemoveHiddenGraph; 456 vtkSmartPointer<vtkApplyIcons> ApplyVertexIcons; 457 vtkSmartPointer<vtkGraphToPoints> VertexIconPoints; 458 vtkSmartPointer<vtkTransformCoordinateSystems> VertexIconTransform; 459 vtkSmartPointer<vtkIconGlyphFilter> VertexIconGlyph; 460 vtkSmartPointer<vtkPolyDataMapper2D> VertexIconMapper; 461 vtkSmartPointer<vtkTexturedActor2D> VertexIconActor; 462 //@} 463 464 char* VertexHoverArrayName; 465 char* EdgeHoverArrayName; 466 467 vtkSetStringMacro(VertexColorArrayNameInternal); 468 vtkGetStringMacro(VertexColorArrayNameInternal); 469 char* VertexColorArrayNameInternal; 470 471 vtkSetStringMacro(EdgeColorArrayNameInternal); 472 vtkGetStringMacro(EdgeColorArrayNameInternal); 473 char* EdgeColorArrayNameInternal; 474 475 vtkSetStringMacro(ScalingArrayNameInternal); 476 vtkGetStringMacro(ScalingArrayNameInternal); 477 char* ScalingArrayNameInternal; 478 479 vtkSetStringMacro(LayoutStrategyName); 480 char* LayoutStrategyName; 481 vtkSetStringMacro(EdgeLayoutStrategyName); 482 char* EdgeLayoutStrategyName; 483 bool HideVertexLabelsOnInteraction; 484 bool HideEdgeLabelsOnInteraction; 485 486 bool EdgeSelection; 487 488 private: 489 vtkRenderedGraphRepresentation(const vtkRenderedGraphRepresentation&) = delete; 490 void operator=(const vtkRenderedGraphRepresentation&) = delete; 491 }; 492 493 #endif 494 495