Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlVertexArrayManager.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 Tulip_GLVERTEXARRAYMANAGER_H
22 #define Tulip_GLVERTEXARRAYMANAGER_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 #endif
35 
36 #include <tulip/Coord.h>
37 #include <tulip/Color.h>
38 #include <tulip/Observable.h>
39 #include <tulip/tuliphash.h>
40 
41 #include <vector>
42 
43 namespace tlp {
44 
45 class Graph;
46 class GlEdge;
47 class GlNode;
48 class GlGraphInputData;
49 class PropertyInterface;
50 class ColorProperty;
51 class LayoutProperty;
52 class SizeProperty;
53 class IntegerProperty;
54 class DoubleProperty;
55 
56 /** \brief Class used to render edges/nodes with vertex array
57  *
58  * Class used to render edges/nodes with vertex array
59  */
60 class TLP_GL_SCOPE GlVertexArrayManager : private Observable {
61 
62 public:
63 
64  /**
65  * Constructor
66  * \param inputData : input data to use for this GlVertexArrayManager
67  */
68  GlVertexArrayManager(GlGraphInputData *inputData);
69 
70  ~GlVertexArrayManager();
71 
72  /**
73  * Call this function when you want to change input data used by this GlVertexArrayManager
74  */
75  void setInputData(GlGraphInputData *inputData);
76 
77  /**
78  * Return if this GlVertexArrayManager is used to render entities of the scene
79  */
80  inline bool renderingIsBegin() {
81  return isBegin;
82  }
83 
84  /**
85  * Return if this GlVertexArrayManager have to compute its data
86  */
87  bool haveToCompute();
88 
89  /**
90  * Call this function if this GlVertexArrayManager have to compute colors and layout properties
91  */
92  void setHaveToComputeAll(bool compute);
93  /**
94  * Call this function if this GlVertexArrayManager have to compute layout propertie
95  */
96  void setHaveToComputeLayout(bool compute);
97  /**
98  * Call this function if this GlVertexArrayManager have to compute colors propertie
99  */
100  void setHaveToComputeColor(bool compute);
101 
102  /**
103  * Call this function at the begining of the rendering
104  * This function clear entities to render
105  */
106  void beginRendering();
107  /**
108  * Call this funtion at the end of rendering
109  * This function draw needed entities
110  */
111  void endRendering();
112 
113  /**
114  * This function is call by GlVertexArraySceneVisitor to inform GlVertexArrayManager that we need to render an edge
115  */
116  void addEdge(GlEdge *edge);
117  /**
118  * This function is call by GlVertexArraySceneVisitor to inform GlVertexArrayManager that we need to render a node
119  */
120  void addNode(GlNode *node);
121 
122  /**
123  * You can call this function to pause rendering
124  * For example this function is call in GlMetaNodeTrueRenderer to don't use GlVertexArrayManager
125  */
126  void pauseRendering(bool pause);
127 
128  /**
129  * You can call this function to deactivate/activate GlVertexArrayManager
130  */
131  void activate(bool act);
132 
133  bool isActivated() {
134  return activated;
135  }
136 
137  /**
138  * This function is call when you want to activate line rendering of a specific edge
139  */
140  void activateLineEdgeDisplay(GlEdge *edge, bool selected);
141  /**
142  * This function is call when you want to activate quad rendering of a specific edge
143  */
144  void activateQuadEdgeDisplay(GlEdge *edge, bool selected);
145  /**
146  * This function is call when you want to activate point rendering of a specific edge
147  */
148  void activatePointEdgeDisplay(GlEdge *edge, bool selected);
149  /**
150  * This function is call when you want to activate point rendering of a specific node
151  */
152  void activatePointNodeDisplay(GlNode *node, bool selected);
153 
154 protected:
155 
156  void propertyValueChanged(tlp::PropertyInterface *property);
157  void treatEvent(const Event&);
158 
159  void clearLayoutData();
160  void clearColorData();
161  void clearData();
162  void initObservers();
163  void clearObservers(PropertyInterface *deletedProperty=NULL);
164 
165  GlGraphInputData *inputData;
166  Graph *graph;
167  //Store properties used to compute the arrays
168  LayoutProperty* layoutProperty;
169  SizeProperty* sizeProperty;
170  IntegerProperty* shapeProperty;
171  DoubleProperty* rotationProperty;
172  ColorProperty* colorProperty;
173  ColorProperty* borderColorProperty;
174  DoubleProperty* borderWidthProperty;
175  IntegerProperty *srcAnchorShapeProperty;
176  IntegerProperty *tgtAnchorShapeProperty;
177  SizeProperty *srcAnchorSizeProperty;
178  SizeProperty *tgtAnchorSizeProperty;
179  bool graphObserverActivated;
180  bool layoutObserverActivated;
181  bool colorObserverActivated;
182 
183  bool activated;
184  bool isBegin;
185  bool toComputeAll;
186  bool toComputeLayout;
187  bool toComputeColor;
188 
189  bool vectorLayoutSizeInit;
190  bool vectorColorSizeInit;
191  bool vectorIndexSizeInit;
192 
193  bool edgesModified;
194  bool colorInterpolate;
195  bool sizeInterpolate;
196  bool viewArrow;
197 
198 
199  std::vector<Coord> linesCoordsArray;
200  std::vector<Color> linesColorsArray;
201  std::vector<GLint> linesIndexArray;
202  std::vector<GLsizei> linesIndexCountArray;
203 
204  std::vector<GLuint> linesRenderingIndicesArray;
205  std::vector<GLuint> linesSelectedRenderingIndicesArray;
206 
207  std::vector<Coord> quadsCoordsArray;
208  std::vector<Color> quadsColorsArray;
209  std::vector<Color> quadsOutlineColorsArray;
210  std::vector<GLuint> quadsIndexArray;
211  std::vector<GLsizei> quadsIndexCountArray;
212  std::vector<std::vector<GLuint> > quadsBottomOutlineIndexArray;
213  std::vector<std::vector<GLuint> > quadsTopOutlineIndexArray;
214 
215  std::vector<GLuint> quadsRenderingIndicesArray;
216  std::vector<GLuint> quadsSelectedRenderingIndicesArray;
217 
218  std::map<float, std::vector<GLuint> > quadsOutlineRenderingIndicesArray;
219  std::map<float, std::vector<GLuint> > quadsSelectedOutlineRenderingIndicesArray;
220 
221  std::vector<Coord> pointsCoordsArray;
222  std::vector<Color> pointsColorsArray;
223 
224  std::vector<GLuint> pointsNodesRenderingIndexArray;
225  std::vector<GLuint> pointsNodesSelectedRenderingIndexArray;
226  std::vector<GLuint> pointsEdgesRenderingIndexArray;
227  std::vector<GLuint> pointsEdgesSelectedRenderingIndexArray;
228 
229  TLP_HASH_MAP<unsigned int, std::pair<unsigned int,unsigned int> > edgeToLineIndexVector;
230  TLP_HASH_MAP<unsigned int, std::pair<unsigned int,unsigned int> > edgeToQuadIndexVector;
231  TLP_HASH_MAP<unsigned int, unsigned int> edgeToBottomOulineIndexVector;
232  TLP_HASH_MAP<unsigned int, unsigned int> edgeToTopOutlineIndexVector;
233  TLP_HASH_MAP<unsigned int, unsigned int> edgeToPointIndexVector;
234  TLP_HASH_MAP<unsigned int, unsigned int> nodeToPointIndexVector;
235 
236  GLuint pointsVerticesVBO;
237  GLuint pointsColorsVBO;
238  GLuint linesVerticesVBO;
239  GLuint linesColorsVBO;
240  GLuint quadsVerticesVBO;
241  GLuint quadsColorsVBO;
242  GLuint quadsOutlineColorsVBO;
243 
244  bool pointsVerticesUploaded;
245  bool pointsColorsUploaded;
246  bool linesVerticesUploaded;
247  bool linesColorsUploaded;
248  bool quadsVerticesUploaded;
249  bool quadsColorsUploaded;
250  bool quadsOutlineColorsUploaded;
251 
252  bool verticesUploadNeeded;
253  bool colorsUploadNeeded;
254 
255 };
256 
257 }
258 
259 #endif
260 ///@endcond
PropertyInterface describes the interface of a graph property.