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

Add lidar point cloud to visualization of sensor data #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1)
add_subdirectory(open-simulation-interface)
project(osi-visualizer)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
Expand Down Expand Up @@ -46,6 +46,8 @@ set(SOURCES
src/glfieldofview.cpp
src/fmureceiver.cpp
src/utils.cpp
src/glpointcloud.cpp
src/pointcloud.cpp
)

set(HEADERS
Expand All @@ -68,11 +70,13 @@ set(HEADERS
include/appconfig.h
include/global.h
include/glpoint.h
include/glpointcloud.h
include/gltrafficsign.h
include/osiparser.h
include/glfieldofview.h
include/fmureceiver.h
include/utils.h
include/pointcloud.h
)


Expand Down
Binary file added Resources/Images/PointCloudColors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion include/globject.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GLObject

void SetText(QString text);

void SetTexture(QImage image, bool generateMipMaps);
void SetTexture(QImage image, bool generateMipMaps, GLint wrapping = GL_REPEAT);

void SetColor(QColor color) { color_ = color; }
QColor GetColor() const { return color_; }
Expand Down
9 changes: 9 additions & 0 deletions include/glpointcloud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include "globject.h"


class GLPointCloud : public GLObject
{
public:
GLPointCloud(QOpenGLFunctions_4_3_Core* functions, const QString& srcPath);
};
4 changes: 3 additions & 1 deletion include/glwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "camera.h"
#include "appconfig.h"
#include "lane.h"
#include "pointcloud.h"
#include "imessagesource.h"

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

protected:
void paintGL();
Expand All @@ -85,6 +86,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Core
QPoint mousePos_;
const AppConfig& config_;
QVector<Lane*> lanes_;
PointCloud pointcloud_;
QSet<int> pressedKeys_;
QList<int> sceneKeys_;
IMessageSource* msgSource_;
Expand Down
6 changes: 4 additions & 2 deletions include/osiparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class OsiParser : public QObject

signals:
void MessageParsed(const Message& message,
const LaneMessage& laneMessage);
const LaneMessage& laneMessage,
const PointMessage& pointMessage);
void EnableExport(bool enable);
void SaveOSIMsgOverflow(int osiMsgSaveThreshold);

Expand Down Expand Up @@ -56,7 +57,8 @@ class OsiParser : public QObject

void ParseSensorData(const osi3::SensorData& sensorData,
Message& objectMessage,
LaneMessage& laneMessage);
LaneMessage& laneMessage,
PointMessage& pointMessage);

void ParseSensorDataMovingObject(Message& objectMessage,
const osi3::BaseMoving& baseObject,
Expand Down
23 changes: 23 additions & 0 deletions include/pointcloud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "types.h"
#include "glpointcloud.h"
#include <QVector3D>
#include <QOpenGLFunctions_4_3_Core>
#include <memory>

class PointCloud
{
public:
PointCloud(int id, QOpenGLFunctions_4_3_Core* functions, const QString& srcPath);

void UpdatePointCloud(const QVector<PointStruct>& pm); // Creates new GLPointCloud object from the PointStruct-list

int pointcloudId_;
bool isVisible_;
std::unique_ptr<GLPointCloud> glPointCloud_;
QImage colorscheme; // Color scheme of the point cloud. The line from texture coordinates (0,0) to (1,1) defines color(intensity)

private:
QOpenGLFunctions_4_3_Core* functions_;
QString srcPath_;
};
9 changes: 7 additions & 2 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "osi_common.pb.h"
#include <QVector>
#include <QVector3D>

#include <QColor>

#include <memory>

Expand Down Expand Up @@ -72,4 +72,9 @@ struct LaneStruct
};
using LaneMessage = QVector<LaneStruct>;


struct PointStruct
{
QVector3D position; // Carthesian global coordinates of the point
float color; // The color is a real number in [0,1]
};
using PointMessage = QVector<PointStruct>;
6 changes: 3 additions & 3 deletions src/globject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ GLObject::SetText(QString text)
}

void
GLObject::SetTexture(QImage image, bool generateMipMaps)
GLObject::SetTexture(QImage image, bool generateMipMaps, GLint wrapping)
{
if (textureId_ > -1)
{
Expand All @@ -163,8 +163,8 @@ GLObject::SetTexture(QImage image, bool generateMipMaps)
functions_->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
image.width(), image.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
functions_->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);

if (generateMipMaps)
{
Expand Down
7 changes: 7 additions & 0 deletions src/glpointcloud.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "glpointcloud.h"

GLPointCloud::GLPointCloud(QOpenGLFunctions_4_3_Core* functions, const QString& srcPath)
: GLObject(GL_POINTS, functions, "", GL_STREAM_DRAW)
{

}
18 changes: 15 additions & 3 deletions src/glwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "glwidget.h"
#include "glvehicle.h"
#include "glpointcloud.h"
#include "gltriangle.h"
#include "glpoint.h"
#include "global.h"
Expand Down Expand Up @@ -33,6 +34,7 @@ GLWidget::GLWidget(QWidget* parent,
, mousePos_()
, config_(config)
, lanes_()
, pointcloud_(100, this, config_.srcPath_)
, pressedKeys_()
, sceneKeys_()
, msgSource_(msgSource)
Expand Down Expand Up @@ -159,7 +161,7 @@ GLWidget::paintGL()
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

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

if (pointcloud_.isVisible_ && pointcloud_.glPointCloud_ != nullptr) {
RenderObject(pointcloud_.glPointCloud_.get());
}

foreach (GLObject* object, simulationObjects_)
{
if (object->GetTextObject() != nullptr && object->GetTextObject()->isVisible_)
Expand Down Expand Up @@ -231,7 +237,6 @@ GLWidget::RenderObject(GLObject* object)
}
shaderProgram_.setUniformValue(uniformColorLocation_, color);
}

glBindVertexArray(object->vaoId_);
glDrawArrays(object->GetPrimitiveType(), 0, object->vertices_.size());
}
Expand Down Expand Up @@ -408,7 +413,8 @@ GLWidget::ResetObjectTextOrientations()

void
GLWidget::MessageParsed(const Message& message,
const LaneMessage& laneMessage)
const LaneMessage& laneMessage,
const PointMessage& pointMessage)
{
// The check for a connected receiver is necessary because the signals for received messages
// the receiver emits are asynchronous. It sometimes happens that after the receiver disconnected,
Expand Down Expand Up @@ -594,6 +600,12 @@ GLWidget::MessageParsed(const Message& message,
}
}

// copy point clouds
if (pointMessage.size() > 0) {
pointcloud_.UpdatePointCloud(pointMessage);
}


// TODO: Remove ununsed objects from object tree, also stop tracking etc
// Hide unused objects
foreach (GLObject* object, objectControlList)
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Q_DECLARE_METATYPE(DataType)
Q_DECLARE_METATYPE(Message)
Q_DECLARE_METATYPE(LaneMessage)
Q_DECLARE_METATYPE(PointMessage)
Q_DECLARE_METATYPE(osi3::SensorData)
Q_DECLARE_METATYPE(osi3::SensorView)

Expand All @@ -17,6 +18,7 @@ int main(int argc, char *argv[])
{
qRegisterMetaType<Message>();
qRegisterMetaType<LaneMessage>();
qRegisterMetaType<PointMessage>();
qRegisterMetaType<DataType>();
qRegisterMetaType<osi3::SensorData>();
qRegisterMetaType<osi3::SensorView>();
Expand Down
Loading