Apollo 11.0
自动驾驶开放平台
radarpoints.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#include "radarpoints.h"
18#include <cmath>
19
20#include <iostream>
21
23 const std::shared_ptr<QOpenGLShaderProgram>& shaderProgram)
24 : RenderableObject(1, 3, shaderProgram),
25 color_(1.0f, 0.0f, 0.0f),
26 buffer_(nullptr) {}
27
29 const std::shared_ptr<const apollo::drivers::RadarObstacles>& rawData) {
30 bool ret = false;
31
32 set_vertex_count(rawData->radar_obstacle_size());
33 buffer_ = new GLfloat[vertex_count() * vertex_element_count()];
34
35 if (buffer_) {
36 GLfloat* ptr = buffer_;
37 const ::google::protobuf::Map<::google::protobuf::int32,
39 radarObstacles = rawData->radar_obstacle();
40 for (::google::protobuf::Map<::google::protobuf::int32,
41 apollo::drivers::RadarObstacle>::const_iterator
42 iter = radarObstacles.cbegin();
43 iter != radarObstacles.cend(); ++iter, ptr += vertex_element_count()) {
44 const apollo::common::Point2D& position =
45 iter->second.absolute_position();
46
47 ptr[0] = static_cast<float>(position.x());
48 ptr[1] = static_cast<float>(position.y());
49 ptr[2] = std::pow(10.0f, static_cast<float>(iter->second.rcs() / 20.0));
50 } // end for
51
52 ret = true;
53 }
54
55 return ret;
56}
57
58bool RadarPoints::FillVertexBuffer(GLfloat* pBuffer) {
59 if (buffer_ && pBuffer) {
60 memcpy(pBuffer, buffer_, VertexBufferSize());
61 delete[] buffer_;
62 buffer_ = nullptr;
63 return true;
64 } else {
65 std::cout << "---Error!!! cannot upload data to Graphics Card----"
66 << std::endl;
67 return false;
68 }
69}
bool FillVertexBuffer(GLfloat *pBuffer) override
RadarPoints(const std::shared_ptr< QOpenGLShaderProgram > &shaderProgram=nullptr)
bool FillData(const std::shared_ptr< const apollo::drivers::RadarObstacles > &pData)
int vertex_element_count(void) const
int vertex_count(void) const
int VertexBufferSize(void) const
void set_vertex_count(int vertexCount)