Tulip  6.0.0
Large graphs analysis and drawing
GlVertexArrayManager.h
1 /*
2  *
3  * This file is part of Tulip (https://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 <map>
32 #include <vector>
33 
34 namespace tlp {
35 
36 class Graph;
37 class GlEdge;
38 class GlNode;
39 class GlGraphInputData;
40 class PropertyInterface;
41 class ColorProperty;
42 class LayoutProperty;
43 class SizeProperty;
44 class IntegerProperty;
45 class DoubleProperty;
46 
47 /** \brief Class used to render edges/nodes with vertex array
48  *
49  * Class used to render edges/nodes with vertex array
50  */
51 class TLP_GL_SCOPE GlVertexArrayManager : public GlSceneVisitor, private Observable {
52 
53 public:
54  /**
55  * Constructor
56  * \param inputData : input data to use for this GlVertexArrayManager
57  */
58  GlVertexArrayManager(GlGraphInputData *inputData);
59 
60  ~GlVertexArrayManager() override;
61 
62  /**
63  * Method used for GlSimpleEntity
64  */
65  void visit(GlSimpleEntity *) override {}
66 
67  /**
68  * Method used for GlNodes (and GlMetaNodes)
69  */
70  void visit(GlNode *glNode) override;
71 
72  /**
73  * Method used for GlEdges
74  */
75  void visit(GlEdge *glEdge) override;
76 
77  void endOfVisit() override;
78 
79  void reserveMemoryForGraphElts(unsigned int nbNodes, unsigned int nbEdges) override;
80 
81  /**
82  * Call this function when you want to change input data used by this GlVertexArrayManager
83  */
84  void setInputData(GlGraphInputData *inputData);
85 
86  /**
87  * Return if this GlVertexArrayManager is used to render entities of the scene
88  */
89  inline bool renderingIsBegin() {
90  return isBegin;
91  }
92 
93  /**
94  * Return if this GlVertexArrayManager have to compute its data
95  */
96  bool haveToCompute();
97 
98  /**
99  * Call this function if this GlVertexArrayManager have to compute colors and layout properties
100  */
101  void setHaveToComputeAll(bool compute);
102  /**
103  * Call this function if this GlVertexArrayManager have to compute layout property
104  */
105  void setHaveToComputeLayout(bool compute);
106  /**
107  * Call this function if this GlVertexArrayManager have to compute colors property
108  */
109  void setHaveToComputeColor(bool compute);
110 
111  /**
112  * Call this function at the beginning of the rendering
113  * This function clear entities to render
114  */
115  void beginRendering();
116  /**
117  * Call this function at the end of rendering
118  * This function draws needed entities
119  */
120  void endRendering();
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  void propertyValueChanged(tlp::PropertyInterface *property);
156  void treatEvent(const Event &) override;
157 
158  void clearLayoutData();
159  void clearColorData();
160  void clearData();
161  void initObservers();
162  void clearObservers(PropertyInterface *deletedProperty = nullptr);
163 
164  GlGraphInputData *inputData;
165  Graph *graph;
166  // Store properties used to compute the arrays
167  LayoutProperty *layoutProperty;
168  SizeProperty *sizeProperty;
169  IntegerProperty *shapeProperty;
170  DoubleProperty *rotationProperty, *lengthRatioProperty;
171  ColorProperty *colorProperty;
172  ColorProperty *borderColorProperty;
173  DoubleProperty *borderWidthProperty;
174  IntegerProperty *srcAnchorShapeProperty;
175  IntegerProperty *tgtAnchorShapeProperty;
176  SizeProperty *srcAnchorSizeProperty;
177  SizeProperty *tgtAnchorSizeProperty;
178  bool graphObserverActivated;
179  bool layoutObserverActivated;
180  bool colorObserverActivated;
181 
182  bool activated;
183  bool isBegin;
184  bool toComputeAll;
185  bool toComputeLayout;
186  bool toComputeColor;
187 
188  bool vectorLayoutSizeInit;
189  bool vectorColorSizeInit;
190 
191  bool edgesModified;
192  bool colorInterpolate;
193  bool sizeInterpolate;
194  bool viewArrow;
195 
196  std::vector<Coord> linesCoordsArray;
197  std::vector<Color> linesColorsArray;
198 
199  std::vector<GLuint> linesRenderingIndicesArray;
200  std::vector<GLuint> linesSelectedRenderingIndicesArray;
201 
202  std::vector<Coord> quadsCoordsArray;
203  std::vector<Color> quadsColorsArray;
204  std::vector<Color> quadsOutlineColorsArray;
205 
206  std::vector<GLuint> quadsRenderingIndicesArray;
207  std::vector<GLuint> quadsSelectedRenderingIndicesArray;
208 
209  std::map<float, std::vector<GLuint>> quadsOutlineRenderingIndicesArray;
210  std::map<float, std::vector<GLuint>> quadsSelectedOutlineRenderingIndicesArray;
211 
212  std::vector<Coord> pointsCoordsArray;
213  std::vector<Color> pointsColorsArray;
214 
215  std::vector<GLuint> pointsNodesRenderingIndexArray;
216  std::vector<GLuint> pointsNodesSelectedRenderingIndexArray;
217  std::vector<GLuint> pointsEdgesRenderingIndexArray;
218  std::vector<GLuint> pointsEdgesSelectedRenderingIndexArray;
219 
220  struct edgeInfos {
221  unsigned int linesIndex;
222  std::vector<Coord> lineVertices;
223  unsigned int quadsIndex;
224  std::vector<Coord> quadVertices;
225  std::vector<Color> lineColors;
226  std::vector<Color> quadColors;
227  Color edgeColor, borderColor;
228  };
229 
230  std::vector<edgeInfos> edgeInfosVector;
231 
232  GLuint pointsVerticesVBO;
233  GLuint pointsColorsVBO;
234  GLuint linesVerticesVBO;
235  GLuint linesColorsVBO;
236  GLuint quadsVerticesVBO;
237  GLuint quadsColorsVBO;
238  GLuint quadsOutlineColorsVBO;
239 
240  bool pointsVerticesUploaded;
241  bool pointsColorsUploaded;
242  bool linesVerticesUploaded;
243  bool linesColorsUploaded;
244  bool quadsVerticesUploaded;
245  bool quadsColorsUploaded;
246  bool quadsOutlineColorsUploaded;
247 
248  bool verticesUploadNeeded;
249  bool colorsUploadNeeded;
250 };
251 } // namespace tlp
252 
253 #endif
254 ///@endcond
PropertyInterface describes the interface of a graph property.