Tulip  5.2.0
Large graphs analysis and drawing
GlPolyQuad.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 GLPOLYQUAD_H_
22 #define GLPOLYQUAD_H_
23 
24 #include <tulip/tulipconf.h>
25 #include <tulip/Coord.h>
26 #include <tulip/Color.h>
27 #include <tulip/GlSimpleEntity.h>
28 
29 #include <vector>
30 #include <string>
31 
32 namespace tlp {
33 
34 /**
35  * @ingroup OpenGL
36  * \brief General class used to render a connected group of quadrilaterals (textured or not) that
37  * shares edges as GlEntity
38  *
39  * This generic class is used to render a connected group of quadrilaterals (textured or not) that
40  * shares edges as GlEntity
41  */
42 class TLP_GL_SCOPE GlPolyQuad : public GlSimpleEntity {
43 
44 public:
45  /**
46  * Default Constructor for initializing an empty polyquad
47  * Use the addQuadEdge method to set the quads edges
48  *
49  * \param textureName The absolute path of the texture image file to use
50  *
51  *
52  */
53  GlPolyQuad(const std::string &textureName = "", const bool outlined = false,
54  const int outlineWidth = 1, const Color &outlineColor = Color(0, 0, 0));
55 
56  /**
57  * Constructor for building a polyquad with spefific colors for each edges
58  *
59  * Pay attention to the order of the edges point in the polyQuadEdges vector. Indeed, to draw the
60  * following polyquad
61  *
62  * v2
63  * v0+--------+--------+ v4
64  * | | |
65  * | | |
66  * | | |
67  * v1+--------+--------+ v5
68  * v3
69  *
70  * The content of the polyQuadEdges vector should be {v0, v1, v2, v3, v4, v5} or {v1, v0, v3, v2,
71  * v5, v4}
72  *
73  * \param polyQuadEdges A vector containing the coordinates of the quad edges, its size must be a
74  * multiple of 2 because an edge is defined by 2 points
75  * \param polyQuadEdgesColor A vector containing the edges's colors, its size must be equal to the
76  * number of edges defined by the polyQuadEdges vector
77  * \param textureName The absolute path of the texture image file to use
78  */
79  GlPolyQuad(const std::vector<Coord> &polyQuadEdges, const std::vector<Color> &polyQuadEdgesColor,
80  const std::string &textureName = "", const bool outlined = false,
81  const int outlineWidth = 1, const Color &outlineColor = Color(0, 0, 0));
82 
83  /**
84  * Constructor for building a polyquad with a single color
85  *
86  * \param polyQuadEdges A vector containing the coordinates of the quad edges, its size must be a
87  * multiple of 2 because an edge is defined by 2 points
88  * \param polyQuadColor The polyquad color
89  * \param textureName The absolute path of the texture image file to use
90  */
91  GlPolyQuad(const std::vector<Coord> &polyQuadEdges, const Color &polyQuadColor,
92  const std::string &textureName = "", const bool outlined = false,
93  const int outlineWidth = 1, const Color &outlineColor = Color(0, 0, 0));
94 
95  /**
96  * Method to add a polyquad edge
97  *
98  * \param edgeStart The first end of the edge
99  * \param edgeEnd The other end of the edge
100  * \param edgeColor The edge's color
101  *
102  */
103  void addQuadEdge(const Coord &edgeStart, const Coord &edgeEnd, const Color &edgeColor);
104 
105  /**
106  * Virtual function used to draw the polyquad.
107  */
108  void draw(float lod, Camera *camera) override;
109 
110  /**
111  * Method to set the polyquad color (all edges share the same color)
112  */
113  void setColor(const Color &color);
114 
115  /**
116  * Method to set the polyquad outline color
117  */
118  void setOutlineColor(const Color &color) {
119  outlineColor = color;
120  }
121 
122  /**
123  * Method to toggle polyquad outline
124  */
125  void setOutlined(const bool outline) {
126  outlined = outline;
127  }
128 
129  /**
130  * Method to set the polyquad outline width
131  */
132  void setOutlineWidth(const int width) {
133  outlineWidth = width;
134  }
135 
136  /**
137  * Method to translate entity
138  */
139  void translate(const Coord &move) override;
140 
141  /**
142  * Function to export data in outString (in XML format)
143  */
144  void getXML(std::string &outString) override;
145 
146  /**
147  * Function to set data with inString (in XML format)
148  */
149  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
150 
151 private:
152  std::vector<Coord> polyQuadEdges; // vector which contains polyquad edges, an edge being defined
153  // by a pair of Coord
154  std::vector<Color> polyQuadEdgesColors; // vector which contains polyquad edges colors
155  std::string textureName;
156  bool outlined;
157  int outlineWidth;
158  Color outlineColor;
159 };
160 }
161 #endif /* GLPOLYQUAD_H_ */
162 ///@endcond