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