Tulip  5.1.0
Large graphs analysis and drawing
GlEdge.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 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef Tulip_GLEDGE_H
22 #define Tulip_GLEDGE_H
23 
24 #ifndef DOXYGEN_NOTFOR_DEVEL
25 
26 #include <tulip/PropertyTypes.h>
27 #include <tulip/Size.h>
28 #include <tulip/GlComplexeEntity.h>
29 #include <tulip/Matrix.h>
30 
31 namespace tlp {
32 
33 struct OcclusionTest;
34 class TextRenderer;
35 class GlLabel;
36 class EdgeExtremityGlyph;
37 
38 /**
39  * Class to represent an edge of a graph
40  */
41 class TLP_GL_SCOPE GlEdge : public GlComplexeEntity {
42 
43 public:
44 
45  /**
46  * Build an edge with the id : id
47  * id must be the id of the edge in graph
48  */
49  GlEdge(unsigned int id);
50 
51  /**
52  * Virtual function to accept GlSceneVisitor on this class
53  */
54  virtual void acceptVisitor(GlSceneVisitor *visitor);
55 
56  /**
57  * Return the edge bounding box
58  */
59  virtual BoundingBox getBoundingBox(const GlGraphInputData* data);
60 
61  /**
62  * Draw the edge with level of detail : lod and Camera : camera
63  */
64  virtual void draw(float lod,const GlGraphInputData *data,Camera* camera);
65 
66  /**
67  * Draw the label of the edge if drawEdgesLabel is true and if label selection is equal to drawSelect
68  * Use TextRenderer : renderer to draw the label
69  */
70  void drawLabel(bool drawSelect,OcclusionTest* test,const GlGraphInputData* data, float lod);
71 
72  /**
73  * Draw the label of the edge if drawEdgesLabel is true
74  * Use TextRenderer : renderer to draw the label
75  */
76  void drawLabel(OcclusionTest* test,const GlGraphInputData* data);
77 
78  /**
79  * Draw the label of the edge if drawEdgesLabel is true
80  * Use TextRenderer : renderer to draw the label
81  */
82  void drawLabel(OcclusionTest* test,const GlGraphInputData* data, float lod, Camera *camera=NULL);
83 
84  /**
85  * This function is used by the engine to get line coordinates of the edge
86  */
87  void getVertices(const GlGraphInputData *data,std::vector<Coord> &linesCoordsArray);
88 
89  /**
90  * This function is used by the engine to get line colors of the edge
91  */
92  void getColors(const GlGraphInputData *data,const Coord *vertices,unsigned int numberOfVertices,std::vector<Color> &linesColorsArray);
93  /**
94  * This function is used by the engine to get line colors of the edge
95  */
96  void getColors(const GlGraphInputData *data,const std::vector<Coord> &vertices,std::vector<Color> &linesColorsArray);
97 
98  /**
99  * Compute the edge size
100  */
101  void getEdgeSize(const GlGraphInputData *data,edge e,const Size &srcSize, const Size &tgtSize,const float maxSrcSize,const float maxTgtSize,Size &edgeSize);
102 
103  /**
104  * Compute edge anchor
105  */
106  void getEdgeAnchor(const GlGraphInputData *data,const node &source,const node &target,const LineType::RealType &bends,const Coord &srcCoord,const Coord &tgtCoord,const Size &srcSize,const Size &tgtSize, Coord &srcAnchor, Coord &tgtAnchor);
107 
108  void setSelectionDraw(bool selectDraw) {
109  selectionDraw = selectDraw;
110  }
111 
112  unsigned int id;
113 
114 private :
115 
116  bool selectionDraw;
117  static GlLabel *label;
118 
119  /**
120  * Draw the Edge : this function is used by draw function
121  */
122  void drawEdge(const Coord &srcNodePos, const Coord &tgtNodePos,
123  const Coord &startPoint, const Coord &endPoint, const LineType::RealType &bends,
124  const Color &startColor, const Color &endColor, const Coord &lookDir, bool colorInterpolate, const Color &borderColor,
125  const Size &size, int shape, bool edge3D, float lod,const std::string &textureName, const float outlineWidth);
126 
127  /**
128  * Function used to compute bounding box for edge extremity.
129  */
130  BoundingBox eeGlyphBoundingBox(const Coord& anchor, const Coord& tgt, float glyphNrm,
131  const Matrix<float, 4>& transformation, const Matrix<float, 4>& size);
132 
133  /**
134  * Compute the edge colors and store these colors in srcCol and tgtCol
135  * \param data : input data used to compute edge colors
136  */
137  void getEdgeColor(const GlGraphInputData *data,const edge &e,const node &source,const node &target, bool selected,Color &srcCol, Color &tgtCol);
138 
139 
140 
141  /**
142  * Compute width lod of edge
143  * This lod is used to know if the edge is render in polygon mode or line mode
144  */
145  float getEdgeWidthLod(const Coord &edgeCoord,const Size &edgeSize,Camera *camera);
146 
147  /**
148  * Thgis function is used to render edge arrows
149  */
150  void displayArrowAndAdjustAnchor(const GlGraphInputData *data,const edge &e,const node &source,const Size &sizeRatio,float edgeSize,const Color &color,float maxSize,bool selected,float selectionOutlineSize,
151  int tgtEdgeGlyph,bool hasBends,const Coord &anchor,const Coord &tgtCoord,
152  const Coord &srcAnchor,const Coord &tgtAnchor,Coord &lineAnchor, EdgeExtremityGlyph* srcEdgeGlyph = NULL, Camera *camera = NULL);
153 
154 };
155 
156 }
157 
158 #endif // DOXYGEN_NOTFOR_DEVEL
159 
160 #endif // Tulip_GLEDGE_H
161 ///@endcond