[r9133]: code / player / trunk / server / drivers / localization / ekfvloc / segment_map.cc Maximize Restore History

Download this file

segment_map.cc    96 lines (79 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2010
* Mayte Lรกzaro, Alejandro R. Mosteo
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <fstream>
#include <stdexcept>
#include "segment_map.hh"
SegmentMap::SegmentMap()
{
}
SegmentMap::SegmentMap(string filename)
{
// Initialization from file
ifstream fmap;
fmap.open(filename.c_str());
if (fmap.fail())
{
throw std::invalid_argument(std::string("Error opening file: " + filename));
}
double p1x, p1y, p2x, p2y;
int count = 0;
while (!fmap.eof())
{
fmap >> p1x;
fmap >> p1y;
fmap >> p2x;
fmap >> p2y;
AddSegment(p1x, p1y, p2x, p2y);
count++;
}
printf("Read %d segments from %s\n", count, filename.c_str());
}
void SegmentMap::AddSegment(double x1, double y1, double x2, double y2)
{
const double &p1x = x1, &p1y = y1,
&p2x = x2, &p2y = y2;
Transf seg = Transf((p1x + p2x) / 2,
(p1y + p2y) / 2,
atan2(p2y - p1y,
p2x - p1x));
segments_.push_back(seg);
lengths_.push_back(sqrt((p2x - p1x) * (p2x - p1x) +
(p2y - p1y) * (p2y - p1y)));
}
SegmentMap::~SegmentMap()
{
}
int SegmentMap::NumSegments() const
{
return segments_.size();
}
Transf SegmentMap::segments(int i) const
{
return segments_[i];
}
double SegmentMap::lengths(int i) const
{
return lengths_[i];
}
bool SegmentMap::IsEmpty(void) const
{
return lengths_.size() == 0;
}