1+ /* This file is part of Openrouteservice.
2+ *
3+ * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
4+ * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
5+ * of the License, or (at your option) any later version.
6+
7+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+ * See the GNU Lesser General Public License for more details.
10+
11+ * You should have received a copy of the GNU Lesser General Public License along with this library;
12+ * if not, see <https://www.gnu.org/licenses/>.
13+ */
14+ package org .heigit .ors .routing .graphhopper .extensions .edgefilters ;
15+
16+ import com .graphhopper .routing .util .EdgeFilter ;
17+ import com .graphhopper .storage .GraphHopperStorage ;
18+ import com .graphhopper .util .EdgeIteratorState ;
19+ import org .apache .log4j .Logger ;
20+ import org .heigit .ors .routing .graphhopper .extensions .WheelchairAttributes ;
21+ import org .heigit .ors .routing .graphhopper .extensions .storages .GraphStorageUtils ;
22+ import org .heigit .ors .routing .graphhopper .extensions .storages .WheelchairAttributesGraphStorage ;
23+ import org .heigit .ors .routing .parameters .WheelchairParameters ;
24+
25+ public class WheelchairEdgeFilterOld implements EdgeFilter {
26+ private static final Logger LOGGER = Logger .getLogger (WheelchairEdgeFilterOld .class .getName ());
27+ private final byte [] buffer ;
28+ private final WheelchairAttributesGraphStorage storage ;
29+ private final WheelchairAttributes attributes ;
30+ private WheelchairParameters params ;
31+
32+ public WheelchairEdgeFilterOld (WheelchairParameters params , GraphHopperStorage graphStorage ) throws Exception {
33+ storage = GraphStorageUtils .getGraphExtension (graphStorage , WheelchairAttributesGraphStorage .class );
34+ if (storage == null )
35+ throw new Exception ("ExtendedGraphStorage for wheelchair attributes was not found." );
36+ this .params = params ;
37+ if (this .params == null ) {
38+ this .params = new WheelchairParameters ();
39+ }
40+ attributes = new WheelchairAttributes ();
41+ buffer = new byte [WheelchairAttributesGraphStorage .BYTE_COUNT ];
42+ }
43+
44+ @ Override
45+ public boolean accept (EdgeIteratorState iter ) {
46+ storage .getEdgeValues (iter .getEdge (), attributes , buffer );
47+ LOGGER .debug ("edge: " + iter + (attributes .hasValues () ? " suitable: " + attributes .isSuitable () + " surfaceQualityKnown: " + attributes .isSurfaceQualityKnown () : " no wheelchair attributes" ));
48+ return !attributes .hasValues () || !(
49+ checkSurfaceType ()
50+ || checkSmoothnessType ()
51+ || checkTrackType ()
52+ || checkMaximumIncline ()
53+ || checkMaximumSlopedKerb ()
54+ || checkMinimumWidth ()
55+ || checkSurfaceQualityKnown ()
56+ || checkUnsuitable ()
57+ );
58+ }
59+
60+ private boolean checkSurfaceType () {
61+ return params .getSurfaceType () > 0
62+ && params .getSurfaceType () < attributes .getSurfaceType ();
63+ }
64+
65+ private boolean checkSmoothnessType () {
66+ return params .getSmoothnessType () > 0
67+ && params .getSmoothnessType () < attributes .getSmoothnessType ();
68+ }
69+
70+ private boolean checkTrackType () {
71+ return params .getTrackType () > 0 && attributes .getTrackType () != 0
72+ && params .getTrackType () <= attributes .getTrackType ();
73+ }
74+
75+ private boolean checkMaximumIncline () {
76+ return params .getMaximumIncline () > (Float .MAX_VALUE * -1.0f )
77+ && params .getMaximumIncline () < attributes .getIncline ();
78+ }
79+
80+ private boolean checkMaximumSlopedKerb () {
81+ return params .getMaximumSlopedKerb () >= 0.0
82+ && params .getMaximumSlopedKerb () * 100.0 < attributes .getSlopedKerbHeight ();// Stored in storage in cm
83+ }
84+
85+ private boolean checkMinimumWidth () {
86+ return params .getMinimumWidth () > 0.0
87+ && attributes .getWidth () > 0.0 // if the attribute value is 0, this signifies that no data is available
88+ && params .getMinimumWidth () * 100.0 > attributes .getWidth (); // stored in storage in cm
89+ }
90+
91+ private boolean checkSurfaceQualityKnown () {
92+ return params .isRequireSurfaceQualityKnown () && !attributes .isSurfaceQualityKnown ();
93+ }
94+
95+ private boolean checkUnsuitable () {
96+ return !params .allowUnsuitable () && !attributes .isSuitable ();
97+ }
98+ }
0 commit comments