RoadSideUnitInformationHandler.java 2.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

Tobias Meuser's avatar
Tobias Meuser committed
10
11
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
12
13
14

public class RoadSideUnitInformationHandler {

Tobias Meuser's avatar
Tobias Meuser committed
15
	private List<Location> _positions = new ArrayList<>();
16

Tobias Meuser's avatar
Tobias Meuser committed
17
18
19
20
21
	private boolean _observedAreaSet = false;
	private double _startX = -1;
	private double _startY = -1;
	private double _endX = -1;
	private double _endY = -1;
22

Tobias Meuser's avatar
Tobias Meuser committed
23
24
25
26
27
	public List<Location> getIntersections() {
		if (!_observedAreaSet) {
			return _positions;
		} else {
			List<Location> result = new ArrayList<>();
28

Tobias Meuser's avatar
Tobias Meuser committed
29
			for (Location position : _positions) {
30
31
				if (_startX <= position.getLongitudeOrX() && position.getLongitudeOrX() <= _endX && _startY <= position.getLatitudeOrY() && position.getLatitudeOrY() <= _endY) {
					result.add(new PositionVector(position.getLongitudeOrX() - _startX, position.getLatitudeOrY() - _startY, 0));
Tobias Meuser's avatar
Tobias Meuser committed
32
33
				}
			}
34

Tobias Meuser's avatar
Tobias Meuser committed
35
36
37
			return result;
		}
	}
38

Tobias Meuser's avatar
Tobias Meuser committed
39
40
41
42
43
	public void parseIntersectionsFile(String pRoadSideUnitDataPath) {
		File file = new File(pRoadSideUnitDataPath);
		try {
			FileInputStream inputStream = new FileInputStream(file);
			Scanner scanner = new Scanner(inputStream);
44

Tobias Meuser's avatar
Tobias Meuser committed
45
46
			while (scanner.hasNextLine()) {
				String line = scanner.nextLine();
47

Tobias Meuser's avatar
Tobias Meuser committed
48
49
50
51
52
53
54
55
56
57
58
				if (line.contains(";")) {
					String[] split = line.split(";");
					if (split.length == 2) {
						double x = Double.parseDouble(split[0]);
						double y = Double.parseDouble(split[1]);
						_positions.add(new PositionVector(x, y, 0));
					}
				}
			}
			scanner.close();
		} catch (FileNotFoundException e) {
59
			System.err.println("Unable to read file " + e.getMessage());
Tobias Meuser's avatar
Tobias Meuser committed
60
61
		}
	}
62

Tobias Meuser's avatar
Tobias Meuser committed
63
64
65
66
67
	public void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY) {
		_startX = pStartX;
		_startY = pStartY;
		_endX = pEndX;
		_endY = pEndY;
68

Tobias Meuser's avatar
Tobias Meuser committed
69
70
		_observedAreaSet = true;
	}
71
}