Tulip  5.2.0
Large graphs analysis and drawing
ParametricCurves.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 PARAMETRICCURVES_H_
22 #define PARAMETRICCURVES_H_
23 
24 #include <vector>
25 
26 #include <tulip/tulipconf.h>
27 #include <tulip/Coord.h>
28 
29 namespace tlp {
30 
31 /**
32  * Compute Pascal triangle until nth row
33  *
34  * \param n the number of Pascal triangle rows to compute
35  * \param pascalTriangle a vector of vector of double to store the result. If that vector already
36  * contains m Pascal triangle rows and n > m, the first m row are not recomputed and the vector is
37  * expanded to store the new rows.
38  */
39 TLP_SCOPE void buildPascalTriangle(unsigned int n,
40  std::vector<std::vector<double>> &pascalTriangle);
41 
42 /**
43  * Compute the position of a point 'p' at t (0 <= t <= 1)
44  * along Bezier curve defined by a set of control points
45  *
46  * \param controlPoints a vector of control points
47  * \param t curve parameter value (0 <= t <= 1)
48  */
49 TLP_SCOPE Coord computeBezierPoint(const std::vector<Coord> &controlPoints, const float t);
50 
51 /** Compute a set of points approximating a Bézier curve
52  *
53  * \param controlPoints a vector of control points
54  * \param curvePoints an empty vector to store the computed points
55  * \param nbCurvePoints number of points to generate
56  */
57 TLP_SCOPE void computeBezierPoints(const std::vector<Coord> &controlPoints,
58  std::vector<Coord> &curvePoints,
59  const unsigned int nbCurvePoints = 100);
60 
61 /**
62  * Compute the position of a point 'p' at t (0 <= t <= 1)
63  * along Catmull-Rom curve defined by a set of control points.
64  * The features of this type of spline are the following :
65  * -> the spline passes through all of the control points
66  * -> the spline is C1 continuous, meaning that there are no discontinuities in the tangent
67  * direction and magnitude
68  * -> the spline is not C2 continuous. The second derivative is linearly interpolated within
69  * each segment, causing the curvature to vary linearly over the length of the segment
70  *
71  * \param controlPoints a vector of control points
72  * \param t curve parameter value (0 <= t <= 1)
73  * \param closedCurve if true, the curve will be closed, meaning a Bézier segment will connect the
74  * last and first control point
75  * \param alpha curve parameterization parameter (0 <= alpha <= 1), alpha = 0 -> uniform
76  * parameterization, alpha = 0.5 -> centripetal parameterization, alpha = 1.0 -> chord-length
77  * parameterization
78  */
79 TLP_SCOPE Coord computeCatmullRomPoint(const std::vector<Coord> &controlPoints, const float t,
80  const bool closedCurve = false, const float alpha = 0.5);
81 
82 /** Compute a set of points approximating a Catmull-Rom curve
83  *
84  * \param controlPoints a vector of control points
85  * \param curvePoints an empty vector to store the computed points
86  * \param closedCurve if true, the curve will be closed, meaning a Bézier segment will connect the
87  * last and first control point
88  * \param alpha curve parameterization parameter (0 <= alpha <= 1), alpha = 0 -> uniform
89  * parameterization, alpha = 0.5 -> centripetal parameterization, alpha = 1.0 -> chord-length
90  * parameterization
91  * \param nbCurvePoints number of points to generate
92  */
93 TLP_SCOPE void computeCatmullRomPoints(const std::vector<Coord> &controlPoints,
94  std::vector<Coord> &curvePoints,
95  const bool closedCurve = false,
96  const unsigned int nbCurvePoints = 100,
97  const float alpha = 0.5);
98 
99 /**
100  * Compute the position of a point 'p' at t (0 <= t <= 1)
101  * along open uniform B-spline curve defined by a set of control points.
102  * An uniform B-spline is a piecewise collection of Bézier curves of the same degree, connected end
103  * to end.
104  * The features of this type of spline are the following :
105  * -> the spline is C^2 continuous, meaning there is no discontinuities in curvature
106  * -> the spline has local control : its parameters only affect a small part of the entire
107  * spline
108  * A B-spline is qualified as open when it passes through its first and last control points.
109  * \param controlPoints a vector of control points
110  * \param t curve parameter value (0 <= t <= 1)
111  * \param curveDegree the B-spline degree
112  */
113 
114 TLP_SCOPE Coord computeOpenUniformBsplinePoint(const std::vector<Coord> &controlPoints,
115  const float t, const unsigned int curveDegree = 3);
116 
117 /** Compute a set of points approximating an open uniform B-spline curve
118  *
119  * \param controlPoints a vector of control points
120  * \param curvePoints an empty vector to store the computed points
121  * \param curveDegree the B-spline degree
122  * \param nbCurvePoints number of points to generate
123  */
124 TLP_SCOPE void computeOpenUniformBsplinePoints(const std::vector<Coord> &controlPoints,
125  std::vector<Coord> &curvePoints,
126  const unsigned int curveDegree = 3,
127  const unsigned int nbCurvePoints = 100);
128 }
129 
130 #endif /* PARAMETRICCURVES_H_ */
131 ///@endcond