From 49e64630611e5d337e7c47718adb2568650de67c Mon Sep 17 00:00:00 2001 From: Benedikt Schwab Date: Mon, 23 Sep 2024 19:08:50 +0200 Subject: [PATCH] added handling of junctions without connections --- .../opendrive/additions/optics/Optics.kt | 2 + .../opendrive/modifiers/JunctionModifier.kt | 68 +++++++++++++++++++ .../plans/modelingrules/JunctionEvaluator.kt | 14 ++++ 3 files changed, 84 insertions(+) create mode 100644 rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/modifiers/JunctionModifier.kt diff --git a/rtron-model/src/main/kotlin/io/rtron/model/opendrive/additions/optics/Optics.kt b/rtron-model/src/main/kotlin/io/rtron/model/opendrive/additions/optics/Optics.kt index ba90765..a4677a0 100644 --- a/rtron-model/src/main/kotlin/io/rtron/model/opendrive/additions/optics/Optics.kt +++ b/rtron-model/src/main/kotlin/io/rtron/model/opendrive/additions/optics/Optics.kt @@ -49,6 +49,7 @@ import io.rtron.model.opendrive.road.elevation.RoadElevationProfile import io.rtron.model.opendrive.road.elevation.elevation import io.rtron.model.opendrive.road.elevationProfile import io.rtron.model.opendrive.road.lanes +import io.rtron.model.opendrive.road.link import io.rtron.model.opendrive.road.objects import io.rtron.model.opendrive.road.planView import io.rtron.model.opendrive.road.planview.RoadPlanView @@ -62,6 +63,7 @@ val everyHeaderGeoReference = OpendriveModel.header compose Header.geoReference // road val everyRoad = OpendriveModel.road compose Traversal.list() +val everyRoadLink = everyRoad compose Road.link compose PPrism.some() val everyRoadPlanView = everyRoad compose Road.planView val everyRoadPlanViewGeometry = everyRoadPlanView compose RoadPlanView.geometry compose Traversal.list() val everyRoadElevationProfile = everyRoad compose Road.elevationProfile diff --git a/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/modifiers/JunctionModifier.kt b/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/modifiers/JunctionModifier.kt new file mode 100644 index 0000000..831803e --- /dev/null +++ b/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/modifiers/JunctionModifier.kt @@ -0,0 +1,68 @@ +/* + * Copyright 2019-2024 Chair of Geoinformatics, Technical University of Munich + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rtron.transformer.evaluator.opendrive.modifiers + +import arrow.core.None +import io.rtron.model.opendrive.OpendriveModel +import io.rtron.model.opendrive.additions.identifier.JunctionIdentifier +import io.rtron.model.opendrive.additions.optics.everyRoad +import io.rtron.model.opendrive.additions.optics.everyRoadLink + +object JunctionModifier { + fun removeJunction( + opendriveModel: OpendriveModel, + id: JunctionIdentifier, + ): OpendriveModel { + var modifiedOpendriveModel = opendriveModel.copy() + + // remove the junction itself + modifiedOpendriveModel.junction = modifiedOpendriveModel.junction.filter { it.id != id.junctionId } + + // remove junction references in each road + everyRoad.modify(modifiedOpendriveModel) { currentRoad -> + if (currentRoad.junction == id.junctionId) { + currentRoad.junction = "" + } + + currentRoad + } + + // remove links to junction to be deleted + everyRoadLink.modify(modifiedOpendriveModel) { currentLink -> + + // remove the predecessor link, if it is the junction to be deleted + if (currentLink.predecessor.isSome { currentPredecessor -> + currentPredecessor.getJunctionPredecessorSuccessor().isSome { it == id.junctionId } + } + ) { + currentLink.predecessor = None + } + + // remove the successor link, if it is the junction to be deleted + if (currentLink.successor.isSome { currentSuccessor -> + currentSuccessor.getJunctionPredecessorSuccessor().isSome { it == id.junctionId } + } + ) { + currentLink.successor = None + } + + currentLink + } + + return modifiedOpendriveModel + } +} diff --git a/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/plans/modelingrules/JunctionEvaluator.kt b/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/plans/modelingrules/JunctionEvaluator.kt index 0446d43..8a7966a 100644 --- a/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/plans/modelingrules/JunctionEvaluator.kt +++ b/rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/plans/modelingrules/JunctionEvaluator.kt @@ -17,6 +17,7 @@ package io.rtron.transformer.evaluator.opendrive.plans.modelingrules import arrow.core.None +import arrow.core.Some import arrow.core.flattenOption import io.rtron.io.issues.DefaultIssue import io.rtron.io.issues.DefaultIssueList @@ -25,6 +26,7 @@ import io.rtron.model.opendrive.OpendriveModel import io.rtron.model.opendrive.additions.optics.everyJunction import io.rtron.model.opendrive.junction.EJunctionType import io.rtron.transformer.evaluator.opendrive.OpendriveEvaluatorParameters +import io.rtron.transformer.evaluator.opendrive.modifiers.JunctionModifier import io.rtron.transformer.issues.opendrive.of object JunctionEvaluator { @@ -111,6 +113,18 @@ object JunctionEvaluator { currentJunction } + val junctionsFiltered = modifiedOpendriveModel.junction.filter { it.connection.isEmpty() } + junctionsFiltered.map { it.additionalId }.flattenOption().forEach { currentId -> + modifiedOpendriveModel = JunctionModifier.removeJunction(modifiedOpendriveModel, currentId) + + issueList += + DefaultIssue.of( + "JunctionWithoutConnections", + "Junction contains no valid connections and thus was removed.", + Some(currentId), Severity.ERROR, wasFixed = true, + ) + } + return modifiedOpendriveModel }