From 63d5410fdd638009d21c736c1258288a78c15285 Mon Sep 17 00:00:00 2001 From: Benedikt Schwab Date: Tue, 30 Apr 2024 10:28:30 +0200 Subject: [PATCH] remove orphaned roads belonging to partially cropped junctions --- .../modifiers/opendrive/cropper/OpendriveCropper.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rtron-transformer/src/main/kotlin/io/rtron/transformer/modifiers/opendrive/cropper/OpendriveCropper.kt b/rtron-transformer/src/main/kotlin/io/rtron/transformer/modifiers/opendrive/cropper/OpendriveCropper.kt index e08d22d1..f919db16 100644 --- a/rtron-transformer/src/main/kotlin/io/rtron/transformer/modifiers/opendrive/cropper/OpendriveCropper.kt +++ b/rtron-transformer/src/main/kotlin/io/rtron/transformer/modifiers/opendrive/cropper/OpendriveCropper.kt @@ -41,7 +41,7 @@ class OpendriveCropper( return modifiedOpendriveModel.some() to report } - // remove the roads according depending on the + // remove all roads for which the reference line lies in the crop polygon val roadsFiltered = modifiedOpendriveModel.road.filter { currentRoad -> currentRoad.planView.geometry.any { cropPolygon.contains(Vector2D(it.x, it.y)) } } @@ -65,12 +65,17 @@ class OpendriveCropper( currentJunction } // remove all the junctions with no connections left - val filteredJunctions = modifiedOpendriveModel.junction.filter { it.connection.isNotEmpty() } + val junctionsFiltered = modifiedOpendriveModel.junction.filter { it.connection.isNotEmpty() } report.numberOfJunctionsOriginally = modifiedOpendriveModel.junction.size - report.numberOfJunctionsRemaining = filteredJunctions.size - modifiedOpendriveModel.junction = filteredJunctions + report.numberOfJunctionsRemaining = junctionsFiltered.size + modifiedOpendriveModel.junction = junctionsFiltered val remainingJunctionsIds = modifiedOpendriveModel.junction.map { it.id } + // remove roads belonging to a junction, which was removed + val remainingJunctionIds = junctionsFiltered.map { it.id }.toSet() + val roadsFilteredFiltered = roadsFiltered.filter { currentRoad -> currentRoad.getJunctionOption().fold({ true }, { remainingJunctionIds.contains(it) }) } + modifiedOpendriveModel.road = roadsFilteredFiltered + // adjust the links of each road everyRoad.modify(modifiedOpendriveModel) { currentRoad ->