mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 01:20:25 +08:00
Tango: updated export workflow, added sketchfab activity, added graph optimization parameters, fixed raw images kept in memory (disabled reexctract words on loop closure while updating memory to be able to create more features for transform estimation than needed in vocabulary), portrait/landscape orientation, updated to Eisa TangoSDK. DBReader: fixed high variance when node has no links (if not the first in the current map id). MainWindow: remove frustums not in the current graph.
This commit is contained in:
@@ -46,7 +46,10 @@ const int scanDownsampling = 10;
|
||||
void onPointCloudAvailableRouter(void* context, const TangoPointCloud* point_cloud)
|
||||
{
|
||||
CameraTango* app = static_cast<CameraTango*>(context);
|
||||
app->cloudReceived(cv::Mat(1, point_cloud->num_points, CV_32FC4, point_cloud->points[0]), point_cloud->timestamp);
|
||||
if(point_cloud->num_points>0)
|
||||
{
|
||||
app->cloudReceived(cv::Mat(1, point_cloud->num_points, CV_32FC4, point_cloud->points[0]), point_cloud->timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
void onFrameAvailableRouter(void* context, TangoCameraId id, const TangoImageBuffer* color)
|
||||
@@ -104,7 +107,8 @@ CameraTango::CameraTango(int decimation, bool autoExposure, bool publishRawScan)
|
||||
rawScanPublished_(publishRawScan),
|
||||
cloudStamp_(0),
|
||||
tangoColorType_(0),
|
||||
tangoColorStamp_(0)
|
||||
tangoColorStamp_(0),
|
||||
colorCameraToDisplayRotation_(ROTATION_0)
|
||||
{
|
||||
UASSERT(decimation >= 1);
|
||||
}
|
||||
@@ -641,6 +645,51 @@ SensorData CameraTango::captureImage(CameraInfo * info)
|
||||
//LOGD("rtabmap = %s", odom.prettyPrint().c_str());
|
||||
//LOGD("opengl(r)= %s", (opengl_world_T_rtabmap_world * odom * rtabmap_device_T_opengl_device).prettyPrint().c_str());
|
||||
|
||||
// Rotate image depending on the camera orientation
|
||||
if(colorCameraToDisplayRotation_ == ROTATION_90)
|
||||
{
|
||||
cv::Mat rgbt(rgb.cols, rgb.rows, rgb.type());
|
||||
cv::flip(rgb,rgb,1);
|
||||
cv::transpose(rgb,rgbt);
|
||||
rgb = rgbt;
|
||||
cv::Mat deptht(depth.cols, depth.rows, depth.type());
|
||||
cv::flip(depth,depth,1);
|
||||
cv::transpose(depth,deptht);
|
||||
depth = deptht;
|
||||
cv::Size sizet(model.imageHeight(), model.imageWidth());
|
||||
model = CameraModel(model.fy(), model.fx(), model.cy(), model.cx()>0?model.imageWidth()-model.cx():0, model.localTransform()*rtabmap::Transform(0,0,0,0,0,1.57079632679489661923132169163975144));
|
||||
model.setImageSize(sizet);
|
||||
}
|
||||
else if(colorCameraToDisplayRotation_ == ROTATION_180)
|
||||
{
|
||||
cv::flip(rgb,rgb,1);
|
||||
cv::flip(rgb,rgb,0);
|
||||
cv::flip(depth,depth,1);
|
||||
cv::flip(depth,depth,0);
|
||||
cv::Size sizet(model.imageWidth(), model.imageHeight());
|
||||
model = CameraModel(
|
||||
model.fx(),
|
||||
model.fy(),
|
||||
model.cx()>0?model.imageWidth()-model.cx():0,
|
||||
model.cy()>0?model.imageHeight()-model.cy():0,
|
||||
model.localTransform()*rtabmap::Transform(0,0,0,0,0,1.57079632679489661923132169163975144*2.0));
|
||||
model.setImageSize(sizet);
|
||||
}
|
||||
else if(colorCameraToDisplayRotation_ == ROTATION_270)
|
||||
{
|
||||
cv::Mat rgbt(rgb.cols, rgb.rows, rgb.type());
|
||||
cv::transpose(rgb,rgbt);
|
||||
cv::flip(rgbt,rgbt,1);
|
||||
rgb = rgbt;
|
||||
cv::Mat deptht(depth.cols, depth.rows, depth.type());
|
||||
cv::transpose(depth,deptht);
|
||||
cv::flip(deptht,deptht,1);
|
||||
depth = deptht;
|
||||
cv::Size sizet(model.imageHeight(), model.imageWidth());
|
||||
model = CameraModel(model.fy(), model.fx(), model.cy()>0?model.imageHeight()-model.cy():0, model.cx(), model.localTransform()*rtabmap::Transform(0,0,0,0,0,-1.57079632679489661923132169163975144));
|
||||
model.setImageSize(sizet);
|
||||
}
|
||||
|
||||
if(rawScanPublished_)
|
||||
{
|
||||
data = SensorData(scan, LaserScanInfo(cloud.total()/scanDownsampling, 0, model.localTransform()), rgb, depth, model, this->getNextSeqID(), rgbStamp);
|
||||
|
||||
@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <rtabmap/utilite/UEvent.h>
|
||||
#include <rtabmap/utilite/UTimer.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <tango_support_api.h>
|
||||
|
||||
class TangoPoseData;
|
||||
|
||||
@@ -82,6 +83,7 @@ public:
|
||||
void setDecimation(int value) {decimation_ = value;}
|
||||
void setAutoExposure(bool enabled) {autoExposure_ = enabled;}
|
||||
void setRawScanPublished(bool enabled) {rawScanPublished_ = enabled;}
|
||||
void setScreenRotation(TangoSupportRotation colorCameraToDisplayRotation) {colorCameraToDisplayRotation_ = colorCameraToDisplayRotation;}
|
||||
|
||||
void cloudReceived(const cv::Mat & cloud, double timestamp);
|
||||
void rgbReceived(const cv::Mat & tangoImage, int type, double timestamp);
|
||||
@@ -114,6 +116,7 @@ private:
|
||||
USemaphore dataReady_;
|
||||
CameraModel model_;
|
||||
Transform deviceTColorCamera_;
|
||||
TangoSupportRotation colorCameraToDisplayRotation_;
|
||||
};
|
||||
|
||||
} /* namespace rtabmap */
|
||||
|
||||
@@ -94,18 +94,22 @@ rtabmap::ParametersMap RTABMapApp::getRtabmapParameters()
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRGBDProximityPathMaxNeighbors(), std::string("0"))); // disable scan matching to merged nodes
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRGBDProximityBySpace(), std::string("false"))); // just keep loop closure detection
|
||||
|
||||
if(parameters.find(rtabmap::Parameters::kKpMaxFeatures())!=parameters.end() &&
|
||||
parameters.find(rtabmap::Parameters::kVisMaxFeatures())!=parameters.end())
|
||||
if(parameters.find(rtabmap::Parameters::kOptimizerStrategy()) != parameters.end())
|
||||
{
|
||||
int featuresVoc = uStr2Int(parameters.at(rtabmap::Parameters::kKpMaxFeatures()));
|
||||
int featuresLoop = uStr2Int(parameters.at(rtabmap::Parameters::kVisMaxFeatures()));
|
||||
if(featuresVoc==0 || featuresLoop < featuresVoc)
|
||||
if(parameters.at(rtabmap::Parameters::kOptimizerStrategy()).compare("2") == 0) // GTSAM
|
||||
{
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRGBDLoopClosureReextractFeatures(), std::string("false")));
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOptimizerEpsilon(), "0.00001"));
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOptimizerIterations(), graphOptimization_?"10":"0"));
|
||||
}
|
||||
else
|
||||
else if(parameters.at(rtabmap::Parameters::kOptimizerStrategy()).compare("1") == 0) // g2o
|
||||
{
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRGBDLoopClosureReextractFeatures(), std::string("true")));
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOptimizerEpsilon(), "0.0"));
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOptimizerIterations(), graphOptimization_?"10":"0"));
|
||||
}
|
||||
else // TORO
|
||||
{
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOptimizerEpsilon(), "0.00001"));
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOptimizerIterations(), graphOptimization_?"100":"0"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +170,8 @@ RTABMapApp::RTABMapApp() :
|
||||
renderingTime_(0.0f),
|
||||
visualizingMesh_(false),
|
||||
exportedMeshUpdated_(false),
|
||||
exportedMesh_(new pcl::TextureMesh)
|
||||
exportedMesh_(new pcl::TextureMesh),
|
||||
mapToOdom_(rtabmap::Transform::getIdentity())
|
||||
|
||||
{
|
||||
mappingParameters_.insert(rtabmap::ParametersPair(rtabmap::Parameters::kKpDetectorStrategy(), "5")); // GFTT/FREAK
|
||||
@@ -227,11 +232,14 @@ void RTABMapApp::onCreate(JNIEnv* env, jobject caller_activity)
|
||||
|
||||
void RTABMapApp::setScreenRotation(int displayRotation, int cameraRotation)
|
||||
{
|
||||
LOGI("Set orientation: display=%d camera=%d", displayRotation, cameraRotation);
|
||||
main_scene_.setScreenRotation(displayRotation, cameraRotation);
|
||||
TangoSupportRotation rotation = tango_gl::util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
displayRotation, cameraRotation);
|
||||
LOGI("Set orientation: display=%d camera=%d -> %d", displayRotation, cameraRotation, (int)rotation);
|
||||
main_scene_.setScreenRotation(rotation);
|
||||
camera_->setScreenRotation(rotation);
|
||||
}
|
||||
|
||||
void RTABMapApp::openDatabase(const std::string & databasePath, bool databaseInMemory, bool optimize)
|
||||
int RTABMapApp::openDatabase(const std::string & databasePath, bool databaseInMemory, bool optimize)
|
||||
{
|
||||
this->unregisterFromEventsManager(); // to ignore published init events when closing rtabmap
|
||||
status_.first = rtabmap::RtabmapEventInit::kInitializing;
|
||||
@@ -245,6 +253,7 @@ void RTABMapApp::openDatabase(const std::string & databasePath, bool databaseInM
|
||||
}
|
||||
|
||||
//Rtabmap
|
||||
mapToOdom_.setIdentity();
|
||||
rtabmap_ = new rtabmap::Rtabmap();
|
||||
rtabmap::ParametersMap parameters = getRtabmapParameters();
|
||||
|
||||
@@ -267,6 +276,13 @@ void RTABMapApp::openDatabase(const std::string & databasePath, bool databaseInM
|
||||
true,
|
||||
true);
|
||||
|
||||
int status = 0;
|
||||
if(signatures.size() && poses.empty())
|
||||
{
|
||||
LOGE("Failed to optimize the graph!");
|
||||
status = -1;
|
||||
}
|
||||
|
||||
optimizeOpenedDatabase_ = optimize;
|
||||
clearSceneOnNextRender_ = true;
|
||||
rtabmap::Statistics stats;
|
||||
@@ -289,6 +305,8 @@ void RTABMapApp::openDatabase(const std::string & databasePath, bool databaseInM
|
||||
status_.first = rtabmap::RtabmapEventInit::kInitialized;
|
||||
status_.second = "";
|
||||
rtabmapMutex_.unlock();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool RTABMapApp::onTangoServiceConnected(JNIEnv* env, jobject iBinder)
|
||||
@@ -437,6 +455,11 @@ int RTABMapApp::Render()
|
||||
UTimer fpsTime;
|
||||
boost::mutex::scoped_lock lock(renderingMutex_);
|
||||
|
||||
if(clearSceneOnNextRender_)
|
||||
{
|
||||
visualizingMesh_ = false;
|
||||
}
|
||||
|
||||
bool notifyCameraStarted = false;
|
||||
|
||||
// process only pose events in vsualization mode
|
||||
@@ -449,10 +472,19 @@ int RTABMapApp::Render()
|
||||
poseEvents_.clear();
|
||||
}
|
||||
}
|
||||
rtabmap::Transform mapOdom = rtabmap::Transform::getIdentity();
|
||||
if(!pose.isNull())
|
||||
{
|
||||
// update camera pose?
|
||||
main_scene_.SetCameraPose(opengl_world_T_tango_world*pose);
|
||||
if(graphOptimization_ && !visualizingMesh_ && !mapToOdom_.isIdentity())
|
||||
{
|
||||
mapOdom = mapToOdom_;
|
||||
main_scene_.SetCameraPose(opengl_world_T_rtabmap_world*mapOdom*rtabmap_world_T_tango_world*pose);
|
||||
}
|
||||
else
|
||||
{
|
||||
main_scene_.SetCameraPose(opengl_world_T_tango_world*pose);
|
||||
}
|
||||
if(!camera_->isRunning() && cameraJustInitialized_)
|
||||
{
|
||||
notifyCameraStarted = true;
|
||||
@@ -476,11 +508,6 @@ int RTABMapApp::Render()
|
||||
}
|
||||
}
|
||||
|
||||
if(clearSceneOnNextRender_)
|
||||
{
|
||||
visualizingMesh_ = false;
|
||||
}
|
||||
|
||||
if(visualizingMesh_)
|
||||
{
|
||||
if(exportedMeshUpdated_)
|
||||
@@ -675,6 +702,10 @@ int RTABMapApp::Render()
|
||||
}
|
||||
|
||||
std::map<int, rtabmap::Transform> poses = rtabmapEvents.back().poses();
|
||||
if(!rtabmapEvents.back().mapCorrection().isNull())
|
||||
{
|
||||
mapToOdom_ = rtabmapEvents.back().mapCorrection();
|
||||
}
|
||||
|
||||
// Transform pose in OpenGL world
|
||||
for(std::map<int, rtabmap::Transform>::iterator iter=poses.begin(); iter!=poses.end(); ++iter)
|
||||
@@ -833,7 +864,7 @@ int RTABMapApp::Render()
|
||||
odomEvent.data().imageRaw().cols, odomEvent.data().imageRaw().rows,
|
||||
odomEvent.data().depthRaw().cols, odomEvent.data().depthRaw().rows,
|
||||
(int)cloud->width, (int)cloud->height);
|
||||
main_scene_.addCloud(-1, cloud, indices, opengl_world_T_rtabmap_world*odomEvent.pose());
|
||||
main_scene_.addCloud(-1, cloud, indices, opengl_world_T_rtabmap_world*mapOdom*odomEvent.pose());
|
||||
main_scene_.setCloudVisible(-1, true);
|
||||
}
|
||||
else
|
||||
@@ -1042,6 +1073,10 @@ void RTABMapApp::setLighting(bool enabled)
|
||||
{
|
||||
main_scene_.setLighting(enabled);
|
||||
}
|
||||
void RTABMapApp::setBackfaceCulling(bool enabled)
|
||||
{
|
||||
main_scene_.setBackfaceCulling(enabled);
|
||||
}
|
||||
|
||||
void RTABMapApp::setLocalizationMode(bool enabled)
|
||||
{
|
||||
@@ -1286,6 +1321,7 @@ void RTABMapApp::resetMapping()
|
||||
status_.first = rtabmap::RtabmapEventInit::kInitializing;
|
||||
status_.second = "";
|
||||
|
||||
mapToOdom_.setIdentity();
|
||||
clearSceneOnNextRender_ = true;
|
||||
|
||||
UEventsManager::post(new rtabmap::RtabmapEventCmd(rtabmap::RtabmapEventCmd::kCmdResetMemory));
|
||||
@@ -1557,13 +1593,6 @@ bool RTABMapApp::exportMesh(
|
||||
|
||||
if(mergedClouds->size())
|
||||
{
|
||||
int before = mergedClouds->size();
|
||||
if(optimizedVoxelSize > 0.0f)
|
||||
{
|
||||
mergedClouds = rtabmap::util3d::voxelize(mergedClouds, optimizedVoxelSize);
|
||||
LOGI("Voxelized from %d points to %d points", before, (int)mergedClouds->size());
|
||||
}
|
||||
|
||||
// Mesh reconstruction
|
||||
LOGI("Mesh reconstruction...");
|
||||
pcl::PolygonMesh::Ptr mesh(new pcl::PolygonMesh);
|
||||
@@ -2223,15 +2252,7 @@ int RTABMapApp::postProcessing(int approach)
|
||||
// detect more loop closures
|
||||
if(approach == -1 || approach == 2)
|
||||
{
|
||||
// detect more loop closures, don't re-extract features for this
|
||||
rtabmap::ParametersMap parameters;
|
||||
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRGBDLoopClosureReextractFeatures(), std::string("false")));
|
||||
rtabmap_->parseParameters(parameters);
|
||||
|
||||
returnedValue = rtabmap_->detectMoreLoopClosures(1.0f, M_PI/6.0f, approach == -1?5:1);
|
||||
|
||||
// put back re-extraction if it was set
|
||||
rtabmap_->parseParameters(this->getRtabmapParameters());
|
||||
}
|
||||
|
||||
// graph optimization
|
||||
@@ -2427,7 +2448,9 @@ void RTABMapApp::handleEvent(UEvent * event)
|
||||
int highestHypId = (int)uValue(stats.data(), rtabmap::Statistics::kLoopHighest_hypothesis_id(), 0.0f);
|
||||
int databaseMemoryUsed = (int)uValue(stats.data(), rtabmap::Statistics::kMemoryDatabase_memory_used(), 0.0f);
|
||||
int inliers = (int)uValue(stats.data(), rtabmap::Statistics::kLoopVisual_inliers(), 0.0f);
|
||||
int matches = (int)uValue(stats.data(), rtabmap::Statistics::kLoopVisual_matches(), 0.0f);
|
||||
int rejected = (int)uValue(stats.data(), rtabmap::Statistics::kLoopRejectedHypothesis(), 0.0f);
|
||||
float optimizationMaxError = uValue(stats.data(), rtabmap::Statistics::kLoopOptimization_max_error(), 0.0f);
|
||||
float rehearsalValue = uValue(stats.data(), rtabmap::Statistics::kMemoryRehearsal_sim(), 0.0f);
|
||||
int featuresExtracted = stats.getSignatures().size()?stats.getSignatures().rbegin()->second.getWords().size():0;
|
||||
float hypothesis = uValue(stats.data(), rtabmap::Statistics::kLoopHighest_hypothesis_value(), 0.0f);
|
||||
@@ -2444,7 +2467,7 @@ void RTABMapApp::handleEvent(UEvent * event)
|
||||
jclass clazz = env->GetObjectClass(RTABMapActivity);
|
||||
if(clazz)
|
||||
{
|
||||
jmethodID methodID = env->GetMethodID(clazz, "updateStatsCallback", "(IIIIFIIIIIFIFIF)V" );
|
||||
jmethodID methodID = env->GetMethodID(clazz, "updateStatsCallback", "(IIIIFIIIIIIFIFIFF)V" );
|
||||
if(methodID)
|
||||
{
|
||||
env->CallVoidMethod(RTABMapActivity, methodID,
|
||||
@@ -2457,12 +2480,14 @@ void RTABMapApp::handleEvent(UEvent * event)
|
||||
highestHypId,
|
||||
databaseMemoryUsed,
|
||||
inliers,
|
||||
matches,
|
||||
featuresExtracted,
|
||||
hypothesis,
|
||||
lastDrawnCloudsCount_,
|
||||
renderingTime_>0.0f?1.0f/renderingTime_:0.0f,
|
||||
rejected,
|
||||
rehearsalValue);
|
||||
rehearsalValue,
|
||||
optimizationMaxError);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class RTABMapApp : public UEventsHandler {
|
||||
|
||||
void setScreenRotation(int displayRotation, int cameraRotation);
|
||||
|
||||
void openDatabase(const std::string & databasePath, bool databaseInMemory, bool optimize);
|
||||
int openDatabase(const std::string & databasePath, bool databaseInMemory, bool optimize);
|
||||
|
||||
bool onTangoServiceConnected(JNIEnv* env, jobject iBinder);
|
||||
|
||||
@@ -118,6 +118,7 @@ class RTABMapApp : public UEventsHandler {
|
||||
void setMeshRendering(bool enabled, bool withTexture);
|
||||
void setPointSize(float value);
|
||||
void setLighting(bool enabled);
|
||||
void setBackfaceCulling(bool enabled);
|
||||
void setLocalizationMode(bool enabled);
|
||||
void setTrajectoryMode(bool enabled);
|
||||
void setGraphOptimization(bool enabled);
|
||||
@@ -215,6 +216,8 @@ class RTABMapApp : public UEventsHandler {
|
||||
std::list<rtabmap::OdometryEvent> odomEvents_;
|
||||
std::list<rtabmap::Transform> poseEvents_;
|
||||
|
||||
rtabmap::Transform mapToOdom_;
|
||||
|
||||
boost::mutex rtabmapMutex_;
|
||||
boost::mutex meshesMutex_;
|
||||
boost::mutex odomMutex_;
|
||||
|
||||
@@ -62,7 +62,7 @@ Java_com_introlab_rtabmap_RTABMapLib_setScreenRotation(
|
||||
return app.setScreenRotation(displayRotation, cameraRotation);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNIEXPORT int JNICALL
|
||||
Java_com_introlab_rtabmap_RTABMapLib_openDatabase(
|
||||
JNIEnv* env, jobject, jstring databasePath, bool databaseInMemory, bool optimize)
|
||||
{
|
||||
@@ -157,6 +157,12 @@ Java_com_introlab_rtabmap_RTABMapLib_setLighting(
|
||||
return app.setLighting(enabled);
|
||||
}
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_introlab_rtabmap_RTABMapLib_setBackfaceCulling(
|
||||
JNIEnv*, jobject, bool enabled)
|
||||
{
|
||||
return app.setBackfaceCulling(enabled);
|
||||
}
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_introlab_rtabmap_RTABMapLib_setLocalizationMode(
|
||||
JNIEnv*, jobject, bool enabled)
|
||||
{
|
||||
|
||||
@@ -169,6 +169,7 @@ Scene::Scene() :
|
||||
pointSize_(5.0f),
|
||||
frustumCulling_(true),
|
||||
lighting_(true),
|
||||
backfaceCulling_(true),
|
||||
r_(0.0f),
|
||||
g_(0.0f),
|
||||
b_(0.0f)
|
||||
@@ -255,14 +256,6 @@ void Scene::DeleteResources() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void Scene::setScreenRotation(int displayOrientation, int cameraOrientation)
|
||||
{
|
||||
color_camera_to_display_rotation_ =
|
||||
tango_gl::util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
displayOrientation, cameraOrientation);
|
||||
LOGI("color_camera_to_display_rotation_=%d", color_camera_to_display_rotation_);
|
||||
}
|
||||
|
||||
//Should only be called in OpenGL thread!
|
||||
void Scene::clear()
|
||||
{
|
||||
@@ -299,32 +292,37 @@ int Scene::Render() {
|
||||
UASSERT(gesture_camera_ != 0);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
if(backfaceCulling_)
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glClearColor(r_, g_, b_, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glm::mat4 rotateM;
|
||||
if(gesture_camera_->GetCameraType() == tango_gl::GestureCamera::kFirstPerson)
|
||||
{
|
||||
rotateM = glm::rotate<float>(float(color_camera_to_display_rotation_)*1.57079632679489661923132169163975144, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
}
|
||||
if(!currentPose_->isNull())
|
||||
{
|
||||
glm::vec3 position(currentPose_->x(), currentPose_->y(), currentPose_->z());
|
||||
Eigen::Quaternionf quat = currentPose_->getQuaternionf();
|
||||
glm::quat rotation(quat.w(), quat.x(), quat.y(), quat.z());
|
||||
|
||||
glm::mat4 rotateM;
|
||||
rotateM = glm::rotate<float>(float(color_camera_to_display_rotation_)*-1.57079632679489661923132169163975144, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
if (gesture_camera_->GetCameraType() == tango_gl::GestureCamera::kFirstPerson)
|
||||
{
|
||||
// In first person mode, we directly control camera's motion.
|
||||
gesture_camera_->SetPosition(position);
|
||||
gesture_camera_->SetRotation(rotation);
|
||||
gesture_camera_->SetRotation(rotation*glm::quat(rotateM));
|
||||
}
|
||||
else
|
||||
{
|
||||
// In third person or top down mode, we follow the camera movement.
|
||||
gesture_camera_->SetAnchorPosition(position, rotation);
|
||||
gesture_camera_->SetAnchorPosition(position, rotation*glm::quat(rotateM));
|
||||
|
||||
frustum_->SetPosition(position);
|
||||
frustum_->SetRotation(rotation);
|
||||
@@ -332,25 +330,25 @@ int Scene::Render() {
|
||||
// camera's aspect ratio, this is just for visualization purposes.
|
||||
frustum_->SetScale(kFrustumScale);
|
||||
frustum_->Render(gesture_camera_->GetProjectionMatrix(),
|
||||
rotateM*gesture_camera_->GetViewMatrix());
|
||||
gesture_camera_->GetViewMatrix());
|
||||
|
||||
axis_->SetPosition(position);
|
||||
axis_->SetRotation(rotation);
|
||||
axis_->Render(gesture_camera_->GetProjectionMatrix(),
|
||||
rotateM*gesture_camera_->GetViewMatrix());
|
||||
gesture_camera_->GetViewMatrix());
|
||||
}
|
||||
|
||||
trace_->UpdateVertexArray(position);
|
||||
if(traceVisible_)
|
||||
{
|
||||
trace_->Render(gesture_camera_->GetProjectionMatrix(),
|
||||
rotateM*gesture_camera_->GetViewMatrix());
|
||||
gesture_camera_->GetViewMatrix());
|
||||
}
|
||||
|
||||
if(gridVisible_)
|
||||
{
|
||||
grid_->Render(gesture_camera_->GetProjectionMatrix(),
|
||||
rotateM*gesture_camera_->GetViewMatrix());
|
||||
gesture_camera_->GetViewMatrix());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,7 +399,7 @@ int Scene::Render() {
|
||||
for(unsigned int i=0; i<indices->size(); ++i)
|
||||
{
|
||||
++cloudDrawn;
|
||||
pointClouds_.find(ids[indices->at(i)])->second->Render(gesture_camera_->GetProjectionMatrix(), rotateM*gesture_camera_->GetViewMatrix(), meshRendering_, pointSize_, meshRenderingTexture_, lighting_);
|
||||
pointClouds_.find(ids[indices->at(i)])->second->Render(gesture_camera_->GetProjectionMatrix(), gesture_camera_->GetViewMatrix(), meshRendering_, pointSize_, meshRenderingTexture_, lighting_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,14 +410,14 @@ int Scene::Render() {
|
||||
if((mapRendering_ || iter->first < 0) && iter->second->isVisible())
|
||||
{
|
||||
++cloudDrawn;
|
||||
iter->second->Render(gesture_camera_->GetProjectionMatrix(), rotateM*gesture_camera_->GetViewMatrix(), meshRendering_, pointSize_, meshRenderingTexture_, lighting_);
|
||||
iter->second->Render(gesture_camera_->GetProjectionMatrix(), gesture_camera_->GetViewMatrix(), meshRendering_, pointSize_, meshRenderingTexture_, lighting_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(graphVisible_ && graph_)
|
||||
{
|
||||
graph_->Render(gesture_camera_->GetProjectionMatrix(), rotateM*gesture_camera_->GetViewMatrix());
|
||||
graph_->Render(gesture_camera_->GetProjectionMatrix(), gesture_camera_->GetViewMatrix());
|
||||
}
|
||||
|
||||
return cloudDrawn;
|
||||
|
||||
@@ -57,7 +57,7 @@ class Scene {
|
||||
// Setup GL view port.
|
||||
void SetupViewPort(int w, int h);
|
||||
|
||||
void setScreenRotation(int displayRotation, int cameraRotation);
|
||||
void setScreenRotation(TangoSupportRotation colorCameraToDisplayRotation) {color_camera_to_display_rotation_ = colorCameraToDisplayRotation;}
|
||||
|
||||
void clear(); // removed all point clouds
|
||||
|
||||
@@ -125,6 +125,7 @@ class Scene {
|
||||
void setPointSize(float size) {pointSize_ = size;}
|
||||
void setFrustumCulling(bool enabled) {frustumCulling_ = enabled;}
|
||||
void setLighting(bool enabled) {lighting_ = enabled;}
|
||||
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 isMeshRendering() const {return meshRendering_;}
|
||||
@@ -132,6 +133,7 @@ class Scene {
|
||||
float getPointSize() const {return pointSize_;}
|
||||
bool isFrustumCulling() const {return frustumCulling_;}
|
||||
bool isLighting() const {return lighting_;}
|
||||
bool isBackfaceCulling() const {return backfaceCulling_;}
|
||||
|
||||
private:
|
||||
// Camera object that allows user to use touch input to interact with.
|
||||
@@ -153,7 +155,7 @@ class Scene {
|
||||
bool gridVisible_;
|
||||
bool traceVisible_;
|
||||
|
||||
TangoSupportDisplayRotation color_camera_to_display_rotation_;
|
||||
TangoSupportRotation color_camera_to_display_rotation_;
|
||||
|
||||
std::map<int, PointCloudDrawable*> pointClouds_;
|
||||
|
||||
@@ -170,6 +172,7 @@ class Scene {
|
||||
float pointSize_;
|
||||
bool frustumCulling_;
|
||||
bool lighting_;
|
||||
bool backfaceCulling_;
|
||||
float r_;
|
||||
float g_;
|
||||
float b_;
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace util {
|
||||
// available are 0, 90, 180, 270. Followed by Android camera orientation
|
||||
// standard:
|
||||
// https://developer.android.com/reference/android/hardware/Camera.CameraInfo.html#orientation
|
||||
TangoSupportDisplayRotation GetAndroidRotationFromColorCameraToDisplay(
|
||||
TangoSupportRotation GetAndroidRotationFromColorCameraToDisplay(
|
||||
int display_rotation, int color_camera_rotation);
|
||||
|
||||
// Get the Android rotation integer value from color camera to display.
|
||||
@@ -101,8 +101,8 @@ namespace util {
|
||||
// available are 0, 90, 180, 270. Followed by Android camera orientation
|
||||
// standard:
|
||||
// https://developer.android.com/reference/android/hardware/Camera.CameraInfo.html#orientation
|
||||
TangoSupportDisplayRotation GetAndroidRotationFromColorCameraToDisplay(
|
||||
TangoSupportDisplayRotation display_rotation, int color_camera_rotation);
|
||||
TangoSupportRotation GetAndroidRotationFromColorCameraToDisplay(
|
||||
TangoSupportRotation display_rotation, int color_camera_rotation);
|
||||
|
||||
} // namespace util
|
||||
} // namespace tango_gl
|
||||
|
||||
@@ -238,23 +238,23 @@ glm::vec3 util::ApplyTransform(const glm::mat4& mat, const glm::vec3& vec) {
|
||||
return glm::vec3(mat * glm::vec4(vec, 1.0f));
|
||||
}
|
||||
|
||||
TangoSupportDisplayRotation util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
TangoSupportRotation util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
int display_rotation, int color_camera_rotation) {
|
||||
TangoSupportDisplayRotation r =
|
||||
static_cast<TangoSupportDisplayRotation>(display_rotation);
|
||||
TangoSupportRotation r =
|
||||
static_cast<TangoSupportRotation>(display_rotation);
|
||||
return util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
r, color_camera_rotation);
|
||||
}
|
||||
|
||||
TangoSupportDisplayRotation util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
TangoSupportDisplayRotation display_rotation, int color_camera_rotation) {
|
||||
TangoSupportRotation util::GetAndroidRotationFromColorCameraToDisplay(
|
||||
TangoSupportRotation display_rotation, int color_camera_rotation) {
|
||||
int color_camera_n = NormalizedColorCameraRotation(color_camera_rotation);
|
||||
|
||||
int ret = static_cast<int>(display_rotation) - color_camera_n;
|
||||
if (ret < 0) {
|
||||
ret += 4;
|
||||
}
|
||||
return static_cast<TangoSupportDisplayRotation>(ret % 4);
|
||||
return static_cast<TangoSupportRotation>(ret % 4);
|
||||
}
|
||||
|
||||
} // namespace tango_gl
|
||||
|
||||
Reference in New Issue
Block a user