g2o
Loading...
Searching...
No Matches
sensor_segment2d_pointline.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
28
29#include <cassert>
30
32using namespace std;
33using namespace Eigen;
34
35namespace g2o {
36
41
44 e->setMeasurement(e->measurement() + n);
45 e->setInformation(information());
46}
47
50 if (!_robotPoseObject) return false;
51
52 assert(to && to->vertex());
53 VertexType* v = to->vertex();
54
55 Vector2d p1, p2;
56 SE2 iRobot = _robotPoseObject->vertex()->estimate().inverse();
57 p1 = iRobot * v->estimateP1();
58 p2 = iRobot * v->estimateP2();
59
60 Vector3d vp1(p1.x(), p1.y(), 0.);
61 Vector3d vp2(p2.x(), p2.y(), 0.);
62 Vector3d cp = vp1.cross(vp2); // visibility check
63 if (cp[2] < 0) return false;
64
65 int circleClip = clipSegmentCircle(p1, p2, sqrt(_maxRange2));
66 bool clip1 = false, clip2 = false;
67 switch (circleClip) {
68 case -1:
69 return false;
70 case 0:
71 clip1 = true;
72 break;
73 case 1:
74 clip2 = true;
75 break;
76 case 3:
77 clip1 = true;
78 clip2 = true;
79 break;
80 default:;
81 }
82
83 int fovClip = clipSegmentFov(p1, p2, -_fov, +_fov);
84 switch (fovClip) {
85 case -1:
86 return false;
87 case 0:
88 clip1 = true;
89 break;
90 case 1:
91 clip2 = true;
92 break;
93 case 3:
94 clip1 = true;
95 clip2 = true;
96 break;
97 default:;
98 }
99 if ((clip1 && !clip2)) {
100 _visiblePoint = 1;
101 return true;
102 }
103 if ((!clip1 && clip2)) {
104 _visiblePoint = 0;
105 return true;
106 }
107 return false;
108}
109
112 RobotType* r = dynamic_cast<RobotType*>(robot());
113 std::list<PoseObject*>::reverse_iterator it = r->trajectory().rbegin();
114 int count = 0;
115 while (it != r->trajectory().rend() && count < 1) {
117 ++it;
118 count++;
119 }
120 for (std::set<BaseWorldObject*>::iterator it = world()->objects().begin();
121 it != world()->objects().end(); ++it) {
122 WorldObjectType* o = dynamic_cast<WorldObjectType*>(*it);
123 if (o && isVisible(o)) {
124 EdgeType* e = mkEdge(o);
125 if (e && graph()) {
126 e->setPointNum(_visiblePoint);
127 e->setMeasurementFromState();
128 addNoise(e);
129 graph()->addEdge(e);
130 }
131 }
132 }
133}
134
135} // namespace g2o
internal::BaseEdgeTraits< D >::ErrorVector ErrorVector
Definition base_edge.h:90
OptimizableGraph * graph() const
Definition simulator.cpp:76
World * world() const
Definition simulator.cpp:71
BaseRobot * robot()
Definition simulator.h:162
GaussianSampler< typename EdgeType::ErrorVector, InformationType > _sampler
Definition simulator.h:298
SampleType generateSample()
return a sample of the Gaussian distribution
Definition sampler.h:63
represent SE2
Definition se2.h:43
SE2 inverse() const
invert :-)
Definition se2.h:83
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SensorSegment2DPointLine(const std::string &name_)
std::set< BaseWorldObject * > & objects()
Definition simulator.h:115
Definition jet.h:938
int clipSegmentCircle(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double r)
Definition simutils.cpp:37
int clipSegmentFov(Eigen::Vector2d &p1, Eigen::Vector2d &p2, double min, double max)
Definition simutils.cpp:107
WorldObject< VertexSegment2D > WorldObjectSegment2D
Robot< WorldObjectSE2 > Robot2D
Definition jet.h:876
virtual bool addEdge(HyperGraph::Edge *e)