Skip to content

Commit

Permalink
started adding lane change relations
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 8, 2023
1 parent 39f7d9e commit c4cb32a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.rtron.model.roadspaces.roadspace.road

import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import io.rtron.math.analysis.function.univariate.UnivariateFunction
import io.rtron.model.roadspaces.identifier.LaneIdentifier
import io.rtron.model.roadspaces.roadspace.attribute.AttributeList
Expand Down Expand Up @@ -52,6 +54,24 @@ data class Lane(
init {
require(id.isLeft() || id.isRight()) { "Identifier must be either for a left or right lane." }
}

// Methods
fun getLaneChange(): Option<LaneChange> {
if (roadMarkings.isEmpty()) {
return None
}

val laneChangeSet = roadMarkings.map { it.laneChange }.toSet()
val combinedLaneChange = when {
laneChangeSet.size == 1 -> laneChangeSet.first()
laneChangeSet.contains(LaneChange.BOTH) -> LaneChange.BOTH
laneChangeSet.contains(LaneChange.INCREASE) && laneChangeSet.contains(LaneChange.DECREASE) -> LaneChange.BOTH
laneChangeSet.contains(LaneChange.INCREASE) -> LaneChange.INCREASE
laneChangeSet.contains(LaneChange.DECREASE) -> LaneChange.DECREASE
else -> LaneChange.NONE
}
return Some(combinedLaneChange)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.roadspace.road

enum class LaneChange {
BOTH, DECREASE, INCREASE, NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.rtron.model.roadspaces.roadspace.attribute.AttributeList
*/
data class RoadMarking(
val width: ConstantFunction,
val laneChange: LaneChange,
val attributes: AttributeList
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import io.rtron.math.analysis.function.univariate.pure.LinearFunction
import io.rtron.math.range.Range
import io.rtron.math.range.length
import io.rtron.math.std.fuzzyEquals
import io.rtron.model.opendrive.lane.ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange
import io.rtron.model.opendrive.lane.RoadLanesLaneSectionCenterLane
import io.rtron.model.opendrive.lane.RoadLanesLaneSectionLCRLaneRoadMark
import io.rtron.model.opendrive.lane.RoadLanesLaneSectionLRLane
Expand All @@ -45,6 +46,7 @@ import io.rtron.model.roadspaces.roadspace.attribute.AttributeList
import io.rtron.model.roadspaces.roadspace.attribute.attributes
import io.rtron.model.roadspaces.roadspace.road.CenterLane
import io.rtron.model.roadspaces.roadspace.road.Lane
import io.rtron.model.roadspaces.roadspace.road.LaneChange
import io.rtron.model.roadspaces.roadspace.road.LaneMaterial
import io.rtron.model.roadspaces.roadspace.road.RoadMarking
import io.rtron.std.isStrictlySortedBy
Expand Down Expand Up @@ -221,11 +223,19 @@ class LaneBuilder(
attribute("_width", roadMark.width)
attribute("_type", roadMark.typeAttribute.toString())
attribute("_weight", roadMark.weight.map { it.toString() })
attribute("_laneChange", roadMark.laneChange.getOrElse { ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange.BOTH }.toString())
attribute("_color", roadMark.color.toString())
attribute("_material", roadMark.material)
}

return RoadMarking(width, attributes)
val laneChange = when (roadMark.laneChange.getOrElse { ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange.BOTH }) {
ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange.INCREASE -> LaneChange.INCREASE
ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange.DECREASE -> LaneChange.DECREASE
ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange.BOTH -> LaneChange.BOTH
ERoadLanesLaneSectionLCRLaneRoadMarkLaneChange.NONE -> LaneChange.NONE
}

return RoadMarking(width, laneChange, attributes)
}

private fun buildLaneMaterial(laneMaterials: List<RoadLanesLaneSectionLRLaneMaterial>): Option<LaneMaterial> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.rtron.transformer.converter.roadspaces2citygml
import arrow.core.Option
import arrow.core.flattenOption
import arrow.core.getOrElse
import arrow.core.toOption
import io.rtron.io.logging.ProgressBar
import io.rtron.io.messages.ContextMessageList
import io.rtron.io.messages.DefaultMessageList
Expand Down Expand Up @@ -178,21 +179,36 @@ class Roadspaces2CitygmlTransformer(
val lanesMap = roadspacesModel.getAllLeftRightLanes().associateBy { it.id.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix) }
trafficSpacePropertiesAdjusted.forEach { currentTrafficSpace ->
val currentLane = lanesMap.getValueEither(currentTrafficSpace.`object`.id).getOrElse { return@forEach }

// predecessor
val predecessorLaneIds =
if (currentLane.id.isForward()) {
roadspacesModel.getPredecessorLaneIdentifiers(currentLane.id).getOrElse { throw it }
} else {
roadspacesModel.getSuccessorLaneIdentifiers(currentLane.id).getOrElse { throw it }
}
currentTrafficSpace.`object`.predecessors = predecessorLaneIds
.map { TrafficSpaceReference(parameters.xlinkPrefix + it.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix)) }

// successor
val successorLaneIds =
if (currentLane.id.isForward()) {
roadspacesModel.getSuccessorLaneIdentifiers(currentLane.id).getOrElse { throw it }
} else {
roadspacesModel.getPredecessorLaneIdentifiers(currentLane.id).getOrElse { throw it }
}
currentTrafficSpace.`object`.successors = successorLaneIds
.map { TrafficSpaceReference(parameters.xlinkPrefix + it.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix)) }

// lane

val a = currentLane.getLaneChange()
val outerLaneId = currentLane.id.getAdjacentOuterLaneIdentifier()
val outerLaneGmlId = outerLaneId.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix)
lanesMap[outerLaneGmlId].toOption().tap { outerLane ->
}

currentTrafficSpace.`object`.predecessors = predecessorLaneIds.map { TrafficSpaceReference(parameters.xlinkPrefix + it.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix)) }
currentTrafficSpace.`object`.successors = successorLaneIds.map { TrafficSpaceReference(parameters.xlinkPrefix + it.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix)) }
// if (currentLane.id.isRight())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.rtron.transformer.converter.roadspaces2citygml.module
import io.rtron.model.roadspaces.identifier.AbstractRoadspacesIdentifier
import io.rtron.model.roadspaces.identifier.LaneIdentifier
import io.rtron.model.roadspaces.roadspace.objects.RoadspaceObject
import io.rtron.model.roadspaces.roadspace.road.Lane
import io.rtron.transformer.converter.roadspaces2citygml.Roadspaces2CitygmlParameters
import io.rtron.transformer.converter.roadspaces2citygml.router.RoadspaceObjectRouter
import io.rtron.transformer.converter.roadspaces2citygml.transformer.deriveGmlIdentifier
Expand Down Expand Up @@ -57,6 +58,13 @@ class RelationAdder(
dstCityObject.relatedTo = roadspaceObject.laneRelations.flatMap { it.getAllLeftRightLaneIdentifiers() }.map { createCityObjectRelation(it.deriveTrafficSpaceOrAuxiliaryTrafficSpaceGmlIdentifier(parameters.gmlIdPrefix), "belongsTo", it) }
}

fun addLaneChangeRelation(lane: Lane, dstCityObject: AbstractCityObject) {
// val a = lane.id.getAdjacentOuterLaneIdentifier()

// lane.roadMarkings.first().
// createCityObjectRelation()
}

private fun createCityObjectRelation(gmlId: String, type: String, id: AbstractRoadspacesIdentifier): CityObjectRelationProperty {
val relation = CityObjectRelation(parameters.xlinkPrefix + gmlId)
relation.relationType = Code(type)
Expand Down

0 comments on commit c4cb32a

Please sign in to comment.