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 <tango_client_api.h> // NOLINT
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 
42 #include <pcl/point_cloud.h>
43 #include <pcl/point_types.h>
44 
45 // Scene provides OpenGL drawable objects and renders them for visualization.
46 class Scene {
47  public:
48  // Constructor and destructor.
49  Scene();
50  ~Scene();
51 
52  // Allocate OpenGL resources for rendering.
53  void InitGLContent();
54 
55  // Release non-OpenGL allocated resources.
56  void DeleteResources();
57 
58  // Setup GL view port.
59  void SetupViewPort(int w, int h);
60  int getViewPortWidth() const {return screenWidth_;}
61  int getViewPortHeight() const {return screenHeight_;}
62 
63  void setScreenRotation(TangoSupportRotation colorCameraToDisplayRotation) {color_camera_to_display_rotation_ = colorCameraToDisplayRotation;}
64 
65  void clear(); // removed all point clouds
66 
67  // Render loop.
68  // @param: cur_pose_transformation, latest pose's transformation.
69  // @param: point_cloud_transformation, pose transformation at point cloud
70  // frame's timestamp.
71  // @param: point_cloud_vertices, point cloud's vertices of the current point
72  // frame.
73  int Render();
74 
75  // Set render camera's viewing angle, first person, third person or top down.
76  //
77  // @param: camera_type, camera type includes first person, third person and
78  // top down
80 
81  void SetCameraPose(const rtabmap::Transform & pose);
83  rtabmap::Transform GetOpenGLCameraPose(float * fov = 0) const;
84 
85  // Touch event passed from android activity. This function only support two
86  // touches.
87  //
88  // @param: touch_count, total count for touches.
89  // @param: event, touch event of current touch.
90  // @param: x0, normalized touch location for touch 0 on x axis.
91  // @param: y0, normalized touch location for touch 0 on y axis.
92  // @param: x1, normalized touch location for touch 1 on x axis.
93  // @param: y1, normalized touch location for touch 1 on y axis.
94  void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event,
95  float x0, float y0, float x1, float y1);
96 
97  void updateGraph(
98  const std::map<int, rtabmap::Transform> & poses,
99  const std::multimap<int, rtabmap::Link> & links);
100 
101  void setGraphVisible(bool visible);
102  void setGridVisible(bool visible);
103  void setTraceVisible(bool visible);
104 
105  void addCloud(
106  int id,
107  const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
108  const pcl::IndicesPtr & indices,
109  const rtabmap::Transform & pose);
110  void addMesh(
111  int id,
112  const Mesh & mesh,
113  const rtabmap::Transform & pose,
114  bool createWireframe = false);
115 
116  void setCloudPose(int id, const rtabmap::Transform & pose);
117  void setCloudVisible(int id, bool visible);
118  bool hasCloud(int id) const;
119  bool hasMesh(int id) const;
120  bool hasTexture(int id) const;
121  std::set<int> getAddedClouds() const;
122  void updateCloudPolygons(int id, const std::vector<pcl::Vertices> & polygons);
123  void updateMesh(int id, const Mesh & mesh);
124  void updateGains(int id, float gainR, float gainG, float gainB);
125 
126  void setBlending(bool enabled) {blending_ = enabled;}
127  void setMapRendering(bool enabled) {mapRendering_ = enabled;}
128  void setMeshRendering(bool enabled, bool withTexture) {meshRendering_ = enabled; meshRenderingTexture_ = withTexture;}
129  void setPointSize(float size) {pointSize_ = size;}
130  void setFOV(float angle);
131  void setOrthoCropFactor(float value);
132  void setGridRotation(float angleDeg);
133  void setLighting(bool enabled) {lighting_ = enabled;}
134  void setBackfaceCulling(bool enabled) {backfaceCulling_ = enabled;}
135  void setWireframe(bool enabled) {wireFrame_ = enabled;}
136  void setBackgroundColor(float r, float g, float b) {r_=r; g_=g; b_=b;} // 0.0f <> 1.0f
137  void setGridColor(float r, float g, float b);
138 
139  bool isBlending() const {return blending_;}
140  bool isMapRendering() const {return mapRendering_;}
141  bool isMeshRendering() const {return meshRendering_;}
143  float getPointSize() const {return pointSize_;}
144  bool isLighting() const {return lighting_;}
145  bool isBackfaceCulling() const {return backfaceCulling_;}
146 
147  private:
148  // Camera object that allows user to use touch input to interact with.
150 
151  // Device axis (in device frame of reference).
153 
154  // Device frustum.
156 
157  // Ground grid.
159 
160  // Bounding box
162 
163  // Trace of pose data.
169 
170  TangoSupportRotation color_camera_to_display_rotation_;
171 
172  std::map<int, PointCloudDrawable*> pointClouds_;
173 
175 
176  // Shader to display point cloud.
178 
179  bool blending_;
183  float pointSize_;
185  bool lighting_;
188  float r_;
189  float g_;
190  float b_;
193  GLsizei screenWidth_;
194  GLsizei screenHeight_;
196  cv::Point2f doubleTapPos_;
197 };
198 
199 #endif // TANGO_POINT_CLOUD_SCENE_H_
float b_
Definition: scene.h:190
int getViewPortWidth() const
Definition: scene.h:60
float g_
Definition: scene.h:189
void setGridVisible(bool visible)
Definition: scene.cpp:640
BoundingBoxDrawable * box_
Definition: scene.h:161
bool gridVisible_
Definition: scene.h:167
void setScreenRotation(TangoSupportRotation colorCameraToDisplayRotation)
Definition: scene.h:63
bool isMeshTexturing() const
Definition: scene.h:142
bool isBlending() const
Definition: scene.h:139
void updateCloudPolygons(int id, const std::vector< pcl::Vertices > &polygons)
Definition: scene.cpp:783
void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event, float x0, float y0, float x1, float y1)
Definition: scene.cpp:595
bool wireFrame_
Definition: scene.h:187
void SetupViewPort(int w, int h)
Definition: scene.cpp:208
rtabmap::Transform GetOpenGLCameraPose(float *fov=0) const
Definition: scene.cpp:586
void setCloudPose(int id, const rtabmap::Transform &pose)
Definition: scene.cpp:744
void setFOV(float angle)
Definition: scene.cpp:568
std::map< int, PointCloudDrawable * > pointClouds_
Definition: scene.h:172
bool backfaceCulling_
Definition: scene.h:186
int getViewPortHeight() const
Definition: scene.h:61
void setGridColor(float r, float g, float b)
Definition: scene.cpp:810
void setWireframe(bool enabled)
Definition: scene.h:135
GLuint fboId_
Definition: scene.h:191
float getPointSize() const
Definition: scene.h:143
bool isBackfaceCulling() const
Definition: scene.h:145
bool isMapRendering() const
Definition: scene.h:140
bool hasMesh(int id) const
Definition: scene.cpp:768
void setBackfaceCulling(bool enabled)
Definition: scene.h:134
float r_
Definition: scene.h:188
~Scene()
Definition: scene.cpp:108
GLsizei screenWidth_
Definition: scene.h:193
Definition: util.h:147
bool graphVisible_
Definition: scene.h:166
void clear()
Definition: scene.cpp:184
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
GLsizei screenHeight_
Definition: scene.h:194
bool hasCloud(int id) const
Definition: scene.cpp:763
bool meshRenderingTexture_
Definition: scene.h:182
void setMeshRendering(bool enabled, bool withTexture)
Definition: scene.h:128
tango_gl::Frustum * frustum_
Definition: scene.h:155
unsigned int GLuint
Definition: dummy.cpp:78
void setLighting(bool enabled)
Definition: scene.h:133
void DeleteResources()
Definition: scene.cpp:151
void setOrthoCropFactor(float value)
Definition: scene.cpp:572
bool lighting_
Definition: scene.h:185
void updateGains(int id, float gainR, float gainG, float gainB)
Definition: scene.cpp:801
void InitGLContent()
Definition: scene.cpp:114
bool isLighting() const
Definition: scene.h:144
Scene()
Definition: scene.cpp:71
GraphDrawable * graph_
Definition: scene.h:165
void SetCameraPose(const rtabmap::Transform &pose)
Definition: scene.cpp:561
void setMapRendering(bool enabled)
Definition: scene.h:127
void setBlending(bool enabled)
Definition: scene.h:126
GLuint depthTexture_
Definition: scene.h:192
bool mapRendering_
Definition: scene.h:180
void addCloud(int id, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices, const rtabmap::Transform &pose)
Definition: scene.cpp:651
void setBackgroundColor(float r, float g, float b)
Definition: scene.h:136
bool blending_
Definition: scene.h:179
bool doubleTapOn_
Definition: scene.h:195
void setCloudVisible(int id, bool visible)
Definition: scene.cpp:754
void updateGraph(const std::map< int, rtabmap::Transform > &poses, const std::multimap< int, rtabmap::Link > &links)
Definition: scene.cpp:616
bool isMeshRendering() const
Definition: scene.h:141
void setPointSize(float size)
Definition: scene.h:129
std::set< int > getAddedClouds() const
Definition: scene.cpp:778
bool hasTexture(int id) const
Definition: scene.cpp:773
void updateMesh(int id, const Mesh &mesh)
Definition: scene.cpp:792
cv::Point2f doubleTapPos_
Definition: scene.h:196
tango_gl::Trace * trace_
Definition: scene.h:164
tango_gl::Grid * grid_
Definition: scene.h:158
tango_gl::Axis * axis_
Definition: scene.h:152
void setTraceVisible(bool visible)
Definition: scene.cpp:645
void SetCameraType(tango_gl::GestureCamera::CameraType camera_type)
Definition: scene.cpp:557
rtabmap::Transform GetCameraPose() const
Definition: scene.h:82
Definition: scene.h:46
bool meshRendering_
Definition: scene.h:181
void setGraphVisible(bool visible)
Definition: scene.cpp:635
void addMesh(int id, const Mesh &mesh, const rtabmap::Transform &pose, bool createWireframe=false)
Definition: scene.cpp:671
bool boundingBoxRendering_
Definition: scene.h:184
void setGridRotation(float angleDeg)
Definition: scene.cpp:576
int Render()
Definition: scene.cpp:362
tango_gl::GestureCamera * gesture_camera_
Definition: scene.h:149
TangoSupportRotation color_camera_to_display_rotation_
Definition: scene.h:170
float pointSize_
Definition: scene.h:183
bool traceVisible_
Definition: scene.h:168
rtabmap::Transform * currentPose_
Definition: scene.h:174
GLuint graph_shader_program_
Definition: scene.h:177


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:32