g2o
edge_se3.cpp
Go to the documentation of this file.
1 #include "edge_se3.h"
2 #include "isometry3d_gradients.h"
3 #include <iostream>
4 
5 #ifdef G2O_HAVE_OPENGL
8 #endif
9 
10 namespace g2o {
11  using namespace std;
12  using namespace Eigen;
13 
15  information().setIdentity();
16  }
17 
18  bool EdgeSE3::read(std::istream& is) {
19  Vector7d meas;
20  for (int i=0; i<7; i++)
21  is >> meas[i];
22  // normalize the quaternion to recover numerical precision lost by storing as human readable text
23  Vector4D::MapType(meas.data()+3).normalize();
25 
26  if (is.bad()) {
27  return false;
28  }
29  for ( int i=0; i<information().rows() && is.good(); i++)
30  for (int j=i; j<information().cols() && is.good(); j++){
31  is >> information()(i,j);
32  if (i!=j)
33  information()(j,i)=information()(i,j);
34  }
35  if (is.bad()) {
36  // we overwrite the information matrix with the Identity
37  information().setIdentity();
38  }
39  return true;
40  }
41 
42  bool EdgeSE3::write(std::ostream& os) const {
44  for (int i=0; i<7; i++) os << meas[i] << " ";
45  for (int i=0; i<information().rows(); i++)
46  for (int j=i; j<information().cols(); j++) {
47  os << information()(i,j) << " ";
48  }
49  return os.good();
50  }
51 
53  VertexSE3 *from = static_cast<VertexSE3*>(_vertices[0]);
54  VertexSE3 *to = static_cast<VertexSE3*>(_vertices[1]);
55  Isometry3D delta=_inverseMeasurement * from->estimate().inverse() * to->estimate();
57  }
58 
60  VertexSE3 *from = static_cast<VertexSE3*>(_vertices[0]);
61  VertexSE3 *to = static_cast<VertexSE3*>(_vertices[1]);
62  Isometry3D delta = from->estimate().inverse() * to->estimate();
63  setMeasurement(delta);
64  return true;
65  }
66 
68 
69  // BaseBinaryEdge<6, Isometry3D, VertexSE3, VertexSE3>::linearizeOplus();
70  // return;
71 
72  VertexSE3 *from = static_cast<VertexSE3*>(_vertices[0]);
73  VertexSE3 *to = static_cast<VertexSE3*>(_vertices[1]);
74  Isometry3D E;
75  const Isometry3D& Xi=from->estimate();
76  const Isometry3D& Xj=to->estimate();
77  const Isometry3D& Z=_measurement;
79  }
80 
82  VertexSE3 *from = static_cast<VertexSE3*>(_vertices[0]);
83  VertexSE3 *to = static_cast<VertexSE3*>(_vertices[1]);
84 
85  if (from_.count(from) > 0) {
86  to->setEstimate(from->estimate() * _measurement);
87  } else
88  from->setEstimate(to->estimate() * _measurement.inverse());
89  //cerr << "IE" << endl;
90  }
91 
93 
95  if (typeid(*element).name()!=_typeName)
96  return 0;
98  if (!params->os){
99  std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
100  return 0;
101  }
102 
103  EdgeSE3* e = static_cast<EdgeSE3*>(element);
104  VertexSE3* fromEdge = static_cast<VertexSE3*>(e->vertices()[0]);
105  VertexSE3* toEdge = static_cast<VertexSE3*>(e->vertices()[1]);
106  Vector6d fromV, toV;
107  fromV=internal::toVectorMQT(fromEdge->estimate());
108  toV=internal::toVectorMQT(toEdge->estimate());
109  for (int i=0; i<6; i++){
110  *(params->os) << fromV[i] << " ";
111  }
112  for (int i=0; i<6; i++){
113  *(params->os) << toV[i] << " ";
114  }
115  *(params->os) << std::endl;
116  return this;
117  }
118 
119 #ifdef G2O_HAVE_OPENGL
120  EdgeSE3DrawAction::EdgeSE3DrawAction(): DrawAction(typeid(EdgeSE3).name()){}
121 
122  HyperGraphElementAction* EdgeSE3DrawAction::operator()(HyperGraph::HyperGraphElement* element,
124  if (typeid(*element).name()!=_typeName)
125  return 0;
126  refreshPropertyPtrs(params_);
127  if (! _previousParams)
128  return this;
129 
130  if (_show && !_show->value())
131  return this;
132 
133  EdgeSE3* e = static_cast<EdgeSE3*>(element);
134  VertexSE3* fromEdge = static_cast<VertexSE3*>(e->vertices()[0]);
135  VertexSE3* toEdge = static_cast<VertexSE3*>(e->vertices()[1]);
136  if (! fromEdge || ! toEdge)
137  return this;
138  glColor3f(POSE_EDGE_COLOR);
139  glPushAttrib(GL_ENABLE_BIT);
140  glDisable(GL_LIGHTING);
141  glBegin(GL_LINES);
142  glVertex3f((float)fromEdge->estimate().translation().x(),(float)fromEdge->estimate().translation().y(),(float)fromEdge->estimate().translation().z());
143  glVertex3f((float)toEdge->estimate().translation().x(),(float)toEdge->estimate().translation().y(),(float)toEdge->estimate().translation().z());
144  glEnd();
145  glPopAttrib();
146  return this;
147  }
148 #endif
149 
150 }
void computeError()
Definition: edge_se3.cpp:52
#define __PRETTY_FUNCTION__
Definition: macros.h:89
#define POSE_EDGE_COLOR
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition: edge_se3.cpp:18
Isometry3D fromVectorQT(const Vector7d &v)
void linearizeOplus()
Definition: edge_se3.cpp:67
Abstract action that operates on a graph entity.
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, HyperGraphElementAction::Parameters *params_)
redefine this to do the action stuff. If successful, the action returns a pointer to itself ...
Definition: edge_se3.cpp:94
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition: edge_se3.cpp:42
Eigen::Matrix< double, 7, 1 > Vector7d
Definition: sim3.h:35
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
Definition: edge_se3.cpp:81
const std::string & name() const
returns the name of an action, e.g "draw"
Edge between two 3D pose vertices.
Definition: edge_se3.h:18
virtual bool setMeasurementFromState()
Definition: edge_se3.cpp:59
const VertexContainer & vertices() const
Definition: hyper_graph.h:178
virtual void setMeasurement(const Isometry3D &m)
Definition: edge_se3.h:27
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3D
Definition: eigen_types.h:66
Eigen::Quaterniond & normalize(Eigen::Quaterniond &q)
Vector6d toVectorMQT(const Isometry3D &t)
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
A general case Vertex for optimization.
Isometry3D _inverseMeasurement
Definition: edge_se3.h:58
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:67
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
void computeEdgeSE3Gradient(Isometry3D &E, Eigen::MatrixBase< Derived > const &JiConstRef, Eigen::MatrixBase< Derived > const &JjConstRef, const Isometry3D &Z, const Isometry3D &Xi, const Isometry3D &Xj, const Isometry3D &Pi, const Isometry3D &Pj)
3D pose Vertex, represented as an Isometry3D
Definition: vertex_se3.h:50
Vector7d toVectorQT(const Isometry3D &t)
Matrix< double, 6, 1, Eigen::ColMajor > Vector6d
Definition: types_icp.cpp:75
VertexContainer _vertices
Definition: hyper_graph.h:202