vertex_se3_quat.cpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "vertex_se3_quat.h"
00018 #include "g2o/core/factory.h"
00019 
00020 #ifdef G2O_HAVE_OPENGL
00021 #ifdef __APPLE__
00022 #include <OpenGL/gl.h>
00023 #else
00024 #include <GL/gl.h>
00025 #endif
00026 #endif
00027 
00028 #include <iostream>
00029 
00030 namespace g2o {
00031 
00032   VertexSE3::VertexSE3() :
00033     BaseVertex<6, SE3Quat>()
00034   {
00035   }
00036 
00037   bool VertexSE3::read(std::istream& is)
00038   {
00039     for (int i=0; i<7; i++)
00040       is  >> estimate()[i];
00041     estimate().rotation().normalize();
00042     return true;
00043   }
00044 
00045   bool VertexSE3::write(std::ostream& os) const
00046   {
00047     for (int i=0; i<7; i++)
00048       os << estimate()[i] << " ";
00049     return os.good();
00050   }
00051 
00052   VertexSE3WriteGnuplotAction::VertexSE3WriteGnuplotAction(): WriteGnuplotAction(typeid(VertexSE3).name()){}
00053 
00054   HyperGraphElementAction* VertexSE3WriteGnuplotAction::operator()(HyperGraph::HyperGraphElement* element, HyperGraphElementAction::Parameters* params_){
00055     if (typeid(*element).name()!=_typeName)
00056       return 0;
00057     WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
00058     if (!params->os){
00059       std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
00060       return 0;
00061     }
00062     
00063     VertexSE3* v =  static_cast<VertexSE3*>(element);
00064     *(params->os) << v->estimate().translation().x() << " " 
00065                   << v->estimate().translation().y() << " " 
00066                   << v->estimate().translation().z() << " ";
00067     *(params->os) << v->estimate().rotation().x() << " " 
00068                   << v->estimate().rotation().y() << " " 
00069                   << v->estimate().rotation().z() << " " << std::endl;
00070     return this;
00071   }
00072 
00073 #ifdef G2O_HAVE_OPENGL
00074   VertexSE3DrawAction::VertexSE3DrawAction(): DrawAction(typeid(VertexSE3).name()){}
00075 
00076   HyperGraphElementAction* VertexSE3DrawAction::operator()(HyperGraph::HyperGraphElement* element, 
00077                                                            HyperGraphElementAction::Parameters* /*params_*/){
00078     if (typeid(*element).name()!=_typeName)
00079       return 0;
00080     VertexSE3* that = static_cast<VertexSE3*>(element);
00081     float xSize=1;
00082     float ySize2=.5;
00083     float zSize2=.5;
00084 
00085     static bool first = true;
00086     static Vector3f p[6];
00087     if (first) {
00088       first = false;
00089       p[0] << xSize, 0., 0.;
00090       p[1] << -xSize, -ySize2, -zSize2;
00091       p[2] << -xSize,  ySize2, -zSize2;
00092       p[3] << -xSize,  ySize2,  zSize2;
00093       p[4] << -xSize, -ySize2,  zSize2;
00094       p[5] << -xSize, -ySize2, -zSize2;
00095     }
00096 
00097     glColor3f(0.5,0.5,0.8);
00098     glPushMatrix();
00099     glTranslatef(that->estimate().translation().x(),that->estimate().translation().y(),that->estimate().translation().z());
00100     AngleAxisd aa(that->estimate().rotation());
00101     glRotatef(RAD2DEG(aa.angle()),aa.axis().x(),aa.axis().y(),aa.axis().z());
00102 
00103     glBegin(GL_TRIANGLES);
00104     for (int i = 1; i < 5; ++i) {
00105       Vector3f normal = (p[i] - p[0]).cross(p[i+1] - p[0]);
00106       glNormal3f(normal.x(), normal.y(), normal.z());
00107       glVertex3f(p[0].x(), p[0].y(), p[0].z());
00108       glVertex3f(p[i].x(), p[i].y(), p[i].z());
00109       glVertex3f(p[i+1].x(), p[i+1].y(), p[i+1].z());
00110     }
00111   
00112     glNormal3f(-1,0,0);
00113     for (int i = 1; i < 4; ++i)
00114       glVertex3f(p[i].x(), p[i].y(), p[i].z());
00115     for (int i = 3; i < 6; ++i)
00116       glVertex3f(p[i].x(), p[i].y(), p[i].z());
00117 
00118     glEnd();
00119     glPopMatrix();
00120     return this;
00121   }
00122 #endif
00123 
00124 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:33:41