Tulip  5.7.4
Large graphs analysis and drawing
GlPolyQuad.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 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 specific 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  * \param noCheck when true the bounding box validity is not checked
102  *
103  */
104  void addQuadEdge(const Coord &edgeStart, const Coord &edgeEnd, const Color &edgeColor,
105  bool noCheck = false);
106 
107  /**
108  * Virtual function used to draw the polyquad.
109  */
110  void draw(float lod, Camera *camera) override;
111 
112  /**
113  * Method to set the polyquad color (all edges share the same color)
114  */
115  void setColor(const Color &color);
116 
117  /**
118  * Method to set the polyquad outline color
119  */
120  void setOutlineColor(const Color &color) {
121  outlineColor = color;
122  }
123 
124  /**
125  * Method to toggle polyquad outline
126  */
127  void setOutlined(const bool outline) {
128  outlined = outline;
129  }
130 
131  /**
132  * Method to set the polyquad outline width
133  */
134  void setOutlineWidth(const int width) {
135  outlineWidth = width;
136  }
137 
138  /**
139  * Method to translate entity
140  */
141  void translate(const Coord &move) override;
142 
143  /**
144  * Function to export data in outString (in XML format)
145  */
146  void getXML(std::string &outString) override;
147 
148  /**
149  * Function to set data with inString (in XML format)
150  */
151  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
152 
153 private:
154  std::vector<Coord> polyQuadEdges; // vector which contains polyquad edges, an edge being defined
155  // by a pair of Coord
156  std::vector<Color> polyQuadEdgesColors; // vector which contains polyquad edges colors
157  std::string textureName;
158  bool outlined;
159  int outlineWidth;
160  Color outlineColor;
161 };
162 } // namespace tlp
163 #endif /* GLPOLYQUAD_H_ */
164 ///@endcond