Skip to content

Commit 49e6463

Browse files
added handling of junctions without connections
1 parent 6add55f commit 49e6463

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

rtron-model/src/main/kotlin/io/rtron/model/opendrive/additions/optics/Optics.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import io.rtron.model.opendrive.road.elevation.RoadElevationProfile
4949
import io.rtron.model.opendrive.road.elevation.elevation
5050
import io.rtron.model.opendrive.road.elevationProfile
5151
import io.rtron.model.opendrive.road.lanes
52+
import io.rtron.model.opendrive.road.link
5253
import io.rtron.model.opendrive.road.objects
5354
import io.rtron.model.opendrive.road.planView
5455
import io.rtron.model.opendrive.road.planview.RoadPlanView
@@ -62,6 +63,7 @@ val everyHeaderGeoReference = OpendriveModel.header compose Header.geoReference
6263

6364
// road
6465
val everyRoad = OpendriveModel.road compose Traversal.list()
66+
val everyRoadLink = everyRoad compose Road.link compose PPrism.some()
6567
val everyRoadPlanView = everyRoad compose Road.planView
6668
val everyRoadPlanViewGeometry = everyRoadPlanView compose RoadPlanView.geometry compose Traversal.list()
6769
val everyRoadElevationProfile = everyRoad compose Road.elevationProfile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2019-2024 Chair of Geoinformatics, Technical University of Munich
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rtron.transformer.evaluator.opendrive.modifiers
18+
19+
import arrow.core.None
20+
import io.rtron.model.opendrive.OpendriveModel
21+
import io.rtron.model.opendrive.additions.identifier.JunctionIdentifier
22+
import io.rtron.model.opendrive.additions.optics.everyRoad
23+
import io.rtron.model.opendrive.additions.optics.everyRoadLink
24+
25+
object JunctionModifier {
26+
fun removeJunction(
27+
opendriveModel: OpendriveModel,
28+
id: JunctionIdentifier,
29+
): OpendriveModel {
30+
var modifiedOpendriveModel = opendriveModel.copy()
31+
32+
// remove the junction itself
33+
modifiedOpendriveModel.junction = modifiedOpendriveModel.junction.filter { it.id != id.junctionId }
34+
35+
// remove junction references in each road
36+
everyRoad.modify(modifiedOpendriveModel) { currentRoad ->
37+
if (currentRoad.junction == id.junctionId) {
38+
currentRoad.junction = ""
39+
}
40+
41+
currentRoad
42+
}
43+
44+
// remove links to junction to be deleted
45+
everyRoadLink.modify(modifiedOpendriveModel) { currentLink ->
46+
47+
// remove the predecessor link, if it is the junction to be deleted
48+
if (currentLink.predecessor.isSome { currentPredecessor ->
49+
currentPredecessor.getJunctionPredecessorSuccessor().isSome { it == id.junctionId }
50+
}
51+
) {
52+
currentLink.predecessor = None
53+
}
54+
55+
// remove the successor link, if it is the junction to be deleted
56+
if (currentLink.successor.isSome { currentSuccessor ->
57+
currentSuccessor.getJunctionPredecessorSuccessor().isSome { it == id.junctionId }
58+
}
59+
) {
60+
currentLink.successor = None
61+
}
62+
63+
currentLink
64+
}
65+
66+
return modifiedOpendriveModel
67+
}
68+
}

rtron-transformer/src/main/kotlin/io/rtron/transformer/evaluator/opendrive/plans/modelingrules/JunctionEvaluator.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.rtron.transformer.evaluator.opendrive.plans.modelingrules
1818

1919
import arrow.core.None
20+
import arrow.core.Some
2021
import arrow.core.flattenOption
2122
import io.rtron.io.issues.DefaultIssue
2223
import io.rtron.io.issues.DefaultIssueList
@@ -25,6 +26,7 @@ import io.rtron.model.opendrive.OpendriveModel
2526
import io.rtron.model.opendrive.additions.optics.everyJunction
2627
import io.rtron.model.opendrive.junction.EJunctionType
2728
import io.rtron.transformer.evaluator.opendrive.OpendriveEvaluatorParameters
29+
import io.rtron.transformer.evaluator.opendrive.modifiers.JunctionModifier
2830
import io.rtron.transformer.issues.opendrive.of
2931

3032
object JunctionEvaluator {
@@ -111,6 +113,18 @@ object JunctionEvaluator {
111113
currentJunction
112114
}
113115

116+
val junctionsFiltered = modifiedOpendriveModel.junction.filter { it.connection.isEmpty() }
117+
junctionsFiltered.map { it.additionalId }.flattenOption().forEach { currentId ->
118+
modifiedOpendriveModel = JunctionModifier.removeJunction(modifiedOpendriveModel, currentId)
119+
120+
issueList +=
121+
DefaultIssue.of(
122+
"JunctionWithoutConnections",
123+
"Junction contains no valid connections and thus was removed.",
124+
Some(currentId), Severity.ERROR, wasFixed = true,
125+
)
126+
}
127+
114128
return modifiedOpendriveModel
115129
}
116130

0 commit comments

Comments
 (0)