27 #include <pcl/common/transforms.h> 28 #include <pcl/common/common.h> 51 "precision mediump float;\n" 52 "precision mediump int;\n" 53 "attribute vec3 vertex;\n" 54 "uniform vec3 color;\n" 56 "varying vec3 v_color;\n" 58 " gl_Position = mvp*vec4(vertex.x, vertex.y, vertex.z, 1.0);\n" 62 "precision mediump float;\n" 63 "precision mediump int;\n" 64 "varying vec3 v_color;\n" 66 " gl_FragColor = vec4(v_color.z, v_color.y, v_color.x, 1.0);\n" 72 background_renderer_(0),
83 frustumVisible_(
true),
86 graph_shader_program_(0),
90 meshRenderingTexture_(
true),
92 boundingBoxRendering_(
false),
94 backfaceCulling_(
true),
155 LOGI(
"Scene::DeleteResources()");
177 glDeleteFramebuffers(1, &
fboId_);
189 LOGI(
"Scene::clear()");
194 for(std::map<int, tango_gl::Axis*>::iterator iter=
markers_.begin(); iter!=
markers_.end(); ++iter)
218 LOGE(
"Setup graphic height not valid");
222 glViewport(0, 0, w, h);
227 glDeleteFramebuffers(1, &
fboId_);
236 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
237 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
238 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
239 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
240 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
NULL);
241 glBindTexture(GL_TEXTURE_2D, 0);
245 glGenFramebuffers(1, &
fboId_);
246 glBindFramebuffer(GL_FRAMEBUFFER,
fboId_);
249 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
depthTexture_, 0);
251 GLuint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
252 if ( status != GL_FRAMEBUFFER_COMPLETE)
254 LOGE(
"Frame buffer cannot be generated! Status: %in", status);
256 glBindFramebuffer(GL_FRAMEBUFFER,0);
265 std::vector<glm::vec4> planes(6);
269 planes[0].x = mat[0][3] + mat[0][0];
270 planes[0].y = mat[1][3] + mat[1][0];
271 planes[0].z = mat[2][3] + mat[2][0];
272 planes[0].w = mat[3][3] + mat[3][0];
276 planes[1].x = mat[0][3] - mat[0][0];
277 planes[1].y = mat[1][3] - mat[1][0];
278 planes[1].z = mat[2][3] - mat[2][0];
279 planes[1].w = mat[3][3] - mat[3][0];
283 planes[2].x = mat[0][3] + mat[0][1];
284 planes[2].y = mat[1][3] + mat[1][1];
285 planes[2].z = mat[2][3] + mat[2][1];
286 planes[2].w = mat[3][3] + mat[3][1];
290 planes[3].x = mat[0][3] - mat[0][1];
291 planes[3].y = mat[1][3] - mat[1][1];
292 planes[3].z = mat[2][3] - mat[2][1];
293 planes[3].w = mat[3][3] - mat[3][1];
297 planes[4].x = mat[0][3] + mat[0][2];
298 planes[4].y = mat[1][3] + mat[1][2];
299 planes[4].z = mat[2][3] + mat[2][2];
300 planes[4].w = mat[3][3] + mat[3][2];
304 planes[5].x = mat[0][3] - mat[0][2];
305 planes[5].y = mat[1][3] - mat[1][2];
306 planes[5].z = mat[2][3] - mat[2][2];
307 planes[5].w = mat[3][3] - mat[3][2];
311 for(
unsigned int i=0;i<planes.size(); ++i)
315 float d =
std::sqrt(planes[i].x * planes[i].x + planes[i].y * planes[i].y + planes[i].z * planes[i].z);
335 const std::vector<glm::vec4> &planes,
336 const pcl::PointXYZ &boxMin,
337 const pcl::PointXYZ &boxMax)
340 const pcl::PointXYZ * box[] = {&boxMin, &boxMax};
343 for (
unsigned int i = 0; i < planes.size(); ++i)
351 const int px = p.
x > 0.0f?1:0;
352 const int py = p.
y > 0.0f?1:0;
353 const int pz = p.
z > 0.0f?1:0;
361 (p.
z*box[pz]->z) + p.
w;
364 if (dp < 0) {
return false; }
401 bool renderBackgroundCamera =
406 if(renderBackgroundCamera)
408 projectionMatrix = arProjectionMatrix;
409 viewMatrix = arViewMatrix;
415 0.0
f, 0.0
f, 1.0
f, 0.0
f,
416 0.0
f, 1.0
f, 0.0
f, 0.0
f,
417 -1.0
f, 0.0
f, 0.0
f, 0.0
f);
421 std::vector<PointCloudDrawable*> cloudsToDraw(
pointClouds_.size());
430 if(iter->second->isVisible())
433 iter->second->aabbMinWorld(),
434 iter->second->aabbMaxWorld()))
436 cloudsToDraw[oi++] = iter->second;
440 cloudsToDraw.resize(oi);
443 glEnable(GL_DEPTH_TEST);
444 glDepthFunc(GL_LESS);
445 glDepthMask(GL_TRUE);
446 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
447 glDisable (GL_BLEND);
448 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
452 glEnable(GL_CULL_FACE);
456 glDisable(GL_CULL_FACE);
462 if(onlineBlending &&
fboId_)
465 glBindFramebuffer(GL_FRAMEBUFFER,
fboId_);
468 glClearColor(1, 1, 1, 1);
469 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
471 if(renderBackgroundCamera)
474 drawable.
Render(projectionMatrix, viewMatrix,
true,
pointSize_,
false,
false, 999.0
f);
479 for(std::vector<PointCloudDrawable*>::const_iterator iter=cloudsToDraw.begin(); iter!=cloudsToDraw.end(); ++iter)
487 glBindFramebuffer(GL_FRAMEBUFFER, 0);
488 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
493 glClearColor(0, 0, 0, 0);
494 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
496 for(std::vector<PointCloudDrawable*>::const_iterator iter=cloudsToDraw.begin(); iter!=cloudsToDraw.end(); ++iter)
499 (*iter)->Render(projectionMatrix, viewMatrix,
meshRendering_,
pointSize_*10.0
f,
false,
false, 999.0f, 0, 0, 0, 0, 0,
true);
504 float fromFixed = 256.0f/255.0f;
505 float zValueF = float(zValue[0]/255.0
f)*fromFixed + float(zValue[1]/255.0
f)*fromFixed/255.0f + float(zValue[2]/255.0
f)*fromFixed/65025.0f + float(zValue[3]/255.0
f)*fromFixed/160581375.0f;
509 zValueF = zValueF*2.0-1.0;
517 glClearColor(
r_,
g_,
b_, 1.0
f);
518 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
520 if(renderBackgroundCamera)
541 glm::vec3 positionCamera(cameraFrame.
x(), cameraFrame.
y(), cameraFrame.
z());
543 glm::quat rotationCamera(quatCamera.w(), quatCamera.x(), quatCamera.y(), quatCamera.z());
574 for(std::vector<PointCloudDrawable*>::const_iterator iter=cloudsToDraw.begin(); iter!=cloudsToDraw.end(); ++iter)
584 Eigen::Vector3f cloudToCamera(
587 cloud->
getPose().
z() - openglCamera.
z());
588 float distanceToCameraSqr = cloudToCamera[0]*cloudToCamera[0] + cloudToCamera[1]*cloudToCamera[1] + cloudToCamera[2]*cloudToCamera[2];
590 cloud->
Render(projectionMatrix, viewMatrix,
meshRendering_,
pointSize_,
meshRenderingTexture_,
lighting_, distanceToCameraSqr, onlineBlending?
depthTexture_:0,
screenWidth_,
screenHeight_,
gesture_camera_->
getNearClipPlane(),
gesture_camera_->
getFarClipPlane(),
false,
wireFrame_);
595 glDisable (GL_BLEND);
596 glDepthMask(GL_TRUE);
600 for(std::map<int, tango_gl::Axis*>::const_iterator iter=
markers_.begin(); iter!=
markers_.end(); ++iter)
602 iter->second->Render(projectionMatrix, viewMatrix);
605 return (
int)cloudsToDraw.size();
651 float y0,
float x1,
float y1) {
671 const std::map<int, rtabmap::Transform> & poses,
672 const std::multimap<int, rtabmap::Link> & links)
714 LOGI(
"add marker %d",
id);
715 std::map<int, tango_gl::Axis*>::iterator iter=
markers_.find(
id);
722 markers_.insert(std::make_pair(
id, drawable));
729 std::map<int, tango_gl::Axis*>::iterator iter=
markers_.find(
id);
735 iter->second->SetPosition(position);
736 iter->second->SetRotation(
rotation);
745 std::map<int, tango_gl::Axis*>::iterator iter=
markers_.find(
id);
759 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
760 const pcl::IndicesPtr & indices,
763 LOGI(
"add cloud %d (%d points %d indices)",
id, (
int)cloud->size(), indices.get()?(int)indices->size():0);
764 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
781 bool createWireframe)
783 LOGI(
"add mesh %d",
id);
784 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
803 for(
unsigned int i=0; i<mesh.
polygons.size(); ++i)
805 for(
unsigned int j=0; j<mesh.
polygons[i].vertices.size(); ++j)
817 if(mesh.
cloud->isOrganized())
819 for(
unsigned int i=0; i<mesh.
indices->size(); ++i)
830 for(
unsigned int i=0; i<mesh.
cloud->size(); ++i)
845 LOGD(
"compute min height %f s", time.
ticks());
853 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
856 iter->second->setPose(pose);
862 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
865 iter->second->setVisible(visible);
891 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
894 iter->second->updatePolygons(polygons);
900 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
903 iter->second->updateMesh(mesh);
909 std::map<int, PointCloudDrawable*>::iterator iter=
pointClouds_.find(
id);
912 iter->second->setGains(gainR, gainG, gainB);
void Render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix)
static void releaseShaderPrograms()
const glm::vec3 kHeightOffset
void addMesh(int id, const rtabmap::Mesh &mesh, const rtabmap::Transform &pose, bool createWireframe=false)
void setGridVisible(bool visible)
BoundingBoxDrawable * box_
0 degree rotation (natural orientation)
rtabmap::Transform glmToTransform(const glm::mat4 &mat)
void updateCloudPolygons(int id, const std::vector< pcl::Vertices > &polygons)
void OnTouchEvent(int touch_count, tango_gl::GestureCamera::TouchEvent event, float x0, float y0, float x1, float y1)
void SetLineWidth(const float pixels)
cv::Point3f RTABMAP_EXP transformPoint(const cv::Point3f &pt, const Transform &transform)
void SetupViewPort(int w, int h)
rtabmap::Transform GetOpenGLCameraPose(float *fov=0) const
static const rtabmap::Transform optical_T_opengl(1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f)
std::set< int > getAddedMarkers() const
void setCloudPose(int id, const rtabmap::Transform &pose)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr cloud
void SetCameraType(CameraType camera_index)
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
std::map< int, PointCloudDrawable * > pointClouds_
void setPose(const rtabmap::Transform &pose)
void setGridColor(float r, float g, float b)
const glm::vec3 kFrustumScale
highp_quat quat
Quaternion of default single-precision floating-point numbers.
std::set< K > uKeysSet(const std::map< K, V > &m)
bool hasMesh(int id) const
void SetWindowSize(const float width, const float height)
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
BackgroundRenderer * background_renderer_
GLuint CreateProgram(const char *vertex_source, const char *fragment_source)
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
bool hasCloud(int id) const
bool meshRenderingTexture_
std::vector< pcl::Vertices > polygons
tango_gl::Frustum * frustum_
void removeMarker(int id)
const std::string kGraphVertexShader
void setOrthoCropFactor(float value)
float getFarClipPlane() const
#define UASSERT(condition)
Wrappers of STL for convenient functions.
void updateGains(int id, float gainR, float gainG, float gainB)
GLM_FUNC_DECL genType normalize(genType const &x)
std::map< int, tango_gl::Axis * > markers_
rtabmap::Transform getPose() const
void SetFieldOfView(const float fov)
void SetCameraPose(const rtabmap::Transform &pose)
bool hasMarker(int id) const
const std::string kGraphFragmentShader
void addCloud(int id, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &cloud, const pcl::IndicesPtr &indices, const rtabmap::Transform &pose)
void setCloudVisible(int id, bool visible)
std::vector< glm::vec4 > computeFrustumPlanes(const glm::mat4 &mat, bool normalize=true)
void updateGraph(const std::map< int, rtabmap::Transform > &poses, const std::multimap< int, rtabmap::Link > &links)
std::set< int > getAddedClouds() const
void SetColor(const Color &color)
bool hasTexture(int id) const
cv::Point2f doubleTapPos_
void OnTouchEvent(int touch_count, TouchEvent event, float x0, float y0, float x1, float y1)
rtabmap::ScreenRotation color_camera_to_display_rotation_
void addMarker(int id, const rtabmap::Transform &pose)
GLM_FUNC_DECL detail::tquat< T, P > rotation(detail::tvec3< T, P > const &orig, detail::tvec3< T, P > const &dest)
void setFrustumVisible(bool visible)
void SetAnchorPosition(const glm::vec3 &pos, const glm::quat &rotation)
void SetOrthoCropFactor(float value)
bool intersectFrustumAABB(const std::vector< glm::vec4 > &planes, const pcl::PointXYZ &boxMin, const pcl::PointXYZ &boxMax)
const pcl::PointXYZ & aabbMaxWorld() const
void Render(const glm::mat4 &projection_mat, const glm::mat4 &view_mat) const
void UpdateVertexArray(const glm::vec3 &v)
int Render(const float *uvsTransformed=0, glm::mat4 arViewMatrix=glm::mat4(0), glm::mat4 arProjectionMatrix=glm::mat4(0), const rtabmap::Mesh &occlusionMesh=rtabmap::Mesh())
void setTraceVisible(bool visible)
void SetCameraType(tango_gl::GestureCamera::CameraType camera_type)
void SetAnchorOffset(const glm::vec3 &pos)
ULogger class and convenient macros.
void Draw(const float *transformed_uvs)
void Render(const glm::mat4 &projection_mat, const glm::mat4 &view_mat) const
void updateMesh(int id, const rtabmap::Mesh &mesh)
void setGraphVisible(bool visible)
const pcl::PointXYZ & aabbMinWorld() const
float getNearClipPlane() const
void setMarkerPose(int id, const rtabmap::Transform &pose)
static void createShaderPrograms()
static const rtabmap::Transform opticalRotationInv
bool boundingBoxRendering_
CameraType GetCameraType() const
void setGridRotation(float angleDeg)
void updateVertices(const pcl::PointXYZ &min, const pcl::PointXYZ &max)
glm::mat4 GetProjectionMatrix()
tango_gl::GestureCamera * gesture_camera_
const tango_gl::Color kGridColor(0.85f, 0.85f, 0.85f)
const tango_gl::Color kTraceColor(0.66f, 0.66f, 0.66f)
rtabmap::Transform * currentPose_
glm::mat4 GetViewMatrix()
GLM_FUNC_DECL matType< T, P > inverse(matType< T, P > const &m)
GLuint graph_shader_program_