25 static double B0(
double u);
26 static double B1(
double u);
27 static double B2(
double u);
28 static double B3(
double u);
42 return (((*
a)[0] * (*
a)[0]) + ((*
a)[1] * (*
a)[1]));
55 (*v)[0] *= newlen /
len;
56 (*v)[1] *= newlen /
len;
64 return (((*
a)[0] * (*
b)[0]) + ((*
a)[1] * (*
b)[1]));
70 double dx = (*a)[0] - (*b)[0];
71 double dy = (*a)[1] - (*b)[1];
72 return (
sqrt((dx * dx) + (dy * dy)));
78 (*c)[0] = (*a)[0] + (*b)[0];
79 (*c)[1] = (*a)[1] + (*b)[1];
126 nPts = last - first + 1;
135 for (i = 0; i < nPts; i++) {
159 det_C0_C1 =
C[0][0] *
C[1][1] -
C[1][0] *
C[0][1];
160 det_C0_X =
C[0][0] *
X[1] -
C[0][1] *
X[0];
161 det_X_C1 =
X[0] *
C[1][1] -
X[1] *
C[0][1];
164 if (det_C0_C1 == 0.0) {
165 det_C0_C1 = (
C[0][0] *
C[1][1]) * 10.0e-12;
167 alpha_l = det_X_C1 / det_C0_C1;
168 alpha_r = det_C0_X / det_C0_C1;
173 if (alpha_l < 1.0e-6 || alpha_r < 1.0e-6) {
176 bezCurve[0] = d[first];
177 bezCurve[3] = d[last];
178 V2Add(&(bezCurve[0]),
V2Scale(&(tHat1), dist), &(bezCurve[1]));
179 V2Add(&(bezCurve[3]),
V2Scale(&(tHat2), dist), &(bezCurve[2]));
187 bezCurve[0] = d[first];
188 bezCurve[3] = d[last];
189 V2Add(&bezCurve[0],
V2Scale(&tHat1, alpha_l), &bezCurve[1]);
190 V2Add(&bezCurve[3],
V2Scale(&tHat2, alpha_r), &bezCurve[2]);
204 int nPts = last - first + 1;
208 uPrime = (
double *)malloc(nPts *
sizeof(
double));
209 for (i = first; i <= last; i++) {
224 double numerator, denominator;
234 for (i = 0; i <= 2; i++) {
235 Q1[i][0] = (Q[i + 1][0] - Q[i][0]) * 3.0;
236 Q1[i][1] = (Q[i + 1][1] - Q[i][1]) * 3.0;
240 for (i = 0; i <= 1; i++) {
241 Q2[i][0] = (Q1[i + 1][0] - Q1[i][0]) * 2.0;
242 Q2[i][1] = (Q1[i + 1][1] - Q1[i][1]) * 2.0;
250 numerator = (Q_u[0] -
P[0]) * (Q1_u[0]) + (Q_u[1] -
P[1]) * (Q1_u[1]);
251 denominator = (Q1_u[0]) * (Q1_u[0]) + (Q1_u[1]) * (Q1_u[1]) + (Q_u[0] -
P[0]) * (Q2_u[0]) +
252 (Q_u[1] -
P[1]) * (Q2_u[1]);
255 if (denominator == 0) {
258 uPrime = u - (numerator / denominator);
276 Vtemp = (
Vector2 *)malloc((
unsigned)((degree + 1) *
sizeof(
Vector2)));
277 for (i = 0; i <= degree; i++) {
282 for (i = 1; i <= degree; i++) {
283 for (j = 0; j <= degree - i; j++) {
284 Vtemp[j][0] = (1.0 -
t) * Vtemp[j][0] +
t * Vtemp[j + 1][0];
285 Vtemp[j][1] = (1.0 -
t) * Vtemp[j][1] +
t * Vtemp[j + 1][1];
298 static double B0(
double u)
300 double tmp = 1.0 - u;
301 return (tmp * tmp * tmp);
304 static double B1(
double u)
306 double tmp = 1.0 - u;
307 return (3 * u * (tmp * tmp));
310 static double B2(
double u)
312 double tmp = 1.0 - u;
313 return (3 * u * u * tmp);
316 static double B3(
double u)
331 tHat1 =
V2SubII(d[end + 1], d[end]);
342 tHat2 =
V2SubII(d[end - 1], d[end]);
356 tHatCenter[0] = (V1[0] + V2[0]) / 2.0;
357 tHatCenter[1] = (V1[1] + V2[1]) / 2.0;
379 u = (
double *)malloc((
unsigned)(last - first + 1) *
sizeof(
double));
382 for (i = first + 1; i <= last; i++) {
386 for (i = first + 1; i <= last; i++) {
387 u[i - first] = u[i - first] / u[last - first];
411 *splitPoint = (last - first + 1) / 2;
413 for (i = first + 1; i < last; i++) {
417 if (dist >= maxDist) {
451 FitCurveWrapper::~FitCurveWrapper()
458 for (
int i = 0; i <= n; ++i) {
459 _vertices.push_back(
curve[i]);
463 void FitCurveWrapper::FitCurve(vector<Vec2d> &
data, vector<Vec2d> &oCurve,
double error)
467 for (
int i = 0; i <
size; ++i) {
468 d[i][0] =
data[i][0];
469 d[i][1] =
data[i][1];
477 for (vector<Vector2>::iterator
v = _vertices.begin(), vend = _vertices.end();
v != vend; ++
v) {
478 oCurve.emplace_back(
v->x(),
v->y());
488 FitCubic(d, 0, nPts - 1, tHat1, tHat2,
error);
491 void FitCurveWrapper::FitCubic(
500 double iterationError;
501 int maxIterations = 4;
506 nPts = last - first + 1;
513 bezCurve[0] = d[first];
514 bezCurve[3] = d[last];
515 V2Add(&bezCurve[0],
V2Scale(&tHat1, dist), &bezCurve[1]);
516 V2Add(&bezCurve[3],
V2Scale(&tHat2, dist), &bezCurve[2]);
517 DrawBezierCurve(3, bezCurve);
518 free((
void *)bezCurve);
528 if (maxError <
error) {
529 DrawBezierCurve(3, bezCurve);
531 free((
void *)bezCurve);
536 if (maxError < iterationError) {
537 for (i = 0; i < maxIterations; i++) {
541 free((
void *)bezCurve);
547 if (maxError <
error) {
548 DrawBezierCurve(3, bezCurve);
550 free((
void *)bezCurve);
558 free((
void *)bezCurve);
560 FitCubic(d, first, splitPoint, tHat1, tHatCenter,
error);
562 FitCubic(d, splitPoint, last, tHatCenter, tHat2,
error);
void BLI_kdtree_nd_() free(KDTree *tree)
An Algorithm for Automatically Fitting Digitized Curves by Philip J. Schneider,.
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static void error(const char *str)
static Vector2 BezierII(int degree, Vector2 *V, double t)
static Vector2 * V2Scale(Vector2 *v, double newlen)
static double NewtonRaphsonRootFind(BezierCurve Q, Vector2 P, double u)
static double * Reparameterize(Vector2 *d, int first, int last, double *u, BezierCurve bezCurve)
static Vector2 V2AddII(Vector2 a, Vector2 b)
static double B1(double u)
static const real M_EPSILON
static Vector2 ComputeRightTangent(Vector2 *d, int end)
static Vector2 V2ScaleIII(Vector2 v, double s)
static double V2Dot(Vector2 *a, Vector2 *b)
static double B0(double u)
static Vector2 * V2Normalize(Vector2 *v)
static Vector2 * V2Add(Vector2 *a, Vector2 *b, Vector2 *c)
static BezierCurve GenerateBezier(Vector2 *d, int first, int last, double *uPrime, Vector2 tHat1, Vector2 tHat2)
static Vector2 ComputeLeftTangent(Vector2 *d, int end)
static double V2SquaredLength(Vector2 *a)
static double * ChordLengthParameterize(Vector2 *d, int first, int last)
static double B3(double u)
static double B2(double u)
static double V2DistanceBetween2Points(Vector2 *a, Vector2 *b)
static double ComputeMaxError(Vector2 *d, int first, int last, BezierCurve bezCurve, double *u, int *splitPoint)
static double V2Length(Vector2 *a)
static Vector2 V2SubII(Vector2 a, Vector2 b)
static Vector2 * V2Negate(Vector2 *v)
static Vector2 ComputeCenterTangent(Vector2 *d, int center)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
CCL_NAMESPACE_BEGIN struct Window V