g2o
edge_se2_line2d.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_se2_line2d.h"
28 
29 #ifdef WINDOWS
30 #include <windows.h>
31 #endif
32 
33 #ifdef G2O_HAVE_OPENGL
34 #ifdef __APPLE__
35 #include <OpenGL/gl.h>
36 #else
37 #include <GL/gl.h>
38 #endif
39 #endif
40 
41 namespace g2o {
42 
45  {
46  }
47 
48  bool EdgeSE2Line2D::read(std::istream& is)
49  {
50  is >> _measurement[0] >> _measurement[1];
51  is >> information()(0,0) >> information()(0,1) >> information()(1,1);
52  information()(1,0) = information()(0,1);
53  return true;
54  }
55 
56  bool EdgeSE2Line2D::write(std::ostream& os) const
57  {
58  os << measurement()[0] << " " << measurement()[1] << " ";
59  os << information()(0,0) << " " << information()(0,1) << " " << information()(1,1);
60  return os.good();
61  }
62 
64  {
65  assert(from.size() == 1 && from.count(_vertices[0]) == 1 && "Can not initialize VertexSE2 position by VertexLine2D");
66 
67  VertexSE2* vi = static_cast<VertexSE2*>(_vertices[0]);
68  VertexLine2D* vj = static_cast<VertexLine2D*>(_vertices[1]);
69  if (from.count(vi) > 0 && to == vj) {
70  SE2 T=vi->estimate();
72  est[0] += T.rotation().angle();
73  est[0] = normalize_theta(est[0]);
74  Vector2D n(cos(est[0]), sin(est[0]));
75  est[1] += n.dot(T.translation());
76  vj->setEstimate(est);
77  }
78  }
79 
80 // #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES
81 // void EdgeSE2Line2D::linearizeOplus()
82 // {
83 // const VertexSE2* vi = static_cast<const VertexSE2*>(_vertices[0]);
84 // const VertexLine2D* vj = static_cast<const VertexLine2D*>(_vertices[1]);
85 // const double& x1 = vi->estimate().translation()[0];
86 // const double& y1 = vi->estimate().translation()[1];
87 // const double& th1 = vi->estimate().rotation().angle();
88 // const double& x2 = vj->estimate()[0];
89 // const double& y2 = vj->estimate()[1];
90 
91 // double aux_1 = cos(th1) ;
92 // double aux_2 = -aux_1 ;
93 // double aux_3 = sin(th1) ;
94 
95 // _jacobianOplusXi( 0 , 0 ) = aux_2 ;
96 // _jacobianOplusXi( 0 , 1 ) = -aux_3 ;
97 // _jacobianOplusXi( 0 , 2 ) = aux_1*y2-aux_1*y1-aux_3*x2+aux_3*x1 ;
98 // _jacobianOplusXi( 1 , 0 ) = aux_3 ;
99 // _jacobianOplusXi( 1 , 1 ) = aux_2 ;
100 // _jacobianOplusXi( 1 , 2 ) = -aux_3*y2+aux_3*y1-aux_1*x2+aux_1*x1 ;
101 
102 // _jacobianOplusXj( 0 , 0 ) = aux_1 ;
103 // _jacobianOplusXj( 0 , 1 ) = aux_3 ;
104 // _jacobianOplusXj( 1 , 0 ) = -aux_3 ;
105 // _jacobianOplusXj( 1 , 1 ) = aux_1 ;
106 // }
107 // #endif
108 
109 // EdgeSE2Line2DWriteGnuplotAction::EdgeSE2Line2DWriteGnuplotAction(): WriteGnuplotAction(typeid(EdgeSE2Line2D).name()){}
110 
111 // HyperGraphElementAction* EdgeSE2Line2DWriteGnuplotAction::operator()(HyperGraph::HyperGraphElement* element, HyperGraphElementAction::Parameters* params_){
112 // if (typeid(*element).name()!=_typeName)
113 // return 0;
114 // WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
115 // if (!params->os){
116 // std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
117 // return 0;
118 // }
119 
120 // EdgeSE2Line2D* e = static_cast<EdgeSE2Line2D*>(element);
121 // VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
122 // VertexLine2D* toEdge = static_cast<VertexLine2D*>(e->vertex(1));
123 // *(params->os) << fromEdge->estimate().translation().x() << " " << fromEdge->estimate().translation().y()
124 // << " " << fromEdge->estimate().rotation().angle() << std::endl;
125 // *(params->os) << toEdge->estimate().x() << " " << toEdge->estimate().y() << std::endl;
126 // *(params->os) << std::endl;
127 // return this;
128 // }
129 
130 // #ifdef G2O_HAVE_OPENGL
131 // EdgeSE2Line2DDrawAction::EdgeSE2Line2DDrawAction(): DrawAction(typeid(EdgeSE2Line2D).name()){}
132 
133 // HyperGraphElementAction* EdgeSE2Line2DDrawAction::operator()(HyperGraph::HyperGraphElement* element,
134 // HyperGraphElementAction::Parameters* params_){
135 // if (typeid(*element).name()!=_typeName)
136 // return 0;
137 
138 // refreshPropertyPtrs(params_);
139 // if (! _previousParams)
140 // return this;
141 
142 // if (_show && !_show->value())
143 // return this;
144 
145 
146 // EdgeSE2Line2D* e = static_cast<EdgeSE2Line2D*>(element);
147 // VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
148 // VertexLine2D* toEdge = static_cast<VertexLine2D*>(e->vertex(1));
149 // glColor3f(0.4f,0.4f,0.2f);
150 // glPushAttrib(GL_ENABLE_BIT);
151 // glDisable(GL_LIGHTING);
152 // glBegin(GL_LINES);
153 // glVertex3f((float)fromEdge->estimate().translation().x(),(float)fromEdge->estimate().translation().y(),0.f);
154 // glVertex3f((float)toEdge->estimate().x(),(float)toEdge->estimate().y(),0.f);
155 // glEnd();
156 // glPopAttrib();
157 // return this;
158 // }
159 // #endif
160 
161 } // end namespace
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
virtual bool write(std::ostream &os) const
write the vertex to a stream
Measurement _measurement
Definition: base_edge.h:87
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
represent SE2
Definition: se2.h:40
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
const Eigen::Rotation2Dd & rotation() const
rotational component
Definition: se2.h:58
double normalize_theta(double theta)
Definition: misc.h:94
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeSE2Line2D()
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 Vector2D & translation() const
translational component
Definition: se2.h:54
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
VertexContainer _vertices
Definition: hyper_graph.h:202