Tulip  4.3.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 #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 the system to render the graph, you have to create a new GlGraphRender
48  * @see GlGraphRenderer
49  */
50 class TLP_GL_SCOPE GlGraphComposite : public GlComposite, public Observable {
51 
52 public:
53 
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 used to display the graph
58  */
59  GlGraphComposite(Graph* graph, GlGraphRenderer *graphRenderer=NULL);
60 
61  /**
62  * @brief Build a GlGraphComposite with the graph data
63  *
64  * Is better to use the other one constructor
65  *
66  * This graph composite is associated to the scene passed in parameter
67  */
68  GlGraphComposite(Graph* graph, GlScene *scene);
69 
70  /**
71  * @brief Destructor
72  */
74 
75  /**
76  * @brief Return a copy of rendering parameters use for rendering
77  *
78  * So after you have to call setRenderingParameters
79  */
80  const GlGraphRenderingParameters& getRenderingParameters();
81  /**
82  * @brief Set the rendering parameters use for rendering
83  */
84  void setRenderingParameters(const GlGraphRenderingParameters &parameter);
85 
86  /**
87  * @brief Return a pointer on rendering parameters used for rendering
88  *
89  * With this function you don't have to call setRenderingParameters() function
90  */
91  GlGraphRenderingParameters* getRenderingParametersPointer();
92 
93  /**
94  * @brief Return the inputData use by the composite
95  *
96  * In GlGraphInputData you have properties used to render the graph
97  */
98  GlGraphInputData* getInputData();
99 
100  /**
101  * @brief Return the graph used by this GlGraphComposite
102  */
104  return inputData.getGraph();
105  }
106 
107 ///@cond DOXYGEN_HIDDEN
108 
109  /**
110  * Function used to visit composite's children
111  */
112  virtual void acceptVisitor(GlSceneVisitor *visitor);
113  /**
114  * You have to use this function if you want to visit nodes/edges of the graph composite
115  */
116  virtual void acceptVisitorOnGraph(GlSceneVisitor *visitor);
117 
118  virtual void draw(float lod,Camera* camera);
119 
120  virtual void selectEntities(Camera *camera,RenderingEntitiesFlag type,int x, int y, int w, int h, std::vector<SelectedEntity>& selectedEntities);
121 
122  /**
123  * Return set of metaNodes
124  */
125  std::set<node> &getMetaNodes() {
126  if(nodesModified) {
127  metaNodes.clear();
128 
129  Graph *graph=inputData.getGraph();
130  Iterator<node>* nodesIterator = graph->getNodes();
131 
132  while (nodesIterator->hasNext()) {
133  node n=nodesIterator->next();
134 
135  if(graph->getNodeMetaInfo(n))
136  metaNodes.insert(n);
137  }
138 
139  delete nodesIterator;
140 
141  nodesModified=false;
142  }
143 
144  return metaNodes;
145  }
146 
147  GlGraphRenderer *getRenderer() {
148  return graphRenderer;
149  }
150 
151  /**
152  * @brief setRenderer Delete the old renderer and replace it by the new one. If the new renderer is equal to NULL create a GlGraphHighDetailsRenderer.
153  */
154  void setRenderer(tlp::GlGraphRenderer*);
155 
156 ///@endcond
157 
158  /**
159  * @brief Function to export data in outString (in XML format)
160  */
161  virtual void getXML(std::string &outString);
162 
163  /**
164  * @brief Function to set data with inString (in XML format)
165  */
166  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
167 
168 protected:
169 
170 ///@cond DOXYGEN_HIDDEN
171 
172  void treatEvent(const Event& evt);
173 
174 ///@endcond
175 
176  GlGraphRenderingParameters parameters;
177  GlGraphInputData inputData;
178  Graph *rootGraph;
179 
180  GlGraphRenderer *graphRenderer;
181 
182  bool nodesModified;
183  std::set<node> metaNodes;
184 
185 };
186 }
187 
188 #endif