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