Tulip  5.2.1
Large graphs analysis and drawing
DrawingTools.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
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 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef _DRAWINGTOOLS_H
22 #define _DRAWINGTOOLS_H
23 
24 #include <vector>
25 #include <tulip/Node.h>
26 #include <tulip/Edge.h>
27 #include <tulip/Coord.h>
28 #include <tulip/BoundingBox.h>
29 #include <tulip/Matrix.h>
30 #include <tulip/Size.h>
31 
32 namespace tlp {
33 
34 template <class itType>
35 struct Iterator;
36 
37 class Graph;
38 class LayoutProperty;
39 class SizeProperty;
40 class DoubleProperty;
41 class BooleanProperty;
42 
43 typedef Matrix<float, 3> Mat3f;
44 
45 /**
46  *
47  * Computes the bounding box of a graph according to nodes positions, edges bends,
48  * nodes z-rotations and sizes of elements.
49  *
50  */
51 TLP_SCOPE BoundingBox computeBoundingBox(const Graph *graph, const LayoutProperty *layout,
52  const SizeProperty *size, const DoubleProperty *rotation,
53  const BooleanProperty *selection = nullptr);
54 
55 //======================================================================================================
56 
57 /**
58  * Compute the bounding box of graph elements in corresponding vectors according to node positions,
59  * edges bends,
60  * nodes z-rotations and sizes of elements.
61  *
62  */
63 TLP_SCOPE BoundingBox computeBoundingBox(const std::vector<node> &nodes,
64  const std::vector<edge> &edges,
65  const LayoutProperty *layout, const SizeProperty *size,
66  const DoubleProperty *rotation,
67  const BooleanProperty *selection = nullptr);
68 
69 //======================================================================================================
70 
71 /**
72  *
73  * Computes a bounding sphere (or a bounding circle if the graph has a 2D layout) of a graph
74  * according to nodes positions, edges bends,
75  * nodes z-rotations and sizes of elements.
76  *
77  * Returns a pair of tlp::Coord whose first member is the center of the bounding sphere (circle for
78  * 2D layout)
79  * and second member is the farthest point from the center (computed from graph elements
80  * positions).
81  * To get the bounding radius, you have to compute the distance between the two members of the pair
82  * (use the dist method from tlp::Coord).
83  *
84  */
85 
86 TLP_SCOPE std::pair<Coord, Coord>
87 computeBoundingRadius(const Graph *graph, const LayoutProperty *layout, const SizeProperty *size,
88  const DoubleProperty *rotation, const BooleanProperty *selection = nullptr);
89 
90 //======================================================================================================
91 
92 /**
93  *
94  * Computes a convex hull of a graph according to nodes positions, edges bends,
95  * nodes z-rotations, and sizes of elements. Only works with 2D layouts.
96  *
97  * Returns a vector of tlp::Coord containing the vertices of the graph convex hull correctly
98  * ordered.
99  *
100  */
101 TLP_SCOPE std::vector<Coord> computeConvexHull(const Graph *graph, const LayoutProperty *layout,
102  const SizeProperty *size,
103  const DoubleProperty *rotation,
104  const BooleanProperty *selection = nullptr);
105 
106 //======================================================================================================
107 
108 /**
109  *
110  * Computes a convex hull of a set of points,
111  * Only works with 2D layouts.
112  *
113  * Returns a vector of tlp::Coord containing the vertices of the points convex hull correctly
114  * ordered.
115  *
116  */
117 TLP_SCOPE std::vector<Coord> computeConvexHull(const std::vector<tlp::Coord> &points);
118 
119 //======================================================================================================
120 
121 /**
122  * Computes the intersection point (if any) of two 3d lines.
123  * Returns true if the line intersects, false otherwise (parallel or skew lines).
124  *
125  */
126 TLP_SCOPE bool computeLinesIntersection(const std::pair<tlp::Coord, tlp::Coord> &line1,
127  const std::pair<tlp::Coord, tlp::Coord> &line2,
128  tlp::Coord &intersectionPoint);
129 
130 //======================================================================================================
131 
132 /**
133  * Computes the centroid of a polygon.
134  * Polygon vertices must be provided correctly ordered in the points vector.
135  *
136  */
137 TLP_SCOPE tlp::Coord computePolygonCentroid(const std::vector<tlp::Coord> &points);
138 
139 //======================================================================================================
140 
141 /**
142  * Checks if a layout is co-planar, returns true if so.
143  * If the layout is co-planar, the inverse transform matrix is also returned
144  * in order to project the layout in the z=0 plane.
145  *
146  */
147 TLP_SCOPE bool isLayoutCoPlanar(const std::vector<Coord> &points, Mat3f &invTransformMatrix);
148 
149 //======================================================================================================
150 
151 /**
152  * Computes the vertices of a regular polygon.
153  * A regular polygon is a polygon that is equiangular (all angles are equal in measure)
154  * and equilateral (all sides have the same length).
155  *
156  * @since Tulip 4.8
157  *
158  * @param numberOfSides the number of sides of the polygon (minimum value is 3)
159  * @param center the center point of the polygon
160  * @param size the size of the rectangle enclosing the polygon in the form (width/2, height/2)
161  * @param startAngle the start angle when computing the polygon vertices
162  * @return a vector filled with the numberOfSides polygon vertices
163  *
164  */
165 TLP_SCOPE std::vector<tlp::Coord> computeRegularPolygon(unsigned int numberOfSides,
166  const tlp::Coord &center,
167  const tlp::Size &size,
168  float startAngle = 0);
169 } // namespace tlp
170 
171 #endif
172 ///@endcond