g2o
sensor_segment2d_line.cpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 G. Grisetti, R. Kuemmerle, 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 "sensor_segment2d_line.h"
29 using namespace std;
30 using namespace Eigen;
31 
32 namespace g2o{
33 
34  SensorSegment2DLine::SensorSegment2DLine(const std::string& name_): BinarySensor<Robot2D, EdgeSE2Segment2DLine, WorldObjectSegment2D>(name_) {}
35 
38  e->setMeasurement(e->measurement()+n);
40  }
41 
42 
44  if (! _robotPoseObject)
45  return false;
46 
47  assert(to && to->vertex());
48  VertexType* v=to->vertex();
49 
50  Vector2d p1, p2;
51  SE2 iRobot=_robotPoseObject->vertex()->estimate().inverse();
52  p1 = iRobot * v->estimateP1();
53  p2 = iRobot * v->estimateP2();
54 
55  Vector3d vp1(p1.x(), p1.y(), 0.);
56  Vector3d vp2(p2.x(), p2.y(), 0.);
57  Vector3d cp=vp1.cross(vp2); // visibility check
58  if (cp[2]<0)
59  return false;
60 
61  int circleClip = clipSegmentCircle(p1,p2,sqrt(_maxRange2));
62  bool clip1=false, clip2=false;
63  switch(circleClip){
64  case -1:
65  return false;
66  case 0:
67  clip1 = true;
68  break;
69  case 1:
70  clip2 = true;
71  break;
72  case 3:
73  clip1 = true;
74  clip2 = true;
75  break;
76  default:;
77  }
78 
79  int fovClip=clipSegmentFov(p1,p2,-_fov, +_fov);
80  switch(fovClip){
81  case -1:
82  return false;
83  case 0:
84  clip1 = true;
85  break;
86  case 1:
87  clip2 = true;
88  break;
89  case 3:
90  clip1 = true;
91  clip2 = true;
92  break;
93  default:;
94  }
95  if (clip1 && clip2) // only if both endpoints have been clipped do something
96  return true;
97  // if all these checks went well, we set the point
98  return false;
99  }
100 
101 
104  RobotType* r= dynamic_cast<RobotType*>(robot());
105  std::list<PoseObject*>::reverse_iterator it=r->trajectory().rbegin();
106  int count = 0;
107  while (it!=r->trajectory().rend() && count < 1){
108  if (!_robotPoseObject)
109  _robotPoseObject = *it;
110  it++;
111  count++;
112  }
113  for (std::set<BaseWorldObject*>::iterator it=world()->objects().begin(); it!=world()->objects().end(); it++){
114  WorldObjectType* o=dynamic_cast<WorldObjectType*>(*it);
115  if (o && isVisible(o)){
116  EdgeType* e=mkEdge(o);
117  if (e && graph()) {
119  addNoise(e);
120  graph()->addEdge(e);
121  }
122  }
123  }
124  }
125 
126 } // end namespace
int clipSegmentCircle(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double r)
Definition: simutils.cpp:11
bool isVisible(WorldObjectType *to)
int clipSegmentFov(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double min, double max)
Definition: simutils.cpp:82
virtual G2O_TYPES_SLAM2D_ADDONS_API bool setMeasurementFromState()
virtual void addNoise(EdgeType *e)
GaussianSampler< typename EdgeType::ErrorVector, InformationType > _sampler
Definition: simulator.h:271
represent SE2
Definition: se2.h:40
SampleType generateSample()
Definition: sampler.h:67
virtual void setMeasurement(const Measurement &m)
Definition: base_edge.h:76
World * world()
Definition: simulator.cpp:69
EIGEN_STRONG_INLINE void setInformation(const InformationType &information)
Definition: base_edge.h:69
TrajectoryType & trajectory()
Definition: simulator.h:119
OptimizableGraph * graph()
Definition: simulator.cpp:75
BaseRobot * robot()
Definition: simulator.h:129
std::set< BaseWorldObject * > & objects()
Definition: simulator.h:284
virtual bool addEdge(HyperGraph::Edge *e)
VertexType * vertex()
Definition: simulator.h:72
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75