Tulip  5.0.0
Large graphs analysis and drawing
LayoutProperty.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef TULIP_LAYOUT_H
21 #define TULIP_LAYOUT_H
22 
23 #include <tulip/tuliphash.h>
24 #include <tulip/PropertyTypes.h>
25 #include <tulip/Observable.h>
26 #include <tulip/AbstractProperty.h>
27 #include <tulip/PropertyAlgorithm.h>
28 #include <tulip/minmaxproperty.h>
29 
30 namespace tlp {
31 
32 template <>
34 
35 template <>
36 std::pair<tlp::Coord, tlp::Coord> tlp::MinMaxProperty<tlp::PointType, tlp::LineType>::computeMinMaxNode(const Graph *sg);
37 
38 class PropertyContext;
39 class Graph;
40 
41 typedef AbstractProperty<tlp::PointType, tlp::LineType> AbstractLayoutProperty;
42 typedef MinMaxProperty<tlp::PointType, tlp::LineType> LayoutMinMaxProperty;
43 
44 /**
45  * @ingroup Graph
46  * @brief A graph property that maps a tlp::Coord value to graph nodes and std::vector<tlp::Coord> for edges.
47  */
48 class TLP_SCOPE LayoutProperty : public LayoutMinMaxProperty {
49 public:
50  LayoutProperty(Graph *graph, const std::string& name=""/*, bool updateOnEdgeReversal=true*/);
51 
52  // override some PropertyInterface methods
53  PropertyInterface* clonePrototype(Graph *, const std::string&) const;
54  static const std::string propertyTypename;
55  const std::string& getTypename() const {
56  return propertyTypename;
57  }
58 
59  //=======================================
60  //Methods for extra layout information
61  //=======================================
62 
63  /**
64  * Returns the maximum coordinate of the layout, i.e. the top-right corner of the induced bounding box
65  *
66  * @param subgraph If not null, returns the maximum coordinate for a sub-graph layout
67  **/
68  Coord getMax(const Graph *subgraph=NULL);
69 
70  /**
71  * Returns the minimum coordinate of the layout, i.e. the bottom-left corner of the induced bounding box
72  *
73  * @param subgraph If not null, returns the minimum coordinate for a sub-graph layout
74  **/
75  Coord getMin(const Graph *subgraph=NULL);
76 
77  //============================================
78  //Functions for layout modification
79  //============================================
80 
81  /**
82  * Translates the current layout according to a movement vector
83  *
84  * @param move a movement vector
85  * @param subgraph If not null, only translates the layout of that sub-graph
86  **/
87  void translate(const Vec3f &move, const Graph *subgraph=NULL);
88 
89  /**
90  * Translates the layout of a set of nodes and edges provided through iterators
91  * according to a movement vector
92  *
93  * @param move a movement vector
94  * @param itNodes an iterator on graph nodes
95  * @param itEdges an iterator on graph edges
96  *
97  * @warning The iterators are not deleted
98  **/
99  void translate(const Vec3f &move, Iterator<node> *itNodes, Iterator<edge> *itEdges);
100 
101  /**
102  * Scales the current layout according to a vector of scale factors (sx, sy, sz).
103  *
104  * @param scaleFactors a vector of scale factors
105  * @param subgraph If not null, only scales the layout of that sub-graph
106  **/
107  void scale(const Vec3f &scaleFactors, const Graph *subgraph=NULL);
108 
109  /**
110  * Scales the layout of a set of nodes and edges provided through iterators
111  * according to a vector of scale factors (sx, sy, sz).
112  *
113  * @param scaleFactors a vector of scale factors
114  * @param itNodes an iterator on graph nodes
115  * @param itEdges an iterator on graph edges
116  *
117  * @warning The iterators are not deleted
118  **/
119  void scale(const Vec3f &scaleFactors, Iterator<node> *itNodes, Iterator<edge> *itEdges);
120 
121  /**
122  * Rotates the layout around the X-axis according to an angle in degrees.
123  *
124  * @param alpha an angle in degrees
125  * @param subgraph If not null, only rotates the layout of that sub-graph
126  **/
127  void rotateX(const double &alpha, const Graph *subgraph=NULL);
128 
129  /**
130  * Rotates the layout around the Y-axis according to an angle in degrees.
131  *
132  * @param alpha an angle in degrees
133  * @param subgraph If not null, only rotates the layout of that sub-graph
134  **/
135  void rotateY(const double &alpha, const Graph *subgraph=NULL);
136 
137  /**
138  * Rotates the layout around the Z-axis according to an angle in degrees.
139  *
140  * @param alpha an angle in degrees
141  * @param subgraph If not null, only rotates the layout of that sub-graph
142  **/
143  void rotateZ(const double &alpha, const Graph *subgraph=NULL);
144 
145  /**
146  * Rotates the layout around the X-axis of the nodes and edges provided
147  * through iterators according to an angle in degrees.
148  *
149  * @param alpha an angle in degrees
150  * @param itNodes an iterator on graph nodes
151  * @param itEdges an iterator on graph edges
152  *
153  * @warning The iterators are not deleted
154  **/
155  void rotateX(const double &alpha, Iterator<node> *itNodes, Iterator<edge> *itEdges);
156 
157  /**
158  * Rotates the layout around the Y-axis of the nodes and edges provided
159  * through iterators according to an angle in degrees.
160  *
161  * @param alpha an angle in degrees
162  * @param itNodes an iterator on graph nodes
163  * @param itEdges an iterator on graph edges
164  *
165  * @warning The iterators are not deleted
166  **/
167  void rotateY(const double &alpha, Iterator<node> *itNodes, Iterator<edge> *itEdges);
168 
169  /**
170  * Rotates the layout around the Z-axis of the nodes and edges provided through
171  * iterators according to an angle in degrees.
172  *
173  * @param alpha an angle in degrees
174  * @param itNodes an iterator on graph nodes
175  * @param itEdges an iterator on graph edges
176  *
177  * @warning The iterators are not deleted
178  **/
179  void rotateZ(const double &alpha, Iterator<node> *itNodes, Iterator<edge> *itEdges);
180 
181  /**
182  * Centers the layout, meaning translating it in order that
183  * the center of its bounding box is (0,0,0)
184  *
185  * @param subgraph If not null, only centers the layout of that sub-graph
186  **/
187  void center(const Graph *subgraph=NULL);
188 
189  /**
190  * Centers the layout to newCenter, meaning translating it in order that
191  * the center of its bounding box is equal to newCenter
192  *
193  * @param newCenter the coordinate of the new layout center
194  * @param subgraph If not null, only centers the layout of that sub-graph
195  **/
196  void center(const Vec3f &newCenter, const Graph *subgraph=NULL);
197 
198  /**
199  * Normalizes the layout, meaning dividing each nodes and edges coordinate by the maximum magnitude of the whole coordinates set
200  *
201  * @param subgraph If not null, only normalizes the layout of that sub-graph
202  **/
203  void normalize(const Graph *subgraph=NULL);
204 
205  /**
206  * Scales the layout in order to approach an aspect ratio (width / height) of 1.0 .
207  * @param subgraph If not null, only scales the layout of that sub-graph
208  **/
209  void perfectAspectRatio(const Graph* subgraph=NULL);
210 
211  //=======================================================================
212  // Set of function in order to measure the quality of the LayoutAlgorithm
213  //=======================================================================
214 
215  /**
216  * Returns the length of an edge, the bends are taken into account.
217  * Thus, it measure the length of a polyline.
218  *
219  * @param e the graph edge on which to compute its length
220  *
221  * @warning this function only measure the length of the polyline between bends,
222  * when using curves like Bézier etc... the result will not be the length of the curve.
223  **/
224  double edgeLength(const edge e) const;
225 
226  /**
227  * Returns the average edge length of the layout, the bends are taken into account
228  *
229  * @param subgraph If not null, only compute the average edge length for that sub-graph
230  **/
231  double averageEdgeLength(const Graph *subgraph=NULL) const;
232 
233  /**
234  * Returns the average angular resolution of the layout.
235  * It is only defined for 2D drawing, meaning the third coordinate
236  * is omitted
237  *
238  * @param subgraph It not null, only computes the average angular resolution for that sub-graph
239  **/
240  double averageAngularResolution(const Graph *subgraph=NULL) const;
241 
242  /**
243  * Returns the average angular resolution of a node.
244  * It is only defined for 2D drawing, meaning the third coordinate
245  * is omitted
246  *
247  * @param n the graph node on which to compute the angular resolution
248  * @param subgraph If not null, only computes the average angular resolution for the node in that sub-graph
249  **/
250  double averageAngularResolution(const node n, const Graph *subgraph=NULL) const;
251 
252  /**
253  * Returns a vector of all angular resolution of a node.
254  * It is only defined for 2D drawing, meaning the third coordinate
255  * is omitted
256  *
257  * @param n the graph node on which to compute the angular resolution
258  * @param subgraph If not null, only computes the average angular resolution for the node in that sub-graph
259  **/
260  std::vector<double> angularResolutions(const node n, const Graph *subgraph=NULL) const;
261 
262  /**
263  * Fixes embedding of the graph according to the layout
264  * ie. sort edges around nodes according to their neighbors/bends position in the layout/
265  * Only works in 2D, the third coordinate is not taken into account.
266  *
267  * @param subgraph It not null, only fixes embedding in that sub-graph
268  **/
269  void computeEmbedding(Graph *subgraph=NULL);
270 
271  /**
272  * Fixes embedding of the node according to the layout
273  * ie. sort edges around the node according to its neighbors/bends position in the layout/
274  * Only work in 2D, the third coordinate is not taken into account.
275  *
276  * @param n the graph node on which to fix embedding
277  * @param subgraph If not null, only fixes the embedding of the node in that sub-graph
278  **/
279  void computeEmbedding(const node n, Graph *subgraph=NULL);
280 
281  /**
282  * Returns the number of crossings in the layout
283  **/
284  //methods removed until we have a working implementation
285  //unsigned int crossingNumber() const;
286 
287  // redefinition of some AbstractProperty methods
288  virtual void setNodeValue(const node, tlp::StoredType<Coord>::ReturnedConstValue v);
289  virtual void setEdgeValue(const edge, tlp::StoredType<std::vector<Coord> >::ReturnedConstValue v);
290  virtual void setAllNodeValue(tlp::StoredType<Coord>::ReturnedConstValue v);
291  virtual void setValueToGraphNodes(tlp::StoredType<Coord>::ReturnedConstValue v, const Graph *graph );
292  virtual void setAllEdgeValue(tlp::StoredType<std::vector<Coord> >::ReturnedConstValue v);
293  virtual void setValueToGraphEdges(tlp::StoredType<std::vector<Coord> >::ReturnedConstValue v, const Graph *graph );
294 
295  _DEPRECATED virtual void setAllNodeValue(tlp::StoredType<Coord>::ReturnedConstValue v, const Graph *graph );
296  _DEPRECATED virtual void setAllEdgeValue(tlp::StoredType<std::vector<Coord> >::ReturnedConstValue v, const Graph *graph );
297 
298 protected:
299  virtual void clone_handler(AbstractProperty<tlp::PointType, tlp::LineType> &);
300 
301 private:
302  void resetBoundingBox();
303  void rotate(const double& alpha, int rot, Iterator<node> *, Iterator<edge> *);
304  // override Observable::treatEvent
305  void treatEvent(const Event&);
306 
307 public:
308  // the number of edges with bends
309  unsigned int nbBendedEdges;
310 };
311 
312 /**
313  * @ingroup Graph
314  * @brief A graph property that maps a std::vector<tlp::Coord> value to graph elements.
315  */
316 class TLP_SCOPE CoordVectorProperty:public AbstractVectorProperty<tlp::CoordVectorType, tlp::PointType> {
317 public :
318  CoordVectorProperty(Graph *g, const std::string& n=""):AbstractVectorProperty<CoordVectorType, tlp::PointType>(g, n) {}
319  // redefinition of some PropertyInterface methods
320  PropertyInterface* clonePrototype(Graph *, const std::string&) const;
321  static const std::string propertyTypename;
322  const std::string& getTypename() const {
323  return propertyTypename;
324  }
325 
326 };
327 
329 
330 
331 
332 }
333 #endif
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
Abstracts the computation of minimal and maximal values on node and edge values of properties...
A graph property that maps a std::vector<tlp::Coord> value to graph elements.
PropertyInterface describes the interface of a graph property.
The edge struct represents an edge in a Graph object.
Definition: Edge.h:39
The node struct represents a node in a Graph object.
Definition: Node.h:39
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47
void updateEdgeValue(tlp::edge e, typename edgeType::RealType newValue)
Updates the value on an edge, and updates the minimal/maximal cached values if necessary. Should be called by subclasses in order to keep the cache up to date.
A graph property that maps a tlp::Coord value to graph nodes and std::vector<tlp::Coord> for edges...