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_
float b_
Definition: scene.h:208
void addMesh(int id, const rtabmap::Mesh &mesh, const rtabmap::Transform &pose, bool createWireframe=false)
Definition: scene.cpp:816
float g_
Definition: scene.h:207
void setGridVisible(bool visible)
Definition: scene.cpp:733
BoundingBoxDrawable * box_
Definition: scene.h:176
bool gridVisible_
Definition: scene.h:182
void updateCloudPolygons(int id, const std::vector< pcl::Vertices > &polygons)
Definition: scene.cpp:928
void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event, float x0, float y0, float x1, float y1)
Definition: scene.cpp:696
bool wireFrame_
Definition: scene.h:205
void SetupViewPort(int w, int h)
Definition: scene.cpp:219
bool hasMarker(int id) const
Definition: scene.cpp:778
std::set< int > getAddedMarkers() const
Definition: scene.cpp:791
CameraType GetCameraType() const
void setCloudPose(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:889
void setFOV(float angle)
Definition: scene.cpp:669
std::map< int, PointCloudDrawable * > pointClouds_
Definition: scene.h:190
bool backfaceCulling_
Definition: scene.h:204
int getViewPortWidth() const
Definition: scene.h:63
bool hasTexture(int id) const
Definition: scene.cpp:918
void setGridColor(float r, float g, float b)
Definition: scene.cpp:955
void setWireframe(bool enabled)
Definition: scene.h:147
GLuint fboId_
Definition: scene.h:209
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
std::set< int > getAddedClouds() const
Definition: scene.cpp:923
void setBackfaceCulling(bool enabled)
Definition: scene.h:146
float r_
Definition: scene.h:206
bool isMeshRendering() const
Definition: scene.h:153
~Scene()
Definition: scene.cpp:111
GLsizei screenWidth_
Definition: scene.h:212
void setScreenRotation(rtabmap::ScreenRotation colorCameraToDisplayRotation)
Definition: scene.h:67
bool isMapRendering() const
Definition: scene.h:152
bool graphVisible_
Definition: scene.h:181
void clear()
Definition: scene.cpp:190
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
int getViewPortHeight() const
Definition: scene.h:64
BackgroundRenderer * background_renderer_
Definition: scene.h:160
GLsizei screenHeight_
Definition: scene.h:213
bool meshRenderingTexture_
Definition: scene.h:200
bool isBlending() const
Definition: scene.h:151
void setMeshRendering(bool enabled, bool withTexture)
Definition: scene.h:140
bool frustumVisible_
Definition: scene.h:184
tango_gl::Frustum * frustum_
Definition: scene.h:170
void removeMarker(int id)
Definition: scene.cpp:782
unsigned int GLuint
Definition: dummy.cpp:78
void setLighting(bool enabled)
Definition: scene.h:145
void DeleteResources()
Definition: scene.cpp:154
void setOrthoCropFactor(float value)
Definition: scene.cpp:673
bool lighting_
Definition: scene.h:203
void updateGains(int id, float gainR, float gainG, float gainB)
Definition: scene.cpp:946
std::map< int, tango_gl::Axis * > markers_
Definition: scene.h:186
void InitGLContent()
Definition: scene.cpp:118
bool isWireframe() const
Definition: scene.h:158
rtabmap::Transform GetCameraPose() const
Definition: scene.h:87
Scene()
Definition: scene.cpp:71
GraphDrawable * graph_
Definition: scene.h:180
void SetCameraPose(const rtabmap::Transform &pose)
Definition: scene.cpp:659
void setMapRendering(bool enabled)
Definition: scene.h:139
void setBlending(bool enabled)
Definition: scene.h:138
GLuint depthTexture_
Definition: scene.h:211
bool mapRendering_
Definition: scene.h:198
void addCloud(int id, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices, const rtabmap::Transform &pose)
Definition: scene.cpp:796
void setBackgroundColor(float r, float g, float b)
Definition: scene.h:148
bool blending_
Definition: scene.h:197
bool doubleTapOn_
Definition: scene.h:214
void setCloudVisible(int id, bool visible)
Definition: scene.cpp:899
void updateGraph(const std::map< int, rtabmap::Transform > &poses, const std::multimap< int, rtabmap::Link > &links)
Definition: scene.cpp:717
void setPointSize(float size)
Definition: scene.h:141
bool isBackfaceCulling() const
Definition: scene.h:157
bool hasCloud(int id) const
Definition: scene.cpp:908
cv::Point2f doubleTapPos_
Definition: scene.h:215
tango_gl::Trace * trace_
Definition: scene.h:179
rtabmap::ScreenRotation color_camera_to_display_rotation_
Definition: scene.h:188
void addMarker(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:749
void setFrustumVisible(bool visible)
Definition: scene.cpp:743
tango_gl::Grid * grid_
Definition: scene.h:173
tango_gl::Axis * axis_
Definition: scene.h:167
void setTraceVisible(bool visible)
Definition: scene.cpp:738
void SetCameraType(tango_gl::GestureCamera::CameraType camera_type)
Definition: scene.cpp:655
Definition: scene.h:49
float getPointSize() const
Definition: scene.h:155
bool meshRendering_
Definition: scene.h:199
void updateMesh(int id, const rtabmap::Mesh &mesh)
Definition: scene.cpp:937
void setGraphVisible(bool visible)
Definition: scene.cpp:728
bool hasMesh(int id) const
Definition: scene.cpp:913
void setMarkerPose(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:765
bool isMeshTexturing() const
Definition: scene.h:154
bool boundingBoxRendering_
Definition: scene.h:202
tango_gl::GestureCamera::CameraType GetCameraType() const
Definition: scene.h:84
void setGridRotation(float angleDeg)
Definition: scene.cpp:677
rtabmap::ScreenRotation getScreenRotation() const
Definition: scene.h:66
ScreenRotation
Definition: util.h:194
tango_gl::GestureCamera * gesture_camera_
Definition: scene.h:164
rtabmap::Transform GetOpenGLCameraPose(float *fov=0) const
Definition: scene.cpp:687
GLuint rboId_
Definition: scene.h:210
float pointSize_
Definition: scene.h:201
bool isLighting() const
Definition: scene.h:156
bool traceVisible_
Definition: scene.h:183
rtabmap::Transform * currentPose_
Definition: scene.h:192
GLuint graph_shader_program_
Definition: scene.h:195


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:30