Tulip  5.2.1
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 endOfVisit() override;
77 
78  void reserveMemoryForGraphElts(unsigned int nbNodes, unsigned int nbEdges) override;
79 
80  /**
81  * Call this function when you want to change input data used by this GlVertexArrayManager
82  */
83  void setInputData(GlGraphInputData *inputData);
84 
85  /**
86  * Return if this GlVertexArrayManager is used to render entities of the scene
87  */
88  inline bool renderingIsBegin() {
89  return isBegin;
90  }
91 
92  /**
93  * Return if this GlVertexArrayManager have to compute its data
94  */
95  bool haveToCompute();
96 
97  /**
98  * Call this function if this GlVertexArrayManager have to compute colors and layout properties
99  */
100  void setHaveToComputeAll(bool compute);
101  /**
102  * Call this function if this GlVertexArrayManager have to compute layout propertie
103  */
104  void setHaveToComputeLayout(bool compute);
105  /**
106  * Call this function if this GlVertexArrayManager have to compute colors propertie
107  */
108  void setHaveToComputeColor(bool compute);
109 
110  /**
111  * Call this function at the begining of the rendering
112  * This function clear entities to render
113  */
114  void beginRendering();
115  /**
116  * Call this funtion at the end of rendering
117  * This function draw needed entities
118  */
119  void endRendering();
120 
121  /**
122  * You can call this function to pause rendering
123  * For example this function is call in GlMetaNodeTrueRenderer to don't use GlVertexArrayManager
124  */
125  void pauseRendering(bool pause);
126 
127  /**
128  * You can call this function to deactivate/activate GlVertexArrayManager
129  */
130  void activate(bool act);
131 
132  bool isActivated() {
133  return activated;
134  }
135 
136  /**
137  * This function is call when you want to activate line rendering of a specific edge
138  */
139  void activateLineEdgeDisplay(GlEdge *edge, bool selected);
140  /**
141  * This function is call when you want to activate quad rendering of a specific edge
142  */
143  void activateQuadEdgeDisplay(GlEdge *edge, bool selected);
144  /**
145  * This function is call when you want to activate point rendering of a specific edge
146  */
147  void activatePointEdgeDisplay(GlEdge *edge, bool selected);
148  /**
149  * This function is call when you want to activate point rendering of a specific node
150  */
151  void activatePointNodeDisplay(GlNode *node, bool selected);
152 
153 protected:
154  void propertyValueChanged(tlp::PropertyInterface *property);
155  void treatEvent(const Event &) override;
156 
157  void clearLayoutData();
158  void clearColorData();
159  void clearData();
160  void initObservers();
161  void clearObservers(PropertyInterface *deletedProperty = nullptr);
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 
190  bool edgesModified;
191  bool colorInterpolate;
192  bool sizeInterpolate;
193  bool viewArrow;
194 
195  std::vector<Coord> linesCoordsArray;
196  std::vector<Color> linesColorsArray;
197 
198  std::vector<GLuint> linesRenderingIndicesArray;
199  std::vector<GLuint> linesSelectedRenderingIndicesArray;
200 
201  std::vector<Coord> quadsCoordsArray;
202  std::vector<Color> quadsColorsArray;
203  std::vector<Color> quadsOutlineColorsArray;
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  struct edgeInfos {
220  unsigned int linesIndex;
221  std::vector<Coord> lineVertices;
222  unsigned int quadsIndex;
223  std::vector<Coord> quadVertices;
224  std::vector<Color> lineColors;
225  std::vector<Color> quadColors;
226  Color edgeColor, borderColor;
227  };
228 
229  std::vector<edgeInfos> edgeInfosVector;
230 
231  GLuint pointsVerticesVBO;
232  GLuint pointsColorsVBO;
233  GLuint linesVerticesVBO;
234  GLuint linesColorsVBO;
235  GLuint quadsVerticesVBO;
236  GLuint quadsColorsVBO;
237  GLuint quadsOutlineColorsVBO;
238 
239  bool pointsVerticesUploaded;
240  bool pointsColorsUploaded;
241  bool linesVerticesUploaded;
242  bool linesColorsUploaded;
243  bool quadsVerticesUploaded;
244  bool quadsColorsUploaded;
245  bool quadsOutlineColorsUploaded;
246 
247  bool verticesUploadNeeded;
248  bool colorsUploadNeeded;
249 };
250 } // namespace tlp
251 
252 #endif
253 ///@endcond
PropertyInterface describes the interface of a graph property.