Пример #1
0
// ##### getMinPoint() ###############################################
Point BSpline::getMinPoint() {
  assert (!controlPoints.empty());

  Point minPoint= getControlPoint(0, 0);
  for (int m= 0; m < getCount(M_DIR); ++m) {
    for (int n= 0; n < getCount(N_DIR); ++n) {
      minPoint= minPoint.min(getControlPoint(m, n));
    }
  }
  return minPoint;
}
Пример #2
0
// ##### print() #####################################################
void BSpline::print() {
  cout << "Spline : " << endl;
  cout << "\tM-Richtung: " << (closedM ? "closed " : "") << "[";
  for (int i= 0; i < getCount(M_DIR); ++i) {
    getControlPoint(i, 0).print();
  }
  cout << "]" << endl;
  cout << "\tN-Richtung: " << (closedN ? "closed " : "") << "[";
  for (int i= 0; i < getCount(N_DIR); ++i) {
    getControlPoint(0, i).print();
  }
  cout << "]" << endl << endl;
}
Пример #3
0
		/**
		* Calls virtual drawShape() method to draw the actial shape.
		* Draws bounding rect and control points if the shape is selected.
		*
		* @param painter :: QPainter used for drawing.
		*/
		void Shape2D::draw(QPainter& painter) const
		{
			if (!m_visible) return;
			painter.setPen(m_color);
			this->drawShape(painter);
			if (m_editing || m_selected)
			{
				QColor c(255, 255, 255, 100);
				painter.setPen(c);
				painter.drawRect(m_boundingRect.toQRectF());
				size_t np = NCommonCP;
				double rsize = 2;
				int alpha = 100;
				if (m_editing)
				{
					// if editing show all CP, make them bigger and opaque
					np = getNControlPoints();
					rsize = sizeCP;
					alpha = 255;
				}
				for (size_t i = 0; i < np; ++i)
				{
					QPointF p = painter.transform().map(getControlPoint(i));
					QRectF r(p - QPointF(rsize, rsize), p + QPointF(rsize, rsize));
					painter.save();
					painter.resetTransform();
					QColor c(255, 255, 255, alpha);
					painter.fillRect(r, c);
					r.adjust(-1, -1, 0, 0);
					painter.setPen(QColor(0, 0, 0, alpha));
					painter.drawRect(r);
					painter.restore();
				}
			}
		}
