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