g2o
edge_se3_quat.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #include "edge_se3_quat.h"
28 #include "g2o/core/factory.h"
29 #include "se3quat_gradients.h"
30 
31 #ifdef G2O_HAVE_OPENGL
33 #endif
34 
35 #include <iostream>
36 
37 using namespace std;
38 using namespace Eigen;
39 
40 namespace g2o {
41 namespace deprecated {
42 
43 
44  EdgeSE3::EdgeSE3() :
46  {
47  }
48 
49 
51  const VertexSE3* v1 = dynamic_cast<const VertexSE3*>(_vertices[0]);
52  const VertexSE3* v2 = dynamic_cast<const VertexSE3*>(_vertices[1]);
53  _measurement = (v1->estimate().inverse()*v2->estimate());
55  return true;
56  }
57 
58  bool EdgeSE3::read(std::istream& is)
59  {
60  Vector7d meas;
61  for (int i=0; i<7; i++)
62  is >> meas[i];
63  setMeasurement(SE3Quat(meas));
64 
65  for (int i=0; i<6; i++)
66  for (int j=i; j<6; j++) {
67  is >> information()(i,j);
68  if (i!=j)
69  information()(j,i) = information()(i,j);
70  }
71  return true;
72  }
73 
74  bool EdgeSE3::write(std::ostream& os) const
75  {
76  for (int i=0; i<7; i++)
77  os << measurement()[i] << " ";
78  for (int i=0; i<6; i++)
79  for (int j=i; j<6; j++){
80  os << " " << information()(i,j);
81  }
82  return os.good();
83  }
84 
86  {
87  VertexSE3* from = static_cast<VertexSE3*>(_vertices[0]);
88  VertexSE3* to = static_cast<VertexSE3*>(_vertices[1]);
89  if (from_.count(from) > 0) {
90  to->setEstimate(from->estimate() * _measurement);
91  } else
93  }
94 
95 #ifdef EDGE_SE3_QUAT_ANALYTIC_JACOBIAN
97  VertexSE3* from = static_cast<VertexSE3*>(_vertices[0]);
98  VertexSE3* to = static_cast<VertexSE3*>(_vertices[1]);
99 
100  Matrix3d izR = _inverseMeasurement.rotation().toRotationMatrix();
101  const Vector3d& izt = _inverseMeasurement.translation();
102 
103  SE3Quat iXiXj = from->estimate().inverse() * to->estimate();
104  Matrix3d iRiRj = iXiXj.rotation().toRotationMatrix();
105  const Vector3d& ititj = iXiXj.translation();
106 
108  izR(0,0), izR(0,1), izR(0,2), izt(0),
109  izR(1,0), izR(1,1), izR(1,2), izt(1),
110  izR(2,0), izR(2,1), izR(2,2), izt(2),
111  iRiRj(0,0), iRiRj(0,1), iRiRj(0,2), ititj(0),
112  iRiRj(1,0), iRiRj(1,1), iRiRj(1,2), ititj(1),
113  iRiRj(2,0), iRiRj(2,1), iRiRj(2,2), ititj(2));
114  }
115 #endif
116 
117 
118 
120 
122  if (typeid(*element).name()!=_typeName)
123  return 0;
124  WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
125  if (!params->os){
126  std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
127  return 0;
128  }
129 
130  EdgeSE3* e = static_cast<EdgeSE3*>(element);
131  VertexSE3* fromEdge = static_cast<VertexSE3*>(e->vertex(0));
132  VertexSE3* toEdge = static_cast<VertexSE3*>(e->vertex(1));
133  *(params->os) << fromEdge->estimate().translation().x() << " "
134  << fromEdge->estimate().translation().y() << " "
135  << fromEdge->estimate().translation().z() << " ";
136  *(params->os) << fromEdge->estimate().rotation().x() << " "
137  << fromEdge->estimate().rotation().y() << " "
138  << fromEdge->estimate().rotation().z() << " " << std::endl;
139  *(params->os) << toEdge->estimate().translation().x() << " "
140  << toEdge->estimate().translation().y() << " "
141  << toEdge->estimate().translation().z() << " ";
142  *(params->os) << toEdge->estimate().rotation().x() << " "
143  << toEdge->estimate().rotation().y() << " "
144  << toEdge->estimate().rotation().z() << " " << std::endl;
145  *(params->os) << std::endl;
146  return this;
147  }
148 
149 #ifdef G2O_HAVE_OPENGL
150  EdgeSE3DrawAction::EdgeSE3DrawAction(): DrawAction(typeid(EdgeSE3).name()){}
151 
152  HyperGraphElementAction* EdgeSE3DrawAction::operator()(HyperGraph::HyperGraphElement* element,
154  if (typeid(*element).name()!=_typeName)
155  return 0;
156  refreshPropertyPtrs(params_);
157  if (! _previousParams)
158  return this;
159 
160  if (_show && !_show->value())
161  return this;
162 
163  EdgeSE3* e = static_cast<EdgeSE3*>(element);
164  VertexSE3* fromEdge = static_cast<VertexSE3*>(e->vertex(0));
165  VertexSE3* toEdge = static_cast<VertexSE3*>(e->vertex(1));
166  glColor3f(0.5f,0.5f,0.8f);
167  glPushAttrib(GL_ENABLE_BIT);
168  glDisable(GL_LIGHTING);
169  glBegin(GL_LINES);
170  glVertex3f((float)fromEdge->estimate().translation().x(),(float)fromEdge->estimate().translation().y(),(float)fromEdge->estimate().translation().z());
171  glVertex3f((float)toEdge->estimate().translation().x(),(float)toEdge->estimate().translation().y(),(float)toEdge->estimate().translation().z());
172  glEnd();
173  glPopAttrib();
174  return this;
175  }
176 #endif
177 
178 } // end namespace
179 } // end namespace
const Vertex * vertex(size_t i) const
Definition: hyper_graph.h:186
#define __PRETTY_FUNCTION__
Definition: macros.h:89
Abstract action that operates on a graph entity.
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
void jacobian_3d_qman(Eigen::MatrixBase< Derived > &Ji, Eigen::MatrixBase< Derived > &Jj, const double &z11, const double &z12, const double &z13, const double &z14, const double &z21, const double &z22, const double &z23, const double &z24, const double &z31, const double &z32, const double &z33, const double &z34, const double &xab11, const double &xab12, const double &xab13, const double &xab14, const double &xab21, const double &xab22, const double &xab23, const double &xab24, const double &xab31, const double &xab32, const double &xab33, const double &xab34)
Eigen::Matrix< double, 7, 1 > Vector7d
Definition: sim3.h:35
SE3Quat inverse() const
Definition: se3quat.h:120
const std::string & name() const
returns the name of an action, e.g "draw"
virtual bool setMeasurementFromState()
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 ...
virtual void linearizeOplus()
3D edge between two VertexSE3
Definition: edge_se3_quat.h:48
const Eigen::Quaterniond & rotation() const
Definition: se3quat.h:97
3D pose Vertex, (x,y,z,qw,qx,qy,qz) the parameterization for the increments constructed is a 6d vecto...
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.
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
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual void setMeasurement(const SE3Quat &m)
Definition: edge_se3_quat.h:66
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
virtual bool write(std::ostream &os) const
write the vertex to a stream
const Vector3D & translation() const
Definition: se3quat.h:93
VertexContainer _vertices
Definition: hyper_graph.h:202