Пример #4
0
void boundaryCurve::segment( list< point2<int> > & pixels, int index, int time )
{
	if ( points.size <= 1 ) return;
	point2<int> prev, start, end, next;
	if ( cyclic ) {
		if ( ! between( 0, index, points.size - 1 ) ) return;
		prev = points.value( ( index + points.size - 1 ) % points.size )( time );
		start = points.value( ( index ) % points.size )( time );
		end = points.value( ( index + 1 ) % points.size )( time );
		next = points.value( ( index + 2 ) % points.size )( time );
	} else {
		if ( ! between( 0, index, points.size - 2 ) ) return;
		prev = points.value( clamp( 0, index - 1, points.size - 1 ) )( time );
		start = points.value( clamp( 0, index, points.size - 1 ) )( time );
		end = points.value( clamp( 0, index + 1, points.size - 1 ) )( time );
		next = points.value( clamp( 0, index + 2, points.size - 1 ) )( time );
	}
	point2<int> p0, p1, p2, p3;
	if ( getControlPoint( prev, start, end, next, p0, p1, p2, p3 ) ) {
		list< point2<int> > wk;
		getBezier3( p0, p1, p2, p3, wk );
		for ( list< point2<int> >::iterator it( wk ); it; ++it ) {
			pixels.push_back( it() );
		}
	}
}
Пример #5
0
Vector BezierSpline::getPoint(double t) const {
    Vector result = Vector(0,0,0);
    for(uint32_t i = 0; i < num; i++) {
	result += Math::bernsteinPolynomial(i,num-1,t) * getControlPoint(i);
    }
    return result;
}
Пример #6
0
Vector3d Track::getPos(double t) const
{
    // Find out in which interval we are on the spline
    int p = (int)(t / delta_t);
    // Compute local control point indices
#define BOUNDS(pp) { if (pp < 0) pp = 0; else if (pp >= (int)pos.size()-1) pp = pos.size() - 1; }
    int p0 = p - 1;     BOUNDS(p0);
    int p1 = p;         BOUNDS(p1);
    int p2 = p + 1;     BOUNDS(p2);
    int p3 = p + 2;     BOUNDS(p3);
    
	// Relative (local) time 
	double lt = (t - delta_t*(double)p) / delta_t;
	
	// Interpolate
	//printf("lt: %f, p: %d, p0:%d, p1:%d, p2:%d, p3:%d \n", lt, p, p0, p1, p2, p3);
	return Track::Eq(lt, getControlPoint(p0), getControlPoint(p1), getControlPoint(p2), getControlPoint(p3));
}
Пример #7
0
void Warp::mouseDown( cinder::app::MouseEvent &event )
{
	if( !sIsEditMode ) return;
	if( mSelected >= mPoints.size() ) return;

	// calculate offset by converting control point from normalized to standard screen space
	ivec2 p = ( getControlPoint( mSelected ) * mWindowSize );
	mOffset = event.getPos() - p;

	event.setHandled( true );
}
Пример #8
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;
}
void WarpPerspectiveBilinear::moveControlPoint(unsigned index, const Vec2f &shift)
{
	// depending on index, move perspective or bilinear control point
	if( isCorner( index ) ) {
		// perspective: simply move the control point
		mWarp->moveControlPoint( convertIndex( index ), shift );
	}
	else {
		// bilinear: transform control point from normalized screen space to warped space
		Vec2f pt = getControlPoint(index);
		setControlPoint(index, pt + shift);
	}
}
Пример #10
0
void BezierSpline::read_text(std::istream &is, int num_points)
{

    for (int j = 0; j < num_points; ++j)
    {
        Point point;
        is >> point[0] >> point[1] >> point[2];

        if (j == num_points-1 && (point-getControlPoint(0)).norm() < FLT_EPSILON)
            setClosed(true);
        else
            addControlPoint(point);
    }
}
Пример #11
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;
}
Пример #12
0
void Shape2D::draw(QPainter& painter) const
{
  painter.setPen(m_color);
  this->drawShape(painter);
  if (m_editing)
  {
    QColor c(255,255,255,100);
    painter.setPen(c);
    painter.setCompositionMode(QPainter::CompositionMode_Plus);
    painter.drawRect(m_boundingRect.toQRectF());
    for(size_t i = 0; i < getNControlPoints(); ++i)
    {
      QPointF p = painter.transform().map(getControlPoint(i));
      QRectF r(p - QPointF(sizeCP,sizeCP),p + QPointF(sizeCP,sizeCP));
      painter.save();
      painter.resetTransform();
      painter.fillRect(r,c);
      painter.restore();
    }
  }
}
void WarpPerspectiveBilinear::draw(bool controls)
{
	// apply perspective transform
	gl::pushModelView();
	gl::multModelView( mWarp->getTransform() );

	// draw bilinear warp
	WarpBilinear::draw(false);

	// restore transform
	gl::popModelView();

	// draw edit interface
	if( isEditModeEnabled() ) {
		if(controls) {
			// draw control points
			for(unsigned i=0;i<mPoints.size();++i) 
				drawControlPoint( getControlPoint(i) * mWindowSize, mSelected==i );
		}
	}
}
Пример #14
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;
}
Пример #15
0
unsigned Warp::findControlPoint( const vec2 &pos, float *distance ) const
{
	unsigned index;

	// store mouse position for later use in e.g. WarpBilinear::keyDown().
	mMouse = pos;

	// find closest control point
	float dist = 10.0e6f;

	for( unsigned i = 0; i < mPoints.size(); i++ ) {
		float d = glm::distance( pos, getControlPoint( i ) * mWindowSize );

		if( d < dist ) {
			dist = d;
			index = i;
		}
	}

	*distance = dist;

	return index;
}
Пример #16
0
/**
 * Get a tangent vector.
 *
 * The derivative of the Bernstein polynomial above is
 *
 * \f[ \frac{d}{dt}B_{i,n}(t) = n \left( B_{i-1,n-1}(t) - B_{i,n-1}(t) \right) \f]
 */
Vector BezierSpline::getTangent(double t) const {
    Vector result = Vector(0,0,0);
    for(uint32_t i = 0; i < num; i++) {
	result += num*(Math::bernsteinPolynomial(i-1,num-2,t) - Math::bernsteinPolynomial(i,num-2,t)) * getControlPoint(i);
    }
    result.normalize();
    return result;
}