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