g2o
sensor_segment2d.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.h"
29 #include <iostream>
30 
31 namespace g2o{
32  using namespace std;
33  using namespace Eigen;
34 
36  cerr << "I am the constructor" << endl;
37  }
38 
41  e->setMeasurement(e->measurement()+n);
43  }
44 
46  if (! _robotPoseObject)
47  return false;
48 
49  assert(to && to->vertex());
50  VertexType* v=to->vertex();
51 
52  Vector2d p1, p2;
53  SE2 iRobot=_robotPoseObject->vertex()->estimate().inverse();
54  p1 = iRobot * v->estimateP1();
55  p2 = iRobot * v->estimateP2();
56 
57  Vector3d vp1(p1.x(), p1.y(), 0.);
58  Vector3d vp2(p2.x(), p2.y(), 0.);
59  Vector3d cp=vp1.cross(vp2); // visibility check
60  if (cp[2]<0)
61  return false;
62 
63  int circleClip = clipSegmentCircle(p1,p2,sqrt(_maxRange2));
64  bool clip1=false, clip2=false;
65  switch(circleClip){
66  case -1:
67  return false;
68  case 0:
69  clip1 = true;
70  break;
71  case 1:
72  clip2 = true;
73  break;
74  case 3:
75  clip1 = true;
76  clip2 = true;
77  break;
78  default:;
79  }
80 
81  int fovClip=clipSegmentFov(p1,p2,-_fov, +_fov);
82  switch(fovClip){
83  case -1:
84  return false;
85  case 0:
86  clip1 = true;
87  break;
88  case 1:
89  clip2 = true;
90  break;
91  case 3:
92  clip1 = true;
93  clip2 = true;
94  break;
95  default:;
96  }
97  if (!clip1 && !clip2){ // only if both endpoints have not been clipped do something
98  return true;
99  }
100  // if all these checks went well, we set the point
101  return false;
102  }
103 
106  RobotType* r= dynamic_cast<RobotType*>(robot());
107  std::list<PoseObject*>::reverse_iterator it=r->trajectory().rbegin();
108  int count = 0;
109  while (it!=r->trajectory().rend() && count < 1){
110  if (!_robotPoseObject)
111  _robotPoseObject = *it;
112  it++;
113  count++;
114  }
115  for (std::set<BaseWorldObject*>::iterator it=world()->objects().begin(); it!=world()->objects().end(); it++){
116  WorldObjectType* o=dynamic_cast<WorldObjectType*>(*it);
117  if (o && isVisible(o)){
118  EdgeType* e=mkEdge(o);
119  if (e && graph()) {
121  addNoise(e);
122  graph()->addEdge(e);
123  }
124  }
125  }
126  }
127 
128 } // end namespace
bool isVisible(WorldObjectType *to)
virtual void addNoise(EdgeType *e)
int clipSegmentCircle(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double r)
Definition: simutils.cpp:11
int clipSegmentFov(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double min, double max)
Definition: simutils.cpp:82
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
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SensorSegment2D(const std::string &name_)
virtual G2O_TYPES_SLAM2D_ADDONS_API bool setMeasurementFromState()
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