Beispiel #1
0
MPxGeometryIterator* apiSimpleShape::geometryIteratorSetup(MObjectArray& componentList,
													MObject& components,
													bool forReadOnly )
//
// Description
//
//    Creates a geometry iterator compatible with his shape.
//
// Arguments
//
//    componentList - list of components to be iterated
//    components    - component to be iterator
//    forReadOnly   -
//
// Returns
//
//    An iterator for the components
//
{
	apiSimpleShapeIterator * result = NULL;
	if ( components.isNull() ) 
	{
		result = new apiSimpleShapeIterator( getControlPoints(), componentList );
	}
	else 
	{
		result = new apiSimpleShapeIterator( getControlPoints(), components );
	}
	return result;
}
Beispiel #2
0
/*==================================================================================
 psbspl - subroutine to generate open bsplines
	We receive only the vertices from perplex, so we must figure out good control
	points to use for the spline.
 ==================================================================================*/
void psbspl_ (double *x, double *y, int *npts, double *rline, double *width, int *ifill) {
	int i, N;
	double ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y;
	
	N = *npts;
	
	DEBUGPRINT(("In psbspl. With %i points, rline=%f, wdith=%f, fill=%i.\n", N, *rline, *width, *ifill));
	completeRelativeOperation();

	if (dmh_inRotatedTransform) {
		cairo_set_matrix(dmh_cr, &dmh_unrotatedMatrix);	/* remove rotation */
		dmh_inRotatedTransform = 0;
		DEBUGPRINT(("Removing rotation.\n"));
	}

	if (N >= 4) {
		cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
		getControlPoints(deviceX(x[0]), deviceY(y[0]), deviceX(x[0]), deviceY(y[0]), 
						 deviceX(x[1]), deviceY(y[1]), deviceX(x[2]), deviceY(y[2]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[1]), deviceY(y[1]));
//		cairo_line_to(dmh_cr, deviceX(x[1]), deviceY(y[1]));
		for (i=1; i <= N-3; i++) {
			getControlPoints(deviceX(x[i-1]), deviceY(y[i-1]), deviceX(x[i]), deviceY(y[i]), 
							 deviceX(x[i+1]), deviceY(y[i+1]), deviceX(x[i+2]), deviceY(y[i+2]), 
							 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
			cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[i+1]), deviceY(y[i+1]));
		}
		
		/* We've now drawn all the way to N-2.  We need to draw through N-1.
			We can get one more control point by working backwards from the end: */
		getControlPoints(deviceX(x[N-3]), deviceY(y[N-3]), deviceX(x[N-2]), deviceY(y[N-2]), 
						 deviceX(x[N-1]), deviceY(y[N-1]), deviceX(x[N-1]), deviceY(y[N-1]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[N-1]), deviceY(y[N-1]));
//		cairo_line_to(dmh_cr, deviceX(x[N-1]), deviceY(y[N-1]));
	} else if (N == 3) {
		/* for three points, we'll pretend for the purposes of control point calculation that
		 it's a closed loop */
		cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
		getControlPoints(deviceX(x[2]), deviceY(y[2]), deviceX(x[0]), deviceY(y[0]), 
						 deviceX(x[1]), deviceY(y[1]), deviceX(x[2]), deviceY(y[2]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[1]), deviceY(y[1]));
		getControlPoints(deviceX(x[0]), deviceY(y[0]), deviceX(x[1]), deviceY(y[1]), 
						 deviceX(x[2]), deviceY(y[2]), deviceX(x[0]), deviceY(y[0]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[2]), deviceY(y[2]));
	} else if (N == 2) {
		/* for two points, it's a line segment.  Duh. */
		cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
		cairo_line_to(dmh_cr, deviceX(x[1]), deviceY(y[1]));
	}
	setLineProperties((int) *rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */
	cairo_stroke_preserve(dmh_cr);
	setFillType (*ifill);
	cairo_fill(dmh_cr);
}
bool RelativePointPath::ElementBase::isDynamic()
{
    int numPoints;
    const RelativePoint* const points = getControlPoints (numPoints);

    for (int i = numPoints; --i >= 0;)
        if (points[i].isDynamic())
            return true;

    return false;
}
Beispiel #4
0
		fm::vec2 SpriteManagerBaseNonTemplate::fetchSize(const fm::Size spriteIndex) const
		{
			if (useInstancing())
			{
				fm::vec2 ret;
				m_sizProp.fetch(spriteIndex,&ret.x);
				return ret;
			}
			else
			{
				fm::vec3 pts[4];
				getControlPoints(pts,spriteIndex);
				
				return fm::vec2((pts[0] - pts[1]).length(),(pts[1] - pts[2]).length());
			}
		}
