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


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:35:00