Tulip  4.10.0
Better Visualization Through Research
GlComplexPolygon.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
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 -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves)
73  * You can also specify the texture name if you want to create a textured complex polygon
74  *
75  * In complex polygon you can add a smooth border : see activateQuadBorder(..) function
76  * And you can specify the texture zoom : see setTextureZoom(...) function
77  */
78 class TLP_GL_SCOPE GlComplexPolygon : public GlSimpleEntity {
79 
80 public:
81  /**
82  * @brief Default constructor
83  * @warning don't use this constructor if you want to create a complex polygon, see others constructors
84  */
86  /**
87  * @brief Constructor with a vector of coords, a fill color, a polygon edges type(0 -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
88  */
89  GlComplexPolygon(const std::vector<Coord> &coords,Color fcolor,int polygonEdgesType=0,const std::string &textureName = "");
90  /**
91  * @brief Constructor with a vector of coords, a fill color, an outline color, a polygon edges type(0 -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
92  */
93  GlComplexPolygon(const std::vector<Coord> &coords,Color fcolor,Color ocolor,int polygonEdgesType=0,const std::string &textureName = "");
94  /**
95  * @brief Constructor with a vector of vector of coords (the first vector of coord is the polygon and others vectors are holes in polygon), a fill color, a polygon edges type(0 -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
96  */
97  GlComplexPolygon(const std::vector<std::vector<Coord> >&coords,Color fcolor,int polygonEdgesType=0,const std::string &textureName = "");
98  /**
99  * @brief Constructor with a vector of vector of coords (the first vector of coord is the polygon and others vectors are holes in polygon), a fill color, an outline color a polygon edges type(0 -> straight lines, 1 -> catmull rom curves, 2 -> bezier curves) and a textureName if you want
100  */
101  GlComplexPolygon(const std::vector<std::vector<Coord> >&coords,Color fcolor,Color ocolor,int polygonEdgesType=0,const std::string &textureName = "");
102 
103  virtual ~GlComplexPolygon() {}
104 
105  /**
106  * @brief Draw the complex polygon
107  */
108  virtual void draw(float lod,Camera *camera);
109 
110  /**
111  * @brief Set if the polygon is outlined or not
112  */
113  void setOutlineMode(const bool);
114 
115  /**
116  * @brief Set size of outline
117  */
118  void setOutlineSize(double size);
119 
120  /**
121  * @brief Get fill color of GlComplexPolygon
122  */
123  Color getFillColor() const {
124  return fillColor;
125  }
126 
127  /**
128  * @brief Set fill color of GlComplexPolygon
129  */
130  void setFillColor(const Color &color) {
131  fillColor=color;
132  }
133 
134  /**
135  * @brief Get outline color of GlComplexPolygon
136  */
137  Color getOutlineColor() const {
138  return outlineColor;
139  }
140 
141  /**
142  * @brief Set outline color of GlComplexPolygon
143  */
144  void setOutlineColor(const Color &color) {
145  outlineColor=color;
146  }
147 
148  /**
149  * @brief Get the texture zoom factor
150  */
151  float getTextureZoom() {
152  return textureZoom;
153  }
154 
155  /**
156  * @brief Set the texture zoom factor
157  *
158  * By default if you have a polygon with a size bigger than (1,1,0) the texture will be repeated
159  * If you want to don't have this texture repeat you have to modify texture zoom
160  * For example if you have a polygon with coords ((0,0,0),(5,0,0),(5,5,0),(0,5,0)) you can set texture zoom to 5. to don't have texture repeat
161  */
162  void setTextureZoom(float zoom) {
163  textureZoom=zoom;
164  runTesselation();
165  }
166 
167  /**
168  * @brief Get the textureName
169  */
170  std::string getTextureName();
171 
172  /**
173  * @brief Set the textureName
174  */
175  void setTextureName(const std::string &name);
176 
177  /**
178  * @brief Draw a thick (textured) border around the polygon.
179  *
180  * The graphic card must support geometry shader to make this feature to work.
181  * The position parameter determines the way the border is drawn (depending on the polygon points ordering):
182  * - 0 : the border is drawn outside (or inside) the polygon
183  * - 1 : the border is centered on the polygon outline
184  * - 2 : the border is drawn inside (or outside) the polygon
185  *
186  * The texCoordFactor parameter determines the way the texture is applied : if < 1, the texture will be expanded and > 1, the texture will be compressed
187  * The polygonId parameter determines on which contour of the polygon, the border will be applied
188  */
189  void activateQuadBorder(const float borderWidth, const Color &color, const std::string &texture = "", const int position = 1,
190  const float texCoordFactor = 1.f, const int polygonId = 0);
191 
192  /**
193  * @brief Desactivate the textured quad border
194  */
195  void desactivateQuadBorder(const int polygonId = 0);
196 
197  /**
198  * @brief Translate entity
199  */
200  virtual void translate(const Coord& mouvement);
201 
202  /**
203  * @brief Function to export data and type outString (in XML format)
204  */
205  virtual void getXML(std::string &outString);
206 
207  /**
208  * @brief Function to export data in outString (in XML format)
209  */
210  virtual void getXMLOnlyData(std::string &outString);
211 
212  /**
213  * @brief Function to set data with inString (in XML format)
214  */
215  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
216 
217  const std::vector<std::vector<Coord> > &getPolygonSides() const {
218  return points;
219  }
220 
221 
222 protected:
223 
224  /**
225  * @brief Add a new point in polygon
226  */
227  virtual void addPoint(const Coord& point);
228  /**
229  * @brief Begin a new hole in the polygon
230  */
231  virtual void beginNewHole();
232 
233  void runTesselation();
234  void createPolygon(const std::vector<Coord> &coords,int polygonEdgesType);
235 
236  std::vector<std::vector<Coord> > points;
237  std::vector<std::vector<float> > pointsIdx;
238  std::vector<float> verticesData;
239  std::vector<unsigned int> verticesIndices;
240  int currentVector;
241  bool outlined;
242  Color fillColor;
243  Color outlineColor;
244  double outlineSize;
245  std::string textureName;
246  float textureZoom;
247  std::vector<bool> quadBorderActivated;
248  std::vector<float> quadBorderWidth;
249  std::vector<Color> quadBorderColor;
250  std::vector<std::string> quadBorderTexture;
251  std::vector<int> quadBorderPosition;
252  std::vector<float> quadBorderTexFactor;
253 };
254 
255 }
256 #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:45
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.