Skip to content

Commit

Permalink
added handling of junctions without connections
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 23, 2024
1 parent 6add55f commit 49e6463
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 49e6463

Please sign in to comment.