g2o
edge_se2_segment2d_pointLine.h
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 #ifndef G2O_EDGE_SE2_SEGMENT2D_POINTLINE_H
28 #define G2O_EDGE_SE2_SEGMENT2D_POINTLINE_H
29 
30 #include "g2o/config.h"
32 #include "vertex_segment2d.h"
35 
36 namespace g2o {
37 
38  class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DPointLine : public BaseBinaryEdge<3, Vector3D, VertexSE2, VertexSegment2D>
39  {
40  public:
41  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43 
44  double theta() const {return _measurement[2];}
45  Vector2D point() const {Eigen::Map<const Vector2D> p(&_measurement[0]); return p;}
46 
47  void setTheta(double t) {_measurement[2] = t;}
48  void setPoint(const Vector2D& p_) {Eigen::Map<Vector2D> p(&_measurement[0]); p=p_; }
49 
50  int pointNum() const {return _pointNum;}
51  void setPointNum(int pn) {_pointNum = pn;}
52 
53  void computeError()
54  {
55  const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
56  const VertexSegment2D* l2 = static_cast<const VertexSegment2D*>(_vertices[1]);
57  SE2 iEst=v1->estimate().inverse();
58  Vector2D predP1 = iEst * l2->estimateP1();
59  Vector2D predP2 = iEst * l2->estimateP2();
60  Vector2D dP = predP2 - predP1;
61  Vector2D normal(dP.y(), -dP.x()); normal.normalize();
62  Vector3D prediction;
63  prediction [2] = atan2(normal.y(), normal.x());
64  Eigen::Map<Vector2D> pt(&prediction[0]);
65  pt = (_pointNum==0) ? predP1 : predP2;
66  _error=prediction-_measurement;
67  _error[2]=normalize_theta(_error[2]);
68  }
69 
70  virtual bool setMeasurementData(const double* d){
71  Eigen::Map<const Vector3D> data(d);
72  _measurement = data;
73  return true;
74  }
75 
76  virtual bool getMeasurementData(double* d) const{
77  Eigen::Map<Vector3D> data(d);
78  data = _measurement;
79  return true;
80  }
81 
82  virtual int measurementDimension() const {return 3;}
83 
84  virtual bool setMeasurementFromState(){
85  const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
86  const VertexSegment2D* l2 = static_cast<const VertexSegment2D*>(_vertices[1]);
87  SE2 iEst=v1->estimate().inverse();
88  Vector2D predP1 = iEst * l2->estimateP1();
89  Vector2D predP2 = iEst * l2->estimateP2();
90  Vector2D dP = predP2 - predP1;
91  Vector2D normal(dP.y(), -dP.x()); normal.normalize();
92  Vector3D prediction;
93  prediction [2] = atan2(normal.y(), normal.x());
94  Eigen::Map<Vector2D> pt(&prediction[0]);
95  pt = (_pointNum==0)?predP1:predP2;
96  setMeasurement(prediction);
97  return true;
98  }
99 
100  virtual bool read(std::istream& is);
101  virtual bool write(std::ostream& os) const;
102 
103  protected:
105 
106 /* #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES */
107 /* virtual void linearizeOplus(); */
108 /* #endif */
109  };
110 
111 /* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DPointLineWriteGnuplotAction: public WriteGnuplotAction { */
112 /* public: */
113 /* EdgeSE2Segment2DPointLineWriteGnuplotAction(); */
114 /* virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, */
115 /* HyperGraphElementAction::Parameters* params_); */
116 /* }; */
117 
118 /* #ifdef G2O_HAVE_OPENGL */
119 /* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DPointLineDrawAction: public DrawAction{ */
120 /* public: */
121 /* EdgeSE2Segment2DPointLineDrawAction(); */
122 /* virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, */
123 /* HyperGraphElementAction::Parameters* params_); */
124 /* }; */
125 /* #endif */
126 
127 } // end namespace
128 
129 #endif
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
represent SE2
Definition: se2.h:40
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
virtual bool getMeasurementData(double *d) const
double normalize_theta(double theta)
Definition: misc.h:94
#define G2O_TYPES_SLAM2D_ADDONS_API
Vector2D estimateP1() const
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
Vector2D estimateP2() const
SE2 inverse() const
invert :-)
Definition: se2.h:82
virtual bool setMeasurementData(const double *d)