Tulip  5.3.1
Large graphs analysis and drawing
GlCatmullRomCurve.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 GLCATMULLROMCURVE_H_
21 #define GLCATMULLROMCURVE_H_
22 
23 #include <vector>
24 
25 #include <tulip/AbstractGlCurve.h>
26 
27 namespace tlp {
28 
29 /**
30  * @ingroup OpenGL
31  * @brief A class to draw a Catmull-Rom curve
32  *
33  * This class allow to draw a Catmull-Rom curve, a smooth curve which passes through all its control
34  * points.
35  * Catmull-Rom splines are a family of cubic interpolating splines formulated such that the tangent
36  * at each
37  * control point is calculated using the previous and next control point point of the spline.
38  * Catmull-Rom splines have C^1 continuity, local control, and interpolation, but do not lie within
39  * the convex
40  * hull of their control points.
41  */
42 class TLP_GL_SCOPE GlCatmullRomCurve : public AbstractGlCurve {
43 
44  enum ParameterizationType { UNIFORM, CHORD_LENGTH, CENTRIPETAL };
45 
46 public:
48 
49  /**
50  * @brief GlCatmullRomCurve constructor
51  *
52  * @param controlPoints a vector of control points (size must be greater or equal to 4)
53  * @param startColor the color at the start of the curve
54  * @param endColor the color at the end of the curve
55  * @param startSize the width at the start of the curve
56  * @param endSize the width at the end of the curve
57  * @param closedCurve if true, the curve will be closed and a bezier segment will be drawn between
58  * the last and first control point
59  * @param paramType curve parameterization type (GlCatmullRomCurve::UNIFORM |
60  * GlCatmullRomCurve::CENTRIPETAL | GlCatmullRomCurve::CHORD_LENGTH (default))
61  * @param nbCurvePoints the number of curve points to generate
62  */
63  GlCatmullRomCurve(const std::vector<Coord> &controlPoints, const Color &startColor,
64  const Color &endColor, const float startSize, const float endSize,
65  const bool closedCurve = false, const unsigned int nbCurvePoints = 200,
66  const ParameterizationType paramType = CENTRIPETAL);
67 
68  ~GlCatmullRomCurve() override;
69 
70  void setParameterizationType(const ParameterizationType paramType) {
71  this->paramType = paramType;
72  }
73 
74  void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor,
75  const float startSize, const float endSize,
76  const unsigned int nbCurvePoints = 200) override;
77 
78  void setClosedCurve(const bool closedCurve) {
79  this->closedCurve = closedCurve;
80  }
81 
82 protected:
83  void setCurveVertexShaderRenderingSpecificParameters() override;
84 
85  Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t) override;
86 
87  void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints,
88  std::vector<Coord> &curvePoints,
89  unsigned int nbCurvePoints) override;
90 
91 private:
92  bool closedCurve;
93  float totalLength;
94  float alpha;
95  ParameterizationType paramType;
96 };
97 } // namespace tlp
98 
99 #endif /* GLCATMULLROMCURVE_H_ */
A class to draw a Catmull-Rom curve.