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