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