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