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