Apollo 11.0
自动驾驶开放平台
pointcloud.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
18
19#include <iostream>
20
22 int pointCount, int vertexElementCount,
23 const std::shared_ptr<QOpenGLShaderProgram>& shaderProgram)
24 : RenderableObject(pointCount, vertexElementCount, shaderProgram),
25 buffer_(nullptr) {}
26
28 if (buffer_) {
29 delete[] buffer_;
30 buffer_ = nullptr;
31 }
32}
33
34bool PointCloud::FillVertexBuffer(GLfloat* pBuffer) {
35 if (buffer_ && pBuffer) {
36 memcpy(pBuffer, buffer_, VertexBufferSize());
37 delete[] buffer_;
38 buffer_ = nullptr;
39 return true;
40 } else {
41 std::cout << "---Error!!! cannot upload data to Graphics Card----"
42 << std::endl;
43 return false;
44 }
45}
46
48 const std::shared_ptr<const apollo::drivers::PointCloud>& pdata) {
49 assert(vertex_count() == pdata->point_size());
50 buffer_ = new GLfloat[vertex_count() * vertex_element_count()];
51 if (buffer_) {
52 GLfloat* tmp = buffer_;
53
54 for (int i = 0; i < vertex_count(); ++i, tmp += vertex_element_count()) {
55 const apollo::drivers::PointXYZIT& point = pdata->point(i);
56 tmp[0] = point.x();
57 tmp[1] = point.z();
58 tmp[2] = -point.y();
59 tmp[3] = static_cast<float>(point.intensity());
60 }
61 return true;
62 }
63 return false;
64}
bool FillData(const std::shared_ptr< const apollo::drivers::PointCloud > &pData)
Definition pointcloud.cc:47
~PointCloud(void)
Definition pointcloud.cc:27
PointCloud(int pointCount=1, int vertex_element_count=3, const std::shared_ptr< QOpenGLShaderProgram > &shaderProgram=NullRenderableObj)
Definition pointcloud.cc:21
int vertex_element_count(void) const
int vertex_count(void) const
int VertexBufferSize(void) const