39 #include <visp3/ustk_gui/usImageDisplayWidgetQmlOverlay.h>
41 #if (defined(USTK_HAVE_VTK_QT5) || defined(USTK_HAVE_QT5))
50 this->setMinimumSize(200, 200);
51 m_qQuickOverlay =
new QQuickWidget(
m_label);
52 m_qQuickOverlay->setAttribute(Qt::WA_AlwaysStackOnTop);
53 m_qQuickOverlay->setClearColor(Qt::transparent);
54 m_qQuickOverlay->setSource(QUrl(
"qrc:/qml/overlay-tracking-rect.qml"));
59 QQuickWidget::Status status(QQuickWidget::Null);
61 while (status != QQuickWidget::Ready) {
62 status = m_qQuickOverlay->status();
76 if (m_qQuickOverlay->rootObject()) {
77 m_qQuickOverlay->rootObject()->setProperty(
"width", event->size().width());
78 m_qQuickOverlay->rootObject()->setProperty(
"height", event->size().height());
82 vpImagePoint usImageDisplayWidgetQmlOverlay::displayImageToRealImageDimentions(
const vpImagePoint displayPoint)
85 unsigned int imageHeight;
86 unsigned int imageWidth;
91 imageHeight =
m_image.getHeight();
92 imageWidth =
m_image.getWidth();
94 p.set_i((displayPoint.get_i() * imageHeight) / (
double)height());
95 p.set_j((displayPoint.get_j() * imageWidth) / (
double)width());
100 vpImagePoint usImageDisplayWidgetQmlOverlay::realImageToDisplayImageDimentions(
const vpImagePoint realImagePoint)
103 unsigned int imageHeight;
104 unsigned int imageWidth;
109 imageHeight =
m_image.getHeight();
110 imageWidth =
m_image.getWidth();
112 p.set_i((realImagePoint.get_i() * height()) / (
double)imageHeight);
113 p.set_j((realImagePoint.get_j() * width()) / (
double)imageWidth);
118 vpRectOriented usImageDisplayWidgetQmlOverlay::displayImageToRealImageDimentions(
const vpRectOriented displayRectangle)
122 center = displayImageToRealImageDimentions(displayRectangle.getCenter());
125 unsigned int imageHeight;
126 unsigned int imageWidth;
131 imageHeight =
m_image.getHeight();
132 imageWidth =
m_image.getWidth();
135 (displayRectangle.getHeight() * imageHeight / (double)height()) * std::cos(displayRectangle.getOrientation()) +
136 (displayRectangle.getWidth() * imageWidth / (double)width()) * std::sin(displayRectangle.getOrientation());
138 (displayRectangle.getHeight() * imageHeight / (double)height()) * std::sin(displayRectangle.getOrientation()) +
139 (displayRectangle.getWidth() * imageWidth / (double)width()) * std::cos(displayRectangle.getOrientation());
141 return vpRectOriented(center, newWidth, newHeight, displayRectangle.getOrientation());
144 vpRectOriented usImageDisplayWidgetQmlOverlay::realImageToDisplayImageDimentions(
const vpRectOriented realRectangle)
148 center = realImageToDisplayImageDimentions(realRectangle.getCenter());
151 unsigned int imageHeight;
152 unsigned int imageWidth;
157 imageHeight =
m_image.getHeight();
158 imageWidth =
m_image.getWidth();
161 (realRectangle.getHeight() * height() / (double)imageHeight) * std::cos(realRectangle.getOrientation()) +
162 (realRectangle.getWidth() * width() / (double)imageWidth) * std::sin(realRectangle.getOrientation());
165 (realRectangle.getHeight() * height() / (double)imageHeight) * std::sin(realRectangle.getOrientation()) +
166 (realRectangle.getWidth() * width() / (double)imageWidth) * std::cos(realRectangle.getOrientation());
168 return vpRectOriented(center, newWidth, newHeight, realRectangle.getOrientation());
178 vpRectOriented displayRectangle;
179 displayRectangle = realImageToDisplayImageDimentions(newRectangle);
181 QObject *rectItem = m_qQuickOverlay->rootObject()->findChild<QObject *>(
"selectionRectangle");
182 rectItem->setProperty(
"x", displayRectangle.getCenter().get_j());
183 rectItem->setProperty(
"y", displayRectangle.getCenter().get_i());
184 rectItem->setProperty(
"rotation", vpMath::deg(displayRectangle.getOrientation()));
185 rectItem->setProperty(
"height", displayRectangle.getHeight());
186 rectItem->setProperty(
"width", displayRectangle.getWidth());
194 QObject *rectangleObject = m_qQuickOverlay->rootObject()->findChild<QObject *>(
"selectionRectangle");
195 int centerX = rectangleObject->property(
"x").toInt();
196 int centerY = rectangleObject->property(
"y").toInt();
197 int height = rectangleObject->property(
"height").toInt();
198 int width = rectangleObject->property(
"width").toInt();
199 int rotation = rectangleObject->property(
"rotation").toInt();
201 vpRectOriented displayRect(vpImagePoint(centerY, centerX), width, height, rotation);
203 emit(
startTracking(displayImageToRealImageDimentions(displayRect)));