Exemplo n.º 1
0
/////////////////////////////////////////////////////////
// floatMess
//
/////////////////////////////////////////////////////////
void spline_path :: floatMess(float val)
{
    if (!m_array)
    {
        error("no array");
        return;
    }

    int size;
    t_float *vec;
    if (!garray_getfloatarray(m_array, &size, &vec))
        return;

    if (size % m_numDimens)
    {
        error("size is not a mod of dimensions");
        return;
    }

    float output[64];
    splineFunc(val, output, m_numDimens, size / m_numDimens, vec);

	t_atom argv[64];
    for (int i = 0; i < m_numDimens; i++)
        SETFLOAT((&argv[i]), output[i]);

	outlet_list(m_out1, &s_list, m_numDimens, argv);
}
Exemplo n.º 2
0
double splineFunc(int i, int k, S_DoubleVec * pKnots, double t)
{
    double      t1, t2, diff1, diff2;

    IZG_ASSERT( pKnots && i > -1 && i + k < dvecSize(pKnots) );

    if( k == 0 )
    {
        if( dvecGet(pKnots, i) <= t && t < dvecGet(pKnots, i + 1) ) return 1.0;
        else return 0.0;
    }
    
    diff1 = dvecGet(pKnots, i + k) - dvecGet(pKnots, i);
    diff2 = dvecGet(pKnots, i + k + 1) - dvecGet(pKnots, i + 1);

    t1 = IS_ZERO(diff1) ? 0.0 : (t - dvecGet(pKnots, i)) / diff1 * splineFunc(i, k - 1, pKnots, t);
    t2 = IS_ZERO(diff2) ? 0.0 : (dvecGet(pKnots, i + k + 1) - t) / diff2 * splineFunc(i + 1, k - 1, pKnots, t);
    
    return t1 + t2;
}
Exemplo n.º 3
0
S_Coords curvePoint(S_Curve *pCurve, double t)
{
    S_Coords    point = makeCoords(0.0, 0.0, 0.0);
    double      A, denom = 0.0;
    int         i, size;

    IZG_ASSERT(pCurve);

    /* velikost krivky */
    size = curveSize(pCurve);

    /* kontrola hodnoty parametru t <0, 1> */
    if( t < 0.0 ) t = 0.0;
    else if( t >= 1.0 ) t = 1.0;

    /* vypocet bodu krivky pomoci Bernsteinovych polynomu */
    for( i = 0; i < size; ++i )
    {
        A = dvecGet(pCurve->weights, i) * splineFunc(i, pCurve->degree, pCurve->knots, t);
        point.x += cvecGet(pCurve->points, i).x * A;
        point.y += cvecGet(pCurve->points, i).y * A;
        point.z += cvecGet(pCurve->points, i).z * A;
        denom += A;
    }     

    /* podeleni jmenovatelem */
    if( !IS_ZERO(denom) )
    {
        denom = 1.0 / denom;
    }
    point.x *= denom;
    point.y *= denom;
    point.z *= denom;

    return point;
}
Exemplo n.º 4
0
/////////////////////////////////////////////////////////
// floatMess
//
/////////////////////////////////////////////////////////
void spline_path :: lookupFunc(t_float x, t_float *ret, int numDimen,
                               int npnts, t_float *pnts)
{
  splineFunc(x, ret, numDimen, npnts, pnts);
}