Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes
spline_rep Struct Reference
Inheritance diagram for spline_rep:
Inheritance graph
[legend]
Collaboration diagram for spline_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 spline_rep (array< point > a, array< path > cip, bool close=false, bool interpol=true)
double d (int i, int k)
double m (int i)
double convert (double u)
double unconvert (double u)
int interval_no (double u)
point spline (int i, double u, int o=0)
double S (array< dpol > p1, array< dpol > p2, array< dpol > p3, int i, double u)
point evaluate (double t, int o)
point evaluate (double t)
double bound (double t, double eps)
point grad (double t, bool &error)
double curvature (int i, double t1, double t2)
double curvature (double t1, double t2)
bool approx (int i, double u1, double u2, double eps)
void rectify_cumul (array< point > &cum, int i, double u1, double u2, double eps)
void rectify_cumul (array< point > &cum, double eps)
int get_control_points (array< double > &abs, array< point > &pts, array< path > &cip)
virtual int nr_components ()
array< pointrectify (double eps)
virtual array< double > find_closest_points (double t1, double t2, point p, double eps)
virtual double find_closest_point (double t1, double t2, point p, double eps, bool &found)

Public Attributes

array< pointa
array< pathcip
int n
array< double > U
array< dpolsp
bool close
bool interpol
int ref_count

Detailed Description

Definition at line 340 of file curve.cpp.


Constructor & Destructor Documentation

spline_rep::spline_rep ( array< point a,
array< path cip,
bool  close = false,
bool  interpol = true 
)

Definition at line 379 of file curve.cpp.

                                                                :
  a(a2), cip(cip2), n(N(a)-1), close(close2), interpol(interpol2)
{
  array<dpol> p1,p2,p3;
  p1= array<dpol> (n+3);
  p2= array<dpol> (n+3);
  p3= array<dpol> (n+3);
  p = array<dpols> (n+3);
  U = array<double> (n+6);
  if (close) {
    int i;
    a->resize(N(a)+2);
    for (i=0;i<=1;i++)
      a[n+1+i]=a[i];
    n+=2;
  }
  int i;
  double x=0;
  if (!close) {
    for (i=0;i<3;i++) {
      U[i]=x;
      x+=epsilon; 
    }
    x+=1-epsilon;
    for (i=3;i<=n;i++) {
      U[i]=x;
      x+=1;
    }
    for (i=n+1;i<=n+3;i++) {
      U[i]=x;
      x+=epsilon;
    }
  }
  else {
    for (i=0;i<=n+3;i++) {
      U[i]=x;
      x+=1;
    }
  }
  for (i=0;i<=n;i++) {
    double di22= d(i+2,2);
    double di11= d(i+1,1);
    double di21= d(i+2,1);
    double di32= d(i+3,2);
    double di31= d(i+3,1);
    p1[i]= dpol (square(U[i])/di22/di11,
               -2*U[i]/di22/di11,
               1/di22/di11);
    p2[i]= dpol (-U[i+2]*U[i]/di22/di21-U[i+3]*U[i+1]/di32/di21,
               (U[i+2]+U[i])/di22/di21+(U[i+3]+U[i+1])/di32/di21,
               -1/di22/di21-1/di32/di21);
    p3[i]= dpol (square(U[i+3])/di32/di31,
               -2*U[i+3]/di32/di31,
               1/di32/di31);
    /*
    p1[i][2]= 1/di22/di11;
    p1[i][1]= -2*U[i]/di22/di11;
    p1[i][0]= square(U[i])/di22/di11;
    p2[i][2]= -1/di22/di21-1/di32/di21;
    p2[i][1]= (U[i+2]+U[i])/di22/di21+(U[i+3]+U[i+1])/di32/di21;
    p2[i][0]= -U[i+2]*U[i]/di22/di21-U[i+3]*U[i+1]/di32/di21;
    p3[i][2]= 1/di32/di31;
    p3[i][1]= -2*U[i+3]/di32/di31;
    p3[i][0]= square(U[i+3])/di32/di31;
    */
  }
  if (interpol) {
    array<point> x(n+1), y(n+1);
    y= a;
    {
      array<double> a(n+1), b(n+1), c(n+1);
      if (close) {
        a[n-2]= S (p1, p2, p3, n-3, m(n-1));
        b[0]= S (p1, p2, p3, 1, m(2));
        b[n-2]= S (p1, p2, p3, n-2, m(n-1));
        c[0]=S (p1, p2, p3, 2, m(2));
        for (i=1; i<n-2; i++) {
           a[i]= S (p1, p2, p3, i, m(i+2));
           b[i]= S (p1, p2, p3, i+1, m(i+2));
           c[i]= S (p1, p2, p3, i+2, m(i+2));
        }
        xtridiag_solve (a, b, c, S(p1, p2, p3, n-1, m(n-1)),
                                 S(p1, p2, p3, 0, m(2)),
                                 x, y, n-1);
     /* Rotate the result in order to have an appropriate
        parametrization (to keep in sync the ordering of
        the points & the paths in cip, in particular) */
        point p=x[n-2];
        for (i=n-2;i>=1;i--)
          x[i]=x[i-1];
        x[0]=p;
     // Splice the spline
        x[n-1]= x[0];
        x[n]= x[1];
      }
      else {
        a[n]= S (p1, p2, p3, n-1, U[n+1]);
        b[0]= S (p1, p2, p3, 0, U[2]);
        b[n]= S (p1, p2, p3, n, U[n+1]);
        c[0]= S (p1, p2, p3, 1, U[2]);
        for (i=1; i<n; i++) {
           a[i]= S (p1, p2, p3, i-1, m(i+1));
           b[i]= S (p1, p2, p3, i, m(i+1));
           c[i]= S (p1, p2, p3, i+1, m(i+1));
        }
        tridiag_solve (a, b, c, x, y, n+1);
      }
    }
    a= x;
  }
  for (i=2; i<=n; i++)
    p[i]= a[i]*p1[i] + a[i-1]*p2[i-1] + a[i-2]*p3[i-2];
}

