osrm-backend/DataStructures/NodeInformationHelpDesk.h

97 lines
3.3 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 <fstream>
#include <iostream>
#include <vector>
#include "../typedefs.h"
#include "NNGrid.h"
#include "PhantomNodes.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
// NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) {
// readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
// }
~NodeInformationHelpDesk() {
delete readOnlyGrid;
}
void initNNGrid(std::ifstream& in) {
NodeInfo b;
while(!in.eof()) {
in.read((char *)&b, sizeof(NodeInfo));
2011-12-17 16:19:08 -05:00
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
}
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
numberOfNodes = coordinateVector.size();
in.close();
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();
}
2011-12-17 16:19:08 -05:00
inline int getLatitudeOfNode(const NodeID node) const { return coordinateVector.at(node).lat; }
2010-07-09 05:05:40 -04:00
2011-12-17 16:19:08 -05:00
inline int getLongitudeOfNode(const NodeID node) const { return coordinateVector.at(node).lon; }
2010-07-09 05:05:40 -04:00
2011-12-17 16:19:08 -05:00
inline NodeID getNumberOfNodes() const { return numberOfNodes; }
inline NodeID getNumberOfNodes2() const { return coordinateVector.size(); }
2010-07-09 05:05:40 -04:00
2011-12-17 16:19:08 -05:00
inline void FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) const {
readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result);
2010-11-17 08:37:17 -05:00
}
2011-12-17 16:19:08 -05:00
inline void FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode) const {
readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode);
}
2010-07-09 05:05:40 -04:00
2011-12-17 16:19:08 -05:00
inline void FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes) const {
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
}
inline void FindNearestPointOnEdge(const _Coordinate & input, _Coordinate& output){
readOnlyGrid->FindNearestPointOnEdge(input, output);
}
inline unsigned GetCheckSum() const {
return checkSum;
}
private:
2011-12-17 16:19:08 -05:00
std::vector<_Coordinate> coordinateVector;
ReadOnlyGrid * readOnlyGrid;
unsigned numberOfNodes;
unsigned checkSum;
};
2010-07-09 05:05:40 -04:00
#endif /*NODEINFORMATIONHELPDESK_H_*/