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_
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "../typedefs.h"
|
2012-04-25 04:51:16 -04:00
|
|
|
#include "../DataStructures/QueryEdge.h"
|
2010-08-31 10:00:40 -04:00
|
|
|
#include "NNGrid.h"
|
|
|
|
#include "PhantomNodes.h"
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "NodeCoords.h"
|
2010-07-09 05:05:40 -04:00
|
|
|
|
|
|
|
class NodeInformationHelpDesk{
|
|
|
|
public:
|
2012-04-02 07:44:44 -04:00
|
|
|
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) {
|
|
|
|
readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
|
|
|
|
assert(0 == coordinateVector.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
//Todo: Shared memory mechanism
|
2012-04-14 11:40:59 -04:00
|
|
|
// NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) {
|
|
|
|
// readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
|
|
|
|
// }
|
2011-11-14 13:36:31 -05:00
|
|
|
|
2011-01-09 16:42:27 -05:00
|
|
|
~NodeInformationHelpDesk() {
|
|
|
|
delete readOnlyGrid;
|
|
|
|
}
|
2012-04-25 04:51:16 -04:00
|
|
|
void initNNGrid(std::ifstream& nodesInstream, std::ifstream& edgesInStream) {
|
2012-05-03 05:59:58 -04:00
|
|
|
DEBUG("Loading node data");
|
2012-04-14 11:40:59 -04:00
|
|
|
NodeInfo b;
|
2012-04-25 04:51:16 -04:00
|
|
|
while(!nodesInstream.eof()) {
|
|
|
|
nodesInstream.read((char *)&b, sizeof(NodeInfo));
|
2011-12-17 16:19:08 -05:00
|
|
|
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
2011-01-09 16:42:27 -05:00
|
|
|
}
|
2012-04-14 11:40:59 -04:00
|
|
|
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
2012-04-25 04:51:16 -04:00
|
|
|
nodesInstream.close();
|
|
|
|
|
2012-05-03 05:59:58 -04:00
|
|
|
DEBUG("Loading edge data");
|
2012-04-25 04:51:16 -04:00
|
|
|
unsigned numberOfOrigEdges(0);
|
|
|
|
edgesInStream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
|
|
|
|
origEdgeData.resize(numberOfOrigEdges);
|
|
|
|
edgesInStream.read((char*)&(origEdgeData[0]), numberOfOrigEdges*sizeof(OriginalEdgeData));
|
|
|
|
edgesInStream.close();
|
2012-05-03 05:59:58 -04:00
|
|
|
DEBUG("Loaded " << numberOfOrigEdges << " orig edges");
|
|
|
|
DEBUG("Opening NN indices");
|
2012-04-25 04:51:16 -04:00
|
|
|
readOnlyGrid->OpenIndexFiles();
|
2010-07-26 04:17:52 -04:00
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2012-04-02 07:44:44 -04:00
|
|
|
void initNNGrid() {
|
|
|
|
readOnlyGrid->OpenIndexFiles();
|
|
|
|
}
|
|
|
|
|
2012-04-25 04:51:16 -04:00
|
|
|
inline int getLatitudeOfNode(const unsigned id) const {
|
|
|
|
const NodeID node = origEdgeData.at(id).viaNode;
|
|
|
|
return coordinateVector.at(node).lat;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getLongitudeOfNode(const unsigned id) const {
|
|
|
|
const NodeID node = origEdgeData.at(id).viaNode;
|
|
|
|
return coordinateVector.at(node).lon;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned getNameIndexFromEdgeID(const unsigned id) const {
|
|
|
|
return origEdgeData.at(id).nameID;
|
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2012-12-17 07:14:43 -05:00
|
|
|
inline TurnInstruction getTurnInstructionFromEdgeID(const unsigned id) const {
|
2012-04-25 04:51:16 -04:00
|
|
|
return origEdgeData.at(id).turnInstruction;
|
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2012-04-25 04:51:16 -04:00
|
|
|
inline NodeID getNumberOfNodes() const { return numberOfNodes; }
|
2011-12-17 16:19:08 -05:00
|
|
|
inline NodeID getNumberOfNodes2() const { return coordinateVector.size(); }
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2012-05-04 08:49:30 -04:00
|
|
|
inline bool FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) const {
|
|
|
|
return readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result);
|
2010-11-17 08:37:17 -05:00
|
|
|
}
|
2012-07-13 11:01:21 -04:00
|
|
|
|
|
|
|
inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) const {
|
|
|
|
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode, zoomLevel);
|
2011-07-11 11:16:14 -04:00
|
|
|
}
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2012-07-13 11:01:21 -04:00
|
|
|
inline void FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes, const unsigned zoomLevel) const {
|
|
|
|
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes, zoomLevel);
|
2010-08-31 10:00:40 -04:00
|
|
|
}
|
2010-11-18 11:56:22 -05:00
|
|
|
|
2011-03-29 11:02:07 -04:00
|
|
|
inline void FindNearestPointOnEdge(const _Coordinate & input, _Coordinate& output){
|
|
|
|
readOnlyGrid->FindNearestPointOnEdge(input, output);
|
|
|
|
}
|
|
|
|
|
2012-02-17 02:15:33 -05:00
|
|
|
inline unsigned GetCheckSum() const {
|
|
|
|
return checkSum;
|
|
|
|
}
|
|
|
|
|
2010-08-31 10:00:40 -04:00
|
|
|
private:
|
2011-12-17 16:19:08 -05:00
|
|
|
std::vector<_Coordinate> coordinateVector;
|
2012-04-25 04:51:16 -04:00
|
|
|
std::vector<OriginalEdgeData> origEdgeData;
|
|
|
|
|
2011-01-09 16:42:27 -05:00
|
|
|
ReadOnlyGrid * readOnlyGrid;
|
2012-07-13 11:01:21 -04:00
|
|
|
const unsigned numberOfNodes;
|
|
|
|
const unsigned checkSum;
|
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_*/
|