Tulip  4.6.0
Better Visualization Through Research
library/tulip-ogl/include/tulip/GlGraphComposite.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef Tulip_GLGRAPHCOMPOSITE_H
00021 #define Tulip_GLGRAPHCOMPOSITE_H
00022 
00023 #include <tulip/GlComposite.h>
00024 #include <tulip/Observable.h>
00025 #include <tulip/GlGraphRenderingParameters.h>
00026 #include <tulip/GlGraphInputData.h>
00027 #include <tulip/GlScene.h>
00028 
00029 namespace tlp {
00030 
00031 class Graph;
00032 class GlGraphRenderer;
00033 
00034 /**
00035  * @ingroup OpenGL
00036  * @brief Class use to visualize graph in OpenGL Tulip engine
00037  *
00038  * GlSimpleEntity specialisation used to visualize graph in GlScene system
00039  * @see GlSimpleEntity
00040  * @see GlScene
00041  *
00042  * To visualize graph you have to create a new GlGraphComposite and add it to a GlLayer of a GlScene
00043  * After that you can change some visualize parameters throw GlGraphRenderingParameters class
00044  * @see GlGraphRenderingParameters
00045  * @see getRenderingParametersPointer()
00046  *
00047  * 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
00048  * @see GlGraphRenderer
00049  */
00050 class TLP_GL_SCOPE GlGraphComposite : public GlComposite, public Observable {
00051 
00052 public:
00053 
00054   /**
00055    * @brief Build a GlGraphComposite with the graph data
00056    *
00057    * You can specify a GlGraphRenderer, if you don't do this a GlGraphHighDetailsRenderer will be used to display the graph
00058    */
00059   GlGraphComposite(Graph* graph, GlGraphRenderer *graphRenderer=NULL);
00060 
00061   /**
00062    * @brief Build a GlGraphComposite with the graph data
00063    *
00064    * Is better to use the other one constructor
00065    *
00066    * This graph composite is associated to the scene passed in parameter
00067    */
00068   GlGraphComposite(Graph* graph, GlScene *scene);
00069 
00070   /**
00071    * @brief Destructor
00072    */
00073   ~GlGraphComposite();
00074 
00075   /**
00076    * @brief Return a copy of rendering parameters use for rendering
00077    *
00078    * So after you have to call setRenderingParameters
00079    */
00080   const GlGraphRenderingParameters& getRenderingParameters();
00081   /**
00082    * @brief Set the rendering parameters use for rendering
00083    */
00084   void setRenderingParameters(const GlGraphRenderingParameters &parameter);
00085 
00086   /**
00087    * @brief Return a pointer on rendering parameters used for rendering
00088    *
00089    * With this function you don't have to call setRenderingParameters() function
00090    */
00091   GlGraphRenderingParameters* getRenderingParametersPointer();
00092 
00093   /**
00094    * @brief Return the inputData use by the composite
00095    *
00096    * In GlGraphInputData you have properties used to render the graph
00097    */
00098   GlGraphInputData* getInputData();
00099 
00100   /**
00101    * @brief Return the graph used by this GlGraphComposite
00102    */
00103   Graph *getGraph() {
00104     return inputData.getGraph();
00105   }
00106 
00107 ///@cond DOXYGEN_HIDDEN
00108 
00109   /**
00110    * Function used to visit composite's children
00111    */
00112   virtual void acceptVisitor(GlSceneVisitor *visitor);
00113   /**
00114    * You have to use this function if you want to visit nodes/edges of the graph composite
00115    */
00116   virtual void acceptVisitorOnGraph(GlSceneVisitor *visitor);
00117 
00118   virtual void draw(float lod,Camera* camera);
00119 
00120   virtual void selectEntities(Camera *camera,RenderingEntitiesFlag type,int x, int y, int w, int h, std::vector<SelectedEntity>& selectedEntities);
00121 
00122   /**
00123    * Return set of metaNodes
00124    */
00125   std::set<node> &getMetaNodes() {
00126     if(nodesModified) {
00127       metaNodes.clear();
00128 
00129       Graph *graph=inputData.getGraph();
00130       Iterator<node>* nodesIterator = graph->getNodes();
00131 
00132       while (nodesIterator->hasNext()) {
00133         node n=nodesIterator->next();
00134 
00135         if(graph->getNodeMetaInfo(n))
00136           metaNodes.insert(n);
00137       }
00138 
00139       delete nodesIterator;
00140 
00141       nodesModified=false;
00142     }
00143 
00144     return metaNodes;
00145   }
00146 
00147   GlGraphRenderer *getRenderer() {
00148     return graphRenderer;
00149   }
00150 
00151   /**
00152    * @brief setRenderer Delete the old renderer and replace it by the new one. If the new renderer is equal to NULL create a GlGraphHighDetailsRenderer.
00153    */
00154   void setRenderer(tlp::GlGraphRenderer*);
00155 
00156 ///@endcond
00157 
00158   /**
00159    * @brief Function to export data in outString (in XML format)
00160    */
00161   virtual void getXML(std::string &outString);
00162 
00163   /**
00164    * @brief Function to set data with inString (in XML format)
00165    */
00166   virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
00167 
00168 protected:
00169 
00170 ///@cond DOXYGEN_HIDDEN
00171 
00172   void treatEvent(const Event& evt);
00173 
00174 ///@endcond
00175 
00176   GlGraphRenderingParameters parameters;
00177   GlGraphInputData inputData;
00178   Graph *rootGraph;
00179 
00180   GlGraphRenderer *graphRenderer;
00181 
00182   bool nodesModified;
00183   std::set<node> metaNodes;
00184 
00185 };
00186 }
00187 
00188 #endif
 All Classes Files Functions Variables Enumerations Enumerator Properties