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
|
|
|
|
2010-07-14 12:29:18 -04:00
|
|
|
#ifndef NODEINFORMATIONHELPDESK_H_
|
2010-07-09 05:05:40 -04:00
|
|
|
#define NODEINFORMATIONHELPDESK_H_
|
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
#include "NodeCoords.h"
|
|
|
|
#include "PhantomNodes.h"
|
|
|
|
#include "StaticRTree.h"
|
|
|
|
#include "../Contractor/EdgeBasedGraphFactory.h"
|
|
|
|
#include "../typedefs.h"
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
2010-07-09 05:05:40 -04:00
|
|
|
#include <iostream>
|
2013-07-22 10:32:19 -04:00
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2010-07-09 05:05:40 -04:00
|
|
|
#include <vector>
|
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf;
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2013-01-06 13:38:03 -05:00
|
|
|
class NodeInformationHelpDesk : boost::noncopyable{
|
2010-07-09 05:05:40 -04:00
|
|
|
public:
|
2013-06-26 09:32:03 -04:00
|
|
|
NodeInformationHelpDesk(
|
2013-07-22 10:32:19 -04:00
|
|
|
const std::string & ramIndexInput,
|
|
|
|
const std::string & fileIndexInput,
|
|
|
|
const std::string & nodes_filename,
|
|
|
|
const std::string & edges_filename,
|
2013-06-26 09:32:03 -04:00
|
|
|
const unsigned number_of_nodes,
|
2013-07-22 10:32:19 -04:00
|
|
|
const unsigned check_sum
|
|
|
|
) : number_of_nodes(number_of_nodes), check_sum(check_sum)
|
|
|
|
{
|
2013-06-26 09:32:03 -04:00
|
|
|
read_only_rtree = new StaticRTree<RTreeLeaf>(
|
|
|
|
ramIndexInput,
|
|
|
|
fileIndexInput
|
|
|
|
);
|
|
|
|
BOOST_ASSERT_MSG(
|
|
|
|
0 == coordinateVector.size(),
|
|
|
|
"Coordinate vector not empty"
|
|
|
|
);
|
2013-07-22 10:32:19 -04:00
|
|
|
|
|
|
|
LoadNodesAndEdges(nodes_filename, edges_filename);
|
2012-04-02 07:44:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//Todo: Shared memory mechanism
|
2011-01-09 16:42:27 -05:00
|
|
|
~NodeInformationHelpDesk() {
|
2013-06-26 09:32:03 -04:00
|
|
|
delete read_only_rtree;
|
2011-01-09 16:42:27 -05:00
|
|
|
}
|
2013-06-26 09:32:03 -04:00
|
|
|
|
2012-04-25 04:51:16 -04:00
|
|
|
inline int getLatitudeOfNode(const unsigned id) const {
|
2013-01-06 13:38:03 -05:00
|
|
|
const NodeID node = origEdgeData_viaNode.at(id);
|
2012-04-25 04:51:16 -04:00
|
|
|
return coordinateVector.at(node).lat;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getLongitudeOfNode(const unsigned id) const {
|
2013-01-06 13:38:03 -05:00
|
|
|
const NodeID node = origEdgeData_viaNode.at(id);
|
2012-04-25 04:51:16 -04:00
|
|
|
return coordinateVector.at(node).lon;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned getNameIndexFromEdgeID(const unsigned id) const {
|
2013-01-06 13:38:03 -05:00
|
|
|
return origEdgeData_nameID.at(id);
|
2012-04-25 04:51:16 -04:00
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2012-12-17 07:14:43 -05:00
|
|
|
inline TurnInstruction getTurnInstructionFromEdgeID(const unsigned id) const {
|
2013-01-06 13:38:03 -05:00
|
|
|
return origEdgeData_turnInstruction.at(id);
|
2012-04-25 04:51:16 -04:00
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
inline NodeID getNumberOfNodes() const {
|
|
|
|
return number_of_nodes;
|
|
|
|
}
|
2012-07-13 11:01:21 -04:00
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
inline NodeID getNumberOfNodes2() const {
|
|
|
|
return coordinateVector.size();
|
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
inline bool FindNearestNodeCoordForLatLon(
|
|
|
|
const _Coordinate& input_coordinate,
|
|
|
|
_Coordinate& result,
|
|
|
|
const unsigned zoom_level = 18
|
|
|
|
) const {
|
|
|
|
PhantomNode resulting_phantom_node;
|
2013-06-27 16:09:21 -04:00
|
|
|
bool foundNode = FindPhantomNodeForCoordinate(
|
|
|
|
input_coordinate,
|
|
|
|
resulting_phantom_node, zoom_level
|
|
|
|
);
|
2013-06-26 09:32:03 -04:00
|
|
|
result = resulting_phantom_node.location;
|
|
|
|
return foundNode;
|
|
|
|
}
|
2010-11-18 11:56:22 -05:00
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
inline bool FindPhantomNodeForCoordinate(
|
|
|
|
const _Coordinate & input_coordinate,
|
|
|
|
PhantomNode & resulting_phantom_node,
|
|
|
|
const unsigned zoom_level
|
|
|
|
) const {
|
|
|
|
return read_only_rtree->FindPhantomNodeForCoordinate(
|
|
|
|
input_coordinate,
|
|
|
|
resulting_phantom_node,
|
|
|
|
zoom_level
|
|
|
|
);
|
|
|
|
}
|
2011-03-29 11:02:07 -04:00
|
|
|
|
2012-02-17 02:15:33 -05:00
|
|
|
inline unsigned GetCheckSum() const {
|
2013-07-22 10:32:19 -04:00
|
|
|
return check_sum;
|
2012-02-17 02:15:33 -05:00
|
|
|
}
|
|
|
|
|
2010-08-31 10:00:40 -04:00
|
|
|
private:
|
2013-07-22 10:32:19 -04:00
|
|
|
void LoadNodesAndEdges(
|
|
|
|
const std::string & nodes_file,
|
|
|
|
const std::string & edges_file
|
|
|
|
) {
|
|
|
|
std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary);
|
|
|
|
if(!nodes_input_stream) { ERR(nodes_file << " not found"); }
|
|
|
|
std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary);
|
|
|
|
if(!edges_input_stream) { ERR(edges_file << " not found"); }
|
|
|
|
|
|
|
|
DEBUG("Loading node data");
|
|
|
|
NodeInfo b;
|
|
|
|
while(!nodes_input_stream.eof()) {
|
|
|
|
nodes_input_stream.read((char *)&b, sizeof(NodeInfo));
|
|
|
|
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
|
|
|
}
|
|
|
|
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
|
|
|
nodes_input_stream.close();
|
|
|
|
|
|
|
|
DEBUG("Loading edge data");
|
|
|
|
unsigned numberOfOrigEdges(0);
|
|
|
|
edges_input_stream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
|
|
|
|
origEdgeData_viaNode.resize(numberOfOrigEdges);
|
|
|
|
origEdgeData_nameID.resize(numberOfOrigEdges);
|
|
|
|
origEdgeData_turnInstruction.resize(numberOfOrigEdges);
|
|
|
|
|
|
|
|
OriginalEdgeData deserialized_originalEdgeData;
|
|
|
|
for(unsigned i = 0; i < numberOfOrigEdges; ++i) {
|
|
|
|
edges_input_stream.read(
|
|
|
|
(char*)&(deserialized_originalEdgeData),
|
|
|
|
sizeof(OriginalEdgeData)
|
|
|
|
);
|
|
|
|
origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode;
|
|
|
|
origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID;
|
|
|
|
origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction;
|
|
|
|
}
|
|
|
|
edges_input_stream.close();
|
|
|
|
DEBUG("Loaded " << numberOfOrigEdges << " orig edges");
|
|
|
|
DEBUG("Opening NN indices");
|
|
|
|
}
|
|
|
|
|
2011-12-17 16:19:08 -05:00
|
|
|
std::vector<_Coordinate> coordinateVector;
|
2013-01-06 13:38:03 -05:00
|
|
|
std::vector<NodeID> origEdgeData_viaNode;
|
|
|
|
std::vector<unsigned> origEdgeData_nameID;
|
|
|
|
std::vector<TurnInstruction> origEdgeData_turnInstruction;
|
2012-04-25 04:51:16 -04:00
|
|
|
|
2013-06-26 09:32:03 -04:00
|
|
|
StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode> * read_only_rtree;
|
|
|
|
const unsigned number_of_nodes;
|
2013-07-22 10:32:19 -04:00
|
|
|
const unsigned check_sum;
|
2010-08-31 10:00:40 -04:00
|
|
|
};
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2010-07-14 12:29:18 -04:00
|
|
|
#endif /*NODEINFORMATIONHELPDESK_H_*/
|