Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
AbstractGlCurve.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 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef ABSTRACTGLCURVE_H
22 #define ABSTRACTGLCURVE_H
23 
24 #include <tulip/GlSimpleEntity.h>
25 #include <tulip/Coord.h>
26 #include <tulip/Color.h>
27 #include <tulip/GlShaderProgram.h>
28 
29 namespace tlp {
30 
31 class TLP_GL_SCOPE AbstractGlCurve : public GlSimpleEntity {
32 
33 public :
34 
35  AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
36 
37  AbstractGlCurve(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode, const std::vector<Coord> &controlPoints,
38  const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints);
39 
40  virtual ~AbstractGlCurve();
41 
42  void draw(float lod, Camera *camera);
43 
44  void translate(const Coord &move);
45 
46  virtual void setTexture(const std::string &texture) {
47  this->texture = texture;
48  }
49 
50  virtual void setOutlined(const bool outlined) {
51  this->outlined = outlined;
52  }
53 
54  virtual void setOutlineColor(const Color &outlineColor) {
55  this->outlineColor = outlineColor;
56  }
57 
58  /**
59  * If set to true, the curve quad outlines will have the same colors
60  * than the curve quad
61  */
62  virtual void setOutlineColorInterpolation(const bool outlineColorInterpolation) {
63  this->outlineColorInterpolation = outlineColorInterpolation;
64  }
65 
66  /**
67  * If set to true, the curve is drawn as a line and not as a thick quad
68  */
69  void setLineCurve(const bool lineCurve) {
70  this->lineCurve = lineCurve;
71  }
72 
73  void setCurveLineWidth(const float curveLineWidth) {
74  this->curveLineWidth = curveLineWidth;
75  }
76 
77  void setCurveQuadBordersWidth(const float curveQuadBorderWidth) {
78  this->curveQuadBordersWidth = curveQuadBorderWidth;
79  }
80 
81  virtual void setBillboardCurve(const bool billboardCurve) {
82  this->billboardCurve = billboardCurve;
83  }
84 
85  virtual void setLookDir(const Coord &lookDir) {
86  this->lookDir = lookDir;
87  }
88 
89  void getXML(std::string &);
90 
91  void setWithXML(const std::string &,unsigned int &);
92 
93  virtual void drawCurve(std::vector<Coord> &controlPoints, const Color &startColor, const Color &endColor, const float startSize, const float endSize, const unsigned int nbCurvePoints=100);
94 
95 protected:
96 
97  virtual void setCurveVertexShaderRenderingSpecificParameters() {};
98 
99  virtual void cleanupAfterCurveVertexShaderRendering() {};
100 
101  virtual Coord computeCurvePointOnCPU(const std::vector<Coord> &controlPoints, float t) = 0;
102 
103  virtual void computeCurvePointsOnCPU(const std::vector<Coord> &controlPoints, std::vector<Coord> &curvePoints, unsigned int nbCurvePoints) = 0;
104 
105  static void buildCurveVertexBuffers(const unsigned int nbCurvePoints, bool vboOk);
106 
107  void initShader(const std::string &shaderProgramName, const std::string &curveSpecificShaderCode);
108 
109  static std::map<unsigned int, GLfloat *> curveVertexBuffersData;
110  static std::map<unsigned int, std::vector<GLushort *> > curveVertexBuffersIndices;
111  static std::map<unsigned int, GLuint* > curveVertexBuffersObject;
112  static std::map<std::string, GlShaderProgram *> curvesShadersMap;
113  static std::map<std::string, GlShaderProgram *> curvesBillboardShadersMap;
114  static GlShader *curveVertexShaderNormalMain;
115  static GlShader *curveVertexShaderBillboardMain;
116  static GlShader *fisheyeDistortionVertexShader;
117  static bool canUseGeometryShader;
118  static std::map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *> > curvesGeometryShadersMap;
119  static GlShader *curveVertexGeometryShaderNormalMain;
120  static std::map<std::string, std::pair<GlShaderProgram *, GlShaderProgram *> > curvesBillboardGeometryShadersMap;
121 
122  std::string shaderProgramName;
123  GlShaderProgram *curveShaderProgramNormal;
124  GlShaderProgram *curveShaderProgramBillboard;
125  GlShaderProgram *curveShaderProgram;
126 
127 
128  std::vector<Coord> controlPoints;
129  Color startColor;
130  Color endColor;
131  float startSize;
132  float endSize;
133  unsigned int nbCurvePoints;
134  bool outlined;
135  Color outlineColor;
136  std::string texture;
137  float texCoordFactor;
138  bool billboardCurve;
139  Coord lookDir;
140  bool lineCurve;
141  float curveLineWidth;
142  float curveQuadBordersWidth;
143  bool outlineColorInterpolation;
144 };
145 
146 }
147 
148 #endif
149 
150 ///@endcond