/* * Copyright 2014 Google Inc. 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. */ #include #include "point_cloud_drawable.h" #include "rtabmap/utilite/ULogger.h" #include "util.h" #include PointCloudDrawable::PointCloudDrawable( GLuint shaderProgram, const pcl::PointCloud::Ptr & cloud, const std::vector & indices) : vertex_buffers_(0), nPoints_(0), pose_(1.0f), visible_(true), shader_program_(shaderProgram) { UASSERT(!cloud->empty()); glGenBuffers(1, &vertex_buffers_); if(vertex_buffers_) { LOGI("Creating cloud buffer %d", vertex_buffers_); std::vector vertices = std::vector(cloud->size()*4); for(unsigned int i=0; isize(); ++i) { vertices[i*4] = cloud->at(i).x; vertices[i*4+1] = cloud->at(i).y; vertices[i*4+2] = cloud->at(i).z; vertices[i*4+3] = cloud->at(i).rgb; } glBindBuffer(GL_ARRAY_BUFFER, vertex_buffers_); glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * (int)vertices.size(), (const void *)vertices.data(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLint error = glGetError(); if(error != GL_NO_ERROR) { LOGI("OpenGL: Could not allocate point cloud (0x%x)\n", error); vertex_buffers_ = 0; } else { nPoints_ = cloud->size(); if(indices.size()) { int polygonSize = indices[0].vertices.size(); UASSERT(polygonSize == 3); indices_.resize(indices.size() * polygonSize); int oi = 0; for(unsigned int i=0; i::Ptr & cloud, const std::vector & indices) : vertex_buffers_(0), nPoints_(0), pose_(1.0f), visible_(true), shader_program_(shaderProgram) { UASSERT(!cloud->empty()); glGenBuffers(1, &vertex_buffers_); if(vertex_buffers_) { LOGI("Creating cloud buffer %d", vertex_buffers_); std::vector vertices = std::vector(cloud->size()*4); for(unsigned int i=0; isize(); ++i) { vertices[i*4] = cloud->at(i).x; vertices[i*4+1] = cloud->at(i).y; vertices[i*4+2] = cloud->at(i).z; vertices[i*4+3] = cloud->at(i).rgb; } glBindBuffer(GL_ARRAY_BUFFER, vertex_buffers_); glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * (int)vertices.size(), (const void *)vertices.data(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLint error = glGetError(); if(error != GL_NO_ERROR) { LOGI("OpenGL: Could not allocate point cloud (0x%x)\n", error); vertex_buffers_ = 0; } else { nPoints_ = cloud->size(); if(indices.size()) { int polygonSize = indices[0].vertices.size(); UASSERT(polygonSize == 3); indices_.resize(indices.size() * polygonSize); int oi = 0; for(unsigned int i=0; i