Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 00020 00021 00022 #ifndef GLCATMULLROMCURVE_H_ 00023 #define GLCATMULLROMCURVE_H_ 00024 00025 #include <vector> 00026 00027 #include <tulip/AbstractGlCurve.h> 00028 00029 namespace tlp { 00030 00031 00032 /** 00033 * @ingroup OpenGL 00034 * @brief A class to draw a Catmull-Rom curve 00035 * 00036 * This class allow to draw a Catmull-Rom curve, a smooth curve which passes through all its control points. 00037 * Catmull-Rom splines are a family of cubic interpolating splines formulated such that the tangent at each 00038 * control point is calculated using the previous and next control point point of the spline. 00039 * Catmull-Rom splines have C^1 continuity, local control, and interpolation, but do not lie within the convex 00040 * hull of their control points. 00041 */ 00042 class TLP_GL_SCOPE GlCatmullRomCurve : public AbstractGlCurve { 00043 00044 enum ParameterizationType {UNIFORM, CHORD_LENGTH, CENTRIPETAL}; 00045 00046 public : 00047 00048 GlCatmullRomCurve(); 00049 00050 /** 00051 * @brief GlCatmullRomCurve constructor 00052 * 00053 * @param controlPoints a vector of control points (size must be greater or equal to 4) 00054 * @param startColor the color at the start of the curve 00055 * @param endColor the color at the end of the curve 00056 * @param startSize the width at the start of the curve 00057 * @param endSize the width at the end of the curve 00058 * @param closedCurve if true, the curve will be closed and a bezier segment will be drawn between the last and first control point 00059 * @param paramType curve parameterization type (GlCatmullRomCurve::UNIFORM | GlCatmullRomCurve::CENTRIPETAL | GlCatmullRomCurve::CHORD_LENGTH (default)) 00060 * @param nbCurvePoints the number of curve points to generate 00061 */ 00062 GlCatmullRomCurve(const std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor, 00063 const float startSize, const float endSize, const bool closedCurve = false, 00064 const unsigned int nbCurvePoints = 200, const ParameterizationType paramType = CENTRIPETAL); 00065 00066 ~GlCatmullRomCurve(); 00067 00068 void setParameterizationType(const ParameterizationType paramType) { 00069 this->paramType = paramType; 00070 } 00071 00072 void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints=200); 00073 00074 void setClosedCurve(const bool closedCurve) { 00075 this->closedCurve = closedCurve; 00076 } 00077 00078 protected : 00079 00080 void setCurveVertexShaderRenderingSpecificParameters(); 00081 00082 Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t); 00083 00084 void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints, std::vector<Coord> &curvePoints, unsigned int nbCurvePoints); 00085 00086 private : 00087 00088 bool closedCurve; 00089 float totalLength; 00090 float alpha; 00091 ParameterizationType paramType; 00092 }; 00093 00094 00095 } 00096 00097 #endif /* GLCATMULLROMCURVE_H_ */ 00098