3

I'm trying to use quadToQuad to transform coordinates so I can draw a pixel on a resized image, and transfer that coordiantes back to the original image.

For a sample purpose, I made 2 rectangles, but the quadToQuad function always returns false.

Does anyone know why its failing?

QRectF origRect(QPointF(0, 0), QPointF(800, 800));

QRectF resizeRect(QPointF(0, 0), QPointF(400, 400));

QTransform mappingTransform;

qDebug() << (QTransform::quadToQuad(origRect, resizeRect, mappingTransform));

QPointF point = mappingTransform.map(QPointF(x, y));
Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
footose
  • 325
  • 1
  • 2
  • 8

1 Answers1

2

Just of hand I'd say the problem is that quadToQuad takes QPolygonF as input, not QRectF. Try inserting the following after declaring mappingTransform:

QPolygonF orig(origRect);
QPolygonF resize(resizeRect);
qDebug() << (QTransform::quadToQuad(orig, resize, mappingTransform));

Dug into some of my source code, this is how I compute one transform:

QRectF  tileBox(QPointF(w, s+D), QPointF(w+D, s));
QPolygonF   q0 = rectToQuad(tileBox);

QPolygonF   q1;
q1      <<  QPointF(0,0)
    <<  QPointF(1201,0)
    <<  QPointF(1201,1201)
    <<  QPointF(0, 1201);

QTransform  tileTransform;

bool ok = QTransform::quadToQuad(q0, q1, tileTransform);

I coded rectToQuad like this:

QPolygonF   MyClass::rectToQuad(QRectF rect) {
QPolygonF   quad;

quad    << rect.topLeft()
    << rect.topRight()
    << rect.bottomRight()
    << rect.bottomLeft();

return quad;
}

So I must have had an issue similar to yours. You may wish to try something similar.

Richard
  • 8,920
  • 2
  • 18
  • 24
  • Gave that a shot, still returns false. – footose Apr 07 '13 at 14:40
  • Whats the QRectF tileBox(QPointF(w, s+D), QPointF(w+D, s)); w, s and D? – footose Apr 13 '13 at 02:49
  • Helped me, also, thanks. The difference between using the constructor and your method is that the constructor for QPolygonF creates a "closed" polygon (first point = last) resulting in 5 points while your code creates only 4 points ("open" polygon). – Nicu Tofan Aug 06 '14 at 11:22