Go to the documentation of this file.00001
00004
00005
00006
00007
00008 #include <Eigen/Core>
00009 #include <Eigen/Geometry>
00010
00011 #include "../../include/qglv/gl/headers.hpp"
00012 #include "../../include/qglv/primitives/arrow.hpp"
00013 #include "../../include/qglv/objects/edges.hpp"
00014
00015
00016
00017
00018
00019 namespace qglv {
00020
00021
00022
00023
00024
00025 Edges::Edges()
00026 : updated(false)
00027 , gl_id(-1)
00028 {
00029 }
00030
00031 Edges::~Edges() {
00032 if ( gl_id > 0 ) {
00033 glDeleteLists(gl_id, 1);
00034 }
00035 }
00036
00037 void Edges::add(const Sophus::SE3f& T_start, const Sophus::SE3f& T_end) {
00038
00039 Sophus::SE3f T_inv = T_start.inverse();
00040 vertice_array.push_back(T_inv.translation().x());
00041 vertice_array.push_back(T_inv.translation().y());
00042 vertice_array.push_back(T_inv.translation().z());
00043 T_inv = T_end.inverse();
00044 vertice_array.push_back(T_inv.translation().x());
00045 vertice_array.push_back(T_inv.translation().y());
00046 vertice_array.push_back(T_inv.translation().z());
00047 updated = true;
00048 }
00049
00050 void Edges::clear() {
00051 vertice_array.clear();
00052 updated = true;
00053 }
00054
00055 void Edges::draw() {
00056 if ( updated ) {
00057 _glGenLists();
00058 }
00059 ::glCallList(gl_id);
00060 }
00061
00062 void Edges::_glGenLists() {
00063 gl_id = ::glGenLists(1);
00064 glNewList( gl_id, GL_COMPILE );
00065 glColor3f(0.1f, 0.2f, 0.1f);
00066 glLineWidth(0.1f);
00067 glEnableClientState(GL_VERTEX_ARRAY);
00068 glVertexPointer(3, GL_FLOAT, 0, vertice_array.data() );
00069 glDrawArrays(GL_LINES, 0, vertice_array.size() / 3 );
00070 glDisableClientState(GL_VERTEX_ARRAY);
00071 glEndList();
00072 }
00073
00074
00075
00076
00077
00078 DirectedEdges::DirectedEdges(const Colour& colour, const float& radius)
00079 : updated(false)
00080 , gl_id(-1)
00081 , colour(colour)
00082 , radius(radius)
00083 {
00084 }
00085
00086 DirectedEdges::~DirectedEdges() {
00087 if ( gl_id > 0 ) {
00088 glDeleteLists(gl_id, 1);
00089 }
00090 }
00091
00092 void DirectedEdges::add(const Sophus::SE3f& T_start, const Sophus::SE3f& T_end) {
00093 transforms.push_back(std::pair<Sophus::SE3f, Sophus::SE3f>(T_start, T_end));
00094 updated = true;
00095 }
00096
00097 void DirectedEdges::clear() {
00098 transforms.clear();
00099 updated = true;
00100 }
00101
00102 void DirectedEdges::draw() {
00103 if ( updated ) {
00104 _glGenLists();
00105 }
00106 if ( (gl_id > 0) ) {
00107 ::glCallList(gl_id);
00108 }
00109 }
00110
00111 void DirectedEdges::_glGenLists() {
00112 if ( gl_id > 0 ) {
00113 glDeleteLists(gl_id, 1);
00114 }
00115 gl_id = ::glGenLists(1);
00116 glNewList( gl_id, GL_COMPILE );
00117 qglv::colour(colour);
00118 for ( const auto& transform_pair : transforms ) {
00119 Sophus::SE3f T_end_rel_start = transform_pair.second*transform_pair.first.inverse();
00120 float length = T_end_rel_start.inverse().translation().norm();
00121 Eigen::Vector3f new_x_axis = transform_pair.second.inverse().translation() - transform_pair.first.inverse().translation();
00122 Eigen::Quaternionf orientation = Eigen::Quaternionf::FromTwoVectors(Eigen::Vector3f::UnitX(), new_x_axis);
00123 Eigen::Vector3f translation = transform_pair.first.inverse().translation();
00124 Sophus::SE3f pose(orientation, translation);
00125 qglv::arrow(pose, length, radius);
00126 }
00127 glEndList();
00128 updated = false;
00129 }
00130
00131
00132 }