dispmap/svpointcloudviewer.cpp

95 lines
2.5 KiB
C++
Raw Normal View History

2014-07-25 11:32:00 +04:00
#include "svpointcloudviewer.h"
2014-07-28 00:04:18 +04:00
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QOpenGLContext>
2014-07-25 11:32:00 +04:00
SvPointCloudViewer::SvPointCloudViewer(QQuickItem *parent) :
2014-07-28 00:04:18 +04:00
QQuickPaintedItem(parent)
2014-07-25 11:32:00 +04:00
{
2014-07-28 00:04:18 +04:00
setRenderTarget(QQuickPaintedItem::FramebufferObject);
2014-07-25 11:32:00 +04:00
}
2014-07-30 14:42:29 +04:00
2014-07-28 00:04:18 +04:00
void SvPointCloudViewer::paint(QPainter *painter)
2014-07-25 11:32:00 +04:00
{
2014-07-28 20:25:39 +04:00
if (!m_pointCloud) {
qDebug() << "point cloud not set!";
return;
2014-07-25 11:32:00 +04:00
}
2014-07-28 20:25:39 +04:00
painter->beginNativePainting();
2014-07-28 00:04:18 +04:00
2014-07-28 20:25:39 +04:00
glViewport(0, 0, width(), height());
2014-07-29 17:47:14 +04:00
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2014-07-28 20:25:39 +04:00
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
2014-07-30 14:42:29 +04:00
glTranslatef(0.0f, height(), -40.0f);
glPointSize(1.0f);
glScalef(1.0f, 1.0f, 1.0f);
foreach (SvFigure *figure, m_pointCloud->figures()) {
glBegin(GL_POLYGON);
glColor3ub(qRed(figure->color()), qGreen(figure->color()), qBlue(figure->color()));
foreach (SvCurve *curve, figure->curves()) {
foreach (SvPoint *point, curve->points()) {
glVertex3i(point->x(), point->y(), 0);
}
}
glEnd();
}
painter->endNativePainting();
}
/*
void SvPointCloudViewer::paint(QPainter *painter)
{
if (!m_pointCloud) {
qDebug() << "point cloud not set!";
return;
}
painter->beginNativePainting();
glViewport(0, 0, width(), height());
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, height(), -40.0f);
glPointSize(1.0f);
glScalef(1.0f, 1.0f, 1.0f);
2014-07-28 20:25:39 +04:00
glBegin(GL_POINTS);
2014-07-30 14:42:29 +04:00
for (int y = 1; y < m_pointCloud->getHeight(); y++) {
for (int x = 1; x < m_pointCloud->getWidth() - 1; x++) {
SvPoint *lp = m_pointCloud->point(x - 1, y);
SvPoint *tlp = m_pointCloud->point(x - 1, y - 1);
SvPoint *tp = m_pointCloud->point(x, y - 1);
SvPoint *trp = m_pointCloud->point(x + 1, y - 1);
2014-07-28 20:25:39 +04:00
SvPoint *p = m_pointCloud->point(x, y);
if (p) {
2014-07-30 14:42:29 +04:00
//glColor3ub(0, 0, 0);
int topRight = abs(p->diff(SvPoint::RIGHT_TOP));
int topLeft = abs(p->diff(SvPoint::LEFT_TOP));
int left = abs(p->diff(SvPoint::LEFT));
int top = abs(p->diff(SvPoint::TOP));
glColor3ub(top * 4 > 255 ? 255 : top * 4, left * 4 > 255 ? 255 : left * 4, 0);
2014-07-28 20:25:39 +04:00
}
}
}
glEnd();
2014-07-28 00:04:18 +04:00
painter->endNativePainting();
2014-07-25 11:32:00 +04:00
}
2014-07-30 14:42:29 +04:00
*/