Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 <cassert>
25 #include <iostream>
26 #include <tulip/OpenGlConfigManager.h>
27 
28 #include <tulip/tulipconf.h>
29 #include <tulip/Coord.h>
30 #include <tulip/Color.h>
31 #include <tulip/Size.h>
32 #include <tulip/tuliphash.h>
33 #include <tulip/Observable.h>
34 #include <tulip/PropertyInterface.h>
35 
36 #include <vector>
37 
38 namespace tlp {
39 
40 class Graph;
41 class GlEdge;
42 class GlNode;
43 class GlGraphInputData;
44 
45 /** \brief Class used to render edges/nodes with vertex array
46  *
47  * Class used to render edges/nodes with vertex array
48  */
49 class TLP_GL_SCOPE GlVertexArrayManager : private Observable {
50 
51 public:
52 
53  /**
54  * Constructor
55  * \param inputData : input data to use for this GlVertexArrayManager
56  */
57  GlVertexArrayManager(GlGraphInputData *inputData);
58 
59  ~GlVertexArrayManager();
60 
61  /**
62  * Call this function when you want to change input data used by this GlVertexArrayManager
63  */
64  void setInputData(GlGraphInputData *inputData);
65 
66  /**
67  * Return if this GlVertexArrayManager is used to render entities of the scene
68  */
69  inline bool renderingIsBegin() {
70  return isBegin;
71  }
72 
73  /**
74  * Return if this GlVertexArrayManager have to compute its data
75  */
76  bool haveToCompute();
77 
78  /**
79  * Call this function if this GlVertexArrayManager have to compute colors and layout properties
80  */
81  void setHaveToComputeAll(bool compute);
82  /**
83  * Call this function if this GlVertexArrayManager have to compute layout propertie
84  */
85  void setHaveToComputeLayout(bool compute);
86  /**
87  * Call this function if this GlVertexArrayManager have to compute colors propertie
88  */
89  void setHaveToComputeColor(bool compute);
90 
91  /**
92  * Call this function at the begining of the rendering
93  * This function clear entities to render
94  */
95  void beginRendering();
96  /**
97  * Call this funtion at the end of rendering
98  * This function draw needed entities
99  */
100  void endRendering();
101 
102  /**
103  * This function is call by GlVertexArraySceneVisitor to inform GlVertexArrayManager that we need to render an edge
104  */
105  void addEdge(GlEdge *edge);
106  /**
107  * This function is call by GlVertexArraySceneVisitor to inform GlVertexArrayManager that we need to render a node
108  */
109  void addNode(GlNode *node);
110 
111  /**
112  * You can call this function to pause rendering
113  * For example this function is call in GlMetaNodeTrueRenderer to don't use GlVertexArrayManager
114  */
115  void pauseRendering(bool pause);
116 
117  /**
118  * You can call this function to deactivate/activate GlVertexArrayManager
119  */
120  void activate(bool act);
121 
122  bool isActivated() {
123  return activated;
124  }
125 
126  /**
127  * This function is call when you want to activate line rendering of a specific edge
128  */
129  void activateLineEdgeDisplay(GlEdge *edge, bool selected);
130  /**
131  * This function is call when you want to activate quad rendering of a specific edge
132  */
133  void activateQuadEdgeDisplay(GlEdge *edge, bool selected);
134  /**
135  * This function is call when you want to activate point rendering of a specific edge
136  */
137  void activatePointEdgeDisplay(GlEdge *edge, bool selected);
138  /**
139  * This function is call when you want to activate point rendering of a specific node
140  */
141  void activatePointNodeDisplay(GlNode *node, bool onePixel, bool selected);
142 
143 protected:
144 
145  void propertyValueChanged(tlp::PropertyInterface *property);
146  void treatEvent(const Event&);
147 
148  void clearLayoutData();
149  void clearColorData();
150  void clearData();
151  void initObservers();
152  void clearObservers(PropertyInterface *deletedProperty=NULL);
153 
154  GlGraphInputData *inputData;
155  Graph *graph;
156  bool graphObserverActivated;
157  bool layoutObserverActivated;
158  bool colorObserverActivated;
159 
160  bool activated;
161  bool isBegin;
162  bool toComputeAll;
163  bool toComputeLayout;
164  bool toComputeColor;
165 
166  bool vectorLayoutSizeInit;
167  bool vectorColorSizeInit;
168  bool vectorIndexSizeInit;
169 
170  bool colorInterpolate;
171  bool sizeInterpolate;
172  bool edgesModified;
173 
174  std::vector<Coord> linesCoordsArray;
175  std::vector<Color> linesColorsArray;
176  std::vector<GLint> linesIndexArray;
177  std::vector<GLsizei> linesIndexCountArray;
178 
179  std::vector<GLint> linesRenderingStartIndexArray;
180  std::vector<GLsizei> linesRenderingCountArray;
181  std::vector<GLint> linesSelectedRenderingStartIndexArray;
182  std::vector<GLsizei> linesSelectedRenderingCountArray;
183 
184  std::vector<Coord> quadsCoordsArray;
185  std::vector<Color> quadsColorsArray;
186  std::vector<Color> quadsOutlineColorsArray;
187  std::vector<GLint> quadsIndexArray;
188  std::vector<GLsizei> quadsIndexCountArray;
189  std::vector<std::vector<GLuint> > quadsBottomOutlineIndexArray;
190  std::vector<std::vector<GLuint> > quadsTopOutlineIndexArray;
191 
192  std::vector<GLint> quadsRenderingStartIndexArray;
193  std::vector<GLsizei> quadsRenderingCountArray;
194  std::vector<GLint> quadsSelectedRenderingStartIndexArray;
195  std::vector<GLsizei> quadsSelectedRenderingCountArray;
196  std::map<float, std::vector<const GLuint* > > quadsOutlineRenderingIndexArray;
197  std::map<float, std::vector<GLsizei> > quadsOutlineRenderingCountArray;
198  std::map<float, std::vector<const GLuint* > > quadsOutlineSelectedRenderingIndexArray;
199  std::map<float, std::vector<GLsizei> > quadsOutlineSelectedRenderingCountArray;
200 
201  std::vector<Coord> pointsCoordsArray;
202  std::vector<Color> pointsColorsArray;
203 
204  std::vector<GLuint> points1PNodesRenderingIndexArray;
205  std::vector<GLuint> points1PNodesSelectedRenderingIndexArray;
206  std::vector<GLuint> points2PNodesRenderingIndexArray;
207  std::vector<GLuint> points2PNodesSelectedRenderingIndexArray;
208  std::vector<GLuint> points1PEdgesRenderingIndexArray;
209  std::vector<GLuint> points1PEdgesSelectedRenderingIndexArray;
210 
211  std::vector<std::pair<unsigned int,unsigned int> > edgeToLineIndexVector;
212  std::vector<std::pair<unsigned int,unsigned int> > edgeToQuadIndexVector;
213  std::vector<unsigned int> edgeToBottomOulineIndexVector;
214  std::vector<unsigned int> edgeToTopOutlineIndexVector;
215  std::vector<unsigned int> edgeToPointIndexVector;
216  std::vector<unsigned int> nodeToPointIndexVector;
217 };
218 
219 }
220 
221 #endif
222 ///@endcond