odometry.cpp
Go to the documentation of this file.
00001 
00004 /*****************************************************************************
00005 ** Includes
00006 *****************************************************************************/
00007 
00008 #include <cmath> // M_PI
00009 
00010 #include "../../include/qglv/gl/headers.hpp"
00011 #include "../../include/qglv/gl/colours.hpp"
00012 #include "../../include/qglv/gl/helpers.hpp"
00013 #include "../../include/qglv/primitives/arrow.hpp"
00014 #include "../../include/qglv/objects/odometry.hpp"
00015 
00016 /*****************************************************************************
00017 ** Namespaces
00018 *****************************************************************************/
00019 
00020 namespace qglv {
00021 
00022 /*****************************************************************************
00023  ** Odometry
00024  *****************************************************************************/
00025 
00026 Odometry::Odometry(const Sophus::SE3f& T_cam_rel_base)
00027 : gl_id_global(-1)
00028 , gl_id_window(-1)
00029 , need_to_rebuild_global_list(false)
00030 , need_to_rebuild_window_list(false)
00031 , size_of_odometry_trail(25)
00032 {
00033   T_extrinsics_rotation = Sophus::SE3f(T_cam_rel_base.rotationMatrix(), T_cam_rel_base.translation());
00034 }
00035 
00036 Odometry::~Odometry() {
00037   if ( gl_id_global > 0 ) {
00038     glDeleteLists(gl_id_global, 1);
00039   }
00040   if ( gl_id_window > 0 ) {
00041     glDeleteLists(gl_id_window, 1);
00042   }
00043 }
00044 
00045 void Odometry::update(const Sophus::SE3f& T_cam_rel_odom) {
00046   /********************
00047    ** All Odometry List
00048    ********************/
00049   static const float rotation_constraint = 18.0f * M_PI / 180.0;  // degrees to radians
00050   static const float squared_translation_constraint = 0.5*0.5;
00051   // check if we push a frame on the global
00052   Sophus::SE3f T_current = T_extrinsics_rotation.inverse()*T_cam_rel_odom;
00053   Sophus::SE3f pose_current = T_current.inverse();
00054   if ( global.size() == 0 ) {
00055     global.push_back(pose_current);
00056     need_to_rebuild_global_list = true;
00057   } else {
00058     Sophus::SE3f pose_last = global.back();
00059     Sophus::SE3f T_last = global.back().inverse();
00060     Sophus::SE3f T_difference = T_current * T_last.inverse();
00061     float squared_translation_difference = T_difference.translation().squaredNorm();
00062     float angle_difference_radians = T_last.unit_quaternion().angularDistance(T_current.unit_quaternion());
00063     if ( ( squared_translation_difference > squared_translation_constraint ) ||
00064          (angle_difference_radians > rotation_constraint ) ) {
00065 //        std::cout << "*Differences: " << squared_translation_difference << "," << angle_difference_radians << "[" << rotation_constraint << "]" << std::endl;
00066       need_to_rebuild_global_list = true;
00067       global.push_back(pose_current);
00068     }
00069   }
00070 
00071   /********************
00072    ** Odometry Trail
00073    ********************/
00074   // Unrotate the camera rel odom transform so that it aligns with the robot front
00075   Sophus::SE3f T = T_extrinsics_rotation.inverse()*T_cam_rel_odom;
00076   window.push_back(T.inverse());
00077   if ( window.size() > size_of_odometry_trail ) {
00078     window.pop_front();
00079     need_to_rebuild_window_list = true;
00080   }
00081 }
00082 
00083 void Odometry::_glGenLists() {
00084   static const float draw_keyframe_size = 0.1;
00085   static const float draw_arrow_length = 0.3;
00086   static const float draw_arrow_radius = 0.01;
00087 
00088   if ( need_to_rebuild_window_list ) {
00089     if ( gl_id_window > 0 ) {
00090       glDeleteLists(gl_id_window, 1);
00091     }
00092     gl_id_window = ::glGenLists(1);
00093     glNewList( gl_id_window, GL_COMPILE );
00094     for ( const auto& pose : window ) {
00095       arrow(pose, 0.3*draw_arrow_length, 0.5*draw_arrow_radius);
00096     }
00097     glEndList();
00098   }
00099 
00100   if ( need_to_rebuild_global_list ) {
00101     if ( gl_id_global > 0 ) {
00102       glDeleteLists(gl_id_global, 1);
00103     }
00104     gl_id_global = ::glGenLists(1);
00105     glNewList( gl_id_global, GL_COMPILE );
00106     for ( const auto& pose : global ) {
00107       arrow(pose, draw_arrow_length, draw_arrow_radius);
00108     }
00109     glEndList();
00110   }
00111 }
00112 
00113 void Odometry::draw() {
00114   if ( need_to_rebuild_global_list || need_to_rebuild_window_list ) {
00115     _glGenLists();
00116     need_to_rebuild_global_list = false;
00117     need_to_rebuild_window_list = false;
00118   }
00119   qglv::colour(Magenta);
00120   glPushMatrix();
00121   if (gl_id_global > 0) {
00122     glCallList(gl_id_global);
00123   }
00124   if (gl_id_window > 0) {
00125     glCallList(gl_id_window);
00126   }
00127   glPopMatrix();
00128 }
00129 
00130 void Odometry::draw(const Sophus::SE3f& T_map_rel_odom) {
00131   if ( need_to_rebuild_global_list || need_to_rebuild_window_list ) {
00132     _glGenLists();
00133     need_to_rebuild_global_list = false;
00134     need_to_rebuild_window_list = false;
00135   }
00136 
00137   qglv::colour(Orange);
00138   glPushMatrix();
00139   qglv::moveTo(T_map_rel_odom.inverse());
00140   if (gl_id_global > 0) {
00141     glCallList(gl_id_global);
00142   }
00143   if (gl_id_window > 0) {
00144     glCallList(gl_id_window);
00145   }
00146   glPopMatrix();
00147 }
00148 
00149 /*****************************************************************************
00150  ** Trailers
00151  *****************************************************************************/
00152 
00153 } // namespace qglv


qglv_opengl
Author(s): Daniel Stonier
autogenerated on Sat Jun 18 2016 08:19:28