point_cloud_drawable.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef TANGO_POINT_CLOUD_POINT_CLOUD_DRAWABLE_H_
29 #define TANGO_POINT_CLOUD_POINT_CLOUD_DRAWABLE_H_
30 
31 #ifdef __ANDROID__
32 #include <jni.h>
33 #endif
34 
35 #include <tango-gl/util.h>
36 #include <vector>
37 #include <pcl/point_cloud.h>
38 #include <pcl/point_types.h>
39 #include <rtabmap/core/Transform.h>
40 #include <pcl/Vertices.h>
41 #include "util.h"
42 
43 // PointCloudDrawable is responsible for the point cloud rendering.
45 public:
46  static void createShaderPrograms();
47  static void releaseShaderPrograms();
48 
49 private:
50  static std::vector<GLuint> shaderPrograms_;
51 
52  public:
54  const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
55  const pcl::IndicesPtr & indices,
56  float gainR = 1.0f,
57  float gainG = 1.0f,
58  float gainB = 1.0f);
60  const rtabmap::Mesh & mesh,
61  bool createWireframe = false);
62  virtual ~PointCloudDrawable();
63 
64  void updatePolygons(const std::vector<pcl::Vertices> & polygons, const std::vector<pcl::Vertices> & polygonsLowRes = std::vector<pcl::Vertices>(), bool createWireframe = false);
65  void updateCloud(const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud, const pcl::IndicesPtr & indices);
66  void updateMesh(const rtabmap::Mesh & mesh, bool createWireframe = false);
67  void setPose(const rtabmap::Transform & pose);
68  void setVisible(bool visible) {visible_=visible;}
69  void setGains(float gainR, float gainG, float gainB) {gainR_ = gainR; gainG_ = gainG; gainB_ = gainB;}
70  rtabmap::Transform getPose() const {return pose_;}
71  const glm::mat4 & getPoseGl() const {return poseGl_;}
72  bool isVisible() const {return visible_;}
73  bool hasMesh() const {return index_buffers_[0] != 0;}
74  bool hasTexture() const {return texture_ != 0;}
75  float getMinHeight() const {return minHeight_;}
76  const pcl::PointXYZ & aabbMinModel() const {return aabbMinModel_;}
77  const pcl::PointXYZ & aabbMaxModel() const {return aabbMaxModel_;}
78  const pcl::PointXYZ & aabbMinWorld() const {return aabbMinWorld_;}
79  const pcl::PointXYZ & aabbMaxWorld() const {return aabbMaxWorld_;}
80 
81  // Update current point cloud data.
82  //
83  // @param projection_mat: projection matrix from current render camera.
84  // @param view_mat: view matrix from current render camera.
85  // @param model_mat: model matrix for this point cloud frame.
86  // @param vertices: all vertices in this point cloud frame.
87  void Render(
88  const glm::mat4 & projectionMatrix,
89  const glm::mat4 & viewMatrix,
90  bool meshRendering = true,
91  float pointSize = 3.0f,
92  bool textureRendering = false,
93  bool lighting = true,
94  float distanceToCamSqr = 0.0f,
95  const GLuint & depthTexture = 0,
96  int screenWidth = 0, // nonnull if depthTexture>0
97  int screenHeight = 0, // nonnull if depthTexture>0
98  float nearClipPlane = 0, // nonnull if depthTexture>0
99  float farClipPlane = 0, // nonnull if depthTexture>0
100  bool packDepthToColorChannel = false,
101  bool wireFrame = false) const;
102 
103  private:
104  template<class PointT>
105  void updateAABBMinMax(const PointT & pt, pcl::PointXYZ & min, pcl::PointXYZ & max)
106  {
107  if(pt.x<min.x) min.x = pt.x;
108  if(pt.y<min.y) min.y = pt.y;
109  if(pt.z<min.z) min.z = pt.z;
110  if(pt.x>max.x) max.x = pt.x;
111  if(pt.y>max.y) max.y = pt.y;
112  if(pt.z>max.z) max.z = pt.z;
113  }
114  void updateAABBWorld(const rtabmap::Transform & pose);
115 
116  private:
117  // Vertex buffer of the point cloud geometry.
120  std::vector<GLuint> index_buffers_;
121  std::vector<int> index_buffers_count_;
122  int nPoints_;
125  bool visible_;
127  std::vector<unsigned int> organizedToDenseIndices_;
128  float minHeight_; // odom frame
129 
130  float gainR_;
131  float gainG_;
132  float gainB_;
133 
134  pcl::PointXYZ aabbMinModel_;
135  pcl::PointXYZ aabbMaxModel_;
136  pcl::PointXYZ aabbMinWorld_;
137  pcl::PointXYZ aabbMaxWorld_;
138 };
139 
140 #endif // TANGO_POINT_CLOUD_POINT_CLOUD_DRAWABLE_H_
glm::min
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
PointCloudDrawable::releaseShaderPrograms
static void releaseShaderPrograms()
Definition: point_cloud_drawable.cpp:297
PointCloudDrawable::hasTexture
bool hasTexture() const
Definition: point_cloud_drawable.h:74
PointCloudDrawable::shaderPrograms_
static std::vector< GLuint > shaderPrograms_
Definition: point_cloud_drawable.h:50
PointCloudDrawable::setVisible
void setVisible(bool visible)
Definition: point_cloud_drawable.h:68
PointCloudDrawable::updateAABBMinMax
void updateAABBMinMax(const PointT &pt, pcl::PointXYZ &min, pcl::PointXYZ &max)
Definition: point_cloud_drawable.h:105
PointCloudDrawable::getPoseGl
const glm::mat4 & getPoseGl() const
Definition: point_cloud_drawable.h:71
PointCloudDrawable::setPose
void setPose(const rtabmap::Transform &pose)
Definition: point_cloud_drawable.cpp:959
Transform.h
PointCloudDrawable::hasNormals_
bool hasNormals_
Definition: point_cloud_drawable.h:126
util.h
PointCloudDrawable::minHeight_
float minHeight_
Definition: point_cloud_drawable.h:128
PointCloudDrawable::aabbMaxModel_
pcl::PointXYZ aabbMaxModel_
Definition: point_cloud_drawable.h:135
PointCloudDrawable::aabbMinModel
const pcl::PointXYZ & aabbMinModel() const
Definition: point_cloud_drawable.h:76
PointCloudDrawable::organizedToDenseIndices_
std::vector< unsigned int > organizedToDenseIndices_
Definition: point_cloud_drawable.h:127
PointCloudDrawable::pose_
rtabmap::Transform pose_
Definition: point_cloud_drawable.h:123
PointCloudDrawable::vertex_buffer_
GLuint vertex_buffer_
Definition: point_cloud_drawable.h:118
PointCloudDrawable::nPoints_
int nPoints_
Definition: point_cloud_drawable.h:122
glm::detail::tmat4x4
Definition: type_mat.hpp:47
PointCloudDrawable::aabbMinWorld_
pcl::PointXYZ aabbMinWorld_
Definition: point_cloud_drawable.h:136
rtabmap::Mesh
Definition: util.h:165
GLuint
unsigned int GLuint
Definition: dummy.cpp:78
PointCloudDrawable::hasMesh
bool hasMesh() const
Definition: point_cloud_drawable.h:73
PointCloudDrawable::gainR_
float gainR_
Definition: point_cloud_drawable.h:130
PointCloudDrawable::gainG_
float gainG_
Definition: point_cloud_drawable.h:131
PointCloudDrawable::getPose
rtabmap::Transform getPose() const
Definition: point_cloud_drawable.h:70
PointCloudDrawable::PointCloudDrawable
PointCloudDrawable(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices, float gainR=1.0f, float gainG=1.0f, float gainB=1.0f)
Definition: point_cloud_drawable.cpp:306
PointCloudDrawable::updateCloud
void updateCloud(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices)
Definition: point_cloud_drawable.cpp:467
PointCloudDrawable::Render
void Render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix, bool meshRendering=true, float pointSize=3.0f, bool textureRendering=false, bool lighting=true, float distanceToCamSqr=0.0f, const GLuint &depthTexture=0, int screenWidth=0, int screenHeight=0, float nearClipPlane=0, float farClipPlane=0, bool packDepthToColorChannel=false, bool wireFrame=false) const
Definition: point_cloud_drawable.cpp:997
PointCloudDrawable::aabbMinWorld
const pcl::PointXYZ & aabbMinWorld() const
Definition: point_cloud_drawable.h:78
PointCloudDrawable::aabbMaxModel
const pcl::PointXYZ & aabbMaxModel() const
Definition: point_cloud_drawable.h:77
glm::max
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
PointCloudDrawable::aabbMaxWorld
const pcl::PointXYZ & aabbMaxWorld() const
Definition: point_cloud_drawable.h:79
PointCloudDrawable::aabbMaxWorld_
pcl::PointXYZ aabbMaxWorld_
Definition: point_cloud_drawable.h:137
PointCloudDrawable::createShaderPrograms
static void createShaderPrograms()
Definition: point_cloud_drawable.cpp:269
PointCloudDrawable::updateMesh
void updateMesh(const rtabmap::Mesh &mesh, bool createWireframe=false)
Definition: point_cloud_drawable.cpp:621
PointCloudDrawable::updatePolygons
void updatePolygons(const std::vector< pcl::Vertices > &polygons, const std::vector< pcl::Vertices > &polygonsLowRes=std::vector< pcl::Vertices >(), bool createWireframe=false)
Definition: point_cloud_drawable.cpp:375
PointCloudDrawable::index_buffers_count_
std::vector< int > index_buffers_count_
Definition: point_cloud_drawable.h:121
PointCloudDrawable::poseGl_
glm::mat4 poseGl_
Definition: point_cloud_drawable.h:124
PointCloudDrawable::setGains
void setGains(float gainR, float gainG, float gainB)
Definition: point_cloud_drawable.h:69
PointCloudDrawable::visible_
bool visible_
Definition: point_cloud_drawable.h:125
rtabmap::Transform
Definition: Transform.h:41
PointCloudDrawable::getMinHeight
float getMinHeight() const
Definition: point_cloud_drawable.h:75
PointCloudDrawable::aabbMinModel_
pcl::PointXYZ aabbMinModel_
Definition: point_cloud_drawable.h:134
PointCloudDrawable::~PointCloudDrawable
virtual ~PointCloudDrawable()
Definition: point_cloud_drawable.cpp:347
PointCloudDrawable::gainB_
float gainB_
Definition: point_cloud_drawable.h:132
PointCloudDrawable::updateAABBWorld
void updateAABBWorld(const rtabmap::Transform &pose)
Definition: point_cloud_drawable.cpp:972
PointCloudDrawable::texture_
GLuint texture_
Definition: point_cloud_drawable.h:119
PointCloudDrawable::index_buffers_
std::vector< GLuint > index_buffers_
Definition: point_cloud_drawable.h:120
PointCloudDrawable::isVisible
bool isVisible() const
Definition: point_cloud_drawable.h:72
PointCloudDrawable
Definition: point_cloud_drawable.h:44


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:14