Tulip  4.8.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
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  *
76  * Computes a bounding sphere (or a bounding circle if the graph has a 2D layout) of a graph according to nodes positions, edges bends,
77  * nodes z-rotations and sizes of elements.
78  *
79  * Returns a pair of tlp::Coord whose first member is the center of the bounding sphere (circle for 2D layout)
80  * and second member is the farthest point from the center (computed from graph elements 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> computeBoundingRadius (const Graph *graph,
87  const LayoutProperty *layout,
88  const SizeProperty *size,
89  const DoubleProperty *rotation,
90  const BooleanProperty *selection = NULL);
91 
92 //======================================================================================================
93 
94 /**
95  *
96  * Computes a convex hull of a graph according to nodes positions, edges bends,
97  * nodes z-rotations, and sizes of elements. Only works with 2D layouts.
98  *
99  * Returns a vector of tlp::Coord containing the vertices of the graph convex hull correctly ordered.
100  *
101  */
102 TLP_SCOPE std::vector<Coord> computeConvexHull (const Graph *graph,
103  const LayoutProperty *layout,
104  const SizeProperty *size,
105  const DoubleProperty *rotation,
106  const BooleanProperty *selection = NULL);
107 
108 //======================================================================================================
109 
110 /**
111  *
112  * Computes a convex hull of a set of points,
113  * Only works with 2D layouts.
114  *
115  * Returns a vector of tlp::Coord containing the vertices of the points convex hull correctly ordered.
116  *
117  */
118 TLP_SCOPE std::vector<Coord> computeConvexHull(const std::vector<tlp::Coord> &points);
119 
120 //======================================================================================================
121 
122 
123 /**
124  * Computes the intersection point (if any) of two 3d lines.
125  * Returns true if the line intersects, false otherwise (parallel or skew lines).
126  *
127  */
128 TLP_SCOPE bool computeLinesIntersection(const std::pair<tlp::Coord, tlp::Coord> &line1,
129  const std::pair<tlp::Coord, tlp::Coord> &line2,
130  tlp::Coord &intersectionPoint);
131 
132 //======================================================================================================
133 
134 /**
135  * Computes the centroid of a polygon.
136  * Polygon vertices must be provided correctly ordered in the points vector.
137  *
138  */
139 TLP_SCOPE tlp::Coord computePolygonCentroid(const std::vector<tlp::Coord> &points);
140 
141 //======================================================================================================
142 
143 /**
144  * Checks if a layout is co-planar, returns true if so.
145  * If the layout is co-planar, the inverse transform matrix is also returned
146  * in order to project the layout in the z=0 plane.
147  *
148  */
149 TLP_SCOPE bool isLayoutCoPlanar(const std::vector<Coord> &points, Mat3f &invTransformMatrix);
150 
151 //======================================================================================================
152 
153 /**
154  * Computes the vertices of a regular polygon.
155  * A regular polygon is a polygon that is equiangular (all angles are equal in measure)
156  * and equilateral (all sides have the same length).
157  *
158  * @since Tulip 4.8
159  *
160  * @param numberOfSides the number of sides of the polygon (minimum value is 3)
161  * @param center the center point of the polygon
162  * @param size the size of the rectangle enclosing the polygon in the form (width/2, height/2)
163  * @param startAngle the start angle when computing the polygon vertices
164  * @return a vector filled with the numberOfSides polygon vertices
165  *
166  */
167 TLP_SCOPE std::vector<tlp::Coord> computeRegularPolygon(unsigned int numberOfSides, const tlp::Coord &center,
168  const tlp::Size &size, float startAngle = 0);
169 
170 }
171 
172 
173 #endif
174 ///@endcond