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