0.12.3: Increased Tango rendering performance, modified all handleEvent() with new interface (now returning bool)

This commit is contained in:
matlabbe
2017-03-12 21:21:09 -04:00
parent c12980ee91
commit d21ae76fff
56 changed files with 1869 additions and 662 deletions

View File

@@ -27,7 +27,7 @@ public:
class ProgressionStatus: public ProgressState, public UEventsHandler
{
public:
ProgressionStatus() : count_(0), max_(100), canceled_(false), jvm_(0), rtabmap_(0)
ProgressionStatus() : count_(0), max_(100), jvm_(0), rtabmap_(0)
{
registerToEventsManager();
}
@@ -42,7 +42,7 @@ public:
{
count_=-1;
max_ = max;
canceled_ = false;
setCanceled(false);
increment();
}
@@ -65,27 +65,17 @@ public:
virtual bool callback(const std::string & msg) const
{
if(!canceled_)
if(!isCanceled())
{
increment();
}
return !canceled_;
return !isCanceled();
}
virtual ~ProgressionStatus(){}
void cancel()
{
canceled_ = true;
}
bool isCanceled() const
{
return canceled_;
}
protected:
virtual void handleEvent(UEvent * event)
virtual bool handleEvent(UEvent * event)
{
if(event->getClassName().compare("ProgressEvent") == 0)
{
@@ -118,12 +108,12 @@ protected:
UERROR("Failed to call rtabmap::updateProgressionCallback");
}
}
return false;
}
private:
int count_;
int max_;
bool canceled_;
JavaVM *jvm_;
jobject rtabmap_;
};

File diff suppressed because it is too large Load Diff

View File

