Tulip  5.2.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/GlSceneVisitor.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 : public GlSceneVisitor, private Observable {
51 
52 public:
53  /**
54  * Constructor
55  * \param inputData : input data to use for this GlVertexArrayManager
56  */
57  GlVertexArrayManager(GlGraphInputData *inputData);
58 
59  ~GlVertexArrayManager() override;
60 
61  /**
62  * Method used for GlSimpleEntity
63  */
64  void visit(GlSimpleEntity *) override {}
65 
66  /**
67  * Method used for GlNodes (and GlMetaNodes)
68  */
69  void visit(GlNode *glNode) override;
70 
71  /**
72  * Method used for GlEdges
73  */
74  void visit(GlEdge *glEdge) override;
75 
76  void reserveMemoryForGraphElts(unsigned int nbNodes, unsigned int nbEdges) override;
77 
78  /**
79  * Call this function when you want to change input data used by this GlVertexArrayManager
80  */
81  void setInputData(GlGraphInputData *inputData);
82 
83  /**
84  * Return if this GlVertexArrayManager is used to render entities of the scene
85  */
86  inline bool renderingIsBegin() {
87  return isBegin;
88  }
89 
90  /**
91  * Return if this GlVertexArrayManager have to compute its data
92  */
93  bool haveToCompute();
94 
95  /**
96  * Call this function if this GlVertexArrayManager have to compute colors and layout properties
97  */
98  void setHaveToComputeAll(bool compute);
99  /**
100  * Call this function if this GlVertexArrayManager have to compute layout propertie
101  */
102  void setHaveToComputeLayout(bool compute);
103  /**
104  * Call this function if this GlVertexArrayManager have to compute colors propertie
105  */
106  void setHaveToComputeColor(bool compute);
107 
108  /**
109  * Call this function at the begining of the rendering
110  * This function clear entities to render
111  */
112  void beginRendering();
113  /**
114  * Call this funtion at the end of rendering
115  * This function draw needed entities
116  */
117  void endRendering();
118 
119  /**
120  * You can call this function to pause rendering
121  * For example this function is call in GlMetaNodeTrueRenderer to don't use GlVertexArrayManager
122  */
123  void pauseRendering(bool pause);
124 
125  /**
126  * You can call this function to deactivate/activate GlVertexArrayManager
127  */
128  void activate(bool act);
129 
130  bool isActivated() {
131  return activated;
132  }
133 
134  /**
135  * This function is call when you want to activate line rendering of a specific edge
136  */
137  void activateLineEdgeDisplay(GlEdge *edge, bool selected);
138  /**
139  * This function is call when you want to activate quad rendering of a specific edge
140  */
141  void activateQuadEdgeDisplay(GlEdge *edge, bool selected);
142  /**
143  * This function is call when you want to activate point rendering of a specific edge
144  */
145  void activatePointEdgeDisplay(GlEdge *edge, bool selected);
146  /**
147  * This function is call when you want to activate point rendering of a specific node
148  */
149  void activatePointNodeDisplay(GlNode *node, bool selected);
150 
151 protected:
152  void propertyValueChanged(tlp::PropertyInterface *property);
153  void treatEvent(const Event &) override;
154 
155  void clearLayoutData();
156  void clearColorData();
157  void clearData();
158  void initObservers();
159  void clearObservers(PropertyInterface *deletedProperty = nullptr);
160 
161  GlGraphInputData *inputData;
162  Graph *graph;
163  // Store properties used to compute the arrays
164  LayoutProperty *layoutProperty;
165  SizeProperty *sizeProperty;
166  IntegerProperty *shapeProperty;
167  DoubleProperty *rotationProperty;
168  ColorProperty *colorProperty;
169  ColorProperty *borderColorProperty;
170  DoubleProperty *borderWidthProperty;
171  IntegerProperty *srcAnchorShapeProperty;
172  IntegerProperty *tgtAnchorShapeProperty;
173  SizeProperty *srcAnchorSizeProperty;
174  SizeProperty *tgtAnchorSizeProperty;
175  bool graphObserverActivated;
176  bool layoutObserverActivated;
177  bool colorObserverActivated;
178 
179  bool activated;
180  bool isBegin;
181  bool toComputeAll;
182  bool toComputeLayout;
183  bool toComputeColor;
184 
185  bool vectorLayoutSizeInit;
186  bool vectorColorSizeInit;
187 
188  bool edgesModified;
189  bool colorInterpolate;
190  bool sizeInterpolate;
191  bool viewArrow;
192 
193  std::vector<Coord> linesCoordsArray;
194  std::vector<Color> linesColorsArray;
195 
196  std::vector<GLuint> linesRenderingIndicesArray;
197  std::vector<GLuint> linesSelectedRenderingIndicesArray;
198 
199  std::vector<Coord> quadsCoordsArray;
200  std::vector<Color> quadsColorsArray;
201  std::vector<Color> quadsOutlineColorsArray;
202 
203  std::vector<GLuint> quadsRenderingIndicesArray;
204  std::vector<GLuint> quadsSelectedRenderingIndicesArray;
205 
206  std::map<float, std::vector<GLuint>> quadsOutlineRenderingIndicesArray;
207  std::map<float, std::vector<GLuint>> quadsSelectedOutlineRenderingIndicesArray;
208 
209  std::vector<Coord> pointsCoordsArray;
210  std::vector<Color> pointsColorsArray;
211 
212  std::vector<GLuint> pointsNodesRenderingIndexArray;
213  std::vector<GLuint> pointsNodesSelectedRenderingIndexArray;
214  std::vector<GLuint> pointsEdgesRenderingIndexArray;
215  std::vector<GLuint> pointsEdgesSelectedRenderingIndexArray;
216 
217  struct edgeInfos {
218  unsigned int nbVertices;
219  unsigned int linesIndex;
220  unsigned int nbQuadVertices;
221  unsigned int quadsIndex;
222  std::vector<GLuint> quadsBottom;
223  std::vector<GLuint> quadsTop;
224  void init(unsigned int nv, unsigned int li, unsigned int nqv, unsigned int qi) {
225  nbVertices = nv;
226  linesIndex = li;
227  nbQuadVertices = nqv;
228  quadsIndex = qi;
229  quadsBottom.resize(nqv / 2);
230  quadsTop.resize(nqv / 2);
231  }
232  };
233 
234  std::vector<edgeInfos> edgeInfosVector;
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 #endif
258 ///@endcond
PropertyInterface describes the interface of a graph property.