Here is the call graph for this function:


Member Function Documentation

bool spline_rep::approx ( int  i,
double  u1,
double  u2,
double  eps 
)

Definition at line 568 of file curve.cpp.

                                                           {
  double l,R;
  point p1,p2;
  p1=spline(i,u1);
  p2=spline(i,u2);
  l=norm(p1-p2);
  // When l and R are very small, the test l<=R
  // can fail forever. So we set l to exactly 0
  if (l!=0 && fnull (l,1.0e-6)) l=0;
  R=curvature(i,u1,u2);
  return l<=2*sqrt(2*R*eps);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double spline_rep::bound ( double  t,
double  eps 
) [virtual]

Implements curve_rep.

Definition at line 556 of file curve.cpp.

                                       {
  return eps/norm(evaluate(t,1));
}

Here is the call graph for this function:

double spline_rep::convert ( double  u) [inline]

Definition at line 354 of file curve.cpp.

{ return U[2]+u*(U[n+1]-U[2]); }

Here is the caller graph for this function:

double spline_rep::curvature ( int  i,
double  t1,
double  t2 
)

Definition at line 602 of file curve.cpp.

                                                  {
  point a, b;
  a= extract (p[i], 2);
  b= extract (p[i], 1);
  double t,R;
  point pp,ps;
  if (norm(a)==0) return tm_infinity;
  t=-(a*b)/(2*a*a);
  if (t1>t) t=t1;
  else if (t2<t) t=t2;
  pp=spline(i,t,1);
  ps=spline(i,t,2);
  if (norm(ps)==0) return tm_infinity;
  R=square(norm(pp))/norm(ps);
  return R;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double spline_rep::curvature ( double  t1,
double  t2 
) [virtual]

Implements curve_rep.

Definition at line 620 of file curve.cpp.

                                           {
  double res;
  int no,no1,no2;
  t1=convert(t1);
  t2=convert(t2);
  no1=interval_no(t1);
  no2=interval_no(t2);
  res=tm_infinity;
  for (no=no1;no<=no2;no++) {
    double r;
    if (no<2) r=curvature(2,t1,t2);
    else if (no>n) r=curvature(n,t1,t2);
    else r=curvature(no,t1,t2);
    if (r<=res) res=r;
  }
  return res;
}

Here is the call graph for this function:

double spline_rep::d ( int  i,
int  k 
) [inline]

Definition at line 351 of file curve.cpp.

{ return U[i]-U[i-k]; }

Here is the caller graph for this function:

point spline_rep::evaluate ( double  t,
int  o 
)

Definition at line 538 of file curve.cpp.

                                     {
  point res;
  int no;
  t=convert(t);
  double k=U[n+1]-U[2];
  no=interval_no(t);
  if (no<2) res=spline(2,U[2],o);
  else if (no>n) res=spline(n,U[n+1],o);
  else res=spline(no,t,o);
  return prod(k,o)*res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point spline_rep::evaluate ( double  t) [virtual]

Implements curve_rep.

Definition at line 551 of file curve.cpp.

                              {
  return evaluate(t,0);
}

Here is the call graph for this function:

double curve_rep::find_closest_point ( double  t1,
double  t2,
point  p,
double  eps,
bool &  found 
) [virtual, inherited]

Definition at line 138 of file curve.cpp.

{
  array<double> res= find_closest_points (t1, t2, p, eps);
  found= N(res)>0;
  if (found)
    return res[0];
  else
    return -1;
}

Here is the call graph for this function:

array< double > curve_rep::find_closest_points ( double  t1,
double  t2,
point  p,
double  eps 
) [virtual, inherited]

Definition at line 125 of file curve.cpp.

{
  array<curvet> res= curvet_closest_points (curve (this), t1, t2, p, eps);
  merge_sort_leq <curvet, less_eq_curvet> (res);
  array<double> rest= array<double> (N(res));
  int i;
  for (i=0; i<N(res); i++)
    rest[i]= res[i].t;
  return rest;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int spline_rep::get_control_points ( array< double > &  abs,
array< point > &  pts,
array< path > &  cip 
) [virtual]

Reimplemented from curve_rep.

Definition at line 640 of file curve.cpp.

{
  array<double> u(n+1);
  array<point> p(n+1);
  int i;
  if (interpol) {
    if (close) {
      u->resize (n-1);
      p->resize (n-1);
      for (i=0; i<n-1; i++)
       u[i]= unconvert ((U[i+2]+U[i+3])/2);
    }
    else {
      u[0]= unconvert (U[2]);
      u[n]= unconvert (U[n+1]);
      for (i=2; i<=n; i++)
       u[i-1]= unconvert ((U[i]+U[i+1])/2);
    }
    for (i=0; i<=(close ? n-2 : n); i++)
      p[i]= evaluate (u[i]);
  }
  else FAILED ("not yet implemented");
  abs = u;
  pts = p;
  rcip= cip;
  return close ? n-1 : n+1;
}

Here is the call graph for this function:

point spline_rep::grad ( double  t,
bool &  error 
) [virtual]

Implements curve_rep.

Definition at line 561 of file curve.cpp.

                                       {
  error= false;
  return evaluate(t,1);
}

Here is the call graph for this function:

int spline_rep::interval_no ( double  u)

Definition at line 520 of file curve.cpp.

                                 {
  int i;
  for (i=0;i<N(U);i++)
    if (u>=U[i] && u<U[i+1]) return i;
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double spline_rep::m ( int  i) [inline]

Definition at line 352 of file curve.cpp.

{ return (U[i]+U[i+1])/2; }

Here is the caller graph for this function:

virtual int curve_rep::nr_components ( ) [inline, virtual, inherited]

Reimplemented in transformed_curve_rep, inverted_curve_rep, compound_curve_rep, and poly_segment_rep.

Definition at line 21 of file curve.hpp.

{ return 1; }
array< point > curve_rep::rectify ( double  eps) [inherited]

Definition at line 25 of file curve.cpp.

                              {
  array<point> a (1);
  a[0]= evaluate (0.0);
  rectify_cumul (a, eps);
  return a;
}

Here is the call graph for this function:

void spline_rep::rectify_cumul ( array< point > &  cum,
int  i,
double  u1,
double  u2,
double  eps 
)

Definition at line 582 of file curve.cpp.

                                                             {
  if (approx(i,u1,u2,eps))
    cum << spline(i,u2);
  else {
    double u=(u1+u2)/2;
    rectify_cumul(cum,i,u1,u,eps);
    rectify_cumul(cum,i,u,u2,eps);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void spline_rep::rectify_cumul ( array< point > &  cum,
double  eps 
) [virtual]

Implements curve_rep.

Definition at line 594 of file curve.cpp.

                                                        {
  int i;
  for (i=2;i<=n;i++)
    rectify_cumul(cum,i,U[i],U[i+1],eps);
}

Here is the call graph for this function:

double spline_rep::S ( array< dpol p1,
array< dpol p2,
array< dpol p3,
int  i,
double  u 
) [inline]

Definition at line 496 of file curve.cpp.

{
  if (i<0 || i>n) return 0;
  else if (u<U[i] || u>=U[i+3]) return 0;
  else if (u<U[i+1]) return p1[i](u);
  else if (u<U[i+2]) return p2[i](u);
  else if (u<U[i+3]) return p3[i](u);
  else FAILED ("we should **never** go here");
  return 0.0;
}

Here is the caller graph for this function:

point spline_rep::spline ( int  i,
double  u,
int  o = 0 
)

Definition at line 510 of file curve.cpp.

                                          {
  int j, n= N(p[i]);
  point res (n);
  if (o<0 || o>2) o=0;
  for (j=0; j<n; j++)
    res[j]= p[i][j] (u, o);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double spline_rep::unconvert ( double  u) [inline]

Definition at line 355 of file curve.cpp.

{ return (u-U[2])/(U[n+1]-U[2]); }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 341 of file curve.cpp.

Definition at line 342 of file curve.cpp.

Definition at line 346 of file curve.cpp.

Definition at line 346 of file curve.cpp.

Definition at line 343 of file curve.cpp.

Definition at line 345 of file curve.cpp.

int abstract_struct::ref_count [inherited]

Definition at line 142 of file basic.hpp.

Definition at line 344 of file curve.cpp.


The documentation for this struct was generated from the following file: