g2o
edge_se2_segment2d.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_segment2d.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 EdgeSE2Segment2D::read(std::istream& is)
49  {
50  for (size_t i = 0; i < 4 ; i++)
51  is >> _measurement[i];
52  for (size_t i = 0; i < 4 ; i++)
53  for (size_t j = i; j < 4 ; j++) {
54  is >> _information (i,j);
55  _information (j,i) = _information (i,j);
56  }
57  return true;
58  }
59 
60  bool EdgeSE2Segment2D::write(std::ostream& os) const
61  {
62  for (size_t i = 0; i < 4 ; i++)
63  os << _measurement[i] << " ";
64  for (size_t i = 0; i < 4 ; i++)
65  for (size_t j = i; j < 4 ; j++) {
66  os << _information (i,j) << " ";
67  }
68  return os.good();
69  }
70 
72  {
73  assert(from.size() == 1 && from.count(_vertices[0]) == 1 && "Can not initialize VertexSE2 position by VertexSegment2D. I could if i wanted. Not now");
74 
75  VertexSE2* vi = static_cast<VertexSE2*>(_vertices[0]);
76  VertexSegment2D* vj = static_cast<VertexSegment2D*>(_vertices[1]);
77  if (from.count(vi) > 0 && to == vj) {
78  vj->setEstimateP1(vi->estimate() * measurementP1());
79  vj->setEstimateP2(vi->estimate() * measurementP2());
80  }
81  }
82 
83 // #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES
84 // void EdgeSE2Segment2D::linearizeOplus()
85 // {
86 // const VertexSE2* vi = static_cast<const VertexSE2*>(_vertices[0]);
87 // const VertexSegment2D* vj = static_cast<const VertexSegment2D*>(_vertices[1]);
88 // const double& x1 = vi->estimate().translation()[0];
89 // const double& y1 = vi->estimate().translation()[1];
90 // const double& th1 = vi->estimate().rotation().angle();
91 // const double& x2 = vj->estimate()[0];
92 // const double& y2 = vj->estimate()[1];
93 
94 // double aux_1 = cos(th1) ;
95 // double aux_2 = -aux_1 ;
96 // double aux_3 = sin(th1) ;
97 
98 // _jacobianOplusXi( 0 , 0 ) = aux_2 ;
99 // _jacobianOplusXi( 0 , 1 ) = -aux_3 ;
100 // _jacobianOplusXi( 0 , 2 ) = aux_1*y2-aux_1*y1-aux_3*x2+aux_3*x1 ;
101 // _jacobianOplusXi( 1 , 0 ) = aux_3 ;
102 // _jacobianOplusXi( 1 , 1 ) = aux_2 ;
103 // _jacobianOplusXi( 1 , 2 ) = -aux_3*y2+aux_3*y1-aux_1*x2+aux_1*x1 ;
104 
105 // _jacobianOplusXj( 0 , 0 ) = aux_1 ;
106 // _jacobianOplusXj( 0 , 1 ) = aux_3 ;
107 // _jacobianOplusXj( 1 , 0 ) = -aux_3 ;
108 // _jacobianOplusXj( 1 , 1 ) = aux_1 ;
109 // }
110 // #endif
111 
112 // EdgeSE2Segment2DWriteGnuplotAction::EdgeSE2Segment2DWriteGnuplotAction(): WriteGnuplotAction(typeid(EdgeSE2Segment2D).name()){}
113 
114 // HyperGraphElementAction* EdgeSE2Segment2DWriteGnuplotAction::operator()(HyperGraph::HyperGraphElement* element, HyperGraphElementAction::Parameters* params_){
115 // if (typeid(*element).name()!=_typeName)
116 // return 0;
117 // WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
118 // if (!params->os){
119 // std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
120 // return 0;
121 // }
122 
123 // EdgeSE2Segment2D* e = static_cast<EdgeSE2Segment2D*>(element);
124 // VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
125 // VertexSegment2D* toEdge = static_cast<VertexSegment2D*>(e->vertex(1));
126 // *(params->os) << fromEdge->estimate().translation().x() << " " << fromEdge->estimate().translation().y()
127 // << " " << fromEdge->estimate().rotation().angle() << std::endl;
128 // *(params->os) << toEdge->estimate().x() << " " << toEdge->estimate().y() << std::endl;
129 // *(params->os) << std::endl;
130 // return this;
131 // }
132 
133 // #ifdef G2O_HAVE_OPENGL
134 // EdgeSE2Segment2DDrawAction::EdgeSE2Segment2DDrawAction(): DrawAction(typeid(EdgeSE2Segment2D).name()){}
135 
136 // HyperGraphElementAction* EdgeSE2Segment2DDrawAction::operator()(HyperGraph::HyperGraphElement* element,
137 // HyperGraphElementAction::Parameters* params_){
138 // if (typeid(*element).name()!=_typeName)
139 // return 0;
140 
141 // refreshPropertyPtrs(params_);
142 // if (! _previousParams)
143 // return this;
144 
145 // if (_show && !_show->value())
146 // return this;
147 
148 
149 // EdgeSE2Segment2D* e = static_cast<EdgeSE2Segment2D*>(element);
150 // VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
151 // VertexSegment2D* toEdge = static_cast<VertexSegment2D*>(e->vertex(1));
152 // glColor3f(0.4f,0.4f,0.2f);
153 // glPushAttrib(GL_ENABLE_BIT);
154 // glDisable(GL_LIGHTING);
155 // glBegin(GL_LINES);
156 // glVertex3f((float)fromEdge->estimate().translation().x(),(float)fromEdge->estimate().translation().y(),0.f);
157 // glVertex3f((float)toEdge->estimate().x(),(float)toEdge->estimate().y(),0.f);
158 // glEnd();
159 // glPopAttrib();
160 // return this;
161 // }
162 // #endif
163 
164 } // end namespace
G2O_TYPES_SLAM2D_ADDONS_API EIGEN_MAKE_ALIGNED_OPERATOR_NEW G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2D()
Eigen::Matrix< double, 4, 1, Eigen::ColMajor > Vector4D
Definition: eigen_types.h:47
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
InformationType _information
Definition: base_edge.h:88
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
void setEstimateP2(const Vector2D &p2)
virtual G2O_TYPES_SLAM2D_ADDONS_API bool write(std::ostream &os) const
write the vertex to a stream
void setEstimateP1(const Vector2D &p1)
G2O_TYPES_SLAM2D_ADDONS_API Vector2D measurementP1()
A general case Vertex for optimization.
G2O_TYPES_SLAM2D_ADDONS_API Vector2D measurementP2()
virtual G2O_TYPES_SLAM2D_ADDONS_API bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual G2O_TYPES_SLAM2D_ADDONS_API void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
VertexContainer _vertices
Definition: hyper_graph.h:202