Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces 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 
31 namespace tlp {
32 
33 template<class itType >
34 struct Iterator;
35 
36 class Graph;
37 class LayoutProperty;
38 class SizeProperty;
39 class DoubleProperty;
40 class BooleanProperty;
41 
42 typedef Matrix<float, 3> Mat3f;
43 
44 /**
45  *
46  * Computes the bounding box of a graph according to nodes positions, edges bends,
47  * nodes z-rotations and sizes of elements.
48  *
49  */
50 TLP_SCOPE BoundingBox computeBoundingBox(const Graph *graph,
51  const LayoutProperty *layout,
52  const SizeProperty *size,
53  const DoubleProperty *rotation,
54  const BooleanProperty *selection = NULL);
55 
56 //======================================================================================================
57 
58 /**
59  * Compute the bounding box of graph elements according to node positions, edges bends,
60  * nodes z-rotations and sizes of elements.
61  *
62  * Iterator itN and itE will be deleted after the computations (i.e. no need to delete them yourself).
63  */
64 TLP_SCOPE BoundingBox computeBoundingBox(Iterator<node> *itN,
65  Iterator<edge> *itE,
66  const LayoutProperty *layout,
67  const SizeProperty *size,
68  const DoubleProperty *rotation,
69  const BooleanProperty *selection = NULL);
70 
71 //======================================================================================================
72 
73 /**
74  *
75  * Computes a bounding sphere (or a bounding circle if the graph has a 2D layout) of a graph according to nodes positions, edges bends,
76  * nodes z-rotations and sizes of elements.
77  *
78  * Returns a pair of tlp::Coord whose first member is the center of the bounding sphere (circle for 2D layout)
79  * and second member is the farthest point from the center (computed from graph elements positions).
80  * To get the bounding radius, you have to compute the distance between the two members of the pair
81  * (use the dist method from tlp::Coord).
82  *
83  */
84 
85 TLP_SCOPE std::pair<Coord, Coord> computeBoundingRadius (const Graph *graph,
86  const LayoutProperty *layout,
87  const SizeProperty *size,
88  const DoubleProperty *rotation,
89  const BooleanProperty *selection = NULL);
90 
91 //======================================================================================================
92 
93 /**
94  *
95  * Computes a convex hull of a graph according to nodes positions, edges bends,
96  * nodes z-rotations, and sizes of elements. Only works with 2D layouts.
97  *
98  * Returns a vector of tlp::Coord containing the vertices of the graph convex hull correctly ordered.
99  *
100  */
101 TLP_SCOPE std::vector<Coord> computeConvexHull (const Graph *graph,
102  const LayoutProperty *layout,
103  const SizeProperty *size,
104  const DoubleProperty *rotation,
105  const BooleanProperty *selection = NULL);
106 
107 //======================================================================================================
108 
109 /**
110  *
111  * Computes a convex hull of a set of points,
112  * Only works with 2D layouts.
113  *
114  * Returns a vector of tlp::Coord containing the vertices of the points convex hull correctly ordered.
115  *
116  */
117 TLP_SCOPE std::vector<Coord> computeConvexHull(const std::vector<tlp::Coord> &points);
118 
119 //======================================================================================================
120 
121 
122 /**
123  * Computes the intersection point (if any) of two 3d lines.
124  * Returns true if the line intersects, false otherwise (parallel or skew lines).
125  *
126  */
127 TLP_SCOPE bool computeLinesIntersection(const std::pair<tlp::Coord, tlp::Coord> &line1,
128  const std::pair<tlp::Coord, tlp::Coord> &line2,
129  tlp::Coord &intersectionPoint);
130 
131 //======================================================================================================
132 
133 /**
134  * Computes the centroid of a polygon.
135  * Polygon vertices must be provided correctly ordered in the points vector.
136  *
137  */
138 TLP_SCOPE tlp::Coord computePolygonCentroid(const std::vector<tlp::Coord> &points);
139 
140 //======================================================================================================
141 
142 /**
143  * Checks if a layout is co-planar, returns true if so.
144  * If the layout is co-planar, the inverse transform matrix is also returned
145  * in order to project the layout in the z=0 plane.
146  *
147  */
148 TLP_SCOPE bool isLayoutCoPlanar(const std::vector<Coord> &points, Mat3f &invTransformMatrix);
149 
150 }
151 
152 
153 #endif
154 ///@endcond