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