Tulip  5.2.0
Large graphs analysis and drawing
GlComplexPolygon.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 #ifndef GLCOMPLEXPOLYGON_H
20 #define GLCOMPLEXPOLYGON_H
21 
22 #include <vector>
23 #include <map>
24 #include <set>
25 
26 #include <tulip/Color.h>
27 #include <tulip/Coord.h>
28 #include <tulip/tulipconf.h>
29 #include <tulip/GlSimpleEntity.h>
30 
31 namespace tlp {
32 
33 /**
34  * @ingroup OpenGL
35  * @brief Class to create a complex polygon (concave polygon or polygon with hole)
36  * If you want to create a complex polygon you have 4 constructors :
37  * Constructors with vector of coords : to create a complex polygon without hole
38  * - In this case you have two constructor : with and without outline color
39  * - You can create a polygon like this :
40  * \code
41  * vector <Coord> coords;
42  * coords.push_back(Coord(0,0,0));
43  * coords.push_back(Coord(10,0,0));
44  * coords.push_back(Coord(10,10,0));
45  * coords.push_back(Coord(0,10,0));
46  * GlComplexPolygon *complexPolygon=new GlComplexPolygon(coords,Color(255,0,0,255));
47  * layer->addGlEntity(complexPolygon,"complexPolygon");
48  * \endcode
49  *
50  * Constructors with vector of vector of Coords : to create a complex polygon with hole
51  * - In this case you have two constructor : with and without outline color
52  * - The first vector of coords is the polygon and others vector are holes
53  * - You can create a polygon with hole like this :
54  * \code
55  * vector <vector <Coord> > coords;
56  * vector <Coord> polygon;
57  * vector <Coord> hole;
58  * polygon.push_back(Coord(0,0,0));
59  * polygon.push_back(Coord(10,0,0));
60  * polygon.push_back(Coord(10,10,0));
61  * polygon.push_back(Coord(0,10,0));
62  * hole.push_back(Coord(4,4,0));
63  * hole.push_back(Coord(6,4,0));
64  * hole.push_back(Coord(6,6,0));
65  * hole.push_back(Coord(4,6,0));
66  * coords.push_back(polygon);
67  * coords.push_back(hole);
68  * GlComplexPolygon *complexPolygon=new GlComplexPolygon(coords,Color(255,0,0,255));
69  * layer->addGlEntity(complexPolygon,"complexPolygon");
70  * \endcode
71  *
72  * In constructors you can specify the polygon border style : polygonEdgesType parameter (0 ->
73  * straight lines, 1 -> catmull rom curves, 2 -> bezier curves)
74  * You can also specify the texture name if you want to create a textured complex polygon
75  *
76  * In complex polygon you can add a smooth border : see activateQuadBorder(..) function
77  * And you can specify the texture zoom : see setTextureZoom(...) function
78  */
79 class TLP_GL_SCOPE GlComplexPolygon : public GlSimpleEntity {
80 
81 public:
82  /**
83  * @brief Default constructor
84  * @warning don't use this constructor if you want to create a complex polygon, see others
85  * constructors
86  */
88  /**
89  * @brief Constructor with a vector of coords, a fill color, a polygon edges type(0 -> straight
90  * lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
91  */
92  GlComplexPolygon(const std::vector<Coord> &coords, Color fcolor, int polygonEdgesType = 0,
93  const std::string &textureName = "");
94  /**
95  * @brief Constructor with a vector of coords, a fill color, an outline color, a polygon edges
96  * type(0 -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you
97  * want
98  */
99  GlComplexPolygon(const std::vector<Coord> &coords, Color fcolor, Color ocolor,
100  int polygonEdgesType = 0, const std::string &textureName = "");
101  /**
102  * @brief Constructor with a vector of vector of coords (the first vector of coord is the polygon
103  * and others vectors are holes in polygon), a fill color, a polygon edges type(0 -> straight
104  * lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
105  */
106  GlComplexPolygon(const std::vector<std::vector<Coord>> &coords, Color fcolor,
107  int polygonEdgesType = 0, const std::string &textureName = "");
108  /**
109  * @brief Constructor with a vector of vector of coords (the first vector of coord is the polygon
110  * and others vectors are holes in polygon), a fill color, an outline color a polygon edges type(0
111  * -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
112  */
113  GlComplexPolygon(const std::vector<std::vector<Coord>> &coords, Color fcolor, Color ocolor,
114  int polygonEdgesType = 0, const std::string &textureName = "");
115 
116  ~GlComplexPolygon() override {}
117 
118  /**
119  * @brief Draw the complex polygon
120  */
121  void draw(float lod, Camera *camera) override;
122 
123  /**
124  * @brief Set if the polygon is outlined or not
125  */
126  void setOutlineMode(const bool);
127 
128  /**
129  * @brief Set size of outline
130  */
131  void setOutlineSize(double size);
132 
133  /**
134  * @brief Get fill color of GlComplexPolygon
135  */
136  Color getFillColor() const {
137  return fillColor;
138  }
139 
140  /**
141  * @brief Set fill color of GlComplexPolygon
142  */
143  void setFillColor(const Color &color) {
144  fillColor = color;
145  }
146 
147  /**
148  * @brief Get outline color of GlComplexPolygon
149  */
150  Color getOutlineColor() const {
151  return outlineColor;
152  }
153 
154  /**
155  * @brief Set outline color of GlComplexPolygon
156  */
157  void setOutlineColor(const Color &color) {
158  outlineColor = color;
159  }
160 
161  /**
162  * @brief Get the texture zoom factor
163  */
164  float getTextureZoom() {
165  return textureZoom;
166  }
167 
168  /**
169  * @brief Set the texture zoom factor
170  *
171  * By default if you have a polygon with a size bigger than (1,1,0) the texture will be repeated
172  * If you want to don't have this texture repeat you have to modify texture zoom
173  * For example if you have a polygon with coords ((0,0,0),(5,0,0),(5,5,0),(0,5,0)) you can set
174  * texture zoom to 5. to don't have texture repeat
175  */
176  void setTextureZoom(float zoom) {
177  textureZoom = zoom;
178  runTesselation();
179  }
180 
181  /**
182  * @brief Get the textureName
183  */
184  std::string getTextureName();
185 
186  /**
187  * @brief Set the textureName
188  */
189  void setTextureName(const std::string &name);
190 
191  /**
192  * @brief Draw a thick (textured) border around the polygon.
193  *
194  * The graphic card must support geometry shader to make this feature to work.
195  * The position parameter determines the way the border is drawn (depending on the polygon points
196  * ordering):
197  * - 0 : the border is drawn outside (or inside) the polygon
198  * - 1 : the border is centered on the polygon outline
199  * - 2 : the border is drawn inside (or outside) the polygon
200  *
201  * The texCoordFactor parameter determines the way the texture is applied : if < 1, the texture
202  * will be expanded and > 1, the texture will be compressed
203  * The polygonId parameter determines on which contour of the polygon, the border will be applied
204  */
205  void activateQuadBorder(const float borderWidth, const Color &color,
206  const std::string &texture = "", const int position = 1,
207  const float texCoordFactor = 1.f, const int polygonId = 0);
208 
209  /**
210  * @brief Desactivate the textured quad border
211  */
212  void desactivateQuadBorder(const int polygonId = 0);
213 
214  /**
215  * @brief Translate entity
216  */
217  void translate(const Coord &mouvement) override;
218 
219  /**
220  * @brief Function to export data and type outString (in XML format)
221  */
222  void getXML(std::string &outString) override;
223 
224  /**
225  * @brief Function to export data in outString (in XML format)
226  */
227  virtual void getXMLOnlyData(std::string &outString);
228 
229  /**
230  * @brief Function to set data with inString (in XML format)
231  */
232  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
233 
234  const std::vector<std::vector<Coord>> &getPolygonSides() const {
235  return points;
236  }
237 
238 protected:
239  /**
240  * @brief Add a new point in polygon
241  */
242  virtual void addPoint(const Coord &point);
243  /**
244  * @brief Begin a new hole in the polygon
245  */
246  virtual void beginNewHole();
247 
248  void runTesselation();
249  void createPolygon(const std::vector<Coord> &coords, int polygonEdgesType);
250 
251  std::vector<std::vector<Coord>> points;
252  std::vector<std::vector<float>> pointsIdx;
253  std::vector<float> verticesData;
254  std::vector<unsigned int> verticesIndices;
255  int currentVector;
256  bool outlined;
257  Color fillColor;
258  Color outlineColor;
259  double outlineSize;
260  std::string textureName;
261  float textureZoom;
262  std::vector<bool> quadBorderActivated;
263  std::vector<float> quadBorderWidth;
264  std::vector<Color> quadBorderColor;
265  std::vector<std::string> quadBorderTexture;
266  std::vector<int> quadBorderPosition;
267  std::vector<float> quadBorderTexFactor;
268 };
269 }
270 #endif
Color getOutlineColor() const
Get outline color of GlComplexPolygon.
Base class for all Tulip OpenGL entities.
void setTextureZoom(float zoom)
Set the texture zoom factor.
Class to create a complex polygon (concave polygon or polygon with hole) If you want to create a comp...
Tulip OpenGL camera object.
Definition: Camera.h:47
Color getFillColor() const
Get fill color of GlComplexPolygon.
float getTextureZoom()
Get the texture zoom factor.
void setFillColor(const Color &color)
Set fill color of GlComplexPolygon.
void setOutlineColor(const Color &color)
Set outline color of GlComplexPolygon.
GlComplexPolygon()
Default constructor.