Tulip  5.6.3
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 = "", bool textured = true);
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  bool textured = true);
102  /**
103  * @brief Constructor with a vector of vector of coords (the first vector of coord is the polygon
104  * and others vectors are holes in polygon), a fill color, a polygon edges type(0 -> straight
105  * lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
106  */
107  GlComplexPolygon(const std::vector<std::vector<Coord>> &coords, Color fcolor,
108  int polygonEdgesType = 0, const std::string &textureName = "",
109  bool textured = true);
110  /**
111  * @brief Constructor with a vector of vector of coords (the first vector of coord is the polygon
112  * and others vectors are holes in polygon), a fill color, an outline color a polygon edges type(0
113  * -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
114  */
115  GlComplexPolygon(const std::vector<std::vector<Coord>> &coords, Color fcolor, Color ocolor,
116  int polygonEdgesType = 0, const std::string &textureName = "",
117  bool textured = true);
118 
119  ~GlComplexPolygon() override {}
120 
121  /**
122  * @brief Draw the complex polygon
123  */
124  void draw(float lod, Camera *camera) override;
125 
126  /**
127  * @brief Set if the polygon is outlined or not
128  */
129  void setOutlineMode(const bool);
130 
131  /**
132  * @brief Set size of outline
133  */
134  void setOutlineSize(double size);
135 
136  /**
137  * @brief Get fill color of GlComplexPolygon
138  */
139  Color getFillColor() const {
140  return fillColor;
141  }
142 
143  /**
144  * @brief Set fill color of GlComplexPolygon
145  */
146  void setFillColor(const Color &color) {
147  fillColor = color;
148  }
149 
150  /**
151  * @brief Get outline color of GlComplexPolygon
152  */
153  Color getOutlineColor() const {
154  return outlineColor;
155  }
156 
157  /**
158  * @brief Set outline color of GlComplexPolygon
159  */
160  void setOutlineColor(const Color &color) {
161  outlineColor = color;
162  }
163 
164  /**
165  * @brief Get the texture zoom factor
166  */
167  float getTextureZoom() {
168  return textureZoom;
169  }
170 
171  /**
172  * @brief Set the texture zoom factor
173  *
174  * By default if you have a polygon with a size bigger than (1,1,0) the texture will be repeated
175  * If you want to don't have this texture repeat you have to modify texture zoom
176  * For example if you have a polygon with coords ((0,0,0),(5,0,0),(5,5,0),(0,5,0)) you can set
177  * texture zoom to 5. to don't have texture repeat
178  */
179  void setTextureZoom(float zoom) {
180  textureZoom = zoom;
181  runTesselation();
182  }
183 
184  /**
185  * @brief Get the textureName
186  */
187  std::string getTextureName();
188 
189  /**
190  * @brief Set the textureName
191  */
192  void setTextureName(const std::string &name);
193 
194  /**
195  * @brief indicates if texture must be applied
196  */
198  return textured;
199  }
200 
201  /**
202  * @brief set if texture must be applied
203  */
204  void setTextureActivation(bool);
205 
206  /**
207  * @brief Draw a thick (textured) border around the polygon.
208  *
209  * The graphic card must support geometry shader to make this feature to work.
210  * The position parameter determines the way the border is drawn (depending on the polygon points
211  * ordering):
212  * - 0 : the border is drawn outside (or inside) the polygon
213  * - 1 : the border is centered on the polygon outline
214  * - 2 : the border is drawn inside (or outside) the polygon
215  *
216  * The texCoordFactor parameter determines the way the texture is applied : if < 1, the texture
217  * will be expanded and > 1, the texture will be compressed
218  * The polygonId parameter determines on which contour of the polygon, the border will be applied
219  */
220  void activateQuadBorder(const float borderWidth, const Color &color,
221  const std::string &texture = "", const int position = 1,
222  const float texCoordFactor = 1.f, const int polygonId = 0);
223 
224  /**
225  * @brief Deactivate the textured quad border
226  */
227  void deactivateQuadBorder(const int polygonId = 0);
228 
229  /**
230  * @brief Translate entity
231  */
232  void translate(const Coord &mouvement) override;
233 
234  /**
235  * @brief Function to export data and type outString (in XML format)
236  */
237  void getXML(std::string &outString) override;
238 
239  /**
240  * @brief Function to export data in outString (in XML format)
241  */
242  virtual void getXMLOnlyData(std::string &outString);
243 
244  /**
245  * @brief Function to set data with inString (in XML format)
246  */
247  void setWithXML(const std::string &inString, unsigned int &currentPosition) override;
248 
249  const std::vector<std::vector<Coord>> &getPolygonSides() const {
250  return points;
251  }
252 
253 protected:
254  /**
255  * @brief Add a new point in polygon
256  */
257  virtual void addPoint(const Coord &point);
258  /**
259  * @brief Begin a new hole in the polygon
260  */
261  virtual void beginNewHole();
262 
263  void runTesselation();
264  void createPolygon(const std::vector<Coord> &coords, int polygonEdgesType);
265 
266  std::vector<std::vector<Coord>> points;
267  std::vector<std::vector<float>> pointsIdx;
268  std::vector<float> verticesData;
269  std::vector<unsigned int> verticesIndices;
270  int currentVector;
271  bool outlined;
272  Color fillColor;
273  Color outlineColor;
274  double outlineSize;
275  std::string textureName;
276  bool textured;
277  float textureZoom;
278  std::vector<bool> quadBorderActivated;
279  std::vector<float> quadBorderWidth;
280  std::vector<Color> quadBorderColor;
281  std::vector<std::string> quadBorderTexture;
282  std::vector<int> quadBorderPosition;
283  std::vector<float> quadBorderTexFactor;
284 };
285 } // namespace tlp
286 #endif
tlp::GlComplexPolygon::setFillColor
void setFillColor(const Color &color)
Set fill color of GlComplexPolygon.
Definition: GlComplexPolygon.h:146
tlp::GlComplexPolygon::getTextureZoom
float getTextureZoom()
Get the texture zoom factor.
Definition: GlComplexPolygon.h:167
tlp::GlComplexPolygon::GlComplexPolygon
GlComplexPolygon()
Default constructor.
Definition: GlComplexPolygon.h:87
tlp::GlComplexPolygon
Class to create a complex polygon (concave polygon or polygon with hole) If you want to create a comp...
Definition: GlComplexPolygon.h:79
tlp::GlComplexPolygon::getOutlineColor
Color getOutlineColor() const
Get outline color of GlComplexPolygon.
Definition: GlComplexPolygon.h:153
tlp::GlSimpleEntity
Base class for all Tulip OpenGL entities.
Definition: GlSimpleEntity.h:62
tlp::GlComplexPolygon::getFillColor
Color getFillColor() const
Get fill color of GlComplexPolygon.
Definition: GlComplexPolygon.h:139
tlp::GlComplexPolygon::textureActivation
bool textureActivation()
indicates if texture must be applied
Definition: GlComplexPolygon.h:197
tlp::GlComplexPolygon::setTextureZoom
void setTextureZoom(float zoom)
Set the texture zoom factor.
Definition: GlComplexPolygon.h:179
tlp
Definition: AbstractProperty.h:34
tlp::GlComplexPolygon::setOutlineColor
void setOutlineColor(const Color &color)
Set outline color of GlComplexPolygon.
Definition: GlComplexPolygon.h:160