RealWorldMovementPoints.java 3.08 KB
Newer Older
1
/*
2
 * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * PeerfactSim.KOM 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 General Public License
 * along with PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package de.tud.kom.p2psim.impl.topology.movement.local;

23
24
25
import java.util.LinkedList;
import java.util.List;

26
import com.graphhopper.util.PointList;
27
import com.graphhopper.util.shapes.GHPoint3D;
28

29
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
30
31
import de.tud.kom.p2psim.impl.topology.PositionVector;

32
33
34
35
36
37
38
39
40
/**
 * This class contains one trajectory from a start to a destination. It saves
 * the respective points (coordinates) along the path with a given movement
 * speed and also (if enabled) the assigned IDs of the roads and walkways that
 * are traversed.
 * 
 * @author Bjoern Richerzhagen
 * @version 1.0, Aug 9, 2017
 */
41
42
43
public class RealWorldMovementPoints {

	private PositionVector start;
44

45
	private PositionVector destination;
46

47
48
	private PointList pointList;
	
49
50
51
52
53
54
55
56
	private final List<PositionVector> positionsList;

	private int currentIndex;
	
	private int routeLength;

	public RealWorldMovementPoints(PositionVector start,
			PositionVector destination, PointList pointList) {
57
58
59
		this.start = start;
		this.destination = destination;
		this.pointList = pointList;
60
61
62
63
64
65
		this.positionsList = new LinkedList<>();
		// Create Position vectors ONCE
		for (GHPoint3D temp : pointList) {
			positionsList.add(RealWorldStreetsMovement.transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon()));
		}
		routeLength = positionsList.size();
66
67
68
69
70
	}
	
	public PositionVector getStart() {
		return start;
	}
71

72
73
74
	public PositionVector getDestination() {
		return destination;
	}
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	
	/**
	 * Update the internal location with the given movement speed
	 * 
	 * @param speed
	 * @param realPosition
	 * @return
	 */
	public PositionVector updateCurrentLocation(SimLocationActuator comp, double speed, double tolerance) {
		List<PositionVector> sublist = positionsList.subList(currentIndex, routeLength);
		PositionVector newPosition = null;
		for (PositionVector candidate : sublist) {
			newPosition = comp.getRealPosition().moveStep(candidate, speed);
			if (candidate
					.distanceTo(comp.getRealPosition()) < tolerance) {
				currentIndex++;
			} else {
				break;
			}
		}
		return newPosition;
	}
	
	@Override
	public String toString() {
		return "\n\tfrom "+start.toString()+" to "+destination.toString()+ "\n\tstep: "+currentIndex + " length: "+routeLength;
101
	}
102

103
104
105
	public PointList getPointList() {
		return pointList;
	}
106
107
108

	public int getCurrentIndex() {
		return this.currentIndex;
109
110
	}
}