@@ -136,8 +136,9 @@ class RTABMapApp : public UEventsHandler {
void setMeshDecimation(int value);
void setMeshAngleTolerance(float value);
void setMeshTriangleSize(int value);
void setMinClusterSize(int value);
void setClusterRatio(float value);
void setMaxGainRadius(float value);
void setRenderingTextureDecimation(int value);
int setMappingParameter(const std::string & key, const std::string & value);
void resetMapping();
@@ -165,11 +166,14 @@ class RTABMapApp : public UEventsHandler {
int postProcessing(int approach);
protected:
virtual void handleEvent(UEvent * event);
virtual bool handleEvent(UEvent * event);
private:
rtabmap::ParametersMap getRtabmapParameters();
bool smoothMesh(int id, Mesh & mesh);
void gainCompensation(bool full = false);
std::vector<pcl::Vertices> filterOrganizedPolygons(const std::vector<pcl::Vertices> & polygons, int cloudSize) const;
std::vector<pcl::Vertices> filterPolygons(const std::vector<pcl::Vertices> & polygons, int cloudSize) const;
private:
rtabmap::CameraTango * camera_;
@@ -191,15 +195,18 @@ class RTABMapApp : public UEventsHandler {
int meshDecimation_;
int meshTrianglePix_;
float meshAngleToleranceDeg_;
int minClusterSize_;
float clusterRatio_;
float maxGainRadius_;
int renderingTextureDecimation_;
rtabmap::ParametersMap mappingParameters_;
bool paused_;
bool dataRecorderMode_;
bool clearSceneOnNextRender_;
bool optimizeOpenedDatabase_;
bool openingDatabase_;
bool exporting_;
bool postProcessing_;
bool filterPolygonsOnNextRender_;
int gainCompensationOnNextRender_;
bool bilateralFilteringOnNextRender_;
@@ -208,9 +215,10 @@ class RTABMapApp : public UEventsHandler {
int totalPolygons_;
int lastDrawnCloudsCount_;
float renderingTime_;
float previousRenderingTime_;
double lastPostRenderEventTime_;
long processMemoryUsedBytes;
long processGPUMemoryUsedBytes;
std::map<std::string, float> bufferedStatsData_;
bool visualizingMesh_;
bool exportedMeshUpdated_;
@@ -221,7 +229,7 @@ class RTABMapApp : public UEventsHandler {
// movement and point cloud.
Scene main_scene_;
std::list<rtabmap::Statistics> rtabmapEvents_;
std::list<rtabmap::RtabmapEvent*> rtabmapEvents_;
std::list<rtabmap::OdometryEvent> odomEvents_;
std::list<rtabmap::Transform> poseEvents_;

View File

@@ -0,0 +1,131 @@
/*
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Universite de Sherbrooke nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BOUNDING_BOX_DRAWABLE_H_
#define BOUNDING_BOX_DRAWABLE_H_
#include "tango-gl/line.h"
class BoundingBoxDrawable : public tango_gl::Line
{
public:
BoundingBoxDrawable() :
Line(3.0f, GL_LINES)
{
vec_vertices_.resize(24);
}
void updateVertices(const pcl::PointXYZ & min, const pcl::PointXYZ & max)
{
int index = 0;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = min.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = max.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = min.y;
vec_vertices_[index++].z = max.z;
vec_vertices_[index].x = min.x;
vec_vertices_[index].y = max.y;
vec_vertices_[index++].z = max.z;
}
};
#endif // TANGO_GL_LINE_H_

View File

@@ -259,10 +259,10 @@ Java_com_introlab_rtabmap_RTABMapLib_setMeshTriangleSize(
return app.setMeshTriangleSize(value);
}
JNIEXPORT void JNICALL
Java_com_introlab_rtabmap_RTABMapLib_setMinClusterSize(
JNIEnv*, jobject, int value)
Java_com_introlab_rtabmap_RTABMapLib_setClusterRatio(
JNIEnv*, jobject, float value)
{
return app.setMinClusterSize(value);
return app.setClusterRatio(value);
}
JNIEXPORT void JNICALL
Java_com_introlab_rtabmap_RTABMapLib_setMaxGainRadius(
@@ -270,6 +270,12 @@ Java_com_introlab_rtabmap_RTABMapLib_setMaxGainRadius(
{
return app.setMaxGainRadius(value);
}
JNIEXPORT void JNICALL
Java_com_introlab_rtabmap_RTABMapLib_setRenderingTextureDecimation(
JNIEnv*, jobject, int value)
{
return app.setRenderingTextureDecimation(value);
}
JNIEXPORT jint JNICALL
Java_com_introlab_rtabmap_RTABMapLib_setMappingParameter(
JNIEnv* env, jobject, jstring key, jstring value)

View File

@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/utilite/UConversion.h"
#include <opencv2/imgproc/imgproc.hpp>
#include "util.h"
#include "pcl/common/transforms.h"
#include <GLES2/gl2.h>
@@ -47,7 +48,8 @@ PointCloudDrawable::PointCloudDrawable(
vertex_buffers_(0),
textures_(0),
nPoints_(0),
pose_(1.0f),
pose_(rtabmap::Transform::getIdentity()),
poseGl_(1.0f),
visible_(true),
hasNormals_(false),
cloud_shader_program_(cloudShaderProgram),
@@ -64,7 +66,8 @@ PointCloudDrawable::PointCloudDrawable(
vertex_buffers_(0),
textures_(0),
nPoints_(0),
pose_(1.0f),
pose_(rtabmap::Transform::getIdentity()),
poseGl_(1.0f),
visible_(true),
hasNormals_(false),
cloud_shader_program_(cloudShaderProgram),
@@ -138,6 +141,8 @@ void PointCloudDrawable::updateCloud(const pcl::PointCloud<pcl::PointXYZRGB>::Pt
gain_ = gain;
verticesLowRes_.clear();
verticesLowLowRes_.clear();
aabbMinModel_ = aabbMinWorld_ = pcl::PointXYZ(1000,1000,1000);
aabbMaxModel_ = aabbMaxWorld_ = pcl::PointXYZ(-1000,-1000,-1000);
if (vertex_buffers_)
{
@@ -173,10 +178,13 @@ void PointCloudDrawable::updateCloud(const pcl::PointCloud<pcl::PointXYZRGB>::Pt
int oi_lowlow = 0;
for(unsigned int i=0; i<indices->size(); ++i)
{
vertices[i*4] = cloud->at(indices->at(i)).x;
vertices[i*4+1] = cloud->at(indices->at(i)).y;
vertices[i*4+2] = cloud->at(indices->at(i)).z;
vertices[i*4+3] = cloud->at(indices->at(i)).rgb;
const pcl::PointXYZRGB & pt = cloud->at(indices->at(i));
vertices[i*4] = pt.x;
vertices[i*4+1] = pt.y;
vertices[i*4+2] = pt.z;
vertices[i*4+3] = pt.rgb;
updateAABBMinMax(pt, aabbMinModel_, aabbMaxModel_);
if(cloud->isOrganized())
{
@@ -203,10 +211,13 @@ void PointCloudDrawable::updateCloud(const pcl::PointCloud<pcl::PointXYZRGB>::Pt
int oi_lowlow = 0;
for(unsigned int i=0; i<cloud->size(); ++i)
{
vertices[i*4] = cloud->at(i).x;
vertices[i*4+1] = cloud->at(i).y;
vertices[i*4+2] = cloud->at(i).z;
vertices[i*4+3] = cloud->at(i).rgb;
const pcl::PointXYZRGB & pt = cloud->at(i);
vertices[i*4] = pt.x;
vertices[i*4+1] = pt.y;
vertices[i*4+2] = pt.z;
vertices[i*4+3] = pt.rgb;
updateAABBMinMax(pt, aabbMinModel_, aabbMaxModel_);
if(cloud->isOrganized())
{
@@ -243,6 +254,8 @@ void PointCloudDrawable::updateMesh(const Mesh & mesh)
{
UASSERT(mesh.cloud.get() && !mesh.cloud->empty());
nPoints_ = 0;
aabbMinModel_ = aabbMinWorld_ = pcl::PointXYZ(1000,1000,1000);
aabbMaxModel_ = aabbMaxWorld_ = pcl::PointXYZ(-1000,-1000,-1000);
if (vertex_buffers_)
{
@@ -306,12 +319,15 @@ void PointCloudDrawable::updateMesh(const Mesh & mesh)
vertices = std::vector<float>(mesh.indices->size()*9);
for(unsigned int i=0; i<mesh.indices->size(); ++i)
{
vertices[i*items] = mesh.cloud->at(mesh.indices->at(i)).x;
vertices[i*items+1] = mesh.cloud->at(mesh.indices->at(i)).y;
vertices[i*items+2] = mesh.cloud->at(mesh.indices->at(i)).z;
const pcl::PointXYZRGB & pt = mesh.cloud->at(mesh.indices->at(i));
vertices[i*items] = pt.x;
vertices[i*items+1] = pt.y;
vertices[i*items+2] = pt.z;
// rgb
vertices[i*items+3] = mesh.cloud->at(mesh.indices->at(i)).rgb;
vertices[i*items+3] = pt.rgb;
updateAABBMinMax(pt, aabbMinModel_, aabbMaxModel_);
// texture uv
int index = mesh.indices->at(i);
@@ -345,10 +361,13 @@ void PointCloudDrawable::updateMesh(const Mesh & mesh)
vertices = std::vector<float>(mesh.indices->size()*items);
for(unsigned int i=0; i<mesh.indices->size(); ++i)
{
vertices[i*items] = mesh.cloud->at(mesh.indices->at(i)).x;
vertices[i*items+1] = mesh.cloud->at(mesh.indices->at(i)).y;
vertices[i*items+2] = mesh.cloud->at(mesh.indices->at(i)).z;
vertices[i*items+3] = mesh.cloud->at(mesh.indices->at(i)).rgb;
const pcl::PointXYZRGB & pt = mesh.cloud->at(mesh.indices->at(i));
vertices[i*items] = pt.x;
vertices[i*items+1] = pt.y;
vertices[i*items+2] = pt.z;
vertices[i*items+3] = pt.rgb;
updateAABBMinMax(pt, aabbMinModel_, aabbMaxModel_);
if(hasNormals_)
{
@@ -401,12 +420,16 @@ void PointCloudDrawable::updateMesh(const Mesh & mesh)
UASSERT(oi < mesh.texCoords.size());
UASSERT(v.vertices[j] < mesh.cloud->size());
vertices[oi*items] = mesh.cloud->at(v.vertices[j]).x;
vertices[oi*items+1] = mesh.cloud->at(v.vertices[j]).y;
vertices[oi*items+2] = mesh.cloud->at(v.vertices[j]).z;
const pcl::PointXYZRGB & pt = mesh.cloud->at(v.vertices[j]);
vertices[oi*items] = pt.x;
vertices[oi*items+1] = pt.y;
vertices[oi*items+2] = pt.z;
// rgb
vertices[oi*items+3] = mesh.cloud->at(v.vertices[j]).rgb;
vertices[oi*items+3] = pt.rgb;
updateAABBMinMax(pt, aabbMinModel_, aabbMaxModel_);
// texture uv
if(mesh.texCoords[oi][0]>=0.0f)
@@ -444,10 +467,14 @@ void PointCloudDrawable::updateMesh(const Mesh & mesh)
vertices = std::vector<float>(mesh.cloud->size()*items);
for(unsigned int i=0; i<mesh.cloud->size(); ++i)
{
vertices[i*items] = mesh.cloud->at(i).x;
vertices[i*items+1] = mesh.cloud->at(i).y;
vertices[i*items+2] = mesh.cloud->at(i).z;
vertices[i*items+3] = mesh.cloud->at(i).rgb;
const pcl::PointXYZRGB & pt = mesh.cloud->at(i);
vertices[i*items] =pt.x;
vertices[i*items+1] = pt.y;
vertices[i*items+2] = pt.z;
vertices[i*items+3] = pt.rgb;
updateAABBMinMax(pt, aabbMinModel_, aabbMaxModel_);
if(hasNormals_)
{
@@ -513,15 +540,51 @@ void PointCloudDrawable::updateMesh(const Mesh & mesh)
{
updatePolygons(polygons, polygonsLowRes);
}
if(!pose_.isNull())
{
updateAABBWorld(pose_);
}
}
void PointCloudDrawable::setPose(const rtabmap::Transform & pose)
{
UASSERT(!pose.isNull());
pose_ = glmFromTransform(pose);
if(pose_ != pose)
{
updateAABBWorld(pose);
}
pose_ = pose;
poseGl_ = glmFromTransform(pose);
}
void PointCloudDrawable::updateAABBWorld(const rtabmap::Transform & pose)
{
pcl::PointCloud<pcl::PointXYZ> corners;
corners.resize(8);
corners.at(0) = pcl::PointXYZ(aabbMinModel_.x, aabbMinModel_.y, aabbMinModel_.z);
corners.at(1) = pcl::PointXYZ(aabbMinModel_.x, aabbMinModel_.y, aabbMaxModel_.z);
corners.at(2) = pcl::PointXYZ(aabbMinModel_.x, aabbMaxModel_.y, aabbMinModel_.z);
corners.at(3) = pcl::PointXYZ(aabbMaxModel_.x, aabbMinModel_.y, aabbMinModel_.z);
corners.at(4) = pcl::PointXYZ(aabbMaxModel_.x, aabbMaxModel_.y, aabbMaxModel_.z);
corners.at(5) = pcl::PointXYZ(aabbMaxModel_.x, aabbMaxModel_.y, aabbMinModel_.z);
corners.at(6) = pcl::PointXYZ(aabbMaxModel_.x, aabbMinModel_.y, aabbMaxModel_.z);
corners.at(7) = pcl::PointXYZ(aabbMinModel_.x, aabbMaxModel_.y, aabbMaxModel_.z);
pcl::PointCloud<pcl::PointXYZ> cornersTransformed;
pcl::transformPointCloud(corners, cornersTransformed, pose.toEigen3f());
aabbMinWorld_ = pcl::PointXYZ(1000,1000,1000);
aabbMaxWorld_ = pcl::PointXYZ(-1000,-1000,-1000);
for(unsigned int i=0; i<cornersTransformed.size(); ++i)
{
updateAABBMinMax(cornersTransformed.at(i), aabbMinWorld_, aabbMaxWorld_);
}
}
void PointCloudDrawable::Render(const glm::mat4 & projectionMatrix,
const glm::mat4 & viewMatrix,
bool meshRendering,
@@ -537,7 +600,7 @@ void PointCloudDrawable::Render(const glm::mat4 & projectionMatrix,
glUseProgram(texture_shader_program_);
GLuint mvp_handle = glGetUniformLocation(texture_shader_program_, "uMVP");
glm::mat4 mv_mat = viewMatrix * pose_;
glm::mat4 mv_mat = viewMatrix * poseGl_;
glm::mat4 mvp_mat = projectionMatrix * mv_mat;
glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, glm::value_ptr(mvp_mat));
@@ -611,7 +674,7 @@ void PointCloudDrawable::Render(const glm::mat4 & projectionMatrix,
glUseProgram(cloud_shader_program_);
GLuint mvp_handle_ = glGetUniformLocation(cloud_shader_program_, "uMVP");
glm::mat4 mv_mat = viewMatrix * pose_;
glm::mat4 mv_mat = viewMatrix * poseGl_;
glm::mat4 mvp_mat = projectionMatrix * mv_mat;
glUniformMatrix4fv(mvp_handle_, 1, GL_FALSE, glm::value_ptr(mvp_mat));

View File

@@ -59,10 +59,15 @@ class PointCloudDrawable {
void setPose(const rtabmap::Transform & pose);
void setVisible(bool visible) {visible_=visible;}
void setGain(float gain) {gain_ = gain;}
rtabmap::Transform getPose() const {return glmToTransform(pose_);}
rtabmap::Transform getPose() const {return pose_;}
const glm::mat4 & getPoseGl() const {return poseGl_;}
bool isVisible() const {return visible_;}
bool hasMesh() const {return polygons_.size()!=0;}
bool hasTexture() const {return textures_ != 0;}
const pcl::PointXYZ & aabbMinModel() const {return aabbMinModel_;}
const pcl::PointXYZ & aabbMaxModel() const {return aabbMaxModel_;}
const pcl::PointXYZ & aabbMinWorld() const {return aabbMinWorld_;}
const pcl::PointXYZ & aabbMaxWorld() const {return aabbMaxWorld_;}
// Update current point cloud data.
//
@@ -78,6 +83,19 @@ class PointCloudDrawable {
bool lighting = true,
float distanceToCamSqr = 0.0f);
private:
template<class PointT>
void updateAABBMinMax(const PointT & pt, pcl::PointXYZ & min, pcl::PointXYZ & max)
{
if(pt.x<min.x) min.x = pt.x;
if(pt.y<min.y) min.y = pt.y;
if(pt.z<min.z) min.z = pt.z;
if(pt.x>max.x) max.x = pt.x;
if(pt.y>max.y) max.y = pt.y;
if(pt.z>max.z) max.z = pt.z;
}
void updateAABBWorld(const rtabmap::Transform & pose);
private:
// Vertex buffer of the point cloud geometry.
GLuint vertex_buffers_;
@@ -87,7 +105,8 @@ class PointCloudDrawable {
std::vector<GLuint> verticesLowRes_;
std::vector<GLuint> verticesLowLowRes_;
int nPoints_;
glm::mat4 pose_;
rtabmap::Transform pose_;
glm::mat4 poseGl_;
bool visible_;
bool hasNormals_;
std::vector<unsigned int> organizedToDenseIndices_;
@@ -96,6 +115,11 @@ class PointCloudDrawable {
GLuint texture_shader_program_;
float gain_;
pcl::PointXYZ aabbMinModel_;
pcl::PointXYZ aabbMaxModel_;
pcl::PointXYZ aabbMinWorld_;
pcl::PointXYZ aabbMaxWorld_;
};
#endif // TANGO_POINT_CLOUD_POINT_CLOUD_DRAWABLE_H_

View File

@@ -20,6 +20,7 @@
#include <rtabmap/utilite/ULogger.h>
#include <rtabmap/utilite/UStl.h>
#include <rtabmap/core/util3d_filtering.h>
#include <pcl/common/transforms.h>
#include <glm/gtx/transform.hpp>
@@ -153,6 +154,7 @@ Scene::Scene() :
axis_(0),
frustum_(0),
grid_(0),
box_(0),
trace_(0),
graph_(0),
graphVisible_(true),
@@ -168,6 +170,7 @@ Scene::Scene() :
meshRenderingTexture_(true),
pointSize_(5.0f),
frustumCulling_(true),
boundingBoxRendering_(false),
lighting_(true),
backfaceCulling_(true),
r_(0.0f),
@@ -199,6 +202,7 @@ void Scene::InitGLContent()
frustum_ = new tango_gl::Frustum();
trace_ = new tango_gl::Trace();
grid_ = new tango_gl::Grid();
box_ = new BoundingBoxDrawable();
currentPose_ = new rtabmap::Transform();
@@ -208,6 +212,8 @@ void Scene::InitGLContent()
trace_->SetColor(kTraceColor);
grid_->SetColor(kGridColor);
grid_->SetPosition(-kHeightOffset);
box_->SetShader();
box_->SetColor(1,0,0);
if(cloud_shader_program_ == 0)
{
@@ -238,6 +244,7 @@ void Scene::DeleteResources() {
delete trace_;
delete grid_;
delete currentPose_;
delete box_;
}
if (cloud_shader_program_) {
@@ -287,6 +294,113 @@ void Scene::SetupViewPort(int w, int h) {
glViewport(0, 0, w, h);
}
std::vector<glm::vec4> computeFrustumPlanes(const glm::mat4 & mat, bool normalize = true)
{
// http://www.txutxi.com/?p=444
std::vector<glm::vec4> planes(6);
// Left Plane
// col4 + col1
planes[0].x = mat[0][3] + mat[0][0];
planes[0].y = mat[1][3] + mat[1][0];
planes[0].z = mat[2][3] + mat[2][0];
planes[0].w = mat[3][3] + mat[3][0];
// Right Plane
// col4 - col1
planes[1].x = mat[0][3] - mat[0][0];
planes[1].y = mat[1][3] - mat[1][0];
planes[1].z = mat[2][3] - mat[2][0];
planes[1].w = mat[3][3] - mat[3][0];
// Bottom Plane
// col4 + col2
planes[2].x = mat[0][3] + mat[0][1];
planes[2].y = mat[1][3] + mat[1][1];
planes[2].z = mat[2][3] + mat[2][1];
planes[2].w = mat[3][3] + mat[3][1];
// Top Plane
// col4 - col2
planes[3].x = mat[0][3] - mat[0][1];
planes[3].y = mat[1][3] - mat[1][1];
planes[3].z = mat[2][3] - mat[2][1];
planes[3].w = mat[3][3] - mat[3][1];
// Near Plane
// col4 + col3
planes[4].x = mat[0][3] + mat[0][2];
planes[4].y = mat[1][3] + mat[1][2];
planes[4].z = mat[2][3] + mat[2][2];
planes[4].w = mat[3][3] + mat[3][2];
// Far Plane
// col4 - col3
planes[5].x = mat[0][3] - mat[0][2];
planes[5].y = mat[1][3] - mat[1][2];
planes[5].z = mat[2][3] - mat[2][2];
planes[5].w = mat[3][3] - mat[3][2];
//if(normalize)
{
for(unsigned int i=0;i<planes.size(); ++i)
{
if(normalize)
{
float d = std::sqrt(planes[i].x * planes[i].x + planes[i].y * planes[i].y + planes[i].z * planes[i].z); // for normalizing the coordinates
planes[i].x/=d;
planes[i].y/=d;
planes[i].z/=d;
planes[i].w/=d;
}
}
}
return planes;
}
/**
* Tells whether or not b is intersecting f.
* http://www.txutxi.com/?p=584
* @param f Viewing frustum.
* @param b An axis aligned bounding box.
* @return True if b intersects f, false otherwise.
*/
bool intersectFrustumAABB(
const std::vector<glm::vec4> &planes,
const pcl::PointXYZ &boxMin,
const pcl::PointXYZ &boxMax)
{
// Indexed for the 'index trick' later
const pcl::PointXYZ * box[] = {&boxMin, &boxMax};
// We only need to do 6 point-plane tests
for (unsigned int i = 0; i < planes.size(); ++i)
{
// This is the current plane
const glm::vec4 &p = planes[i];
// p-vertex selection (with the index trick)
// According to the plane normal we can know the
// indices of the positive vertex
const int px = p.x > 0.0f?1:0;
const int py = p.y > 0.0f?1:0;
const int pz = p.z > 0.0f?1:0;
// Dot product
// project p-vertex on plane normal
// (How far is p-vertex from the origin)
const float dp =
(p.x*box[px]->x) +
(p.y*box[py]->y) +
(p.z*box[pz]->z) + p.w;
// Doesn't intersect if it is behind the plane
if (dp < 0) {return false; }
}
return true;
}
//Should only be called in OpenGL thread!
int Scene::Render() {
UASSERT(gesture_camera_ != 0);
@@ -353,7 +467,7 @@ int Scene::Render() {
}
float fov = 45.0f;
rtabmap::Transform openglCamera = GetOpenGLCameraPose(&fov)*rtabmap::Transform(0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f);
rtabmap::Transform openglCamera = GetOpenGLCameraPose(&fov);//*rtabmap::Transform(0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f);
// transform in same coordinate as frustum filtering
openglCamera *= rtabmap::Transform(
0.0f, 0.0f, 1.0f, 0.0f,
@@ -363,50 +477,30 @@ int Scene::Render() {
int cloudDrawn=0;
if(mapRendering_ && frustumCulling_)
{
//Use camera frustum to cull nodes that don't need to be drawn
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
std::vector<int> ids(pointClouds_.size());
cloud->resize(pointClouds_.size());
ids.resize(pointClouds_.size());
int oi=0;
std::vector<glm::vec4> planes = computeFrustumPlanes(gesture_camera_->GetProjectionMatrix()*gesture_camera_->GetViewMatrix(), true);
for(std::map<int, PointCloudDrawable*>::const_iterator iter=pointClouds_.begin(); iter!=pointClouds_.end(); ++iter)
{
if(!iter->second->getPose().isNull() && iter->second->isVisible())
if(iter->second->isVisible())
{
(*cloud)[oi] = pcl::PointXYZ(iter->second->getPose().x(), iter->second->getPose().y(), iter->second->getPose().z());
ids[oi++] = iter->first;
}
}
cloud->resize(oi);
ids.resize(oi);
if(intersectFrustumAABB(planes,
iter->second->aabbMinWorld(),
iter->second->aabbMaxWorld()))
{
if(boundingBoxRendering_)
{
box_->updateVertices(iter->second->aabbMinWorld(), iter->second->aabbMaxWorld());
box_->Render(gesture_camera_->GetProjectionMatrix(),
gesture_camera_->GetViewMatrix());
}
if(oi)
{
pcl::IndicesPtr indices = rtabmap::util3d::frustumFiltering(
cloud,
pcl::IndicesPtr(new std::vector<int>),
openglCamera,
fov*2.0f,
fov*2.0f,
0.1f,
100.0f);
//LOGI("Frustum poses filtered = %d (showing %d/%d)",
// (int)(pointClouds_.size()-indices->size()),
// (int)indices->size(),
// (int)pointClouds_.size());
for(unsigned int i=0; i<indices->size(); ++i)
{
++cloudDrawn;
std::map<int, PointCloudDrawable*>::const_iterator iter = pointClouds_.find(ids[indices->at(i)]);
Eigen::Vector3f cloudToCamera(
iter->second->getPose().x() - openglCamera.x(),
iter->second->getPose().y() - openglCamera.y(),
iter->second->getPose().z() - openglCamera.z());
float distanceToCameraSqr = cloudToCamera[0]*cloudToCamera[0] + cloudToCamera[1]*cloudToCamera[1] + cloudToCamera[2]*cloudToCamera[2];
iter->second->Render(gesture_camera_->GetProjectionMatrix(), gesture_camera_->GetViewMatrix(), meshRendering_, pointSize_, meshRenderingTexture_, lighting_, distanceToCameraSqr);
++cloudDrawn;
Eigen::Vector3f cloudToCamera(
iter->second->getPose().x() - openglCamera.x(),
iter->second->getPose().y() - openglCamera.y(),
iter->second->getPose().z() - openglCamera.z());
float distanceToCameraSqr = cloudToCamera[0]*cloudToCamera[0] + cloudToCamera[1]*cloudToCamera[1] + cloudToCamera[2]*cloudToCamera[2];
iter->second->Render(gesture_camera_->GetProjectionMatrix(), gesture_camera_->GetViewMatrix(), meshRendering_, pointSize_, meshRenderingTexture_, lighting_, distanceToCameraSqr);
}
}
}
}
@@ -414,8 +508,20 @@ int Scene::Render() {
{
for(std::map<int, PointCloudDrawable*>::const_iterator iter=pointClouds_.begin(); iter!=pointClouds_.end(); ++iter)
{
if((mapRendering_ || iter->first < 0) && iter->second->isVisible())
if(!mapRendering_ && iter->first > 0)
{
break;
}
if(iter->second->isVisible())
{
if(boundingBoxRendering_)
{
box_->updateVertices(iter->second->aabbMinWorld(), iter->second->aabbMaxWorld());
box_->Render(gesture_camera_->GetProjectionMatrix(),
gesture_camera_->GetViewMatrix());
}
++cloudDrawn;
Eigen::Vector3f cloudToCamera(
iter->second->getPose().x() - openglCamera.x(),
@@ -475,8 +581,11 @@ void Scene::updateGraph(
}
//create
UASSERT(graph_shader_program_ != 0);
graph_ = new GraphDrawable(graph_shader_program_, poses, links);
if(graphVisible_)
{
UASSERT(graph_shader_program_ != 0);
graph_ = new GraphDrawable(graph_shader_program_, poses, links);
}
}
void Scene::setGraphVisible(bool visible)

View File

@@ -37,6 +37,7 @@
#include <point_cloud_drawable.h>
#include <graph_drawable.h>
#include <bounding_box_drawable.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
@@ -127,6 +128,7 @@ class Scene {
void setBackfaceCulling(bool enabled) {backfaceCulling_ = enabled;}
void setBackgroundColor(float r, float g, float b) {r_=r; g_=g; b_=b;} // 0.0f <> 1.0f
bool isMapRendering() const {return mapRendering_;}
bool isMeshRendering() const {return meshRendering_;}
bool isMeshTexturing() const {return meshRendering_ && meshRenderingTexture_;}
float getPointSize() const {return pointSize_;}
@@ -147,6 +149,9 @@ class Scene {
// Ground grid.
tango_gl::Grid* grid_;
// Bounding box
BoundingBoxDrawable * box_;
// Trace of pose data.
tango_gl::Trace* trace_;
GraphDrawable * graph_;
@@ -170,6 +175,7 @@ class Scene {
bool meshRenderingTexture_;
float pointSize_;
bool frustumCulling_;
bool boundingBoxRendering_;
bool lighting_;
bool backfaceCulling_;
float r_;

View File

@@ -34,10 +34,17 @@
#include "glm/gtx/matrix_decompose.hpp"
#define LOG_TAG "rtabmap"
#ifdef DISABLE_LOG
#define LOGD(...) ;
#define LOGI(...) ;
#define LOGW(...) ;
#define LOGE(...) ;
#else
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#endif
#ifndef M_PI
#define M_PI 3.1415926f

View File

@@ -51,7 +51,7 @@ public:
registerToEventsManager();
}
protected:
virtual void handleEvent(UEvent * event)
virtual bool handleEvent(UEvent * event)
{
if(event->getClassName().compare("ULogEvent") == 0)
{
@@ -74,6 +74,7 @@ protected:
}
}
return false;
}
};