1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkGraphLayoutView.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   vtkGraphLayoutView
22  * @brief   Lays out and displays a graph
23  *
24  *
25  * vtkGraphLayoutView performs graph layout and displays a vtkGraph.
26  * You may color and label the vertices and edges using fields in the graph.
27  * If coordinates are already assigned to the graph vertices in your graph,
28  * set the layout strategy to PassThrough in this view. The default layout
29  * is Fast2D which is fast but not that good, for better layout set the
30  * layout to Simple2D or ForceDirected. There are also tree and circle
31  * layout strategies. :)
32  *
33  * .SEE ALSO
34  * vtkFast2DLayoutStrategy
35  * vtkSimple2DLayoutStrategy
36  * vtkForceDirectedLayoutStrategy
37  *
38  * @par Thanks:
39  * Thanks a bunch to the holographic unfolding pattern.
40 */
41 
42 #ifndef vtkGraphLayoutView_h
43 #define vtkGraphLayoutView_h
44 
45 #include "vtkViewsInfovisModule.h" // For export macro
46 #include "vtkRenderView.h"
47 
48 class vtkEdgeLayoutStrategy;
49 class vtkGraphLayoutStrategy;
50 class vtkRenderedGraphRepresentation;
51 class vtkViewTheme;
52 
53 class VTKVIEWSINFOVIS_EXPORT vtkGraphLayoutView : public vtkRenderView
54 {
55 public:
56   static vtkGraphLayoutView *New();
57   vtkTypeMacro(vtkGraphLayoutView, vtkRenderView);
58   void PrintSelf(ostream& os, vtkIndent indent) override;
59 
60   //@{
61   /**
62    * The array to use for vertex labeling.  Default is "VertexDegree".
63    */
64   void SetVertexLabelArrayName(const char* name);
65   const char* GetVertexLabelArrayName();
66   //@}
67 
68   //@{
69   /**
70    * The array to use for edge labeling.  Default is "LabelText".
71    */
72   void SetEdgeLabelArrayName(const char* name);
73   const char* GetEdgeLabelArrayName();
74   //@}
75 
76   //@{
77   /**
78    * Whether to show vertex labels.  Default is off.
79    */
80   void SetVertexLabelVisibility(bool vis);
81   bool GetVertexLabelVisibility();
82   vtkBooleanMacro(VertexLabelVisibility, bool);
83   //@}
84 
85   //@{
86   /**
87    * Whether to hide vertex labels during mouse interactions.  Default is off.
88    */
89   void SetHideVertexLabelsOnInteraction(bool vis);
90   bool GetHideVertexLabelsOnInteraction();
91   vtkBooleanMacro(HideVertexLabelsOnInteraction, bool);
92   //@}
93 
94   //@{
95   /**
96    * Whether to show the edges at all. Default is on
97    */
98   void SetEdgeVisibility(bool vis);
99   bool GetEdgeVisibility();
100   vtkBooleanMacro(EdgeVisibility, bool);
101   //@}
102 
103   //@{
104   /**
105    * Whether to show edge labels.  Default is off.
106    */
107   void SetEdgeLabelVisibility(bool vis);
108   bool GetEdgeLabelVisibility();
109   vtkBooleanMacro(EdgeLabelVisibility, bool);
110   //@}
111 
112   //@{
113   /**
114    * Whether to hide edge labels during mouse interactions.  Default is off.
115    */
116   void SetHideEdgeLabelsOnInteraction(bool vis);
117   bool GetHideEdgeLabelsOnInteraction();
118   vtkBooleanMacro(HideEdgeLabelsOnInteraction, bool);
119   //@}
120 
121   //@{
122   /**
123    * The array to use for coloring vertices.  The default behavior
124    * is to color by vertex degree.
125    */
126   void SetVertexColorArrayName(const char* name);
127   const char* GetVertexColorArrayName();
128   //@}
129 
130   //@{
131   /**
132    * Whether to color vertices.  Default is off.
133    */
134   void SetColorVertices(bool vis);
135   bool GetColorVertices();
136   vtkBooleanMacro(ColorVertices, bool);
137   //@}
138 
139   //@{
140   /**
141    * The array to use for coloring edges.  Default is "color".
142    */
143   void SetEdgeColorArrayName(const char* name);
144   const char* GetEdgeColorArrayName();
145   //@}
146 
147   //@{
148   /**
149    * Whether to color edges.  Default is off.
150    */
151   void SetColorEdges(bool vis);
152   bool GetColorEdges();
153   vtkBooleanMacro(ColorEdges, bool);
154   //@}
155 
156   //@{
157   /**
158    * Whether edges are selectable. Default is on.
159    */
160   void SetEdgeSelection(bool vis);
161   bool GetEdgeSelection();
162   vtkBooleanMacro(EdgeSelection, bool);
163   //@}
164 
165   //@{
166   /**
167    * The array to use for coloring edges.
168    */
169   void SetEnabledEdgesArrayName(const char* name);
170   const char* GetEnabledEdgesArrayName();
171   //@}
172 
173   //@{
174   /**
175    * Whether to color edges.  Default is off.
176    */
177   void SetEnableEdgesByArray(bool vis);
178   int GetEnableEdgesByArray();
179   //@}
180 
181   //@{
182   /**
183    * The array to use for coloring vertices.
184    */
185   void SetEnabledVerticesArrayName(const char* name);
186   const char* GetEnabledVerticesArrayName();
187   //@}
188 
189   //@{
190   /**
191    * Whether to color vertices.  Default is off.
192    */
193   void SetEnableVerticesByArray(bool vis);
194   int GetEnableVerticesByArray();
195   //@}
196 
197   //@{
198   /**
199    * The array used for scaling (if ScaledGlyphs is ON)
200    */
201   void SetScalingArrayName(const char* name);
202   const char* GetScalingArrayName();
203   //@}
204 
205   //@{
206   /**
207    * Whether to use scaled glyphs or not.  Default is off.
208    */
209   void SetScaledGlyphs(bool arg);
210   bool GetScaledGlyphs();
211   vtkBooleanMacro(ScaledGlyphs, bool);
212   //@}
213 
214   //@{
215   /**
216    * The layout strategy to use when performing the graph layout.
217    * The possible strings are:
218    * - "Random"         Randomly places vertices in a box.
219    * - "Force Directed" A layout in 3D or 2D simulating forces on edges.
220    * - "Simple 2D"      A simple 2D force directed layout.
221    * - "Clustering 2D"  A 2D force directed layout that's just like
222    * simple 2D but uses some techniques to cluster better.
223    * - "Community 2D"   A linear-time 2D layout that's just like
224    * Fast 2D but looks for and uses a community
225    * array to 'accentuate' clusters.
226    * - "Fast 2D"       A linear-time 2D layout.
227    * - "Pass Through"  Use locations assigned to the input.
228    * - "Circular"      Places vertices uniformly on a circle.
229    * - "Cone"          Cone tree layout.
230    * - "Span Tree"     Span Tree Layout.
231    * Default is "Simple 2D".
232    */
233   void SetLayoutStrategy(const char* name);
SetLayoutStrategyToRandom()234   void SetLayoutStrategyToRandom()
235     { this->SetLayoutStrategy("Random"); }
SetLayoutStrategyToForceDirected()236   void SetLayoutStrategyToForceDirected()
237     { this->SetLayoutStrategy("Force Directed"); }
SetLayoutStrategyToSimple2D()238   void SetLayoutStrategyToSimple2D()
239     { this->SetLayoutStrategy("Simple 2D"); }
SetLayoutStrategyToClustering2D()240   void SetLayoutStrategyToClustering2D()
241     { this->SetLayoutStrategy("Clustering 2D"); }
SetLayoutStrategyToCommunity2D()242   void SetLayoutStrategyToCommunity2D()
243     { this->SetLayoutStrategy("Community 2D"); }
SetLayoutStrategyToFast2D()244   void SetLayoutStrategyToFast2D()
245     { this->SetLayoutStrategy("Fast 2D"); }
SetLayoutStrategyToPassThrough()246   void SetLayoutStrategyToPassThrough()
247     { this->SetLayoutStrategy("Pass Through"); }
SetLayoutStrategyToCircular()248   void SetLayoutStrategyToCircular()
249     { this->SetLayoutStrategy("Circular"); }
SetLayoutStrategyToTree()250   void SetLayoutStrategyToTree()
251     { this->SetLayoutStrategy("Tree"); }
SetLayoutStrategyToCosmicTree()252   void SetLayoutStrategyToCosmicTree()
253     { this->SetLayoutStrategy("Cosmic Tree"); }
SetLayoutStrategyToCone()254   void SetLayoutStrategyToCone()
255     { this->SetLayoutStrategy("Cone"); }
SetLayoutStrategyToSpanTree()256   void SetLayoutStrategyToSpanTree()
257     { this->SetLayoutStrategy("Span Tree"); }
258   const char* GetLayoutStrategyName();
259   //@}
260 
261   //@{
262   /**
263    * The layout strategy to use when performing the graph layout.
264    * This signature allows an application to create a layout
265    * object directly and simply set the pointer through this method.
266    */
267   vtkGraphLayoutStrategy* GetLayoutStrategy();
268   void SetLayoutStrategy(vtkGraphLayoutStrategy *s);
269   //@}
270 
271   //@{
272   /**
273    * The layout strategy to use when performing the edge layout.
274    * The possible strings are:
275    * "Arc Parallel"   - Arc parallel edges and self loops.
276    * "Pass Through"   - Use edge routes assigned to the input.
277    * Default is "Arc Parallel".
278    */
279   void SetEdgeLayoutStrategy(const char* name);
SetEdgeLayoutStrategyToArcParallel()280   void SetEdgeLayoutStrategyToArcParallel()
281     { this->SetEdgeLayoutStrategy("Arc Parallel"); }
SetEdgeLayoutStrategyToPassThrough()282   void SetEdgeLayoutStrategyToPassThrough()
283     { this->SetEdgeLayoutStrategy("Pass Through"); }
284   const char* GetEdgeLayoutStrategyName();
285   //@}
286 
287   //@{
288   /**
289    * The layout strategy to use when performing the edge layout.
290    * This signature allows an application to create a layout
291    * object directly and simply set the pointer through this method.
292    */
293   vtkEdgeLayoutStrategy* GetEdgeLayoutStrategy();
294   void SetEdgeLayoutStrategy(vtkEdgeLayoutStrategy *s);
295   //@}
296 
297   /**
298    * Associate the icon at index "index" in the vtkTexture to all vertices
299    * containing "type" as a value in the vertex attribute array specified by
300    * IconArrayName.
301    */
302   void AddIconType(const char *type, int index);
303 
304   /**
305    * Clear all icon mappings.
306    */
307   void ClearIconTypes();
308 
309   /**
310    * Specify where the icons should be placed in relation to the vertex.
311    * See vtkIconGlyphFilter.h for possible values.
312    */
313   void SetIconAlignment(int alignment);
314 
315   //@{
316   /**
317    * Whether icons are visible (default off).
318    */
319   void SetIconVisibility(bool b);
320   bool GetIconVisibility();
321   vtkBooleanMacro(IconVisibility, bool);
322   //@}
323 
324   //@{
325   /**
326    * The array used for assigning icons
327    */
328   void SetIconArrayName(const char* name);
329   const char* GetIconArrayName();
330   //@}
331 
332   //@{
333   /**
334    * The type of glyph to use for the vertices
335    */
336   void SetGlyphType(int type);
337   int GetGlyphType();
338   //@}
339 
340   //@{
341   /**
342    * The size of the font used for vertex labeling
343    */
344   virtual void SetVertexLabelFontSize(const int size);
345   virtual int GetVertexLabelFontSize();
346   //@}
347 
348   //@{
349   /**
350    * The size of the font used for edge labeling
351    */
352   virtual void SetEdgeLabelFontSize(const int size);
353   virtual int GetEdgeLabelFontSize();
354   //@}
355 
356   //@{
357   /**
358    * Whether the scalar bar for edges is visible.  Default is off.
359    */
360   void SetEdgeScalarBarVisibility(bool vis);
361   bool GetEdgeScalarBarVisibility();
362   //@}
363 
364   //@{
365   /**
366    * Whether the scalar bar for vertices is visible.  Default is off.
367    */
368   void SetVertexScalarBarVisibility(bool vis);
369   bool GetVertexScalarBarVisibility();
370   //@}
371 
372   /**
373    * Reset the camera based on the bounds of the selected region.
374    */
375   void ZoomToSelection();
376 
377   /**
378    * Is the graph layout complete? This method is useful
379    * for when the strategy is iterative and the application
380    * wants to show the iterative progress of the graph layout
381    * See Also: UpdateLayout();
382    */
383   virtual int IsLayoutComplete();
384 
385   /**
386    * This method is useful for when the strategy is iterative
387    * and the application wants to show the iterative progress
388    * of the graph layout. The application would have something like
389    * while(!IsLayoutComplete())
390    * {
391    * UpdateLayout();
392    * }
393    * See Also: IsLayoutComplete();
394    */
395   virtual void UpdateLayout();
396 
397 protected:
398   vtkGraphLayoutView();
399   ~vtkGraphLayoutView() override;
400 
401   //@{
402   /**
403    * Overrides behavior in vtkView to create a vtkRenderedGraphRepresentation
404    * by default.
405    */
406   vtkDataRepresentation* CreateDefaultRepresentation(vtkAlgorithmOutput* conn) override;
407   virtual vtkRenderedGraphRepresentation* GetGraphRepresentation();
408   // Called to process events.  Overrides behavior in vtkRenderView.
409   void ProcessEvents(vtkObject* caller, unsigned long eventId, void* callData) override;
410   //@}
411 
412 private:
413   vtkGraphLayoutView(const vtkGraphLayoutView&) = delete;
414   void operator=(const vtkGraphLayoutView&) = delete;
415   bool VertexLabelsRequested;
416   bool EdgeLabelsRequested;
417 };
418 
419 #endif
420