Tulip  5.3.0
Large graphs analysis and drawing
GlGraphComposite.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 
20 #ifndef Tulip_GLGRAPHCOMPOSITE_H
21 #define Tulip_GLGRAPHCOMPOSITE_H
22 
23 #include <tulip/GlComposite.h>
24 #include <tulip/Observable.h>
25 #include <tulip/GlGraphRenderingParameters.h>
26 #include <tulip/GlGraphInputData.h>
27 #include <tulip/GlScene.h>
28 
29 namespace tlp {
30 
31 class Graph;
32 class GlGraphRenderer;
33 
34 /**
35  * @ingroup OpenGL
36  * @brief Class use to visualize graph in OpenGL Tulip engine
37  *
38  * GlSimpleEntity specialisation used to visualize graph in GlScene system
39  * @see GlSimpleEntity
40  * @see GlScene
41  *
42  * To visualize graph you have to create a new GlGraphComposite and add it to a GlLayer of a GlScene
43  * After that you can change some visualize parameters throw GlGraphRenderingParameters class
44  * @see GlGraphRenderingParameters
45  * @see getRenderingParametersPointer()
46  *
47  * To render the graph in OpenGL, GlGraphComposite use a GlGraphRenderer. So if you want to change
48  * the system to render the graph, you have to create a new GlGraphRender
49  * @see GlGraphRenderer
50  */
51 class TLP_GL_SCOPE GlGraphComposite : public GlComposite, public Observable {
52 
53 public:
54  /**
55  * @brief Build a GlGraphComposite with the graph data
56  *
57  * You can specify a GlGraphRenderer, if you don't do this a GlGraphHighDetailsRenderer will be
58  * used to display the graph
59  */
60  GlGraphComposite(Graph *graph, GlGraphRenderer *graphRenderer = nullptr);
61 
62  /**
63  * @brief Build a GlGraphComposite with the graph data
64  *
65  * Is better to use the other one constructor
66  *
67  * This graph composite is associated to the scene passed in parameter
68  */
69  GlGraphComposite(Graph *graph, GlScene *scene);
70 
71  /**
72  * @brief Destructor
73  */
74  ~GlGraphComposite() override;
75 
76  /**
77  * @brief Return a copy of rendering parameters use for rendering
78  *
79  * So after you have to call setRenderingParameters
80  */
81  const GlGraphRenderingParameters &getRenderingParameters();
82  /**
83  * @brief Set the rendering parameters use for rendering
84  */
85  void setRenderingParameters(const GlGraphRenderingParameters &parameter);
86 
87  /**
88  * @brief Return a pointer on rendering parameters used for rendering
89  *
90  * With this function you don't have to call setRenderingParameters() function
91  */
92  GlGraphRenderingParameters *getRenderingParametersPointer();
93 
94  /**
95  * @brief Return the inputData use by the composite
96  *
97  * In GlGraphInputData you have properties used to render the graph
98  */
99  GlGraphInputData *getInputData();
100 
101  /**
102  * @brief Return the graph used by this GlGraphComposite
103  */
105  return inputData.getGraph();
106  }
107 
108  ///@cond DOXYGEN_HIDDEN
109 
110  /**
111  * Function used to visit composite's children
112  */
113  void acceptVisitor(GlSceneVisitor *visitor) override;
114  /**
115  * You have to use this function if you want to visit nodes/edges of the graph composite
116  */
117  virtual void acceptVisitorOnGraph(GlSceneVisitor *visitor);
118 
119  void draw(float lod, Camera *camera) override;
120 
121  virtual void selectEntities(Camera *camera, RenderingEntitiesFlag type, int x, int y, int w,
122  int h, std::vector<SelectedEntity> &selectedEntities);
123 
124  /**
125  * Return set of metaNodes
126  */
127  std::set<node> &getMetaNodes() {
128  if (nodesModified) {
129  metaNodes.clear();
130 
131  Graph *graph = inputData.getGraph();
132 
133  for (auto n : graph->nodes()) {
134  if (graph->getNodeMetaInfo(n))
135  metaNodes.insert(n);
136  }
137  nodesModified = false;
138  }
139 
140  return metaNodes;
141  }
142 
143  GlGraphRenderer *getRenderer() {
144  return graphRenderer;
145  }
146 
147  /**
148  * @brief setRenderer Delete the old renderer and replace it by the new one. If the new renderer
149  * is equal to nullptr create a GlGraphHighDetailsRenderer.
150  */
151  void setRenderer(tlp::GlGraphRenderer *);
152 
153  ///@endcond
154 
155  /**
156  * @brief Function to export data in outString (in XML format)
157  */
158  void getXML(std::string &outString) override;
159 
160  /**
161  * @brief Function to set data with inString (in XML format)
162  */
163  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
164 
165 protected:
166  ///@cond DOXYGEN_HIDDEN
167 
168  void treatEvent(const Event &evt) override;
169 
170  ///@endcond
171 
172  GlGraphRenderingParameters parameters;
173  GlGraphInputData inputData;
174  Graph *rootGraph;
175 
176  GlGraphRenderer *graphRenderer;
177 
178  bool nodesModified;
179  std::set<node> metaNodes;
180 };
181 } // namespace tlp
182 
183 #endif
virtual Graph * getNodeMetaInfo(const node metaNode) const =0
Gets the underlying graph of a meta node.
Graph * getGraph()
Return the graph used by this GlGraphComposite.
virtual const std::vector< node > & nodes() const =0
Return a const reference on the vector of nodes of the graph It is the fastest way to access to nodes...
Tulip scene class.
Definition: GlScene.h:160
Tulip OpenGL camera object.
Definition: Camera.h:47
That class defines all the parameters used by GlGraphComposite to render a graph. ...
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:51
Class use to visualize graph in OpenGL Tulip engine.
GlSimpleEntity used to agregate other GlEntity.
Definition: GlComposite.h:39
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:141
Class used by GlGraphComposite to render the graph in OpenGL.