openEmbroider  0.1
an open source embroidery software
OE_curve.h
1 /*
2  * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  *
20  */
21 
22 #ifndef OE_CURVE_H
23 #define OE_CURVE_H
24 
25 #include "OE_base.h"
26 #include "OE_utils.h"
27 #include <stdint.h>
28 #include <vector>
29 
30 class OE_curve : public OE_base
31 {
32  public:
33 
35  bool controls = false;
36 
38  std::vector<vector_2d> discPts;
39 
41  std::vector<vector_2d> pts;
42 
44  OE_curve();
46  virtual ~OE_curve();
47 
48  //virtual bool getNeedRefresh();
49  //virtual bool setNeedRefresh(bool value);
50 
52  int getNpts();
53 
55  bool getClosed();
56 
58  float getLength(float maxDist);
59 
61  void setClosed(bool closed);
62 
66  virtual void getBound(float* xMin, float* yMin, float* xMax, float* yMax);
67 
74  std::vector<vector_2d> subCurve(float start, float end, bool rev);
75 
80  std::vector<vector_2d> discretizeFast(float maxDist);
81 
86  std::vector<vector_2d> discretizeRegular(float dist);
87 
89  void reverse();
90 
92  virtual bool check();
93 
94  virtual void refresh()=0;
95 
97  bool refresh(float dpi);
98 
99 
100  protected:
101 
103  bool closed = false;
104 
106  //float bounds[4];
107 
109  static unsigned char lineColor[4] ;
110 
116  static float distPtSeg(vector_2d pt, vector_2d seg1, vector_2d seg2);
117 
124  std::vector<vector_2d> discretizeCubicBez(vector_2d pt1, vector_2d pt2, vector_2d pt3, vector_2d pt4, float tol, int level);
125 
131  static bool ptInBounds( vector_2d pt, float* bounds);
132 
138  static double evalBezier(double t, double p0, double p1, double p2, double p3);
139 
145  std::vector<vector_2d> interPoint(vector_2d pt1, vector_2d pt2, vector_2d pt3, vector_2d pt4, float t);
146 
151  static void segmentBounds(float* bounds, vector_2d* segment);
152 
153  private:
154 };
155 
156 #endif // OE_CURVE_H
std::vector< vector_2d > interPoint(vector_2d pt1, vector_2d pt2, vector_2d pt3, vector_2d pt4, float t)
return a segment of the original curve
Definition: OE_curve.cpp:75
static float distPtSeg(vector_2d pt, vector_2d seg1, vector_2d seg2)
calculate the distance beetween a point and a segment
Definition: OE_curve.cpp:266
std::vector< vector_2d > discretizeFast(float maxDist)
discretise a curve using a level of detail approach
Definition: OE_curve.cpp:311
static bool ptInBounds(vector_2d pt, float *bounds)
check if a point is in a given bounding box
Definition: OE_curve.cpp:64
virtual ~OE_curve()
Definition: OE_curve.cpp:39
virtual bool check()
check if the curve is valid.
Definition: OE_curve.cpp:257
virtual void getBound(float *xMin, float *yMin, float *xMax, float *yMax)
calculate the curve bounding box
Definition: OE_curve.cpp:156
float getLength(float maxDist)
return the length of the curve.
Definition: OE_curve.cpp:43
float bounds[4]
Tight bounding box of the object [minx,miny,maxx,maxy].
Definition: OE_base.h:67
OE_curve()
Definition: OE_curve.cpp:35
Definition: OE_base.h:30
static unsigned char lineColor[4]
Tight bounding box of the shape [minx,miny,maxx,maxy].
Definition: OE_curve.h:109
std::vector< vector_2d > subCurve(float start, float end, bool rev)
return a segment of the original curve
Definition: OE_curve.cpp:183
static double evalBezier(double t, double p0, double p1, double p2, double p3)
get the position of a 1D point on a bezier segment
Definition: OE_curve.cpp:69
Definition: OE_curve.h:30
bool closed
Flag indicating if shapes should be treated as closed.
Definition: OE_curve.h:103
bool controls
is displaying controls.
Definition: OE_curve.h:35
std::vector< vector_2d > discPts
the curve array of discretized points
Definition: OE_curve.h:38
void setClosed(bool closed)
set the curve closed attribute.
Definition: OE_curve.cpp:255
std::vector< vector_2d > pts
the bezier curve array of points
Definition: OE_curve.h:41
std::vector< vector_2d > discretizeRegular(float dist)
discretise a curve using uniform segment lengths
Definition: OE_curve.cpp:326
bool getClosed()
return true if the curve is set as closed.
Definition: OE_curve.cpp:254
void reverse()
reverse the curve.
Definition: OE_curve.cpp:372
int getNpts()
return the number of points in the curve (control points, without handles)
Definition: OE_curve.cpp:253
Definition: OE_utils.h:28
std::vector< vector_2d > discretizeCubicBez(vector_2d pt1, vector_2d pt2, vector_2d pt3, vector_2d pt4, float tol, int level)
discretise a curve segment to display or treating it
Definition: OE_curve.cpp:285
static void segmentBounds(float *bounds, vector_2d *segment)
calculate a segment bounding box
Definition: OE_curve.cpp:93