Beispiel #5
0
		fm::vec3 SpriteManagerBaseNonTemplate::fetchPos(const fm::Size spriteIndex) const
		{
			if (useInstancing())
			{
				fm::vec3 ret;
				m_posProp.fetch(spriteIndex,&ret.x);
				return ret;
			}
			else
			{
				fm::vec3 pts[4];
				getControlPoints(pts,spriteIndex);
				
				return pts[0];
			}
		}
Beispiel #6
0
		fm::vec2 SpriteManagerBaseNonTemplate::fetchDir(const fm::Size spriteIndex) const
		{
			if (useInstancing())
			{
				fm::vec2 ret;
				m_dirProp.fetch(spriteIndex,&ret.x);
				
				return ret;
			}
			else
			{
				fm::vec3 pts[4];
				getControlPoints(pts,spriteIndex);
				
				return (pts[2] - pts[1]).sgn();
			}
		}
CQIllustratorShapeNearestPoint2D
CQIllustratorShape::
nearestPoint(const CPoint2D &p, ControlType type) const
{
  CQIllustratorShapeNearestPoint2D nearest;

  ControlPointList points;

  getControlPoints(points, type);

  uint num_points = points.size();

  for (uint i = 0; i < num_points; ++i) {
    double dist = points[i]->distance(this, p);

    nearest.updatePoint(points[i], dist);
  }

  return nearest;
}
Beispiel #8
0
QImage ShapeState::buildShape(const std::vector<Point>& _points)
{
    if (_points.empty())
    {
        return QImage();
    }

    size_t n = _points.size();
    std::vector<Point> points = _points;

    QColor shapeColor(84, 84, 84);

    QPointF min, max;
    min.setX(std::numeric_limits<float>::max());
    min.setY(std::numeric_limits<float>::max());
    max.setX(std::numeric_limits<float>::lowest());
    max.setY(std::numeric_limits<float>::lowest());
    for (const auto& p: points)
    {
        max.setX(std::max(max.x(), p.point.x()));
        max.setY(std::max(max.y(), p.point.y()));
        min.setX(std::min(min.x(), p.point.x()));
        min.setY(std::min(min.y(), p.point.y()));
    }

    {
        //re-center the points
        QPointF center = (max + min) / 2.f;
        for (auto& p: points)
        {
            p.point -= center;
        }
    }

    QSizeF imageSize((max - min).x(), (max - min).y());
    imageSize += QSize(200, 200);
    QPointF imageCenter(imageSize.width() / 2.f, imageSize.height() / 2.f);

    QImage image = QImage(imageSize.toSize(), QImage::Format_RGBA8888_Premultiplied);
    image.fill(0);

    QPainter painter(&image);
    painter.setRenderHint(QPainter::Antialiasing, true);

    QPen pen(shapeColor, 3.f);
    pen.setCapStyle(Qt::RoundCap);
    pen.setJoinStyle(Qt::RoundJoin);
    painter.setPen(pen);

    QPainterPath path;

    //   Append and prepend knots and control points to close the curve

    {
        auto last = points.back();
        points.push_back(*(points.begin() + 0));
        points.push_back(*(points.begin() + 1));
        points.insert(points.begin(), last);
    }

    std::vector<QPointF> cp;
    for(size_t i = 0; i < n; i++)
    {
        QPointF cp0, cp1;
        getControlPoints(points[i].point, points[i + 1].point, points[i + 2].point, points[i].t, cp0, cp1);
        cp.push_back(cp0);
        cp.push_back(cp1);
    }
    cp.push_back(cp.front());
    for(size_t i = 1; i < n + 1; i++)
    {
        //var color=HSVtoRGB(Math.floor(240*(i-2)/(n-2)),0.8,0.8);
        //if(!showDetails){color="#555555"}
        //ctx.strokeStyle=hexToCanvasColor(color,0.75);
        path.moveTo(imageCenter + points[i].point);
        path.cubicTo(imageCenter + cp[i*2 - 1], imageCenter + cp[i*2], imageCenter + points[i + 1].point);
    }

    path.setFillRule(Qt::WindingFill);
    painter.drawPath(path);

    return floodFill(image, imageCenter.toPoint(), shapeColor.rgb());
}