Tulip  5.7.4
Large graphs analysis and drawing
GlEdge.h
1 /*
2  *
3  * This file is part of Tulip (https://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, float lengthRatio = 1);
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  float lengthRatio = 1);
113 
114  void setSelectionDraw(bool selectDraw) {
115  selectionDraw = selectDraw;
116  }
117 
118  // edge id and edge position in graph->edges()
119  unsigned int id, pos;
120 
121 private:
122  bool selectionDraw;
123 
124  /**
125  * Draw the Edge : this function is used by draw function
126  */
127  void drawEdge(const Coord &srcNodePos, const Coord &tgtNodePos, const Coord &startPoint,
128  const Coord &endPoint, const LineType::RealType &bends, const Color &startColor,
129  const Color &endColor, const Coord &lookDir, bool colorInterpolate,
130  const Color &borderColor, const Size &size, int shape, bool edge3D, float lod,
131  const std::string &textureName, const float outlineWidth);
132 
133  /**
134  * Function used to compute bounding box for edge extremity.
135  */
136  BoundingBox eeGlyphBoundingBox(const Coord &anchor, const Coord &tgt, float glyphNrm,
137  const Matrix<float, 4> &transformation,
138  const Matrix<float, 4> &size);
139 
140  /**
141  * Compute the edge colors and store these colors in srcCol and tgtCol
142  * \param data : input data used to compute edge colors
143  */
144  void getEdgeColor(const GlGraphInputData *data, const edge e, const node src, const node tgt,
145  bool selected, Color &srcCol, Color &tgtCol);
146 
147  /**
148  * Compute width lod of edge
149  * This lod is used to know if the edge is render in polygon mode or line mode
150  */
151  float getEdgeWidthLod(const Coord &edgeCoord, const Size &edgeSize, Camera *camera);
152 
153  /**
154  * Thgis function is used to render edge arrows
155  */
156  void displayArrowAndAdjustAnchor(const GlGraphInputData *data, const edge e, const node src,
157  const Size &sizeRatio, float edgeSize, const Color &color,
158  float maxSize, bool selected, float selectionOutlineSize,
159  int tgtEdgeGlyph, bool hasBends, const Coord &anchor,
160  const Coord &tgtCoord, const Coord &srcAnchor,
161  const Coord &tgtAnchor, Coord &lineAnchor,
162  EdgeExtremityGlyph *srcEdgeGlyph = nullptr,
163  Camera *camera = nullptr);
164 };
165 } // namespace tlp
166 
167 #endif // DOXYGEN_NOTFOR_DEVEL
168 
169 #endif // Tulip_GLEDGE_H
170 ///@endcond