Fixed passing data through qml
This commit is contained in:
parent
b6b4bf3eb6
commit
23f5479b35
3
Main.qml
3
Main.qml
@ -152,7 +152,8 @@ ApplicationWindow {
|
|||||||
Item {
|
Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
SvPointCloudViewer {
|
SvPointCloudViewer {
|
||||||
pointCloud: app.getPointCloud()
|
id: pointCloudViewer1
|
||||||
|
pointCloud: app.pointCloud()
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
main.cpp
9
main.cpp
@ -14,8 +14,7 @@ int main(int argc, char *argv[])
|
|||||||
QGuiApplication a(argc, argv);
|
QGuiApplication a(argc, argv);
|
||||||
|
|
||||||
qmlRegisterType<SvPointCloudViewer>("SvPCV", 1, 0, "SvPointCloudViewer");
|
qmlRegisterType<SvPointCloudViewer>("SvPCV", 1, 0, "SvPointCloudViewer");
|
||||||
qmlRegisterType<SvApplicationContext>("SvPCV", 1, 0, "SvApplicationContext");
|
qmlRegisterUncreatableType<SvPointCloud>("SvPCV", 1, 0, "SvApplicationContext", "c++ only");
|
||||||
qRegisterMetaType<SvPointCloud*>();
|
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
SvImageProvider imageProvider;
|
SvImageProvider imageProvider;
|
||||||
@ -27,9 +26,9 @@ int main(int argc, char *argv[])
|
|||||||
SvImage right(imgRight);
|
SvImage right(imgRight);
|
||||||
|
|
||||||
SvPointCloud pointCloud(imgLeft.width(), imgLeft.height());
|
SvPointCloud pointCloud(imgLeft.width(), imgLeft.height());
|
||||||
SvApplicationContext m;
|
SvApplicationContext applicationContext;
|
||||||
|
|
||||||
m.setPointCloud(&pointCloud);
|
applicationContext.setPointCloud(&pointCloud);
|
||||||
|
|
||||||
SvProcessor proc(4);
|
SvProcessor proc(4);
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
engine.addImageProvider("images", &imageProvider);
|
engine.addImageProvider("images", &imageProvider);
|
||||||
engine.rootContext()->setContextProperty("processor", &proc);
|
engine.rootContext()->setContextProperty("processor", &proc);
|
||||||
engine.rootContext()->setContextProperty("app", &m);
|
engine.rootContext()->setContextProperty("app", &applicationContext);
|
||||||
engine.load(QUrl(QStringLiteral("qrc:///Main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:///Main.qml")));
|
||||||
|
|
||||||
proc.start();
|
proc.start();
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
explicit SvApplicationContext(QObject *parent = 0);
|
explicit SvApplicationContext(QObject *parent = 0);
|
||||||
|
|
||||||
void setPointCloud(SvPointCloud *pointCloud) { m_pointCloud = pointCloud; }
|
void setPointCloud(SvPointCloud *pointCloud) { m_pointCloud = pointCloud; }
|
||||||
Q_INVOKABLE SvPointCloud* getPointCloud() { return m_pointCloud; }
|
Q_INVOKABLE SvPointCloud* pointCloud() { return m_pointCloud; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SvPointCloud *m_pointCloud;
|
SvPointCloud *m_pointCloud;
|
||||||
|
@ -92,6 +92,8 @@ void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line)
|
|||||||
if (x > 0 && line > 0){
|
if (x > 0 && line > 0){
|
||||||
p.setX(x - 1);
|
p.setX(x - 1);
|
||||||
p.setY(line - 1);
|
p.setY(line - 1);
|
||||||
|
int color = value > 255 ? 255 : value;
|
||||||
|
|
||||||
p.setColor(qRgb(value, value, value));
|
p.setColor(qRgb(value, value, value));
|
||||||
|
|
||||||
pc->addPoint(p);
|
pc->addPoint(p);
|
||||||
|
@ -7,8 +7,9 @@ SvPoint::SvPoint()
|
|||||||
|
|
||||||
SvPoint::SvPoint(SvPoint &point)
|
SvPoint::SvPoint(SvPoint &point)
|
||||||
{
|
{
|
||||||
m_px = point.x();
|
m_px = point.x();
|
||||||
m_py = point.y();
|
m_py = point.y();
|
||||||
|
m_color = point.color();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvPoint::addCurve(SvCurve *curve)
|
void SvPoint::addCurve(SvCurve *curve)
|
||||||
|
@ -20,22 +20,21 @@ void SvPointCloudViewer::paint(QPainter *painter)
|
|||||||
|
|
||||||
glViewport(0, 0, width(), height());
|
glViewport(0, 0, width(), height());
|
||||||
|
|
||||||
glClearColor(0, 1, 1, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT/* | GL_DEPTH_BUFFER_BIT*/);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
//glEnable (GL_BLEND);
|
||||||
|
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.0f, height(), -400.0f);
|
glTranslatef(100.0f, height()-10, -40.0f);
|
||||||
glScalef(0.1f, 0.1f, 0.1f);
|
|
||||||
glColor3f(1.0f, 0.0f, 0.0f);
|
|
||||||
glPointSize(3.0f);
|
|
||||||
|
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
for (int y = 0; y < m_pointCloud->getHeight(); y++) {
|
for (int y = 0; y < m_pointCloud->getHeight(); y++) {
|
||||||
for (int x = 0; x < m_pointCloud->getWidth(); x++) {
|
for (int x = 0; x < m_pointCloud->getWidth(); x++) {
|
||||||
SvPoint *p = m_pointCloud->point(x, y);
|
SvPoint *p = m_pointCloud->point(x, y);
|
||||||
if (p) {
|
if (p) {
|
||||||
glColor3ub(qRed(p->color()),qGreen(p->color()), qBlue(p->color()));
|
glColor3ub(qRed(p->color()), qGreen(p->color()), qBlue(p->color()));
|
||||||
glVertex3i(x, y, 0);
|
glVertex3i(x, -y, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user