osrm-backend/DataStructures/NodeInformationHelpDesk.h

124 lines
3.2 KiB
C
Raw Normal View History

2010-07-09 05:05:40 -04:00
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
2010-07-26 04:17:52 -04:00
*/
2010-07-09 05:05:40 -04:00
#ifndef NODEINFORMATIONHELPDESK_H_
2010-07-09 05:05:40 -04:00
#define NODEINFORMATIONHELPDESK_H_
#include <omp.h>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <deque>
#include <fstream>
#include <iostream>
#include <limits>
#include <list>
#include <stack>
#include <string>
#include <vector>
#include "../typedefs.h"
2010-07-26 04:17:52 -04:00
#include "StaticKDTree.h"
2010-07-09 05:05:40 -04:00
2010-07-26 04:17:52 -04:00
typedef KDTree::StaticKDTree<2, int, NodeID> KDTreeType;
2010-07-09 05:05:40 -04:00
class NodeInformationHelpDesk{
public:
2010-07-26 04:17:52 -04:00
NodeInformationHelpDesk() { int2ExtNodeMap = new vector<KDTreeType::InputPoint>();}
KDTreeType * initKDTree(ifstream& input);
NodeID getExternalNodeID(const NodeID node);
void getExternalNodeInfo(const NodeID node, NodeInfo * info) const;
int getLatitudeOfNode(const NodeID node) const;
int getLongitudeOfNode(const NodeID node) const;
NodeID getNumberOfNodes() const { return int2ExtNodeMap->size(); }
inline NodeID findNearestNodeIDForLatLon(const int lat, const int lon, NodeCoords<NodeID> * data) const
{
KDTreeType::InputPoint i;
KDTreeType::InputPoint o;
i.coordinates[0] = lat;
i.coordinates[1] = lon;
kdtree->NearestNeighbor(&o, i);
data->id = o.data;
data->lat = o.coordinates[0];
data->lon = o.coordinates[1];
return data->id;
}
2010-07-09 05:05:40 -04:00
private:
2010-07-26 04:17:52 -04:00
vector<KDTreeType::InputPoint> * int2ExtNodeMap;
KDTreeType * kdtree;
2010-07-09 05:05:40 -04:00
};
//////////////////
//implementation//
//////////////////
/* @brief: initialize kd-tree and internal->external node id map
*
*/
2010-07-14 10:22:29 -04:00
KDTreeType * NodeInformationHelpDesk::initKDTree(ifstream& in)
2010-07-09 05:05:40 -04:00
{
2010-07-26 04:17:52 -04:00
NodeID id = 0;
while(!in.eof())
{
NodeInfo b;
in.read((char *)&b, sizeof(b));
b.id = id;
KDTreeType::InputPoint p;
p.coordinates[0] = b.lat;
p.coordinates[1] = b.lon;
p.data = id;
int2ExtNodeMap->push_back(p);
id++;
}
in.close();
kdtree = new KDTreeType(int2ExtNodeMap);
return kdtree;
2010-07-09 05:05:40 -04:00
}
NodeID NodeInformationHelpDesk::getExternalNodeID(const NodeID node)
{
2010-07-26 04:17:52 -04:00
return int2ExtNodeMap->at(node).data;
2010-07-09 05:05:40 -04:00
}
2010-07-26 04:17:52 -04:00
void NodeInformationHelpDesk::getExternalNodeInfo(const NodeID node, NodeInfo * info) const
2010-07-09 05:05:40 -04:00
{
2010-07-26 04:17:52 -04:00
info->id = int2ExtNodeMap->at(node).data;
info->lat = int2ExtNodeMap->at(node).coordinates[0];
info->lon = int2ExtNodeMap->at(node).coordinates[1];
2010-07-09 05:05:40 -04:00
}
int NodeInformationHelpDesk::getLatitudeOfNode(const NodeID node) const
2010-07-09 05:05:40 -04:00
{
2010-07-26 04:17:52 -04:00
return int2ExtNodeMap->at(node).coordinates[0];
2010-07-09 05:05:40 -04:00
}
int NodeInformationHelpDesk::getLongitudeOfNode(const NodeID node) const
2010-07-09 05:05:40 -04:00
{
2010-07-26 04:17:52 -04:00
return int2ExtNodeMap->at(node).coordinates[1];
2010-07-09 05:05:40 -04:00
}
#endif /*NODEINFORMATIONHELPDESK_H_*/