Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlEdge.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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  /**
109  * This function must be called before each graph rendering
110  * This function clears previously compute edgeWidthLod
111  */
112  static void clearEdgeWidthLodSystem() {
113  haveToComputeEdgeWidthBaseLod=true;
114  }
115 
116  unsigned int id;
117 
118 private :
119 
120  static GlLabel *label;
121  static bool haveToComputeEdgeWidthBaseLod;
122  static float edgeWidthBaseLod;
123 
124  /**
125  * Draw the Edge : this function is used by draw function
126  */
127  void drawEdge(const Coord &srcNodePos, const Coord &tgtNodePos,
128  const Coord &startPoint, const Coord &endPoint, const LineType::RealType &bends,
129  const Color &startColor, const Color &endColor, const Coord &lookDir, bool colorInterpolate, const Color &borderColor,
130  const Size &size, int shape, bool edge3D, float lod,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, const Matrix<float, 4>& size);
137 
138  /**
139  * Compute the edge colors and store these colors in srcCol and tgtCol
140  * \param data : input data used to compute edge colors
141  */
142  void getEdgeColor(const GlGraphInputData *data,const edge &e,const node &source,const node &target, bool selected,Color &srcCol, Color &tgtCol);
143 
144 
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 &source,const Size &sizeRatio,float edgeSize,const Color &color,float maxSize,bool selected,float selectionOutlineSize,
156  int tgtEdgeGlyph,size_t numberOfBends,const Coord &anchor,const Coord &tgtCoord,
157  const Coord &srcAnchor,const Coord &tgtAnchor,Coord &lineAnchor, EdgeExtremityGlyph* srcEdgeGlyph = NULL, Camera *camera = NULL);
158 
159 };
160 
161 }
162 
163 #endif // DOXYGEN_NOTFOR_DEVEL
164 
165 #endif // Tulip_GLEDGE_H
166 ///@endcond