reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofPath.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofPolyline.h"
4#include "ofVboMesh.h"
5#include "ofTessellator.h"
6#include "ofConstants.h"
7
8template<typename T>
9class ofColor_;
13
15
38class ofPath{
39public:
42
44 ofPath();
45
47 void clear();
48
54 void newSubPath();
55
59 void close();
60
64
67 void lineTo(const glm::vec3 & p);
68 void lineTo(const glm::vec2 & p);
69
72 void lineTo(float x, float y);
73
76 void lineTo(float x, float y, float z);
77
78
82 void moveTo(const glm::vec3 & p);
83 void moveTo(const glm::vec2 & p);
84
88 void moveTo(float x, float y, float z=0);
89
91 void curveTo(const glm::vec3 & p);
92 void curveTo(const glm::vec2 & p);
93
95 void curveTo(float x, float y);
96
98 void curveTo(float x, float y, float z);
99
110 void bezierTo(const glm::vec3 & cp1, const glm::vec3 & cp2, const glm::vec3 & p);
111 void bezierTo(const glm::vec2 & cp1, const glm::vec2 & cp2, const glm::vec2 & p);
112
116 void bezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y);
117
121 void bezierTo(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x, float y, float z);
122
128 void quadBezierTo(const glm::vec3 & cp1, const glm::vec3 & cp2, const glm::vec3 & p);
129 void quadBezierTo(const glm::vec2 & cp1, const glm::vec2 & cp2, const glm::vec2 & p);
130
134 void quadBezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y);
135
139 void quadBezierTo(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x, float y, float z);
140
147 void arc(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd);
148 void arc(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd, bool clockwise);
149 void arc(const glm::vec2 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd);
150 void arc(const glm::vec2 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd, bool clockwise);
151
165 void arc(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd);
166
169 void arc(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd);
170
171 void arcNegative(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd);
172 void arcNegative(const glm::vec2 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd);
173 void arcNegative(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd);
174 void arcNegative(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd);
175
176 void triangle(float x1,float y1,float x2,float y2,float x3, float y3);
177 void triangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3);
178 void triangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3);
179 void triangle(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3);
180
181 void circle(float x, float y, float radius);
182 void circle(float x, float y, float z, float radius);
183 void circle(const glm::vec3 & p, float radius);
184 void circle(const glm::vec2 & p, float radius);
185
186 void ellipse(float x, float y, float width, float height);
187 void ellipse(float x, float y, float z, float width, float height);
188 void ellipse(const glm::vec3 & p, float width, float height);
189 void ellipse(const glm::vec2 & p, float width, float height);
190
191 void rectangle(const ofRectangle & r);
192 void rectangle(const glm::vec3 & p,float w,float h);
193 void rectangle(const glm::vec2 & p,float w,float h);
194 void rectangle(float x,float y,float w,float h);
195 void rectangle(float x,float y,float z,float w,float h);
196
197 void rectRounded(const ofRectangle & b, float r);
198 void rectRounded(const glm::vec3 & p, float w, float h, float r);
199 void rectRounded(const glm::vec2 & p, float w, float h, float r);
200 void rectRounded(float x, float y, float w, float h, float r);
201 void rectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius,
202 float topRightRadius,
203 float bottomRightRadius,
204 float bottomLeftRadius);
205 void rectRounded(const glm::vec2 & p, float w, float h, float topLeftRadius,
206 float topRightRadius,
207 float bottomRightRadius,
208 float bottomLeftRadius);
209 void rectRounded(const ofRectangle & b, float topLeftRadius,
210 float topRightRadius,
211 float bottomRightRadius,
212 float bottomLeftRadius);
213 void rectRounded(float x, float y, float z, float w, float h, float topLeftRadius,
214 float topRightRadius,
215 float bottomRightRadius,
216 float bottomLeftRadius);
220
237
240
244
246 void setFilled(bool hasFill); // default true
247
250 void setStrokeWidth(float width); // default 0
251
255 void setColor( const ofColor& color );
256
260 void setHexColor( int hex );
261
264 void setFillColor(const ofColor & color);
265
268 void setFillHexColor( int hex );
269
272 void setStrokeColor(const ofColor & color);
273
276 void setStrokeHexColor( int hex );
277
281 bool isFilled() const;
282
284 ofColor getFillColor() const;
285
287 ofColor getStrokeColor() const;
288
292 float getStrokeWidth() const;
293
294 bool hasOutline() const { return strokeWidth>0; }
295
296 void setCurveResolution(int curveResolution);
297 int getCurveResolution() const;
298
299 void setCircleResolution(int circleResolution);
300 int getCircleResolution() const;
301
302 OF_DEPRECATED_MSG("Use setCircleResolution instead.", void setArcResolution(int res));
303 OF_DEPRECATED_MSG("Use getCircleResolution instead.", int getArcResolution() const);
304
305 void setUseShapeColor(bool useColor);
306 bool getUseShapeColor() const;
307
311
313 void draw() const;
314
316 void draw(float x, float y) const;
317
321
323 const std::vector<ofPolyline> & getOutline() const;
324
325 void tessellate();
326
327 const ofMesh & getTessellation() const;
328
329 void simplify(float tolerance=0.3f);
330
331 void translate(const glm::vec3 & p);
332
333 void rotateDeg(float degrees, const glm::vec3& axis);
334 void rotateRad(float radians, const glm::vec3& axis);
335 OF_DEPRECATED_MSG("Use Deg/Rad versions.", void rotate(float degrees, const glm::vec3& axis ));
336
337 void translate(const glm::vec2 & p);
338
339 void rotateDeg(float degrees, const glm::vec2& axis);
340 void rotateRad(float radians, const glm::vec2& axis);
341 OF_DEPRECATED_MSG("Use Deg/Rad versions.", void rotate(float degrees, const glm::vec2& axis ));
342
346 void scale(float x, float y);
347
348 void append(const ofPath & path);
349
353
358
359 void setMode(Mode mode);
360 Mode getMode() const;
361
365
366 struct Command{
377
380
382 Command(Type type , const glm::vec3 & p);
383
385 Command(Type type , const glm::vec3 & p, const glm::vec3 & cp1, const glm::vec3 & cp2);
386
388 Command(Type type , const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd);
389
390
392 glm::vec3 to;
393 glm::vec3 cp1, cp2;
395 };
396
397 std::vector<Command> & getCommands();
398 const std::vector<Command> & getCommands() const;
399
401
402private:
403
404 ofPolyline & lastPolyline();
405 void addCommand(const Command & command);
406 void generatePolylinesFromCommands();
407
408 // only needs to be called when path is modified externally
409 void flagShapeChanged();
410 bool hasChanged();
411
412 // path description
413 //vector<ofSubPath> paths;
414 std::vector<Command> commands;
415 ofPolyWindingMode windingMode;
416 ofColor fillColor;
417 ofColor strokeColor;
418 float strokeWidth;
419 bool bFill;
420 bool bUseShapeColor;
421
422 // polyline / tessellation
423 std::vector<ofPolyline> polylines;
424 std::vector<ofPolyline> tessellatedContour; // if winding mode != ODD
425
426#ifdef TARGET_OPENGLES
427 ofMesh cachedTessellation;
428#else
429 ofVboMesh cachedTessellation;
430#endif
431#if defined(TARGET_EMSCRIPTEN)
432 static ofTessellator tessellator;
433#elif HAS_TLS
434 static thread_local ofTessellator tessellator;
435#else
436 ofTessellator tessellator;
437#endif
438 bool bHasChanged;
439 int prevCurveRes;
440 int curveResolution;
441 int circleResolution;
442 bool bNeedsTessellation;
443 bool bNeedsPolylinesGeneration;
444
445 Mode mode;
446};
ofColor represents a color in openFrameworks.
Definition ofColor.h:20
ofPath is a way to create a path or multiple paths consisting of points. It allows you to combine mul...
Definition ofPath.h:38
void close()
Close the current subpath and create a new subpath, either an ofPolyline or ofSubPath by calling newS...
Definition ofPath.cpp:509
void tessellate()
Definition ofPath.cpp:636
void translate(const glm::vec3 &p)
Definition ofPath.cpp:787
void triangle(float x1, float y1, float x2, float y2, float x3, float y3)
Definition ofPath.cpp:285
float getStrokeWidth() const
Get the stroke width of the ofPath.
Definition ofPath.cpp:586
void rectRounded(const ofRectangle &b, float r)
Definition ofPath.cpp:392
void setPolyWindingMode(ofPolyWindingMode mode)
Set the way that the points in the sub paths are connected.
Definition ofPath.cpp:519
void setCircleResolution(int circleResolution)
Definition ofPath.cpp:716
OF_DEPRECATED_MSG("Use getCircleResolution instead.", int getArcResolution() const)
void ellipse(float x, float y, float width, float height)
Definition ofPath.cpp:331
std::vector< Command > & getCommands()
Definition ofPath.cpp:548
const ofMesh & getTessellation() const
Definition ofPath.cpp:660
Mode getMode() const
Definition ofPath.cpp:701
ofColor getFillColor() const
Get the ofColor fill of the ofPath.
Definition ofPath.cpp:576
void clear()
Remove all subpaths from the ofPath instance.
Definition ofPath.cpp:72
void setStrokeWidth(float width)
Set the stroke width of the line if the ofPath is to be drawn not in wireframe.
Definition ofPath.cpp:535
void setCurveResolution(int curveResolution)
Definition ofPath.cpp:706
void draw() const
Draws the path at 0,0. Calling draw() also calls tessellate()
Definition ofPath.cpp:671
void circle(float x, float y, float radius)
Definition ofPath.cpp:309
bool getUseShapeColor() const
Definition ofPath.cpp:741
void append(const ofPath &path)
Definition ofPath.cpp:890
int getCurveResolution() const
Definition ofPath.cpp:711
void scale(float x, float y)
Change the size of either the ofPolyline or ofSubPath instances that the ofPath contains....
Definition ofPath.cpp:863
void rotateRad(float radians, const glm::vec3 &axis)
Definition ofPath.cpp:838
void setFillHexColor(int hex)
Set the fill color of the path. This has no affect if the path is drawn as wireframe.
Definition ofPath.cpp:763
int getCircleResolution() const
Definition ofPath.cpp:721
void setFillColor(const ofColor &color)
Set the fill color of the path. This has no affect if the path is drawn as wireframe.
Definition ofPath.cpp:757
OF_DEPRECATED_MSG("Use Deg/Rad versions.", void rotate(float degrees, const glm::vec2 &axis))
ofColor getStrokeColor() const
Get the stroke color of the ofPath.
Definition ofPath.cpp:581
void setStrokeColor(const ofColor &color)
Set the stroke color of the path. This has no affect if the path is drawn filled.
Definition ofPath.cpp:768
void rotateDeg(float degrees, const glm::vec3 &axis)
Definition ofPath.cpp:813
bool isFilled() const
Get whether the path is using a fill or not.
Definition ofPath.cpp:571
void setMode(Mode mode)
Definition ofPath.cpp:696
void setColor(const ofColor &color)
Set the color of the path. This affects both the line if the path is drawn as wireframe and the fill ...
Definition ofPath.cpp:746
Mode
Definition ofPath.h:354
@ COMMANDS
Definition ofPath.h:355
@ POLYLINES
Definition ofPath.h:356
void setFilled(bool hasFill)
Set whether the path should be drawn as wireframes or filled.
Definition ofPath.cpp:527
void lineTo(const glm::vec3 &p)
Draw a straight line from the current drawing position to the location indicated by p.
Definition ofPath.cpp:91
void setStrokeHexColor(int hex)
Set the stroke color of the path. This has no affect if the path is drawn filled.
Definition ofPath.cpp:774
void bezierTo(const glm::vec3 &cp1, const glm::vec3 &cp2, const glm::vec3 &p)
Create a cubic bezier line from the current drawing point with the 2 control points indicated by glm:...
Definition ofPath.cpp:162
const std::vector< ofPolyline > & getOutline() const
Get an ofPolyline representing the outline of the ofPath.
Definition ofPath.cpp:649
OF_DEPRECATED_MSG("Use setCircleResolution instead.", void setArcResolution(int res))
void moveTo(const glm::vec3 &p)
Move the drawing position to p. This means that a subsequent calls to, for instance,...
Definition ofPath.cpp:116
OF_DEPRECATED_MSG("Use Deg/Rad versions.", void rotate(float degrees, const glm::vec3 &axis))
void simplify(float tolerance=0.3f)
Definition ofPath.cpp:779
ofPath()
Create a new ofPath instance.
Definition ofPath.cpp:56
void newSubPath()
Create a new subpath, either an ofPolyline instance or an ofSubPath instance. All points added after ...
Definition ofPath.cpp:83
void curveTo(const glm::vec3 &p)
Draws a curve to p from the current drawing position.
Definition ofPath.cpp:137
void arc(const glm::vec3 &centre, float radiusX, float radiusY, float angleBegin, float angleEnd)
Create an arc at centre, which has the radiusX, radiusY, and begins at angleBegin and ends at angleEn...
Definition ofPath.cpp:226
void arcNegative(const glm::vec3 &centre, float radiusX, float radiusY, float angleBegin, float angleEnd)
Definition ofPath.cpp:256
void rectangle(const ofRectangle &r)
Definition ofPath.cpp:351
bool hasOutline() const
Definition ofPath.h:294
void setUseShapeColor(bool useColor)
Definition ofPath.cpp:736
ofPolyWindingMode getWindingMode() const
Get the poly winding mode currently in use.
Definition ofPath.cpp:566
void quadBezierTo(const glm::vec3 &cp1, const glm::vec3 &cp2, const glm::vec3 &p)
Create a quadratic bezier line in 3D space from the current drawing point with the beginning indicate...
Definition ofPath.cpp:187
void setHexColor(int hex)
Set the color of the path. This affects both the line if the path is drawn as wireframe and the fill ...
Definition ofPath.cpp:752
A class representing a 2D rectangle.
Definition ofRectangle.h:87
ofTessellator exists for one purpose: to turn ofPolylines into ofMeshes so that they can be more effi...
Definition ofTessellator.h:25
Definition ofVboMesh.h:6
unsigned int height
Definition ofAppEGLWindow.cpp:125
unsigned int width
Definition ofAppEGLWindow.cpp:124
ofPolyWindingMode
represents the available polygon winding modes.
Definition ofGraphicsConstants.h:97
#define b
ofColor_< unsigned char > ofColor
Definition ofPath.h:10
ofColor_< float > ofFloatColor
Definition ofPath.h:11
ofColor_< unsigned short > ofShortColor
Definition ofPath.h:12
Definition ofPath.h:366
float angleEnd
Definition ofPath.h:394
glm::vec3 cp1
Definition ofPath.h:393
Type
Definition ofPath.h:367
@ moveTo
Definition ofPath.h:368
@ arcNegative
Definition ofPath.h:374
@ bezierTo
Definition ofPath.h:371
@ quadBezierTo
Definition ofPath.h:372
@ lineTo
Definition ofPath.h:369
@ curveTo
Definition ofPath.h:370
@ arc
Definition ofPath.h:373
@ close
Definition ofPath.h:375
glm::vec3 to
Definition ofPath.h:392
Type type
Definition ofPath.h:391
float radiusX
Definition ofPath.h:394
float angleBegin
Definition ofPath.h:394
glm::vec3 cp2
Definition ofPath.h:393
float radiusY
Definition ofPath.h:394