Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean(perception): Improve generics usage in perception module #416

Merged
merged 48 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c34b17c
feat: set Java 17 as source/target language level
kschrab Sep 9, 2024
5cb1036
refactor: use pattern matching for instanceof #java17
kschrab Sep 9, 2024
ce7d228
ci: upgrade spotbugs-maven-plugin, don't execute analysis in parallel
kschrab Sep 10, 2024
02038c4
ci: upgrade spotbugs-maven-plugin
kschrab Sep 10, 2024
0230f87
refactor: use Stream.toList() #java17
kschrab Sep 10, 2024
225299f
refactor: use switch expressions #java17
kschrab Sep 10, 2024
b8e7feb
refactor: use record for some inner classes #java17
kschrab Sep 10, 2024
97381ce
fix: fix broken test
kschrab Sep 10, 2024
f1be237
refactor: use text blocks #java17
kschrab Sep 10, 2024
4dc28b3
ci: go back to spotbugs 4.2.3
kschrab Sep 10, 2024
636a1d5
ci: update docker image for builds on eclipse CI
kschrab Sep 10, 2024
05d39ce
ci: go back to spotbugs 4.2.2
kschrab Sep 10, 2024
7c524f2
ci: use spotbugs 4.2.3
kschrab Sep 10, 2024
4878d86
refactor: use pattern matching for instanceof and Stream.toList #java17
kschrab Sep 16, 2024
398c759
build: use JDK 17 in github action
kschrab Sep 16, 2024
7b9c8ba
Merge remote-tracking branch 'origin/891-java-17' into 891-java-17
kschrab Sep 17, 2024
c5f6aa7
clean(sns): remove unnecessary default case
kschrab Sep 17, 2024
9b2559b
improvement(perception): improved generics handling in perception module
schwepmo Sep 24, 2024
41b2105
improvement(perception): adjusted some comments
schwepmo Sep 24, 2024
acb0ffe
chore: update webvisualizer tooling (#415)
hoelger Sep 24, 2024
3bb15fd
build: copy web-visualizer files to work with starter (#414)
hoelger Sep 24, 2024
c85d6dd
ci: use jdk17 container for deploy
kschrab Sep 25, 2024
08c9736
ci: use custom codeql action for jdk17
kschrab Sep 25, 2024
8f853d0
docs: add JDK17 alert to README.md
kschrab Sep 25, 2024
dc3eb6f
feat(visualizer): add icons for bicycles and busses in WebVisualizer …
hoelger Sep 30, 2024
d515343
feat(tutorial): WeatherServerApp now relays the last received DENM (#…
hoelger Sep 30, 2024
ac5feee
fix(tutorial): minor improvements on tutorial applications (#409)
hoelger Oct 1, 2024
0c6c7f0
feat(ns3): improve ns3 installer + minor fixes (#413)
hoelger Oct 1, 2024
81f2abb
fix: show correct icons in barnim scenario (#422)
hoelger Oct 9, 2024
3bed192
docs: link the new documentation page in the README (#421)
hoelger Oct 9, 2024
407170b
build: store etc-files in mosaic-starter and copy them to bundle (#423)
kschrab Oct 15, 2024
6e19fc6
feat(sumo): support sumo 1.21.0 (#424)
kschrab Oct 15, 2024
f35449f
fix: remove VSimRTI from WebVisualizer (#426)
hoelger Oct 17, 2024
21670f6
feat: run windows-mosaic with wsl-ns3 (#425)
hoelger Oct 17, 2024
1af68db
feat(sns): support multi-hop unicast for topological and geographical…
kschrab Nov 5, 2024
62fe5a3
feat: introducing SensorModule to provide access to environmental eve…
kschrab Nov 6, 2024
909ccfe
feat: use WSL in Windows for execution of OMNeT++ federate (#431)
hoelger Nov 19, 2024
ae41bdb
feat: refactor AdHocMessageRoutingBuilder (#433)
FunKuchen Nov 19, 2024
53f118b
feat: add dev-option to ns3 installation script (#435)
hoelger Nov 19, 2024
21aefb5
feat: refactored CellMessageRoutingBuilder (#437)
FunKuchen Nov 20, 2024
d9b7a83
refactor(application): move navigation module interface to api packag…
kschrab Nov 21, 2024
64da606
docs: fixed Jenkins badge
kschrab Nov 25, 2024
a835f98
feat(bundle): build path to java binary with JAVA_HOME if set (#438)
fhilg Nov 26, 2024
5fd5fb0
fix(.gitignore): exception for "bundle/src/assembly/resources/bin/" a…
fhilg Nov 26, 2024
3a3bcb5
feat: set Java 17 as source/target language level
kschrab Sep 9, 2024
ed3050c
Merge branch 'main' of github.com:eclipse/mosaic into improve-percept…
schwepmo Dec 2, 2024
1843b81
cleanup(perception): moved inspection disabling to statement
schwepmo Dec 6, 2024
0356761
cleanup(perception): improved comment
schwepmo Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public List<TrafficLightObject> getPerceivedTrafficLights() {
abstract List<TrafficLightObject> getTrafficLightsInRange();

@Override
public List<SpatialObject> getPerceivedObjects() {
List<SpatialObject> objectsInRange = getObjectsInRange();
public List<SpatialObject<?>> getPerceivedObjects() {
List<SpatialObject<?>> objectsInRange = getObjectsInRange();
objectsInRange = applyPerceptionModifiers(objectsInRange);
return objectsInRange;
}
Expand All @@ -108,12 +108,13 @@ public List<SpatialObject> getPerceivedObjects() {
*
* @return the raw list of objects in range of the ego vehicle
*/
abstract List<SpatialObject> getObjectsInRange();
abstract List<SpatialObject<?>> getObjectsInRange();

private <T extends SpatialObject<T>> List<T> applyPerceptionModifiers(List<T> objectsInRange) {
private <T extends SpatialObject<?>> List<T> applyPerceptionModifiers(List<T> objectsInRange) {
List<T> filteredList = new ArrayList<>(objectsInRange);
// create a copy of all perceived objects to avoid interference with modifiers of other perception modules.
filteredList.replaceAll(T::copy);
//noinspection unchecked
filteredList.replaceAll(object -> (T) object.copy());
for (PerceptionModifier perceptionModifier : configuration.getPerceptionModifiers()) {
filteredList = perceptionModifier.apply(owner, filteredList); // apply filters in sequence
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ List<TrafficLightObject> getTrafficLightsInRange() {
}

@Override
List<SpatialObject> getObjectsInRange() {
List<SpatialObject<?>> getObjectsInRange() {
log.debug("No vehicle index configured, leading to disabled perception.");
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface PerceptionModel {
/**
* Checks, if the other spatial object is within this perception range.
*/
boolean isInRange(SpatialObject other);
boolean isInRange(SpatialObject<?> other);

/**
* Returns the minimum bounding box around this perception area. This is used for range search queries in the perception index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ public List<TrafficLightObject> getTrafficLightsInRange() {
}

@Override
public List<SpatialObject> getObjectsInRange() {
public List<SpatialObject<?>> getObjectsInRange() {
if (perceptionModel == null || owner.getVehicleData() == null) {
log.warn("No perception model initialized.");
return Lists.newArrayList();
}
perceptionModel.updateOrigin(owner.getVehicleData().getProjectedPosition(), owner.getVehicleData().getHeading());
SimulationKernel.SimulationKernel.getCentralPerceptionComponent().updateSpatialIndices();
List<SpatialObject> objectsInRange = new ArrayList<>();
List<SpatialObject<?>> objectsInRange = new ArrayList<>();
objectsInRange.addAll(SimulationKernel.SimulationKernel.getCentralPerceptionComponent()
.getTrafficObjectIndex()
.getVehiclesInRange(perceptionModel));
Expand All @@ -105,7 +105,8 @@ public List<SpatialObject> getObjectsInRange() {

@Override
public Collection<Edge<Vector3d>> getSurroundingWalls() {
return SimulationKernel.SimulationKernel.getCentralPerceptionComponent().getTrafficObjectIndex().getSurroundingWalls(perceptionModel);
return SimulationKernel.SimulationKernel.getCentralPerceptionComponent()
.getTrafficObjectIndex().getSurroundingWalls(perceptionModel);
}

/**
Expand Down Expand Up @@ -157,7 +158,7 @@ public BoundingBox getBoundingBox() {
}

@Override
public boolean isInRange(SpatialObject other) {
public boolean isInRange(SpatialObject<?> other) {
if (other.getId().equals(this.ownerId)) { // cannot see itself
return false;
}
Expand All @@ -167,10 +168,10 @@ public boolean isInRange(SpatialObject other) {
// we use tmpVector2 as origin from the viewpoint of this object
tmpVector2.set(0, 0, 0);

if (tmpVector1.magnitude() > configuration.getViewingRange()) { // other vehicle is NOT in range
if (tmpVector1.magnitude() > configuration.getViewingRange()) { // the other vehicle is NOT in range
return false;
}
if (MathUtils.isFuzzyEqual(configuration.getViewingAngle(), 360d)) { // for 360 degree viewing angle field-of-view check is obsolete
if (MathUtils.isFuzzyEqual(configuration.getViewingAngle(), 360d)) { // for 360° viewing angle FOV check is obsolete
return true;
} else if (configuration.getViewingAngle() < 180d) { // for < 180 degree viewing angle we use left and right vector
return isBetweenVectors(tmpVector1, tmpVector2, leftBoundVector, rightBoundVector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<TrafficLightObject> getTrafficLightsInRange() {
}

@Override
public List<SpatialObject> getObjectsInRange() {
public List<SpatialObject<?>> getObjectsInRange() {
this.log.debug("Traffic Light Perception not implemented for {} only vehicles will be retrieved.", this.getClass().getSimpleName());
return new ArrayList<>(getVehiclesInRange());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
import java.util.ArrayList;
import java.util.List;

/**
* An occlusion modifier for other vehicles configuration is done using {@link #pointsPerSide} and {@link #detectionThreshold}.
* Example for {@code pointsPerSide = 3} (x's are the corners which will be evaluated anyway, o's are the added points):
* <pre>
* x-----o-----x
* | |
* | |
* o o
* | |
* | |
* x-----o-----x
* </pre>
*/
public class BoundingBoxOcclusion implements PerceptionModifier {

private final Vector3d intersectionResult = new Vector3d();
Expand Down Expand Up @@ -58,7 +71,6 @@ public BoundingBoxOcclusion() {
*
* @param pointsPerSide the number of points that will be evaluated per object side (corners count towards 2 edges)
* @param detectionThreshold how many points have to be visible in order for an object to be treated as detected
*
* @throws IllegalArgumentException if pointsPerSide or detectionThreshold is configured wrongly
*/
public BoundingBoxOcclusion(int pointsPerSide, int detectionThreshold) {
Expand All @@ -76,7 +88,7 @@ public BoundingBoxOcclusion(int pointsPerSide, int detectionThreshold) {
}

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
List<T> newObjects = new ArrayList<>();
// the ego object cannot occlude vision
List<T> occludingObjects = spatialObjects.stream()
Expand Down Expand Up @@ -115,7 +127,8 @@ public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List
* @param occludingObjects all objects that potentially occlude the vehicle
* @return {@code true} if the point is visible, else {@code false}
*/
private <T extends SpatialObject> boolean isVisible(Vector3d egoPosition, Vector3d pointToEvaluate, String objectId, List<T> occludingObjects) {
private <T extends SpatialObject<?>> boolean isVisible(Vector3d egoPosition, Vector3d pointToEvaluate,
String objectId, List<T> occludingObjects) {
for (T occludingObject : occludingObjects) {
if (occludingObject.getId().equals(objectId)) {
continue; // cannot be occluded by itself
Expand Down Expand Up @@ -146,12 +159,12 @@ private <T extends SpatialObject> boolean isVisible(Vector3d egoPosition, Vector
* o o
* | |
* | |
* x-----o-----y
* x-----o-----x
* </pre>
*
* @param spatialObject a {@link SpatialObject} for which the occlusion should be evaluated
*/
private <T extends SpatialObject> List<Vector3d> createPointsToEvaluate(T spatialObject) {
private <T extends SpatialObject<?>> List<Vector3d> createPointsToEvaluate(T spatialObject) {
List<Vector3d> pointsToEvaluate = new ArrayList<>();
SpatialObjectBoundingBox boundingBox = spatialObject.getBoundingBox();
// if object has edges and more than 2 points per side are to be evaluated, calculate points that have to be evaluated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,26 @@ public class DimensionsModifier implements PerceptionModifier {
private final RandomNumberGenerator rng;


public DimensionsModifier(RandomNumberGenerator rng, double lengthDeviation, double widthDeviation, double heightDeviation) {
/**
* Constructor for {@link DimensionsModifier} given the sigma values for the gaussian distribution applied to different dimensions.
*
* @param rng {@link RandomNumberGenerator} used to generate pseudo-random gaussian numbers
* @param lengthDeviation sigma value for the length
* @param widthDeviation sigma value for the width
* @param heightDeviation sigma value for the height
*/
public DimensionsModifier(RandomNumberGenerator rng, double lengthDeviation, double widthDeviation, double heightDeviation) {
this.rng = rng;
this.lengthDeviation = lengthDeviation;
this.widthDeviation = widthDeviation;
this.heightDeviation = heightDeviation;
}

/**
* Constructor for {@link DimensionsModifier} using default values of 0.2 for the sigma value of the dimensions
*
* @param rng @link RandomNumberGenerator} used to generate pseudo-random gaussian numbers
*/
public DimensionsModifier(RandomNumberGenerator rng) {
this.rng = rng;
this.lengthDeviation = SIGMA_LENGTH_OFFSET;
Expand All @@ -58,7 +71,7 @@ public DimensionsModifier(RandomNumberGenerator rng) {
}

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
spatialObjects.stream()
.filter(o -> o instanceof VehicleObject)
.forEach(o -> adjustDimensionsOfVehicle((VehicleObject) o));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public DistanceFilter(RandomNumberGenerator rng, double offset) {
}

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
if (spatialObjects.isEmpty()) {
return spatialObjects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public HeadingModifier(RandomNumberGenerator rng) {
this.chanceOfWrongDirection = DEFAULT_CHANCE_WRONG_DIR;
}

/**
* Constructor for the {@link HeadingModifier} using configured values.
*
* @param rng {@link RandomNumberGenerator} for evaluation of probabilities
* @param headingStandardDeviation the sigma value used for the applied heading offset [0, 360]
* @param chanceOfWrongDirection chance for a heading to be rotated by 180° [0, 1]
*/
public HeadingModifier(RandomNumberGenerator rng, double headingStandardDeviation, double chanceOfWrongDirection) {
Validate.inclusiveBetween(0, 360, headingStandardDeviation, "Heading deviation should lie between 0 and 360");
Validate.inclusiveBetween(0, 1, chanceOfWrongDirection, "Wrong direction probability should lie between 0 and 1");
Expand All @@ -69,18 +76,15 @@ public HeadingModifier(RandomNumberGenerator rng, double headingStandardDeviatio
}

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
final Vector3d ownerPosition = owner.getVehicleData().getProjectedPosition().toVector3d();

public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
spatialObjects.stream()
.filter(o -> o instanceof VehicleObject)
.forEach(o -> adjustHeadingOfVehicle(ownerPosition, (VehicleObject) o));
.forEach(o -> adjustHeadingOfVehicle((VehicleObject) o));

return spatialObjects;
}

private void adjustHeadingOfVehicle(Vector3d ownerPosition, VehicleObject vehicleObject) {

private void adjustHeadingOfVehicle(VehicleObject vehicleObject) {
double oldHeading = vehicleObject.getHeading();

if (rng.nextDouble() < chanceOfWrongDirection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public interface PerceptionModifier {
*
* @return the filtered/modified list
*/
<T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects);
<T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public PositionModifier(RandomNumberGenerator rng, double longitudinalStandardDe
}

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
Vector3d ownerPosition = owner.getVehicleData().getProjectedPosition().toVector3d();
Vector3d ownerDirection = new Vector3d();
VectorUtils.getDirectionVectorFromHeading(owner.getVehicleData().getHeading(), ownerDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public SimpleOcclusion(double minDetectionAngle, double maxDetectionAngle) {
}

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
if (spatialObjects.isEmpty()) {
return spatialObjects;
}
Vector3d ownerPosition = owner.getVehicleData().getProjectedPosition().toVector3d();
// sort by distances
List<SpatialObject> sortedByDistance = new ArrayList<>(spatialObjects);
List<T> sortedByDistance = new ArrayList<>(spatialObjects);
sortedByDistance.sort(Comparator.comparingDouble(vehicleObject -> vehicleObject.getPosition().distanceTo(ownerPosition)));
// fit linear function to (closest distance, min angle) and (furthest distance, max angle)
double closestPerceivedDistance = ownerPosition.distanceTo(sortedByDistance.get(0).getPosition());
Expand All @@ -81,7 +81,7 @@ public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List
double m = (maxDetectionAngle - minDetectionAngle) / (furthestPerceivedDistance - closestPerceivedDistance);
double n = minDetectionAngle - (closestPerceivedDistance * m);

List<SpatialObject> notOccludedObjects = new ArrayList<>();
List<T> notOccludedObjects = new ArrayList<>();
List<Vector3d> nonOccludedVectors = new ArrayList<>();
notOccludedObjects.add(sortedByDistance.get(0)); // closest vehicle is always perceived
nonOccludedVectors.add(getVectorRelativeTo(ownerPosition, sortedByDistance.get(0).getPosition()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class WallOcclusion implements PerceptionModifier {
private final Vector3d intersectionResult = new Vector3d();

@Override
public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
public <T extends SpatialObject<?>> List<T> apply(PerceptionModuleOwner owner, List<T> spatialObjects) {
if (spatialObjects.isEmpty()) {
return spatialObjects;
}
Expand Down
Loading
Loading