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