Synchronize with upstream release 0.3 from https://monav.googlecode.com/svn/tags...
[monav:monav.git] / plugins / contractionhierarchies / contractionhierarchiesclient.h
1 /*
2 Copyright 2010  Christian Vetter veaac.fdirct@gmail.com
3
4 This file is part of MoNav.
5
6 MoNav is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MoNav is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with MoNav.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef CONTRACTIONHIERARCHIESCLIENT_H
21 #define CONTRACTIONHIERARCHIESCLIENT_H
22
23 #include <QObject>
24 #include <QStringList>
25 #include "interfaces/irouter.h"
26 #include "binaryheap.h"
27 #include "compressedgraph.h"
28 #include <queue>
29
30 class ContractionHierarchiesClient : public QObject, public IRouter
31 {
32         Q_OBJECT
33         Q_INTERFACES( IRouter )
34 public:
35         ContractionHierarchiesClient();
36         virtual ~ContractionHierarchiesClient();
37
38         virtual QString GetName();
39         virtual void SetInputDirectory( const QString& dir );
40         virtual void ShowSettings();
41         virtual bool IsCompatible( int fileFormatVersion );
42         virtual bool LoadData();
43         virtual bool UnloadData();
44         virtual bool GetRoute( double* distance, QVector< Node>* pathNodes, QVector< Edge >* pathEdges, const IGPSLookup::Result& source, const IGPSLookup::Result& target );
45         virtual bool GetName( QString* result, unsigned name );
46         virtual bool GetNames( QVector< QString >* result, QVector< unsigned > names );
47         virtual bool GetType( QString* result, unsigned type );
48         virtual bool GetTypes( QVector< QString >* result, QVector< unsigned > types );
49
50 protected:
51         struct HeapData {
52                 CompressedGraph::NodeIterator parent;
53                 bool stalled: 1;
54                 HeapData( CompressedGraph::NodeIterator p ) {
55                         parent = p;
56                         stalled = false;
57                 }
58         };
59
60         class AllowForwardEdge {
61                 public:
62                         bool operator()( bool forward, bool /*backward*/ ) const {
63                                 return forward;
64                         }
65         };
66
67         class AllowBackwardEdge {
68                 public:
69                         bool operator()( bool /*forward*/, bool backward ) const {
70                                 return backward;
71                         }
72         };
73
74         typedef CompressedGraph::NodeIterator NodeIterator;
75         typedef CompressedGraph::EdgeIterator EdgeIterator;
76         typedef BinaryHeap< NodeIterator, int, int, HeapData, MapStorage< NodeIterator, unsigned > > Heap;
77
78         CompressedGraph m_graph;
79         const char* m_names;
80         QFile m_namesFile;
81         Heap* m_heapForward;
82         Heap* m_heapBackward;
83         std::queue< NodeIterator > m_stallQueue;
84         QString m_directory;
85         QStringList m_types;
86
87         template< class EdgeAllowed, class StallEdgeAllowed >
88         void computeStep( Heap* heapForward, Heap* heapBackward, const EdgeAllowed& edgeAllowed, const StallEdgeAllowed& stallEdgeAllowed, NodeIterator* middle, int* targetDistance );
89         int computeRoute( const IGPSLookup::Result& source, const IGPSLookup::Result& target, QVector< Node>* pathNodes, QVector< Edge >* pathEdges );
90         bool unpackEdge( const NodeIterator source, const NodeIterator target, bool forward, QVector< Node>* pathNodes, QVector< Edge >* pathEdges );
91
92 };
93
94 #endif // CONTRACTIONHIERARCHIESCLIENT_H