예제 #1
0
 double Bspline::compute_coefficient(
     double x, int knot_span, int degree) const {
   if (knot(knot_span) < knot(knot_span + degree)) {
     double dknot = knot(knot_span + degree) - knot(knot_span);
     return (x - knot(knot_span)) / dknot;
   } else {
     // In this case the result is arbitrary, because the coefficient
     // will only multiply basis functions with the value zero.
     // http://math.stackexchange.com/questions/52157/can-cox-de-boor-recursion-formula-apply-to-b-splines-with-multiple-knots
     return 0;
   }
 }
예제 #2
0
float SolidNoise::noise(const Vector3& p) const {
    int fi = int(floor(p.x()));
    int fj = int(floor(p.y()));
    int fk = int(floor(p.z()));
    float fu = p.x() - float(fi);
    float fv = p.y() - float(fj);
    float fw = p.z() - float(fk);
    float sum = 0.0f;
    
    Vector3 v = Vector3(fu, fv, fw);
    sum += knot(fi, fj, fk, v);
    v = Vector3(fu - 1, fv, fw);
    sum += knot(fi + 1, fj, fk, v);
    v = Vector3(fu, fv - 1, fw);
    sum += knot(fi, fj + 1, fk, v);
    v = Vector3(fu, fv, fw - 1);
    sum += knot(fi, fj, fk + 1, v);
    v = Vector3(fu - 1, fv - 1, fw);
    sum += knot(fi + 1, fj + 1, fk, v);
    v = Vector3(fu - 1, fv, fw - 1);
    sum += knot(fi + 1, fj , fk + 1, v);
    v = Vector3(fu, fv - 1, fw - 1);
    sum += knot(fi, fj + 1, fk + 1, v);
    v = Vector3(fu - 1, fv - 1, fw - 1);
    sum += knot(fi + 1, fj + 1, fk + 1, v);
    return sum;
}
	float CSolidNoice::noice(const CVector3& vec) const
	{
		//	целые части
		int xi = int(floor(vec[0]));
		int yi = int(floor(vec[1]));
		int zi = int(floor(vec[2]));

		//	дробные
		float xf = vec[0] - float(xi);
		float yf = vec[1] - float(yi);
		float zf = vec[2] - float(zi);

		float sum = 0.0f;

		sum += knot(xi, yi, zi, CVector3(xf, yf, zf));

		sum += knot(xi, yi, zi + 1, CVector3(xf, yf, zf - 1));


		sum += knot(xi, yi + 1, zi, CVector3(xf, yf - 1, zf));

		sum += knot(xi, yi + 1, zi + 1, CVector3(xf, yf - 1, zf - 1));


		sum += knot(xi + 1, yi, zi, CVector3(xf - 1, yf, zf));

		sum += knot(xi + 1, yi, zi + 1, CVector3(xf - 1, yf, zf - 1));

		sum += knot(xi + 1, yi + 1, zi, CVector3(xf - 1, yf - 1, zf));

		sum += knot(xi + 1, yi + 1, zi + 1, CVector3(xf - 1, yf - 1, zf - 1));

		return sum;
	}
예제 #4
0
/**
 * Generates a rational B-spline curve using a uniform open knot vector.
 */
void RS_Spline::rbspline(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 open knot vector
	auto const x = knot(npts, k);

    // calculate the points on the rational B-spline curve
	double t = 0;
	double const step = x[nplusc-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 (size_t i = 0; i < npts; i++)
			vp += b[i] * nbasis[i];

		t += step;
    }

}
예제 #5
0
/**
 * Generates a rational B-spline curve using a uniform open knot vector.
 */
void RS_Spline::rbspline(size_t npts, size_t k, size_t p1,
						 const std::vector<double>& b, const std::vector<double>& h, std::vector<double>& p) {

	size_t i,j,icount,jcount;
	size_t 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 open knot vector
    knot(npts,k,x);

    icount = 0;

    // calculate the points on the rational B-spline curve
    t = 0;
    step = ((double)x[nplusc])/((double)(p1-1));

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

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

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

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

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

}
예제 #6
0
void rbspline2( int npts,int k,int p1,double b[],double h[],
                bool bCalculateKnots, double knots[], double p[] )

{
    const int nplusc = npts + k;

    std::vector<double> nbasis;
    nbasis.resize( npts+1 );

/* generate the uniform open knot vector */

    if( bCalculateKnots == true )
        knot(npts, k, knots);

    int icount = 0;

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

    double t = 0.0;
    const double step = ((double)knots[nplusc])/((double)(p1-1));

    for( int i1 = 1; i1<= p1; i1++ )
    {
        if( (double)knots[nplusc] - t < 5e-6 )
        {
            t = (double)knots[nplusc];
        }

        /* generate the basis function for this value of t */
        rbasis(k, t, npts, knots, h, &(nbasis[0]));
        for( int j = 1; j <= 3; j++ )
        {      /* generate a point on the curve */
            int jcount = j;
            p[icount+j] = 0.;

            for( int i = 1; i <= npts; i++ )
            { /* Do local matrix multiplication */
                const double temp = nbasis[i]*b[jcount];
                p[icount + j] = p[icount + j] + temp;
                jcount = jcount + 3;
            }
        }
        icount = icount + 3;
        t = t + step;
    }
}
예제 #7
0
Array1D_Real BSplineBasis<Real>::uniformKnotVector(int num_ctrl_points, int degree)
{
	Real factor = ((Real)1)/(num_ctrl_points - degree);
	int numKnots = num_ctrl_points + degree + 1;

	Array1D_Real knot(numKnots,0);

	int i=0;

	for (i = 0; i <= degree; ++i)	knot[i] = 0.0;

	for (/**/; i < num_ctrl_points; ++i)
	{
		knot[i] = (i - degree) * factor;
	}

	for (/**/; i < numKnots; ++i)	knot[i] = 1.0;

	return knot;
}
예제 #8
0
void rbspline(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 open knot vector */

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

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

    icount = 0;

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

    t = 0;
    step = ((double)x[nplusc])/((double)(p1-1));

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

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

        /* generate the basis function for this value of t */
        rbasis(k,t,npts,&(x[0]),h,&(nbasis[0])); 
        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;
    }
}
예제 #9
0
MGKnotArray& MGKnotArray::add(double t, int mult)
//Add to the end of list.
{
	MGKnot knot(t, mult);
	return add(knot);
}
예제 #10
0
/**
 * Generates a rational B-spline curve using a uniform open knot vector.
 */
void RS_Spline::rbspline(int npts, int k, int p1,
                         double b[], double h[], 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;

    int* x = new int[nplusc+1];
    double* nbasis = new double[npts+1];

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

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

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

    // generate the uniform open knot vector
    knot(npts,k,x);

    icount = 0;

    // calculate the points on the rational B-spline curve
    t = 0;
    step = ((double)x[nplusc])/((double)(p1-1));

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

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

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

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

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

    delete[] x;
    delete[] nbasis;
}