Пример #1
0
// virtual
int Spline2f::insertControlPoint( const Vector2f& p )
{
	float t;
	closestPointOnSpline( p, &t );
	
	int controlPointIndex;

	if( t >= ( 1.f - delta() ) )
	{
		controlPointIndex = numControlPoints();
	}
	else if( t <= delta() )
	{
		controlPointIndex = 0;		
	}
	else
	{
		controlPointIndex = Arithmetic::roundToInt( t * numControlPoints() );
	}

	controlPointIndex = MathUtils::clampToRangeInt( controlPointIndex, 0, numControlPoints() );

	printf( "closest t = %f, controlPointIndex = %d\n", t, controlPointIndex );

	m_xSpline.insertControlPoint( controlPointIndex, p.x );
	m_ySpline.insertControlPoint( controlPointIndex, p.y );
	
	m_bCacheIsDirty = true;

	return controlPointIndex;
}
Пример #2
0
// virtual
int Spline2f::insertControlPoint( const Vector2f& p )
{
    float t;
    closestPointOnSpline( p, &t );

    int controlPointIndex;

    if( t >= ( 1.f - delta() ) )
    {
        controlPointIndex = numControlPoints();
    }
    else if( t <= delta() )
    {
        controlPointIndex = 0;
    }
    else
    {
        controlPointIndex = libcgt::core::math::roundToInt( t * numControlPoints() );
    }

    controlPointIndex = libcgt::core::math::clampToRangeExclusive(
        controlPointIndex, 0, numControlPoints());

    m_xSpline.insertControlPoint( controlPointIndex, p.x );
    m_ySpline.insertControlPoint( controlPointIndex, p.y );

    m_bCacheIsDirty = true;

    return controlPointIndex;
}
Пример #3
0
void BezierSpline::write_text(std::ostream &os, int num_points)
{
    if (num_points == 0)
        num_points = (closed())?numControlPoints()+1:numControlPoints();

    for (int j = 0; j < num_points; ++j)
    {
        Point point = getControlPoint(j % numControlPoints());
        os << point[0] << " "  << point[1] << " "  << point[2] << " ";
    }
    os << std::endl;
}
Пример #4
0
void BezierSpline::displaceHeight(float hdiff)
{
  for (unsigned int i = 0; i < numControlPoints(); ++i)
    {
      control_points_[i][2] += hdiff;
    }
}
Пример #5
0
void BezierSpline::simplify(float min_distance, float max_distance)
{
    if (numControlPoints() <= 2)
        return;

    std::vector<Point> sample_points;
    ::simplify(control_points_, sample_points, min_distance, max_distance);
    control_points_ = sample_points;
}
Пример #6
0
void BezierSpline::subSample(float tol)
{
    if (numControlPoints() <= 2)
        return;

    std::vector<Point> new_points;
    ::subSample(control_points_, new_points, tol);
    control_points_ = new_points;
}
Пример #7
0
void BezierSpline::cleanup()
{
    int n = numControlPoints();
    if (n > 1)
    {
        for (int i = n-1; i >= 1; --i)
            if ((control_points_[i] - control_points_[i-1]).norm() < FLT_EPSILON)
                control_points_.erase(control_points_.begin()+i);
    }
}
Пример #8
0
void BezierSpline::updateKnots()
{
    //assert(numControlPoints() >= order());

    knots_.resize(numControlPoints() + order());
    for (unsigned int i = 0; i < order(); ++i)
        knots_[i] = 0.0f;

    for (unsigned int i = order(); i < numKnots()-order(); ++i)
        knots_[i] = (i-order() + 1) / ((float) numKnots()-2*order() + 1);

    for (unsigned int i = numKnots()-order(); i < numKnots(); ++i)
        knots_[i] = 1.0f;
}
Пример #9
0
Spline2f Spline2f::offsetPath( float distance )
{
    Spline2f offsetSpline;

    int nControlPoints = numControlPoints();
    float delta = 1.f / ( nControlPoints - 1 );

    for( int i = 0; i < nControlPoints; ++i )
    {
        float t = i * delta;

        Vector2f controlPoint = getControlPoint( i );
        Vector2f normalAtControlPoint = normalAt( t ).normalized();

        offsetSpline.appendControlPoint( controlPoint + distance * normalAtControlPoint );
    }

    return offsetSpline;
}
Пример #10
0
int Spline2f::closestControlPoint( const Vector2f& p, float* distanceSquared )
{
    int minIndex = -1;
    float minDistanceSquared = FLT_MAX;

    for( int i = 0; i < numControlPoints(); ++i )
    {
        Vector2f controlPoint = getControlPoint( i );
        float currentDistanceSquared = ( p - controlPoint ).normSquared();
        if( currentDistanceSquared < minDistanceSquared )
        {
            minDistanceSquared = currentDistanceSquared;
            minIndex = i;
        }
    }

    if( distanceSquared != NULL )
    {
        *distanceSquared = minDistanceSquared;
    }
    return minIndex;
}
Пример #11
0
int Spline2f::numPointsToEvaluate()
{
    return numControlPoints() * m_nPointsToEvaluateFactor;
}
Пример #12
0
bool OpenNaturalCubicSpline::isValid()
{
	return( numControlPoints() >= 4 );
}
Пример #13
0
BezierSpline::Point BezierSpline::getControlPoint(int idx) const
{
    assert(idx >= 0 && idx < numControlPoints());
    return control_points_[idx];
}
Пример #14
0
void BezierSpline::setControlPoint(int idx, const Point &point)
{
  assert(idx >= 0 && idx < numControlPoints());
  control_points_[idx] = point;
}