radarpoints.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/******************************************************************************
 * Copyright 2018 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

17
#pragma once
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

#include <QVector3D>
#include <QColor>
#include <QRgb>

#include "modules/tools/visualizer/renderable_object.h"
#include "modules/drivers/proto/radar.pb.h"

class QOpenGLShaderProgram;

class RadarPoints : public RenderableObject
{
    /* struct Point{
     *    GLfloat x, // raw data from radar
     *    GLfloat y,
     *    GLfloat r
     * };
     */

public:
    explicit RadarPoints(std::shared_ptr<QOpenGLShaderProgram> shaderProgram = nullptr);
    ~RadarPoints(void){
        if(buffer_){
            delete [] buffer_;
            buffer_ = nullptr;
        }
    }

    virtual GLenum GetPrimitiveType(void) const { return GL_POINTS; }

    void SetupExtraUniforms(void) {
      shader_program_->setUniformValue("color", color_);
    }

    GLfloat red(void) const { return color_.x(); }
    GLfloat green(void) const { return color_.y(); }
    GLfloat blue(void) const { return color_.z(); }

    const QVector3D& color(void) const { return color_; }

    void set_color(const QRgb& rgb){
        set_color(QColor(rgb));
    }

    void set_color(const QColor& color) {
63 64 65
        color_.setX(static_cast<float>(color.redF()));
        color_.setY(static_cast<float>(color.greenF()));
        color_.setZ(static_cast<float>(color.blueF()));
66 67 68 69 70 71 72 73 74 75 76 77 78
    }

    bool FillData(
        const std::shared_ptr<const apollo::drivers::RadarObstacles>& pData);

protected:
    bool FillVertexBuffer(GLfloat* pBuffer) override;

private:

    QVector3D color_; // r, g, b
    GLfloat* buffer_;
};