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