コード例 #1
0
ファイル: rs_spline.cpp プロジェクト: Azen2011/LibreCAD
void RS_Spline::rbsplinu(size_t npts, size_t k, size_t p1,
                         const std::vector<RS_Vector>& b,
                         const std::vector<double>& h,
                         std::vector<RS_Vector>& p) const{
	size_t const nplusc = npts + k;

	/* generate the periodic knot vector */
	std::vector<double> const x = knotu(npts, k);

    /*    calculate the points on the rational B-spline curve */
	double t = k-1;
	double const step = double(npts - k + 1)/(p1 - 1);

	for (auto& vp: p) {
		if (x[nplusc-1] - t < 5e-6) t = x[nplusc-1];

		/* generate the basis function for this value of t */
		auto const nbasis = rbasis(k, t, npts, x, h);
		/* generate a point on the curve, for x, y, z */
		for (size_t i = 0; i < npts; i++)
			vp += b[i] * nbasis[i];

		t += step;
    }

}
コード例 #2
0
ファイル: intronurbs.cpp プロジェクト: drownedout/datamap
void rbsplinu(int npts,int k,int p1,double b[],double h[], double p[])

{
    int i,j,icount,jcount;
    int i1;
    int nplusc;

    double step;
    double t;
    double temp;
    std::vector<double> nbasis;
    std::vector<int> x;

    nplusc = npts + k;

    x.resize( nplusc+1);
    nbasis.resize(npts+1);

/*  zero and redimension the knot vector and the basis array */

    for(i = 0; i <= npts; i++){
        nbasis[i] = 0.;
    }

    for(i = 0; i <= nplusc; i++){
        x[i] = 0;
    }

/* generate the uniform periodic knot vector */

    knotu(npts,k,&(x[0]));

/*
  printf("The knot vector is ");
  for (i = 1; i <= nplusc; i++){
  printf(" %d ", x[i]);
  }
  printf("\n");

  printf("The usable parameter range is ");
  for (i = k; i <= npts+1; i++){
  printf(" %d ", x[i]);
  }
  printf("\n");
*/

    icount = 0;

/*    calculate the points on the rational B-spline curve */

    t = k-1;
    step = ((double)((npts)-(k-1)))/((double)(p1-1));

    for (i1 = 1; i1<= p1; i1++){

        if ((double)x[nplusc] - t < 5e-6){
            t = (double)x[nplusc];
        }

        rbasis(k,t,npts,&(x[0]),h,&(nbasis[0]));      /* generate the basis function for this value of t */
/*
  printf("t = %f \n",t);
  printf("nbasis = ");
  for (i = 1; i <= npts; i++){
  printf("%f  ",nbasis[i]);
  }
  printf("\n");
*/
        for (j = 1; j <= 3; j++){      /* generate a point on the curve */
            jcount = j;
            p[icount+j] = 0.;

            for (i = 1; i <= npts; i++){ /* Do local matrix multiplication */
                temp = nbasis[i]*b[jcount];
                p[icount + j] = p[icount + j] + temp;
/*
  printf("jcount,nbasis,b,nbasis*b,p = %d %f %f %f %f\n",jcount,nbasis[i],b[jcount],temp,p[icount+j]);
*/
                jcount = jcount + 3;
            }
        }
/*
  printf("icount, p %d %f %f %f \n",icount,p[icount+1],p[icount+2],p[icount+3]);
*/
        icount = icount + 3;
        t = t + step;
    }
}
コード例 #3
0
void RS_Spline::rbsplinu(int npts, int k, int p1,
						 const std::vector<double>& b, const std::vector<double>& h, std::vector<double>& p) {

    int i,j,icount,jcount;
    int i1;
    //int x[30];		/* allows for 20 data points with basis function of order 5 */
    int nplusc;

    double step;
    double t;
    //double nbasis[20];
//    double temp;


    nplusc = npts + k;

	std::vector<int> x(nplusc+1, 0);
	std::vector<double> nbasis(npts+1, 0.);

    /* generate the uniform periodic knot vector */

    knotu(npts,k,x);

    /*
        printf("The knot vector is ");
        for (i = 1; i <= nplusc; i++){
                printf(" %d ", x[i]);
        }
        printf("\n");

        printf("The usable parameter range is ");
        for (i = k; i <= npts+1; i++){
                printf(" %d ", x[i]);
        }
        printf("\n");
    */

    icount = 0;

    /*    calculate the points on the rational B-spline curve */

    t = k-1;
    step = ((double)((npts)-(k-1)))/((double)(p1-1));

    for (i1 = 1; i1<= p1; i1++) {

        if ((double)x[nplusc] - t < 5e-6) {
            t = (double)x[nplusc];
        }

        rbasis(k,t,npts,x,h,nbasis);      /* generate the basis function for this value of t */
        /*
                        printf("t = %f \n",t);
                        printf("nbasis = ");
                        for (i = 1; i <= npts; i++){
                                printf("%f  ",nbasis[i]);
                        }
                        printf("\n");
        */
        for (j = 1; j <= 3; j++) {      /* generate a point on the curve */
            jcount = j;
            p[icount+j] = 0.;

            for (i = 1; i <= npts; i++) { /* Do local matrix multiplication */
//                temp = nbasis[i]*b[jcount];
//                p[icount + j] = p[icount + j] + temp;
                p[icount + j] += nbasis[i]*b[jcount];
                /*
                                                printf("jcount,nbasis,b,nbasis*b,p = %d %f %f %f %f\n",jcount,nbasis[i],b[jcount],temp,p[icount+j]);
                */
                jcount = jcount + 3;
            }
        }
        /*
                        printf("icount, p %d %f %f %f \n",icount,p[icount+1],p[icount+2],p[icount+3]);
        */
        icount = icount + 3;
        t = t + step;
    }

}
コード例 #4
0
ファイル: intronurbs.cpp プロジェクト: Mavrx-inc/gdal
void rbsplinu(int npts,int k,int p1,double b[],double h[], double p[])

{
    int i,j,icount,jcount;
    int i1;
    int nplusc;

    double step;
    double t;
    double temp;
    std::vector<double> nbasis;
    std::vector<double> x;

    nplusc = npts + k;

    x.resize( nplusc+1);
    nbasis.resize(npts+1);

/*  zero and redimension the knot vector and the basis array */

    for(i = 0; i <= npts; i++){
        nbasis[i] = 0.;
    }

    for(i = 0; i <= nplusc; i++){
        x[i] = 0;
    }

/* generate the uniform periodic knot vector */

    knotu(npts,k,&(x[0]));

    icount = 0;

/*    calculate the points on the rational B-spline curve */

    t = k-1;
    step = ((double)((npts)-(k-1)))/((double)(p1-1));

    for (i1 = 1; i1<= p1; i1++){

        if (x[nplusc] - t < 5e-6){
            t = x[nplusc];
        }

        rbasis(k,t,npts,&(x[0]),h,&(nbasis[0]));      /* generate the basis function for this value of t */

        for (j = 1; j <= 3; j++){      /* generate a point on the curve */
            jcount = j;
            p[icount+j] = 0.;

            for (i = 1; i <= npts; i++){ /* Do local matrix multiplication */
                temp = nbasis[i]*b[jcount];
                p[icount + j] = p[icount + j] + temp;
                jcount = jcount + 3;
            }
        }
        icount = icount + 3;
        t = t + step;
    }
}