From cdf35aa281ee03a1c8af1fd9de55880d7f7d7640 Mon Sep 17 00:00:00 2001 From: Benedikt Schwab Date: Tue, 11 Jul 2023 09:08:15 +0200 Subject: [PATCH] added lane identifier range --- .../Poly2TriTriangulationAlgorithm.kt | 2 +- .../identifier/LaneIdentifierRange.kt | 45 +++++++++++++++++++ .../roadspace/objects/RoadspaceObject.kt | 4 ++ .../roadspaces/RoadspaceObjectBuilder.kt | 6 +-- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 rtron-model/src/main/kotlin/io/rtron/model/roadspaces/identifier/LaneIdentifierRange.kt diff --git a/rtron-math/src/main/kotlin/io/rtron/math/processing/triangulation/Poly2TriTriangulationAlgorithm.kt b/rtron-math/src/main/kotlin/io/rtron/math/processing/triangulation/Poly2TriTriangulationAlgorithm.kt index e044a19f..31b47690 100644 --- a/rtron-math/src/main/kotlin/io/rtron/math/processing/triangulation/Poly2TriTriangulationAlgorithm.kt +++ b/rtron-math/src/main/kotlin/io/rtron/math/processing/triangulation/Poly2TriTriangulationAlgorithm.kt @@ -38,7 +38,7 @@ import org.poly2tri.geometry.polygon.PolygonPoint as P2TPolygonPoint class Poly2TriTriangulationAlgorithm : TriangulationAlgorithm() { override fun triangulate(vertices: NonEmptyList, tolerance: Double): Either> = either.eager { - val polygon = P2TPolygon(vertices.map { P2TPolygonPoint(it.x, it.y, it.z) }) + val polygon = P2TPolygon(vertices.toList().map { P2TPolygonPoint(it.x, it.y, it.z) }) poly2TriTriangulation(polygon).bind() val triangles = polygonBackConversion(polygon, tolerance).bind() diff --git a/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/identifier/LaneIdentifierRange.kt b/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/identifier/LaneIdentifierRange.kt new file mode 100644 index 00000000..5bcb51f0 --- /dev/null +++ b/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/identifier/LaneIdentifierRange.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2019-2023 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.model.roadspaces.identifier + +import io.rtron.math.range.Range + +/** + * Identifier of a range of lanes within a lane section. + * + * @param laneIdRange range of lane ids which must have a lower and upper bound + * @param laneSectionIdentifier identifier of the lane section + */ +data class LaneIdentifierRange( + val laneIdRange: Range, + val laneSectionIdentifier: LaneSectionIdentifier +) : AbstractRoadspacesIdentifier(), LaneSectionIdentifierInterface by laneSectionIdentifier { + // Properties and Initializers + init { + require(laneIdRange.hasLowerBound()) { "laneIdRange must have a lower bound." } + require(laneIdRange.hasUpperBound()) { "laneIdRange must have a upper bound." } + } + + val lowerLaneId get() = LaneIdentifier(laneIdRange.lowerEndpointOrNull()!!, laneSectionIdentifier) + val upperLaneId get() = LaneIdentifier(laneIdRange.upperEndpointOrNull()!!, laneSectionIdentifier) + + // Conversions + override fun toStringMap(): Map = + mapOf("lowerLaneId" to laneIdRange.lowerEndpointOrNull()!!.toString(), "upperLaneId" to laneIdRange.upperEndpointOrNull()!!.toString()) + laneSectionIdentifier.toStringMap() + + override fun toIdentifierText() = "LaneIdentifierRange(lowerLaneId=${laneIdRange.lowerEndpointOrNull()!!}, upperLaneId=${laneIdRange.upperEndpointOrNull()!!}, laneSectionId=$laneSectionId, roadId=$roadspaceId)" +} diff --git a/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/roadspace/objects/RoadspaceObject.kt b/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/roadspace/objects/RoadspaceObject.kt index 0256927e..4905c204 100644 --- a/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/roadspace/objects/RoadspaceObject.kt +++ b/rtron-model/src/main/kotlin/io/rtron/model/roadspaces/roadspace/objects/RoadspaceObject.kt @@ -16,7 +16,9 @@ package io.rtron.model.roadspaces.roadspace.objects +import arrow.core.Option import io.rtron.math.geometry.euclidean.threed.AbstractGeometry3D +import io.rtron.model.roadspaces.identifier.LaneIdentifierRange import io.rtron.model.roadspaces.identifier.RoadspaceObjectIdentifier import io.rtron.model.roadspaces.roadspace.attribute.AttributeList @@ -24,12 +26,14 @@ import io.rtron.model.roadspaces.roadspace.attribute.AttributeList * Represents an object within the road space. * * @param geometry geometry of the road space object + * @param laneRelations object relations to road lanes * @param attributes attributes containing information about the road space object */ data class RoadspaceObject( val id: RoadspaceObjectIdentifier, val type: RoadObjectType = RoadObjectType.NONE, val geometry: AbstractGeometry3D, + val laneRelations: Option, val attributes: AttributeList ) { diff --git a/rtron-transformer/src/main/kotlin/io/rtron/transformer/converter/opendrive2roadspaces/roadspaces/RoadspaceObjectBuilder.kt b/rtron-transformer/src/main/kotlin/io/rtron/transformer/converter/opendrive2roadspaces/roadspaces/RoadspaceObjectBuilder.kt index e88b7d68..535b6a84 100644 --- a/rtron-transformer/src/main/kotlin/io/rtron/transformer/converter/opendrive2roadspaces/roadspaces/RoadspaceObjectBuilder.kt +++ b/rtron-transformer/src/main/kotlin/io/rtron/transformer/converter/opendrive2roadspaces/roadspaces/RoadspaceObjectBuilder.kt @@ -97,13 +97,13 @@ class RoadspaceObjectBuilder( val roadspaceObjectId = RoadspaceObjectIdentifier("${roadObject.id}_${repeatIdentifier.repeatIndex}", roadObject.name, id) val geometry = buildGeometries(roadObject, currentRoadObjectRepeat.some(), roadReferenceLine).handleMessageList { messageList += it } - RoadspaceObject(roadspaceObjectId, type, geometry, attributes) + RoadspaceObject(roadspaceObjectId, type, geometry, None, attributes) } val roadObjects = if (roadObjectsFromRepeat.isEmpty()) { val roadspaceObjectId = RoadspaceObjectIdentifier(roadObject.id, roadObject.name, id) val geometry = buildGeometries(roadObject, None, roadReferenceLine).handleMessageList { messageList += it } - nonEmptyListOf(RoadspaceObject(roadspaceObjectId, type, geometry, attributes)) + nonEmptyListOf(RoadspaceObject(roadspaceObjectId, type, geometry, None, attributes)) } else { roadObjectsFromRepeat.toNonEmptyListOrNull()!! } @@ -234,7 +234,7 @@ class RoadspaceObjectBuilder( buildAttributes(roadSignal.curveRelativePosition) + buildAttributes(roadSignal.referenceLinePointRelativeRotation) - return RoadspaceObject(objectId, RoadObjectType.SIGNAL, geometry, attributes) + return RoadspaceObject(objectId, RoadObjectType.SIGNAL, geometry, None, attributes) } private fun buildAttributes(signal: RoadSignalsSignal): AttributeList =