Tulip  5.0.0
Large graphs analysis and drawing
DrawingTools.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 ///@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,
52  const LayoutProperty *layout,
53  const SizeProperty *size,
54  const DoubleProperty *rotation,
55  const BooleanProperty *selection = NULL);
56 
57 //======================================================================================================
58 
59 /**
60  * Compute the bounding box of graph elements according to node positions, edges bends,
61  * nodes z-rotations and sizes of elements.
62  *
63  * Iterator itN and itE will be deleted after the computations (i.e. no need to delete them yourself).
64  */
65 TLP_SCOPE BoundingBox computeBoundingBox(Iterator<node> *itN,
66  Iterator<edge> *itE,
67  const LayoutProperty *layout,
68  const SizeProperty *size,
69  const DoubleProperty *rotation,
70  const BooleanProperty *selection = NULL);
71 
72 //======================================================================================================
73 
74 /**
75  * Compute the bounding box of graph elements in corresponding vectors according to node positions, edges bends,
76  * nodes z-rotations and sizes of elements.
77  *
78  */
79 TLP_SCOPE BoundingBox computeBoundingBox(const std::vector<node>& nodes,
80  const std::vector<edge>& edges,
81  const LayoutProperty *layout,
82  const SizeProperty *size,
83  const DoubleProperty *rotation,
84  const BooleanProperty *selection = NULL);
85 
86 //======================================================================================================
87 
88 /**
89  *
90  * Computes a bounding sphere (or a bounding circle if the graph has a 2D layout) of a graph according to nodes positions, edges bends,
91  * nodes z-rotations and sizes of elements.
92  *
93  * Returns a pair of tlp::Coord whose first member is the center of the bounding sphere (circle for 2D layout)
94  * and second member is the farthest point from the center (computed from graph elements positions).
95  * To get the bounding radius, you have to compute the distance between the two members of the pair
96  * (use the dist method from tlp::Coord).
97  *
98  */
99 
100 TLP_SCOPE std::pair<Coord, Coord> computeBoundingRadius (const Graph *graph,
101  const LayoutProperty *layout,
102  const SizeProperty *size,
103  const DoubleProperty *rotation,
104  const BooleanProperty *selection = NULL);
105 
106 //======================================================================================================
107 
108 /**
109  *
110  * Computes a convex hull of a graph according to nodes positions, edges bends,
111  * nodes z-rotations, and sizes of elements. Only works with 2D layouts.
112  *
113  * Returns a vector of tlp::Coord containing the vertices of the graph convex hull correctly ordered.
114  *
115  */
116 TLP_SCOPE std::vector<Coord> computeConvexHull (const Graph *graph,
117  const LayoutProperty *layout,
118  const SizeProperty *size,
119  const DoubleProperty *rotation,
120  const BooleanProperty *selection = NULL);
121 
122 //======================================================================================================
123 
124 /**
125  *
126  * Computes a convex hull of a set of points,
127  * Only works with 2D layouts.
128  *
129  * Returns a vector of tlp::Coord containing the vertices of the points convex hull correctly ordered.
130  *
131  */
132 TLP_SCOPE std::vector<Coord> computeConvexHull(const std::vector<tlp::Coord> &points);
133 
134 //======================================================================================================
135 
136 
137 /**
138  * Computes the intersection point (if any) of two 3d lines.
139  * Returns true if the line intersects, false otherwise (parallel or skew lines).
140  *
141  */
142 TLP_SCOPE bool computeLinesIntersection(const std::pair<tlp::Coord, tlp::Coord> &line1,
143  const std::pair<tlp::Coord, tlp::Coord> &line2,
144  tlp::Coord &intersectionPoint);
145 
146 //======================================================================================================
147 
148 /**
149  * Computes the centroid of a polygon.
150  * Polygon vertices must be provided correctly ordered in the points vector.
151  *
152  */
153 TLP_SCOPE tlp::Coord computePolygonCentroid(const std::vector<tlp::Coord> &points);
154 
155 //======================================================================================================
156 
157 /**
158  * Checks if a layout is co-planar, returns true if so.
159  * If the layout is co-planar, the inverse transform matrix is also returned
160  * in order to project the layout in the z=0 plane.
161  *
162  */
163 TLP_SCOPE bool isLayoutCoPlanar(const std::vector<Coord> &points, Mat3f &invTransformMatrix);
164 
165 //======================================================================================================
166 
167 /**
168  * Computes the vertices of a regular polygon.
169  * A regular polygon is a polygon that is equiangular (all angles are equal in measure)
170  * and equilateral (all sides have the same length).
171  *
172  * @since Tulip 4.8
173  *
174  * @param numberOfSides the number of sides of the polygon (minimum value is 3)
175  * @param center the center point of the polygon
176  * @param size the size of the rectangle enclosing the polygon in the form (width/2, height/2)
177  * @param startAngle the start angle when computing the polygon vertices
178  * @return a vector filled with the numberOfSides polygon vertices
179  *
180  */
181 TLP_SCOPE std::vector<tlp::Coord> computeRegularPolygon(unsigned int numberOfSides, const tlp::Coord &center,
182  const tlp::Size &size, float startAngle = 0);
183 
184 }
185 
186 
187 #endif
188 ///@endcond
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39