Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit a5f4086

Browse files
committed
Add point cloud to visualization of sensor data
1 parent 5d4d9ed commit a5f4086

13 files changed

Lines changed: 744 additions & 631 deletions

File tree

445 Bytes
Loading

include/globject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GLObject
3434

3535
void SetText(QString text);
3636

37-
void SetTexture(QImage image, bool generateMipMaps);
37+
void SetTexture(QImage image, bool generateMipMaps, GLint wrapping = GL_REPEAT);
3838

3939
void SetColor(QColor color) { color_ = color; }
4040
QColor GetColor() const { return color_; }

include/glpointcloud.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#include "globject.h"
3+
4+
5+
class GLPointCloud : public GLObject
6+
{
7+
public:
8+
GLPointCloud(QOpenGLFunctions_4_3_Core* functions, const QString& srcPath);
9+
};

include/glwidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "camera.h"
1313
#include "appconfig.h"
1414
#include "lane.h"
15+
#include "pointcloud.h"
1516
#include "imessagesource.h"
1617

1718
#include "glfieldofview.h"
@@ -58,7 +59,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Core
5859
void Connected(DataType dataType);
5960
void TreeItemChanged(QTreeWidgetItem* item, int column);
6061
void TreeItemClicked(QTreeWidgetItem* item, int column);
61-
void MessageParsed(const Message& message, const LaneMessage& laneMessage);
62+
void MessageParsed(const Message& message, const LaneMessage& laneMessage, const PointMessage& pointMessage);
6263

6364
protected:
6465
void paintGL();
@@ -85,6 +86,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Core
8586
QPoint mousePos_;
8687
const AppConfig& config_;
8788
QVector<Lane*> lanes_;
89+
PointCloud pointcloud_;
8890
QSet<int> pressedKeys_;
8991
QList<int> sceneKeys_;
9092
IMessageSource* msgSource_;

include/osiparser.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class OsiParser : public QObject
2727

2828
signals:
2929
void MessageParsed(const Message& message,
30-
const LaneMessage& laneMessage);
30+
const LaneMessage& laneMessage,
31+
const PointMessage& pointMessage);
3132
void EnableExport(bool enable);
3233
void SaveOSIMsgOverflow(int osiMsgSaveThreshold);
3334

@@ -56,7 +57,8 @@ class OsiParser : public QObject
5657

5758
void ParseSensorData(const osi3::SensorData& sensorData,
5859
Message& objectMessage,
59-
LaneMessage& laneMessage);
60+
LaneMessage& laneMessage,
61+
PointMessage& pointMessage);
6062

6163
void ParseSensorDataMovingObject(Message& objectMessage,
6264
const osi3::BaseMoving& baseObject,

include/pointcloud.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
#include "types.h"
3+
#include "glpointcloud.h"
4+
#include <QVector3D>
5+
#include <QOpenGLFunctions_4_3_Core>
6+
7+
class PointCloud
8+
{
9+
public:
10+
PointCloud(int id, QOpenGLFunctions_4_3_Core* functions, const QString& srcPath);
11+
12+
void UpdatePointCloud(const QVector<PointStruct>& pm); // Creates new GLPointCloud object from the PointStruct-list
13+
14+
int pointcloudId_;
15+
bool isVisible_;
16+
GLPointCloud glPointCloud_;
17+
QImage colorscheme; // Color scheme of the point cloud. The line from texture coordinates (0,0) to (1,1) defines color(intensity)
18+
19+
private:
20+
QOpenGLFunctions_4_3_Core* functions_;
21+
QString srcPath_;
22+
};

include/types.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "osi_common.pb.h"
1111
#include <QVector>
1212
#include <QVector3D>
13-
13+
#include <QColor>
1414

1515
#include <memory>
1616

@@ -72,4 +72,9 @@ struct LaneStruct
7272
};
7373
using LaneMessage = QVector<LaneStruct>;
7474

