Tulip  5.2.0
Large graphs analysis and drawing
GlBezierCurve.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 
20 #ifndef GLBEZIERCURVE_H_
21 #define GLBEZIERCURVE_H_
22 
23 #include <tulip/AbstractGlCurve.h>
24 
25 namespace tlp {
26 
27 /**
28  * @ingroup OpenGL
29  * @brief A class to draw Bezier curves
30  *
31  * This class allows to draw Bezier curves defined by an arbitrary number of control points.
32  * Bezier curves are named after their inventor, Dr. Pierre Bezier. He was an engineer with the
33  * Renault car company and set out in the early 1960's to develop a curve formulation which would
34  * lend itself to shape design.
35  * Bezier curves are widely used in computer graphics to model smooth curves. A Bezier curve is
36  * completely contained in the convex hull of its control points and passes through its first and
37  * last control points. The curve is also always tangent to the first and last convex hull polygon
38  * segments.
39  * In addition, the curve shape tends to follow the polygon shape.
40  *
41  */
42 class TLP_GL_SCOPE GlBezierCurve : public AbstractGlCurve {
43 
44 public:
45  GlBezierCurve();
46 
47  /**
48  * @brief GlBezierCurve constructor
49  *
50  * @param controlPoints a vector of control points (size must be greater or equal to 2)
51  * @param startColor the color at the start of the curve
52  * @param endColor the color at the end of the curve
53  * @param startSize the width at the start of the curve
54  * @param endSize the width at the end of the curve
55  * @param nbCurvePoints the number of curve points to generate
56  */
57  GlBezierCurve(const std::vector<Coord> &controlPoints, const Color &startColor,
58  const Color &endColor, const float &startSize, const float &endSize,
59  const unsigned int nbCurvePoints = 200);
60 
61  ~GlBezierCurve() override;
62 
63  void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor,
64  const float startSize, const float endSize,
65  const unsigned int nbCurvePoints = 200) override;
66 
67 protected:
68  Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t) override;
69 
70  void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints,
71  std::vector<Coord> &curvePoints,
72  unsigned int nbCurvePoints) override;
73 
74  std::string genCurveVertexShaderSpecificCode();
75 };
76 }
77 #endif /* GLBEZIERCURVE_H_ */
A class to draw Bezier curves.
Definition: GlBezierCurve.h:42