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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
|
/*
Copyright 2010 Christian Vetter veaac.fdirct@gmail.com
This file is part of MoNav.
MoNav is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MoNav 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with MoNav. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OSMIMPORTER_H
#define OSMIMPORTER_H
#include "interfaces/iimporter.h"
#include "interfaces/iguisettings.h"
#include "interfaces/iconsolesettings.h"
#include "ientityreader.h"
#include "statickdtree.h"
#include "types.h"
#include "utils/intersection.h"
#include <QObject>
#include <QHash>
#include <cstring>
class OSMImporter :
public QObject,
#ifndef NOGUI
public IGUISettings,
#endif
public IConsoleSettings,
public IImporter
{
Q_OBJECT
Q_INTERFACES( IImporter )
Q_INTERFACES( IConsoleSettings );
#ifndef NOGUI
Q_INTERFACES( IGUISettings )
#endif
public:
struct Settings {
QString speedProfile;
QStringList languageSettings;
};
OSMImporter();
virtual ~OSMImporter();
// IPreprocessor
virtual QString GetName();
virtual void SetOutputDirectory( const QString& dir );
virtual bool LoadSettings( QSettings* settings );
virtual bool SaveSettings( QSettings* settings );
virtual bool Preprocess( QString filename );
virtual bool SetIDMap( const std::vector< NodeID >& idMap );
virtual bool GetIDMap( std::vector< NodeID >* idMap );
virtual bool SetEdgeIDMap( const std::vector< NodeID >& idMap );
virtual bool GetEdgeIDMap( std::vector< NodeID >* idMap );
virtual bool GetRoutingEdges( std::vector< RoutingEdge >* data );
virtual bool GetRoutingEdgePaths( std::vector< RoutingNode >* data );
virtual bool GetRoutingNodes( std::vector< RoutingNode >* data );
virtual bool GetRoutingWayNames( std::vector< QString >* data );
virtual bool GetRoutingWayTypes( std::vector< QString >* data );
virtual bool GetRoutingPenalties( std::vector< char >* inDegree, std::vector< char >* outDegree, std::vector< double >* penalties );
virtual bool GetAddressData( std::vector< Place >* dataPlaces, std::vector< Address >* dataAddresses, std::vector< UnsignedCoordinate >* dataWayBuffer, std::vector< QString >* addressNames );
virtual bool GetBoundingBox( BoundingBox* box );
virtual void DeleteTemporaryFiles();
#ifndef NOGUI
// IGUISettings
virtual bool GetSettingsWindow( QWidget** window );
virtual bool FillSettingsWindow( QWidget* window );
virtual bool ReadSettingsWindow( QWidget* window );
#endif
// IConsoleSettings
virtual QString GetModuleName();
virtual bool GetSettingsList( QVector< Setting >* settings );
virtual bool SetSetting( int id, QVariant data );
protected:
struct Statistics{
NodeID numberOfNodes;
NodeID numberOfWays;
NodeID numberOfRelations;
NodeID numberOfRestrictions;
NodeID numberOfEdges;
NodeID numberOfUsedNodes;
NodeID numberOfSegments;
NodeID numberOfPlaces;
NodeID numberOfOutlines;
NodeID numberOfMaxspeed;
NodeID numberOfZeroSpeed;
NodeID numberOfDefaultCitySpeed;
NodeID numberOfCityEdges;
NodeID numberOfTurningPenalties;
NodeID numberOfRestrictionsApplied;
double maxTurningPenalty;
double averageLeftPenalty;
double averageRightPenalty;
double averageStraightPenalty;
Statistics() {
memset( this, 0, sizeof( Statistics ) );
}
};
struct Way {
enum {
NotSure, Oneway, Bidirectional, Opposite
} direction;
double maximumSpeed;
bool usefull;
bool access;
int accessPriority;
QString name;
int namePriority;
QString ref;
QString placeName;
Place::Type placeType;
unsigned type;
bool roundabout;
int addPercentage;
int addFixed;
};
struct Node {
QString name;
int namePriority;
unsigned population;
Place::Type type;
int penalty;
bool access;
int accessPriority;
};
struct Restriction {
enum { None, No, Only } type;
unsigned from;
unsigned to;
unsigned via;
bool access;
};
struct Relation {
enum { TypeNone, TypeRestriction } type;
Restriction restriction;
};
struct NodeLocation {
// City / Town
unsigned place;
double distance;
bool isInPlace: 1;
};
struct Location {
QString name;
Place::Type type;
GPSCoordinate coordinate;
};
struct Outline {
QString name;
std::vector< DoublePoint > way;
bool operator<( const Outline& right ) const {
return name < right.name;
}
};
class GPSMetric {
public:
double operator() ( const unsigned left[2], const unsigned right[2] ) {
UnsignedCoordinate leftGPS( left[0], left[1] );
UnsignedCoordinate rightGPS( right[0], right[1] );
double result = leftGPS.ToGPSCoordinate().ApproximateDistance( rightGPS.ToGPSCoordinate() );
return result * result;
}
double operator() ( const KDTree::BoundingBox< 2, unsigned > &box, const unsigned point[2] ) {
unsigned nearest[2];
for ( unsigned dim = 0; dim < 2; ++dim ) {
if ( point[dim] < box.min[dim] )
nearest[dim] = box.min[dim];
else if ( point[dim] > box.max[dim] )
nearest[dim] = box.max[dim];
else
nearest[dim] = point[dim];
}
return operator() ( point, nearest );
}
bool operator() ( const KDTree::BoundingBox< 2, unsigned > &box, const unsigned point[2], const double radiusSquared ) {
unsigned farthest[2];
for ( unsigned dim = 0; dim < 2; ++dim ) {
if ( point[dim] < ( box.min[dim] + box.max[dim] ) / 2 )
farthest[dim] = box.max[dim];
else
farthest[dim] = box.min[dim];
}
return operator() ( point, farthest ) <= radiusSquared;
}
};
typedef KDTree::StaticKDTree< 2, unsigned, unsigned, GPSMetric > GPSTree;
struct NodeTags {
enum Key {
Place = 0, Population = 1, Barrier = 2, MaxTag = 3
};
};
struct WayTags {
enum Key {
Oneway = 0, Junction = 1, Highway = 2, Ref = 3, PlaceName = 4, Place = 5, MaxSpeed = 6, MaxTag = 7
};
};
struct RelationTags {
enum Key {
Type = 0, Restriction = 1, Except = 2, MaxTag = 3
};
};
struct NodePenalty {
unsigned id;
int seconds;
NodePenalty( unsigned _id, int _seconds )
{
id = _id;
seconds = _seconds;
}
NodePenalty( unsigned _id )
{
id = _id;
seconds = 0;
}
bool operator<( const NodePenalty& right ) const
{
return id < right.id;
}
};
// contains information usefull for determening turing costs
struct EdgeInfo {
unsigned node;
char type;
char id;
bool forward : 1;
bool backward : 1;
bool crossing : 1;
unsigned oldID;
double angle; // [-M_PI,+M_PI]
double length;
double speed;
bool operator<( const EdgeInfo& right ) const
{
return node < right.node;
}
};
struct RestrictionInfo {
unsigned from;
unsigned to;
unsigned via;
bool exclude; // false == only
bool operator<( const RestrictionInfo& right ) const
{
return via < right.via;
}
};
void clear();
void printStats();
bool read( const QString& inputFilename, const QString& filename );
void readWay( Way* way, const IEntityReader::Way& inputWay );
void readNode( Node* node, const IEntityReader::Node& inputNode );
void readRelation( Relation* relation, const IEntityReader::Relation& inputRelation );
Place::Type parsePlaceType( const QString& type );
void setRequiredTags( IEntityReader* reader );
bool preprocessData( const QString& filename );
bool computeInCityFlags( QString filename, std::vector< NodeLocation >* nodeLocation, const std::vector< UnsignedCoordinate >& nodeCoordinates, const std::vector< UnsignedCoordinate >& outlineCoordinates );
bool remapEdges( QString filename, const std::vector< UnsignedCoordinate >& nodeCoordinates, const std::vector< NodeLocation >& nodeLocation );
bool computeTurningPenalties( QString filename );
Statistics m_statistics;
QString m_outputDirectory;
Settings m_settings;
MoNav::SpeedProfile m_profile;
std::vector< QString > m_kmhStrings;
std::vector< QString > m_mphStrings;
std::vector< int > m_wayModificatorIDs;
std::vector< int > m_nodeModificatorIDs;
std::vector< NodePenalty > m_penaltyNodes;
std::vector< unsigned > m_noAccessNodes;
std::vector< unsigned > m_usedNodes;
std::vector< unsigned > m_routingNodes;
std::vector< unsigned > m_outlineNodes;
QHash< QString, unsigned > m_wayNames;
QHash< QString, unsigned > m_wayRefs;
std::vector< char > m_inDegree;
std::vector< char > m_outDegree;
std::vector< EdgeInfo > m_edgeInfo;
};
#endif // OSMIMPORTER_H
|