75-
75+
struct PointStruct
76+
{
77+
QVector3D position; // Carthesian global coordinates of the point
78+
float color; // The color is a real number in [0,1]
79+
};
80+
using PointMessage = QVector<PointStruct>;

src/globject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ GLObject::SetText(QString text)
150150
}
151151

152152
void
153-
GLObject::SetTexture(QImage image, bool generateMipMaps)
153+
GLObject::SetTexture(QImage image, bool generateMipMaps, GLint wrapping)
154154
{
155155
if (textureId_ > -1)
156156
{
@@ -163,8 +163,8 @@ GLObject::SetTexture(QImage image, bool generateMipMaps)
163163
functions_->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
164164
image.width(), image.height(), 0,
165165
GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
166-
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
167-
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
166+
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
167+
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
168168

169169
if (generateMipMaps)
170170
{

src/glpointcloud.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "glpointcloud.h"
2+
3+
GLPointCloud::GLPointCloud(QOpenGLFunctions_4_3_Core* functions, const QString& srcPath)
4+
: GLObject(GL_POINTS, functions, "", GL_STREAM_DRAW)
5+
{
6+
7+
}

src/glwidget.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "glwidget.h"
22
#include "glvehicle.h"
3+
#include "glpointcloud.h"
34
#include "gltriangle.h"
45
#include "glpoint.h"
56
#include "global.h"
@@ -33,6 +34,7 @@ GLWidget::GLWidget(QWidget* parent,
3334
, mousePos_()
3435
, config_(config)
3536
, lanes_()
37+
, pointcloud_(100, this, config_.srcPath_)
3638
, pressedKeys_()
3739
, sceneKeys_()
3840
, msgSource_(msgSource)
@@ -159,7 +161,7 @@ GLWidget::paintGL()
159161
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
160162

161163
// Depth test is disabled, thus the static objects (i.e. grid) will be drawn first.
162-
// Afterwards the lanes, then the vehicles etc. are drawn, the texts are the last ones.
164+
// Afterwards the lanes, then the vehicles etc. are drawn, then point clouds and the texts are the last ones.
163165
foreach (GLObject* staticObject, staticObjects_)
164166
{
165167
if(staticObject->isVisible_)
@@ -190,6 +192,10 @@ GLWidget::paintGL()
190192
RenderObject(object);
191193
}
192194

195+
if (pointcloud_.isVisible_) {
196+
RenderObject(&pointcloud_.glPointCloud_);
197+
}
198+
193199
foreach (GLObject* object, simulationObjects_)
194200
{
195201
if (object->GetTextObject() != nullptr && object->GetTextObject()->isVisible_)
@@ -231,7 +237,6 @@ GLWidget::RenderObject(GLObject* object)
231237
}
232238
shaderProgram_.setUniformValue(uniformColorLocation_, color);
233239
}
234-
235240
glBindVertexArray(object->vaoId_);
236241
glDrawArrays(object->GetPrimitiveType(), 0, object->vertices_.size());
237242
}
@@ -408,7 +413,8 @@ GLWidget::ResetObjectTextOrientations()
408413

409414
void
410415
GLWidget::MessageParsed(const Message& message,
411-
const LaneMessage& laneMessage)
416+
const LaneMessage& laneMessage,
417+
const PointMessage& pointMessage)
412418
{
413419
// The check for a connected receiver is necessary because the signals for received messages
414420
// the receiver emits are asynchronous. It sometimes happens that after the receiver disconnected,
@@ -594,6 +600,12 @@ GLWidget::MessageParsed(const Message& message,
594600
}
595601
}
596602

603+
// copy point clouds
604+
if (pointMessage.size() > 0) {
605+
pointcloud_.UpdatePointCloud(pointMessage);
606+
}
607+
608+
597609
// TODO: Remove ununsed objects from object tree, also stop tracking etc
598610
// Hide unused objects
599611
foreach (GLObject* object, objectControlList)

0 commit comments

Comments
 (0)