|
@@ -0,0 +1,619 @@
|
|
|
+/****************************************************************************
|
|
|
+**
|
|
|
+** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
+** Contact: https://www.qt.io/licensing/
|
|
|
+**
|
|
|
+** This file is part of the examples of the Qt Toolkit.
|
|
|
+**
|
|
|
+** $QT_BEGIN_LICENSE:BSD$
|
|
|
+** Commercial License Usage
|
|
|
+** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
+** accordance with the commercial license agreement provided with the
|
|
|
+** Software or, alternatively, in accordance with the terms contained in
|
|
|
+** a written agreement between you and The Qt Company. For licensing terms
|
|
|
+** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
+** information use the contact form at https://www.qt.io/contact-us.
|
|
|
+**
|
|
|
+** BSD License Usage
|
|
|
+** Alternatively, you may use this file under the terms of the BSD license
|
|
|
+** as follows:
|
|
|
+**
|
|
|
+** "Redistribution and use in source and binary forms, with or without
|
|
|
+** modification, are permitted provided that the following conditions are
|
|
|
+** met:
|
|
|
+** * Redistributions of source code must retain the above copyright
|
|
|
+** notice, this list of conditions and the following disclaimer.
|
|
|
+** * Redistributions in binary form must reproduce the above copyright
|
|
|
+** notice, this list of conditions and the following disclaimer in
|
|
|
+** the documentation and/or other materials provided with the
|
|
|
+** distribution.
|
|
|
+** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
+** contributors may be used to endorse or promote products derived
|
|
|
+** from this software without specific prior written permission.
|
|
|
+**
|
|
|
+**
|
|
|
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|
|
+**
|
|
|
+** $QT_END_LICENSE$
|
|
|
+**
|
|
|
+****************************************************************************/
|
|
|
+
|
|
|
+#include "glwidget.h"
|
|
|
+#include <QMouseEvent>
|
|
|
+#include <QOpenGLShaderProgram>
|
|
|
+#include <QCoreApplication>
|
|
|
+#include <math.h>
|
|
|
+
|
|
|
+bool GLWidget::m_transparent = false;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+GLWidget * ggw;
|
|
|
+
|
|
|
+
|
|
|
+void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize <=16)return;
|
|
|
+ unsigned int * pHeadSize = (unsigned int *)strdata;
|
|
|
+ if(*pHeadSize > nSize)
|
|
|
+ {
|
|
|
+ std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<" data size is"<<nSize<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
+ int nNameSize;
|
|
|
+ nNameSize = *pHeadSize - 4-4-8;
|
|
|
+ char * strName = new char[nNameSize+1];strName[nNameSize] = 0;
|
|
|
+ memcpy(strName,(char *)((char *)strdata +4),nNameSize);
|
|
|
+ point_cloud->header.frame_id = strName;
|
|
|
+ memcpy(&point_cloud->header.seq,(char *)strdata+4+nNameSize,4);
|
|
|
+ memcpy(&point_cloud->header.stamp,(char *)strdata+4+nNameSize+4,8);
|
|
|
+ int nPCount = (nSize - *pHeadSize)/sizeof(pcl::PointXYZI);
|
|
|
+ int i;
|
|
|
+ pcl::PointXYZI * p;
|
|
|
+ p = (pcl::PointXYZI *)((char *)strdata + *pHeadSize);
|
|
|
+ for(i=0;i<nPCount;i++)
|
|
|
+ {
|
|
|
+ pcl::PointXYZI xp;
|
|
|
+ xp.x = p->x;
|
|
|
+ xp.y = p->y;
|
|
|
+ xp.z = p->z;
|
|
|
+ xp.intensity = p->intensity;
|
|
|
+ point_cloud->push_back(xp);
|
|
|
+ p++;
|
|
|
+
|
|
|
+ // std::cout<<" x is "<<xp.x<<" y is "<<xp.y<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ // return;
|
|
|
+
|
|
|
+
|
|
|
+ ggw->SetPointCloud(point_cloud);
|
|
|
+ // DBSCAN_PC(point_cloud);
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void Listenlidarcnndectect(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+
|
|
|
+// std::vector<iv::lidar::object> lidarobjvec;
|
|
|
+// strtolidarobj(lidarobjvec,strdata,nSize);
|
|
|
+
|
|
|
+ iv::lidar::objectarray lidarobjvec;
|
|
|
+ std::string in;
|
|
|
+ in.append(strdata,nSize);
|
|
|
+ lidarobjvec.ParseFromString(in);
|
|
|
+ qDebug("obj size is %d ",lidarobjvec.obj_size());
|
|
|
+// if(lidarobjvec.obj_size() > 1)
|
|
|
+// {
|
|
|
+// qDebug("type is %s",lidarobjvec.obj(0).type_name().data());
|
|
|
+// }
|
|
|
+ ggw->SetLidarObj(lidarobjvec);
|
|
|
+}
|
|
|
+
|
|
|
+GLWidget::GLWidget(QWidget *parent)
|
|
|
+ : QOpenGLWidget(parent),
|
|
|
+ m_xRot(600),
|
|
|
+ m_yRot(3000),
|
|
|
+ m_zRot(3500),
|
|
|
+ m_program(0)
|
|
|
+{
|
|
|
+ ggw = this;
|
|
|
+
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
+ mpoint_cloud = point_cloud;
|
|
|
+
|
|
|
+ m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
|
|
|
+ // --transparent causes the clear color to be transparent. Therefore, on systems that
|
|
|
+ // support it, the widget will become transparent apart from the logo.
|
|
|
+ if (m_transparent) {
|
|
|
+ QSurfaceFormat fmt = format();
|
|
|
+ fmt.setAlphaBufferSize(8);
|
|
|
+ setFormat(fmt);
|
|
|
+ }
|
|
|
+
|
|
|
+ void * pa = iv::modulecomm::RegisterRecv("lidarpc_center",ListenPointCloud);
|
|
|
+
|
|
|
+ pa = iv::modulecomm::RegisterRecv("lidar_track",Listenlidarcnndectect);
|
|
|
+}
|
|
|
+
|
|
|
+GLWidget::~GLWidget()
|
|
|
+{
|
|
|
+ cleanup();
|
|
|
+}
|
|
|
+
|
|
|
+QSize GLWidget::minimumSizeHint() const
|
|
|
+{
|
|
|
+ return QSize(50, 50);
|
|
|
+}
|
|
|
+
|
|
|
+QSize GLWidget::sizeHint() const
|
|
|
+{
|
|
|
+ return QSize(400, 400);
|
|
|
+}
|
|
|
+
|
|
|
+static void qNormalizeAngle(int &angle)
|
|
|
+{
|
|
|
+ while (angle < 0)
|
|
|
+ angle += 360 * 16;
|
|
|
+ while (angle > 360 * 16)
|
|
|
+ angle -= 360 * 16;
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::setXRotation(int angle)
|
|
|
+{
|
|
|
+ qNormalizeAngle(angle);
|
|
|
+ if (angle != m_xRot) {
|
|
|
+ m_xRot = angle;
|
|
|
+ emit xRotationChanged(angle);
|
|
|
+ update();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::setYRotation(int angle)
|
|
|
+{
|
|
|
+ qNormalizeAngle(angle);
|
|
|
+ if (angle != m_yRot) {
|
|
|
+ m_yRot = angle;
|
|
|
+ emit yRotationChanged(angle);
|
|
|
+ update();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::setZRotation(int angle)
|
|
|
+{
|
|
|
+ qNormalizeAngle(angle);
|
|
|
+ if (angle != m_zRot) {
|
|
|
+ m_zRot = angle;
|
|
|
+ emit zRotationChanged(angle);
|
|
|
+ update();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::cleanup()
|
|
|
+{
|
|
|
+ if (m_program == nullptr)
|
|
|
+ return;
|
|
|
+ makeCurrent();
|
|
|
+ m_logoVbo.destroy();
|
|
|
+ delete m_program;
|
|
|
+ m_program = 0;
|
|
|
+ doneCurrent();
|
|
|
+}
|
|
|
+
|
|
|
+static const char *vertexShaderSourceCore =
|
|
|
+ "#version 150\n"
|
|
|
+ "in vec4 vertex;\n"
|
|
|
+ "in vec3 normal;\n"
|
|
|
+ "out vec3 vert;\n"
|
|
|
+ "out vec3 vertNormal;\n"
|
|
|
+ "uniform mat4 projMatrix;\n"
|
|
|
+ "uniform mat4 mvMatrix;\n"
|
|
|
+ "uniform mat3 normalMatrix;\n"
|
|
|
+ "void main() {\n"
|
|
|
+ " vert = vertex.xyz;\n"
|
|
|
+ " vertNormal = normalMatrix * normal;\n"
|
|
|
+ " gl_Position = projMatrix * mvMatrix * vertex;\n"
|
|
|
+ "}\n";
|
|
|
+
|
|
|
+static const char *fragmentShaderSourceCore =
|
|
|
+ "#version 150\n"
|
|
|
+ "in highp vec3 vert;\n"
|
|
|
+ "in highp vec3 vertNormal;\n"
|
|
|
+ "out highp vec4 fragColor;\n"
|
|
|
+ "uniform highp vec3 lightPos;\n"
|
|
|
+ "void main() {\n"
|
|
|
+ " highp vec3 L = normalize(lightPos - vert);\n"
|
|
|
+ " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n"
|
|
|
+ " highp vec3 color = vec3(0.39, 1.0, 0.0);\n"
|
|
|
+ " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n"
|
|
|
+ " fragColor = vec4(col, 1.0);\n"
|
|
|
+ "}\n";
|
|
|
+
|
|
|
+static const char *vertexShaderSource =
|
|
|
+ "attribute vec4 vertex;\n"
|
|
|
+ "attribute vec3 normal;\n"
|
|
|
+ "varying vec3 vert;\n"
|
|
|
+ "varying vec3 vertNormal;\n"
|
|
|
+ "uniform mat4 projMatrix;\n"
|
|
|
+ "uniform mat4 mvMatrix;\n"
|
|
|
+ "uniform mat3 normalMatrix;\n"
|
|
|
+ "void main() {\n"
|
|
|
+ " vert = vertex.xyz;\n"
|
|
|
+ " vertNormal = normalMatrix * normal;\n"
|
|
|
+ " gl_Position = projMatrix * mvMatrix * vertex;\n"
|
|
|
+ "}\n";
|
|
|
+
|
|
|
+static const char *fragmentShaderSource =
|
|
|
+ "varying highp vec3 vert;\n"
|
|
|
+ "varying highp vec3 vertNormal;\n"
|
|
|
+ "uniform highp vec3 lightPos;\n"
|
|
|
+ "void main() {\n"
|
|
|
+ " highp vec3 L = normalize(lightPos - vert);\n"
|
|
|
+ " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n"
|
|
|
+ " highp vec3 color = vec3(0.39, 1.0, 0.0);\n"
|
|
|
+ " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n"
|
|
|
+ " gl_FragColor = vec4(col, 1.0);\n"
|
|
|
+ "}\n";
|
|
|
+
|
|
|
+void GLWidget::initializeGL()
|
|
|
+{
|
|
|
+ // In this example the widget's corresponding top-level window can change
|
|
|
+ // several times during the widget's lifetime. Whenever this happens, the
|
|
|
+ // QOpenGLWidget's associated context is destroyed and a new one is created.
|
|
|
+ // Therefore we have to be prepared to clean up the resources on the
|
|
|
+ // aboutToBeDestroyed() signal, instead of the destructor. The emission of
|
|
|
+ // the signal will be followed by an invocation of initializeGL() where we
|
|
|
+ // can recreate all resources.
|
|
|
+ connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &GLWidget::cleanup);
|
|
|
+
|
|
|
+ initializeOpenGLFunctions();
|
|
|
+ glClearColor(0, 0, 0, m_transparent ? 0 : 1);
|
|
|
+
|
|
|
+ m_program = new QOpenGLShaderProgram;
|
|
|
+ m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_core ? vertexShaderSourceCore : vertexShaderSource);
|
|
|
+ // m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_core ? fragmentShaderSourceCore : fragmentShaderSource);
|
|
|
+
|
|
|
+ m_program->addShaderFromSourceCode(QOpenGLShader::Fragment,
|
|
|
+ "uniform mediump vec4 color;\n"
|
|
|
+ "void main(void)\n"
|
|
|
+ "{\n"
|
|
|
+ " gl_FragColor = color;\n"
|
|
|
+ "}");
|
|
|
+ m_program->bindAttributeLocation("vertex", 0);
|
|
|
+ m_program->bindAttributeLocation("normal", 1);
|
|
|
+ m_program->link();
|
|
|
+
|
|
|
+ m_program->bind();
|
|
|
+ m_projMatrixLoc = m_program->uniformLocation("projMatrix");
|
|
|
+ m_mvMatrixLoc = m_program->uniformLocation("mvMatrix");
|
|
|
+ m_normalMatrixLoc = m_program->uniformLocation("normalMatrix");
|
|
|
+ m_lightPosLoc = m_program->uniformLocation("lightPos");
|
|
|
+
|
|
|
+ m_colorLoc = m_program->uniformLocation("color");
|
|
|
+ // Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x
|
|
|
+ // implementations this is optional and support may not be present
|
|
|
+ // at all. Nonetheless the below code works in all cases and makes
|
|
|
+ // sure there is a VAO when one is needed.
|
|
|
+ m_vao.create();
|
|
|
+ QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
|
|
|
+
|
|
|
+
|
|
|
+ // Setup our vertex buffer object.
|
|
|
+ m_logoVbo.create();
|
|
|
+ m_logoVbo.bind();
|
|
|
+ m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
|
|
|
+
|
|
|
+ // Store the vertex attribute bindings for the program.
|
|
|
+ setupVertexAttribs();
|
|
|
+
|
|
|
+ // Our camera never changes in this example.
|
|
|
+ m_camera.setToIdentity();
|
|
|
+ m_camera.translate(0, 0, -m_iMag);
|
|
|
+
|
|
|
+ // Light position is fixed.
|
|
|
+ m_program->setUniformValue(m_lightPosLoc, QVector3D(0, 0, 70));
|
|
|
+
|
|
|
+ m_program->release();
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::setupVertexAttribs()
|
|
|
+{
|
|
|
+ m_logoVbo.bind();
|
|
|
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
|
|
+ f->glEnableVertexAttribArray(0);
|
|
|
+// f->glEnableVertexAttribArray(1);
|
|
|
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
|
|
|
+// f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
|
|
|
+// f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
|
|
|
+ m_logoVbo.release();
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::paintGL()
|
|
|
+{
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
+ glEnable(GL_DEPTH_TEST);
|
|
|
+ glEnable(GL_CULL_FACE);
|
|
|
+
|
|
|
+ // Setup our vertex buffer object.
|
|
|
+ m_logoVbo.create();
|
|
|
+ m_logoVbo.bind();
|
|
|
+ QVector<GLfloat> x_data;
|
|
|
+ mMutex.lock();
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
+ mpoint_cloud.swap(point_cloud);
|
|
|
+ mMutex.unlock();
|
|
|
+ if(point_cloud->size() == 0)
|
|
|
+ {
|
|
|
+ m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ x_data.resize(point_cloud->size()*3);
|
|
|
+ int i;
|
|
|
+ for(i=0;i<point_cloud->size();i++)
|
|
|
+ {
|
|
|
+ pcl::PointXYZI point = point_cloud->at(i);
|
|
|
+ GLfloat *p = x_data.data() + i*3;
|
|
|
+ p[0] = point.x;
|
|
|
+ p[1] = point.y;
|
|
|
+ p[2] = point.z;
|
|
|
+ }
|
|
|
+ m_logoVbo.allocate(x_data.constData(), point_cloud->size()*3 * sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ // Store the vertex attribute bindings for the program.
|
|
|
+ setupVertexAttribs();
|
|
|
+
|
|
|
+ m_camera.setToIdentity();
|
|
|
+ m_camera.translate(0, 0, -m_iMag);
|
|
|
+
|
|
|
+ m_world.setToIdentity();
|
|
|
+ m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0);
|
|
|
+ m_world.rotate(m_yRot / 16.0f, 0, 1, 0);
|
|
|
+ m_world.rotate(m_zRot / 16.0f, 0, 0, 1);
|
|
|
+
|
|
|
+ QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
|
|
|
+ m_program->bind();
|
|
|
+ m_program->setUniformValue(m_projMatrixLoc, m_proj);
|
|
|
+ m_program->setUniformValue(m_mvMatrixLoc, m_camera * m_world);
|
|
|
+ QMatrix3x3 normalMatrix = m_world.normalMatrix();
|
|
|
+ m_program->setUniformValue(m_normalMatrixLoc, normalMatrix);
|
|
|
+
|
|
|
+ QColor x(255,255,255,255);
|
|
|
+ m_program->setUniformValue(m_colorLoc,x);
|
|
|
+
|
|
|
+ if(point_cloud->size()>0)
|
|
|
+ {
|
|
|
+ glDrawArrays(GL_POINTS,0,point_cloud->size());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ glDrawArrays(GL_TRIANGLES, 0, m_logo.vertexCount());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ drawbox(0,0,-0.75,1.8,4.6,1.5,0,Qt::blue); //Our EU
|
|
|
+
|
|
|
+ iv::lidar::objectarray lidarobjvec;
|
|
|
+ mMutexLidarObj.lock();
|
|
|
+ lidarobjvec.CopyFrom(mlidarobjvec);
|
|
|
+ mMutexLidarObj.unlock();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ int i;
|
|
|
+ for(i=0;i<lidarobjvec.obj_size();i++)
|
|
|
+ {
|
|
|
+ int j;
|
|
|
+ iv::lidar::object lo = lidarobjvec.obj(i);
|
|
|
+ QColor colorx = Qt::cyan;
|
|
|
+ switch (lo.mntype()) {
|
|
|
+ case 0:
|
|
|
+ colorx = Qt::yellow;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ colorx = Qt::green;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ colorx = Qt::green;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ colorx = Qt::cyan;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ colorx = Qt::red;
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ drawbox(lo.centroid().x(),lo.centroid().y(),lo.centroid().z(),lo.dimensions().x(),
|
|
|
+ lo.dimensions().y(),lo.dimensions().z(),lo.tyaw(),colorx);
|
|
|
+ }
|
|
|
+
|
|
|
+ m_program->release();
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::drawbox(float x, float y, float z, float l, float w, float h, double yaw,QColor colorx)
|
|
|
+{
|
|
|
+ GLfloat pv[24];
|
|
|
+ int i;
|
|
|
+
|
|
|
+ double s,t;
|
|
|
+ s = l/2;
|
|
|
+ t = w/2;
|
|
|
+
|
|
|
+ for(i=0;i<8;i++)
|
|
|
+ {
|
|
|
+ pv[3*i + 0 ] = -s;
|
|
|
+ pv[3*i + 1 ] = -t;
|
|
|
+ pv[3*i + 2 ] = z-h/2;
|
|
|
+ }
|
|
|
+ pv[3*1 + 0] = + s;
|
|
|
+ pv[3*2 + 1] = + t;
|
|
|
+ pv[3*2 + 0] = + s;
|
|
|
+ pv[3*3 + 1] = + t;
|
|
|
+
|
|
|
+ for(i=0;i<4;i++)
|
|
|
+ {
|
|
|
+ double x0,y0;
|
|
|
+ x0 = pv[3*i + 0 ];
|
|
|
+ y0 = pv[3*i + 1 ];
|
|
|
+ pv[3*i + 0 ] = x0 *cos(yaw) - y0 * sin(yaw) + x;
|
|
|
+ pv[3*i + 1 ] = x0*sin(yaw) + y0* cos(yaw) + y;
|
|
|
+ }
|
|
|
+
|
|
|
+ memcpy(&pv[12],&pv[0],12*sizeof(GLfloat));
|
|
|
+ for(i=4;i<8;i++)
|
|
|
+ {
|
|
|
+ pv[3*i + 2] = z +h/2;
|
|
|
+ }
|
|
|
+
|
|
|
+ QVector<GLfloat> x_data;
|
|
|
+ x_data.resize(72);
|
|
|
+
|
|
|
+ for(i=0;i<4;i++)
|
|
|
+ {
|
|
|
+ GLfloat *p = x_data.data() + i*6;
|
|
|
+ memcpy(p,pv+i*3,3*sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=0;i<3;i++)
|
|
|
+ {
|
|
|
+ GLfloat *p = x_data.data() + i*6 +3;
|
|
|
+ memcpy(p,pv+(i+1)*3,3*sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ GLfloat *p = x_data.data() + 3*6 +3;
|
|
|
+
|
|
|
+ memcpy(p,pv,3*sizeof(GLfloat));
|
|
|
+
|
|
|
+ for(i=8;i<12;i++)
|
|
|
+ {
|
|
|
+ GLfloat *p = x_data.data() + i*6;
|
|
|
+ memcpy(p,pv+(i-4)*3,3*sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=8;i<11;i++)
|
|
|
+ {
|
|
|
+ GLfloat *p = x_data.data() + i*6 +3;
|
|
|
+ memcpy(p,pv+(i-4+1)*3,3*sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ p = x_data.data() + 11*6 +3;
|
|
|
+
|
|
|
+ memcpy(p,pv + 12,3*sizeof(GLfloat));
|
|
|
+
|
|
|
+ for(i=4;i<8;i++)
|
|
|
+ {
|
|
|
+ GLfloat *p = x_data.data() + i*6;
|
|
|
+ memcpy(p,pv+(i-4)*3,3*sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=4;i<8;i++)
|
|
|
+ {
|
|
|
+ GLfloat *p = x_data.data() + i*6 +3;
|
|
|
+ memcpy(p,pv+(i)*3,3*sizeof(GLfloat));
|
|
|
+ }
|
|
|
+
|
|
|
+ m_logoVbo.create();
|
|
|
+ m_logoVbo.bind();
|
|
|
+
|
|
|
+ m_logoVbo.allocate(x_data.constData(), 72 * sizeof(GLfloat));
|
|
|
+ setupVertexAttribs();
|
|
|
+
|
|
|
+ m_program->setUniformValue(m_colorLoc,colorx);
|
|
|
+
|
|
|
+ glDrawArrays(GL_LINES, 0, 24);
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::resizeGL(int w, int h)
|
|
|
+{
|
|
|
+ m_proj.setToIdentity();
|
|
|
+ m_proj.perspective(80.0f, GLfloat(w) / h, -8.0f, 8.0f);
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::mousePressEvent(QMouseEvent *event)
|
|
|
+{
|
|
|
+ m_lastPos = event->pos();
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
|
|
|
+{
|
|
|
+ int dx = event->x() - m_lastPos.x();
|
|
|
+ int dy = event->y() - m_lastPos.y();
|
|
|
+
|
|
|
+ if (event->buttons() & Qt::LeftButton) {
|
|
|
+ setXRotation(m_xRot + 8 * dy);
|
|
|
+ setYRotation(m_yRot + 8 * dx);
|
|
|
+ } else if (event->buttons() & Qt::RightButton) {
|
|
|
+ setXRotation(m_xRot + 8 * dy);
|
|
|
+ setZRotation(m_zRot + 8 * dx);
|
|
|
+ }
|
|
|
+
|
|
|
+ qDebug(" x rot is %d y rot is %d ",m_xRot,m_yRot);
|
|
|
+ m_lastPos = event->pos();
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::wheelEvent(QWheelEvent * e)
|
|
|
+{
|
|
|
+ QPoint qpMag = e->angleDelta();
|
|
|
+ int iMag = qpMag.y();
|
|
|
+ bool bUpdate = false;
|
|
|
+ if(iMag > 0)
|
|
|
+ {
|
|
|
+ if(m_iMag < 300)
|
|
|
+ {
|
|
|
+ m_iMag *= 1.3;
|
|
|
+ bUpdate = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(iMag < 0)
|
|
|
+ {
|
|
|
+ if(m_iMag > 0.1)
|
|
|
+ {
|
|
|
+ m_iMag /= 1.3;
|
|
|
+ bUpdate = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bUpdate)
|
|
|
+ {
|
|
|
+ update();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::SetPointCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr pc)
|
|
|
+{
|
|
|
+ mMutex.lock();
|
|
|
+ pc.swap(mpoint_cloud);
|
|
|
+ mMutex.unlock();
|
|
|
+// qDebug("update");
|
|
|
+ update();
|
|
|
+}
|
|
|
+
|
|
|
+void GLWidget::SetLidarObj(iv::lidar::objectarray lidarobjvec)
|
|
|
+{
|
|
|
+ mMutexLidarObj.lock();
|
|
|
+ mlidarobjvec.clear_obj();
|
|
|
+ mlidarobjvec.CopyFrom(lidarobjvec);
|
|
|
+ mMutexLidarObj.unlock();
|
|
|
+}
|
|
|
+
|