scene.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google Inc. 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 #ifndef TANGO_POINT_CLOUD_SCENE_H_
18 #define TANGO_POINT_CLOUD_SCENE_H_
19 
20 #ifdef __ANDROID__
21 #include <jni.h>
22 #endif
23 #include <memory>
24 #include <set>
25 
26 #include "CameraMobile.h"
27 #include <tango-gl/axis.h>
28 #include <tango-gl/camera.h>
29 #include <tango-gl/color.h>
31 #include <tango-gl/grid.h>
32 #include <tango-gl/frustum.h>
33 #include <tango-gl/trace.h>
34 #include <tango-gl/transform.h>
35 #include <tango-gl/util.h>
36 
37 #include <rtabmap/core/Transform.h>
38 #include <rtabmap/core/Link.h>
39 
40 #include "point_cloud_drawable.h"
41 #include "graph_drawable.h"
42 #include "bounding_box_drawable.h"
43 #include "background_renderer.h"
44 
45 #include <pcl/point_cloud.h>
46 #include <pcl/point_types.h>
47 
48 // Scene provides OpenGL drawable objects and renders them for visualization.
49 class Scene {
50  public:
51  // Constructor and destructor.
52  Scene();
53  ~Scene();
54 
55  // Allocate OpenGL resources for rendering.
56  void InitGLContent();
57 
58  // Release non-OpenGL allocated resources.
59  void DeleteResources();
60 
61  // Setup GL view port.
62  void SetupViewPort(int w, int h);
63  int getViewPortWidth() const {return screenWidth_;}
64  int getViewPortHeight() const {return screenHeight_;}
65 
67  void setScreenRotation(rtabmap::ScreenRotation colorCameraToDisplayRotation) {color_camera_to_display_rotation_ = colorCameraToDisplayRotation;}
68 
69  void clear(); // removed all point clouds
70 
71  // Render loop.
72  // @param: cur_pose_transformation, latest pose's transformation.
73  // @param: point_cloud_transformation, pose transformation at point cloud
74  // frame's timestamp.
75  // @param: point_cloud_vertices, point cloud's vertices of the current point
76  // frame.
77  int Render(const float * uvsTransformed = 0, glm::mat4 arViewMatrix = glm::mat4(0), glm::mat4 arProjectionMatrix=glm::mat4(0), const rtabmap::Mesh & occlusionMesh=rtabmap::Mesh(), bool mapping=false);
78 
79  // Set render camera's viewing angle, first person, third person or top down.
80  //
81  // @param: camera_type, camera type includes first person, third person and
82  // top down
85 
86  void SetCameraPose(const rtabmap::Transform & pose); // opengl camera
88  rtabmap::Transform GetOpenGLCameraPose(float * fov = 0) const;
89 
90  // Touch event passed from android activity. This function only support two
91  // touches.
92  //
93  // @param: touch_count, total count for touches.
94  // @param: event, touch event of current touch.
95  // @param: x0, normalized touch location for touch 0 on x axis.
96  // @param: y0, normalized touch location for touch 0 on y axis.
97  // @param: x1, normalized touch location for touch 1 on x axis.
98  // @param: y1, normalized touch location for touch 1 on y axis.
99  void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event,
100  float x0, float y0, float x1, float y1);
101 
102  void updateGraph(
103  const std::map<int, rtabmap::Transform> & poses,
104  const std::multimap<int, rtabmap::Link> & links);
105 
106  void setGraphVisible(bool visible);
107  void setGridVisible(bool visible);
108  void setTraceVisible(bool visible);
109  void setFrustumVisible(bool visible);
110 
111  void addMarker(int id, const rtabmap::Transform & pose);
112  void setMarkerPose(int id, const rtabmap::Transform & pose);
113  bool hasMarker(int id) const;
114  void removeMarker(int id);
115  std::set<int> getAddedMarkers() const;
116 
117  void addCloud(
118  int id,
119  const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
120  const pcl::IndicesPtr & indices,
121  const rtabmap::Transform & pose);
122  void addMesh(
123  int id,
124  const rtabmap::Mesh & mesh,
125  const rtabmap::Transform & pose,
126  bool createWireframe = false);
127 
128  void setCloudPose(int id, const rtabmap::Transform & pose);
129  void setCloudVisible(int id, bool visible);
130  bool hasCloud(int id) const;
131  bool hasMesh(int id) const;
132  bool hasTexture(int id) const;
133  std::set<int> getAddedClouds() const;
134  void updateCloudPolygons(int id, const std::vector<pcl::Vertices> & polygons);
135  void updateMesh(int id, const rtabmap::Mesh & mesh);
136  void updateGains(int id, float gainR, float gainG, float gainB);
137 
138  void setBlending(bool enabled) {blending_ = enabled;}
139  void setMapRendering(bool enabled) {mapRendering_ = enabled;}
140  void setMeshRendering(bool enabled, bool withTexture) {meshRendering_ = enabled; meshRenderingTexture_ = withTexture;}
141  void setPointSize(float size) {pointSize_ = size;}
142  void setFOV(float angle);
143  void setOrthoCropFactor(float value);
144  void setGridRotation(float angleDeg);
145  void setLighting(bool enabled) {lighting_ = enabled;}
146  void setBackfaceCulling(bool enabled) {backfaceCulling_ = enabled;}
147  void setWireframe(bool enabled) {wireFrame_ = enabled;}
148  void setBackgroundColor(float r, float g, float b) {r_=r; g_=g; b_=b;} // 0.0f <> 1.0f
149  void setGridColor(float r, float g, float b);
150 
151  bool isBlending() const {return blending_;}
152  bool isMapRendering() const {return mapRendering_;}
153  bool isMeshRendering() const {return meshRendering_;}
155  float getPointSize() const {return pointSize_;}
156  bool isLighting() const {return lighting_;}
157  bool isBackfaceCulling() const {return backfaceCulling_;}
158  bool isWireframe() const {return wireFrame_;}
159 
161 
162  private:
163  // Camera object that allows user to use touch input to interact with.
165 
166  // Device axis (in device frame of reference).
168 
169  // Device frustum.
171 
172  // Ground grid.
174 
175  // Bounding box
177 
178  // Trace of pose data.
185 
186  std::map<int, tango_gl::Axis*> markers_;
187 
189 
190  std::map<int, PointCloudDrawable*> pointClouds_;
191 
193 
194  // Shader to display point cloud.
196 
197  bool blending_;
201  float pointSize_;
203  bool lighting_;
206  float r_;
207  float g_;
208  float b_;
211  GLuint depthTexture_; // 0=objects+occlusion
212  GLsizei screenWidth_;
213  GLsizei screenHeight_;
215  cv::Point2f doubleTapPos_;
216 };
217 
218 #endif // TANGO_POINT_CLOUD_SCENE_H_
w
RowVector3d w
Scene::hasTexture
bool hasTexture(int id) const
Definition: scene.cpp:918
Scene::isMeshTexturing
bool isMeshTexturing() const
Definition: scene.h:154
Scene::fboId_
GLuint fboId_
Definition: scene.h:209
Scene::currentPose_
rtabmap::Transform * currentPose_
Definition: scene.h:192
Scene::OnTouchEvent
void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event, float x0, float y0, float x1, float y1)
Definition: scene.cpp:696
Scene::Render
int Render(const float *uvsTransformed=0, glm::mat4 arViewMatrix=glm::mat4(0), glm::mat4 arProjectionMatrix=glm::mat4(0), const rtabmap::Mesh &occlusionMesh=rtabmap::Mesh(), bool mapping=false)
Definition: scene.cpp:385
Scene::b_
float b_
Definition: scene.h:208
Scene::getScreenRotation
rtabmap::ScreenRotation getScreenRotation() const
Definition: scene.h:66
Scene
Definition: scene.h:49
background_renderer.h
Scene::setScreenRotation
void setScreenRotation(rtabmap::ScreenRotation colorCameraToDisplayRotation)
Definition: scene.h:67
Scene::screenWidth_
GLsizei screenWidth_
Definition: scene.h:212
CameraMobile.h
Scene::pointClouds_
std::map< int, PointCloudDrawable * > pointClouds_
Definition: scene.h:190
Scene::graphVisible_
bool graphVisible_
Definition: scene.h:181
Scene::getViewPortWidth
int getViewPortWidth() const
Definition: scene.h:63
Scene::clear
void clear()
Definition: scene.cpp:190
b
Array< int, 3, 1 > b
Scene::rboId_
GLuint rboId_
Definition: scene.h:210
Scene::setGridColor
void setGridColor(float r, float g, float b)
Definition: scene.cpp:955
Scene::setGridVisible
void setGridVisible(bool visible)
Definition: scene.cpp:733
bounding_box_drawable.h
Scene::wireFrame_
bool wireFrame_
Definition: scene.h:205
h
const double h
Scene::graph_shader_program_
GLuint graph_shader_program_
Definition: scene.h:195
Scene::screenHeight_
GLsizei screenHeight_
Definition: scene.h:213
size
Index size
Scene::r_
float r_
Definition: scene.h:206
Scene::isMeshRendering
bool isMeshRendering() const
Definition: scene.h:153
Scene::~Scene
~Scene()
Definition: scene.cpp:111
Scene::isMapRendering
bool isMapRendering() const
Definition: scene.h:152
Scene::frustum_
tango_gl::Frustum * frustum_
Definition: scene.h:170
Scene::backfaceCulling_
bool backfaceCulling_
Definition: scene.h:204
Scene::addMesh
void addMesh(int id, const rtabmap::Mesh &mesh, const rtabmap::Transform &pose, bool createWireframe=false)
Definition: scene.cpp:816
Transform.h
trace.h
Scene::g_
float g_
Definition: scene.h:207
util.h
Scene::setWireframe
void setWireframe(bool enabled)
Definition: scene.h:147
tango_gl::GestureCamera::GetCameraType
CameraType GetCameraType() const
Definition: gesture_camera.h:68
tango_gl::Axis
Definition: axis.h:23
Scene::updateCloudPolygons
void updateCloudPolygons(int id, const std::vector< pcl::Vertices > &polygons)
Definition: scene.cpp:928
grid.h
Scene::SetupViewPort
void SetupViewPort(int w, int h)
Definition: scene.cpp:219
Scene::getAddedClouds
std::set< int > getAddedClouds() const
Definition: scene.cpp:923
Scene::getAddedMarkers
std::set< int > getAddedMarkers() const
Definition: scene.cpp:791
Scene::setBackfaceCulling
void setBackfaceCulling(bool enabled)
Definition: scene.h:146
tango_gl::GestureCamera
Definition: gesture_camera.h:26
Scene::setFOV
void setFOV(float angle)
Definition: scene.cpp:669
Scene::setMeshRendering
void setMeshRendering(bool enabled, bool withTexture)
Definition: scene.h:140
Scene::removeMarker
void removeMarker(int id)
Definition: scene.cpp:782
glm::detail::tmat4x4
Definition: type_mat.hpp:47
BackgroundRenderer
Definition: background_renderer.h:52
Scene::getViewPortHeight
int getViewPortHeight() const
Definition: scene.h:64
Scene::lighting_
bool lighting_
Definition: scene.h:203
graph_drawable.h
rtabmap::Mesh
Definition: util.h:165
Scene::updateGains
void updateGains(int id, float gainR, float gainG, float gainB)
Definition: scene.cpp:946
tango_gl::GestureCamera::CameraType
CameraType
Definition: gesture_camera.h:28
Scene::isWireframe
bool isWireframe() const
Definition: scene.h:158
Scene::meshRenderingTexture_
bool meshRenderingTexture_
Definition: scene.h:200
Scene::isBlending
bool isBlending() const
Definition: scene.h:151
Scene::blending_
bool blending_
Definition: scene.h:197
axis.h
Scene::frustumVisible_
bool frustumVisible_
Definition: scene.h:184
GLuint
unsigned int GLuint
Definition: dummy.cpp:78
Scene::Scene
Scene()
Definition: scene.cpp:71
GraphDrawable
Definition: graph_drawable.h:43
g
float g
Scene::background_renderer_
BackgroundRenderer * background_renderer_
Definition: scene.h:160
BoundingBoxDrawable
Definition: bounding_box_drawable.h:33
Scene::isBackfaceCulling
bool isBackfaceCulling() const
Definition: scene.h:157
frustum.h
Scene::setMapRendering
void setMapRendering(bool enabled)
Definition: scene.h:139
Scene::markers_
std::map< int, tango_gl::Axis * > markers_
Definition: scene.h:186
Scene::GetCameraPose
rtabmap::Transform GetCameraPose() const
Definition: scene.h:87
Scene::addMarker
void addMarker(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:749
tango_gl::GestureCamera::TouchEvent
TouchEvent
Definition: gesture_camera.h:36
Scene::setLighting
void setLighting(bool enabled)
Definition: scene.h:145
tango_gl::Trace
Definition: trace.h:23
Scene::DeleteResources
void DeleteResources()
Definition: scene.cpp:154
Scene::grid_
tango_gl::Grid * grid_
Definition: scene.h:173
Scene::setOrthoCropFactor
void setOrthoCropFactor(float value)
Definition: scene.cpp:673
Scene::InitGLContent
void InitGLContent()
Definition: scene.cpp:118
Scene::depthTexture_
GLuint depthTexture_
Definition: scene.h:211
Scene::setBlending
void setBlending(bool enabled)
Definition: scene.h:138
Scene::doubleTapPos_
cv::Point2f doubleTapPos_
Definition: scene.h:215
Scene::setBackgroundColor
void setBackgroundColor(float r, float g, float b)
Definition: scene.h:148
glm::angle
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
Scene::addCloud
void addCloud(int id, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices, const rtabmap::Transform &pose)
Definition: scene.cpp:796
tango_gl::Frustum
Definition: frustum.h:23
Scene::doubleTapOn_
bool doubleTapOn_
Definition: scene.h:214
Scene::setCloudVisible
void setCloudVisible(int id, bool visible)
Definition: scene.cpp:899
Scene::graph_
GraphDrawable * graph_
Definition: scene.h:180
camera.h
Scene::setPointSize
void setPointSize(float size)
Definition: scene.h:141
Scene::SetCameraPose
void SetCameraPose(const rtabmap::Transform &pose)
Definition: scene.cpp:659
Scene::hasCloud
bool hasCloud(int id) const
Definition: scene.cpp:908
Scene::mapRendering_
bool mapRendering_
Definition: scene.h:198
rtabmap::Transform
Definition: Transform.h:41
tango_gl::Grid
Definition: grid.h:23
Scene::SetCameraType
void SetCameraType(tango_gl::GestureCamera::CameraType camera_type)
Definition: scene.cpp:655
Scene::updateGraph
void updateGraph(const std::map< int, rtabmap::Transform > &poses, const std::multimap< int, rtabmap::Link > &links)
Definition: scene.cpp:717
rtabmap::ScreenRotation
ScreenRotation
Definition: util.h:194
Scene::updateMesh
void updateMesh(int id, const rtabmap::Mesh &mesh)
Definition: scene.cpp:937
Scene::axis_
tango_gl::Axis * axis_
Definition: scene.h:167
transform.h
Scene::trace_
tango_gl::Trace * trace_
Definition: scene.h:179
Scene::color_camera_to_display_rotation_
rtabmap::ScreenRotation color_camera_to_display_rotation_
Definition: scene.h:188
Scene::setMarkerPose
void setMarkerPose(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:765
Scene::setTraceVisible
void setTraceVisible(bool visible)
Definition: scene.cpp:738
Scene::pointSize_
float pointSize_
Definition: scene.h:201
color.h
Scene::setFrustumVisible
void setFrustumVisible(bool visible)
Definition: scene.cpp:743
Scene::setGridRotation
void setGridRotation(float angleDeg)
Definition: scene.cpp:677
Scene::getPointSize
float getPointSize() const
Definition: scene.h:155
Scene::meshRendering_
bool meshRendering_
Definition: scene.h:199
gesture_camera.h
Scene::setGraphVisible
void setGraphVisible(bool visible)
Definition: scene.cpp:728
Scene::gesture_camera_
tango_gl::GestureCamera * gesture_camera_
Definition: scene.h:164
Scene::hasMesh
bool hasMesh(int id) const
Definition: scene.cpp:913
Scene::GetOpenGLCameraPose
rtabmap::Transform GetOpenGLCameraPose(float *fov=0) const
Definition: scene.cpp:687
Scene::box_
BoundingBoxDrawable * box_
Definition: scene.h:176
Scene::gridVisible_
bool gridVisible_
Definition: scene.h:182
Scene::isLighting
bool isLighting() const
Definition: scene.h:156
Scene::traceVisible_
bool traceVisible_
Definition: scene.h:183
Scene::boundingBoxRendering_
bool boundingBoxRendering_
Definition: scene.h:202
Scene::GetCameraType
tango_gl::GestureCamera::CameraType GetCameraType() const
Definition: scene.h:84
Scene::hasMarker
bool hasMarker(int id) const
Definition: scene.cpp:778
Scene::setCloudPose
void setCloudPose(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:889
point_cloud_drawable.h


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