-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometricMap.cpp
More file actions
executable file
·109 lines (89 loc) · 2.34 KB
/
Copy pathGeometricMap.cpp
File metadata and controls
executable file
·109 lines (89 loc) · 2.34 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @file GeometricMap.cpp
* @ingroup Map
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
* @author Amaury Nègre, CNRS, Inria
* @copyright All right reserved.
*/
#include "GeometricMap.hpp"
#include <fstream>
#include <iostream>
using namespace std;
/** @brief constructor.
*/
GeometricMap::GeometricMap()
{
}
/** @brief Copy constructor.
*/
GeometricMap::GeometricMap(const GeometricMap& gm)
: segments(gm.segments)
{
}
/** @brief Load a map from a text file.
*
* @param filename [in] input file name
* @return true if the file has been found and parsed.
*/
bool GeometricMap::loadMap(const char* filename)
{
char Line[10*1024];
FILE * f = fopen( filename, "rb" );
if(f == (FILE*)nullptr)
return false;
// Empty current map before loading new segments (Doms)
segments.clear();
while( fgets( Line, 10*1024, f ) != nullptr )
{
double x0, y0, x1, y1;
if ( sscanf( Line, "%lf %lf %lf %lf", &x0, &y0, &x1, &y1 ) == 4 )
{
segments.push_back(WallSegment(cv::Vec2d(x0, y0),
cv::Vec2d(x1, y1)));
}
}
fclose( f );
cerr << segments.size() << " segments loaded" << endl;
computeBoundingBox();
cerr << "bounding Box : "
<< boundingBox.tl().x << " "
<< boundingBox.tl().y << " "
<< boundingBox.br().x << " "
<< boundingBox.br().y << endl;
return true;
}
/** @brief Compute bounding box of the map.
*/
void GeometricMap::computeBoundingBox()
{
if(segments.empty())
{
boundingBox = cv::Rect_<double>(0.,0., 0., 0.);
return;
}
boundingBox = segments[0].boundingBox();
for(SegmentVector::const_iterator it=++segments.begin();
it!=segments.end();
++it)
{
boundingBox |= it->boundingBox();
}
}
/** @brief Search for a point on the map nearer than dmin distance. Return true if such a point is found.
*
* @param p [in] input point.
* @param dmin [in,out] actual distance of the previous nearest point. Would be modified if a nearest point is found.
* @param np [in,out] actual nearest point distance. Would be modified if a new point is found
* @return true if a new point has been found.
*/
bool GeometricMap::nearestPoint(const cv::Vec2d& p, double& dmin, cv::Vec2d& np) const
{
bool res = false;
for(SegmentVector::const_iterator it=segments.begin();
it!=segments.end();
++it)
{
res |= it->nearestPoint(p, dmin, np);
}
return res;
}