Package org.opentrafficsim.kpi.sampling
Class Trajectory<G extends GtuDataInterface>
java.lang.Object
org.opentrafficsim.kpi.sampling.Trajectory<G>
- Type Parameters:
 G- gtu data type
public final class Trajectory<G extends GtuDataInterface>
extends java.lang.Object
Contains position, speed, acceleration and time data of a GTU, over some section. Position is relative to the start of the
 lane in the direction of travel, also when trajectories have been truncated at a position x > 0. Note that this regards
 internal data and output. Input position always refers to the design line of the lane. This class internally flips input
 positions and boundaries.
 
 Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 
 BSD-style license. See OpenTrafficSim License.
 
- Author:
 - Alexander Verbraeck, Peter Knoppers, Wouter Schakel
 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description classTrajectory.BoundaryCopyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.static classTrajectory.SpaceTimeViewSpace-time view of a trajectory. - 
Constructor Summary
Constructors Constructor Description Trajectory(GtuDataInterface gtu, MetaData metaData, java.util.Set<ExtendedDataType<?,?,?,G>> extendedData, KpiLaneDirection kpiLaneDirection) - 
Method Summary
Modifier and Type Method Description voidadd(Length position, Speed speed, Acceleration acceleration, Time time)Adds values of position, speed, acceleration and time.voidadd(Length position, Speed speed, Acceleration acceleration, Time time, G gtu)Adds values of position, speed, acceleration and time.intbinarySearchT(float time)Returns the last index with a time smaller than or equal to the given time.intbinarySearchX(float position)Returns the last index with a position smaller than or equal to the given position.booleancontains(ExtendedDataType<?,?,?,?> extendedDataType)booleancontains(MetaDataType<?> metaDataType)booleanequals(java.lang.Object obj)float[]getA()floatgetA(int index)Returnsavalue of a single sample.FloatAccelerationVectorgetAcceleration()AccelerationgetAccelerationAtPosition(Length position)Returns an interpolated acceleration at the given position.AccelerationgetAccelerationAtTime(Time time)Returns an interpolated acceleration at the given time.<O, S> OgetExtendedData(ExtendedDataType<?,O,S,?> extendedDataType)<T, S> TgetExtendedData(ExtendedDataType<T,?,S,?> extendedDataType, int index)Returns extended data type value of a single sample.java.util.Set<ExtendedDataType<?,?,?,G>>getExtendedDataTypes()Returns the included extended data types.java.lang.StringgetGtuId()<T> TgetMetaData(MetaDataType<T> metaDataType)java.util.Set<MetaDataType<?>>getMetaDataTypes()Returns the included meta data types.FloatLengthVectorgetPosition()LengthgetPositionAtTime(Time time)Returns an interpolated position at the given time.Trajectory.SpaceTimeViewgetSpaceTimeView(Length startPosition, Length endPosition, Time startTime, Time endTime)Returns a space-time view of this trajectory.FloatSpeedVectorgetSpeed()SpeedgetSpeedAtPosition(Length position)Returns an interpolated speed at the given position.SpeedgetSpeedAtTime(Time time)Returns an interpolated speed at the given time.float[]getT()floatgetT(int index)Returnstvalue of a single sample.FloatTimeVectorgetTime()TimegetTimeAtPosition(Length position)Returns an interpolated time at the given position.DurationgetTotalDuration()LengthgetTotalLength()float[]getV()floatgetV(int index)Returnsvvalue of a single sample.float[]getX()floatgetX(int index)Returnsxvalue of a single sample.inthashCode()intsize()Trajectory<G>subSet(Length startPosition, Length endPosition)Copies the trajectory but with a subset of the data.Trajectory<G>subSet(Length startPosition, Length endPosition, Time startTime, Time endTime)Copies the trajectory but with a subset of the data.Trajectory<G>subSet(Time startTime, Time endTime)Copies the trajectory but with a subset of the data.java.lang.StringtoString() 
- 
Constructor Details
- 
Trajectory
public Trajectory(GtuDataInterface gtu, MetaData metaData, java.util.Set<ExtendedDataType<?,?,?,G>> extendedData, KpiLaneDirection kpiLaneDirection)- Parameters:
 gtu- GtuDataInterface; GTU of this trajectory, only the id is stored.metaData- MetaData; meta dataextendedData- Set<ExtendedDataType<?,?,?,G>>; types of extended datakpiLaneDirection- KpiLaneDirection; direction of travel
 
 - 
 - 
Method Details
- 
add
Adds values of position, speed, acceleration and time.- Parameters:
 position- Length; position is relative to the start of the lane in the direction of the design line, i.e. irrespective of the travel direction, also when trajectories have been truncated at a position x > 0speed- Speed; speedacceleration- Acceleration; accelerationtime- Time; time
 - 
add
Adds values of position, speed, acceleration and time.- Parameters:
 position- Length; position is relative to the start of the lane in the direction of the design line, i.e. irrespective of the travel direction, also when trajectories have been truncated at a position x > 0speed- Speed; speedacceleration- Acceleration; accelerationtime- Time; timegtu- G; gtu to add extended data for
 - 
size
public int size()- Returns:
 - size of the underlying trajectory data
 
 - 
getGtuId
public java.lang.String getGtuId()- Returns:
 - GTU id
 
 - 
getX
public float[] getX()- Returns:
 - si position values, position is relative to the start of the lane, also when trajectories have been truncated at a position x > 0
 
 - 
getV
public float[] getV()- Returns:
 - si speed values
 
 - 
getA
public float[] getA()- Returns:
 - si acceleration values
 
 - 
getT
public float[] getT()- Returns:
 - si time values
 
 - 
binarySearchX
public int binarySearchX(float position)Returns the last index with a position smaller than or equal to the given position.- Parameters:
 position- float; position- Returns:
 - int; last index with a position smaller than or equal to the given position
 
 - 
binarySearchT
public int binarySearchT(float time)Returns the last index with a time smaller than or equal to the given time.- Parameters:
 time- float; time- Returns:
 - int; last index with a time smaller than or equal to the given time
 
 - 
getX
Returnsxvalue of a single sample.- Parameters:
 index- int; index- Returns:
 xvalue of a single sample- Throws:
 SamplingException- if the index is out of bounds
 - 
getV
Returnsvvalue of a single sample.- Parameters:
 index- int; index- Returns:
 vvalue of a single sample- Throws:
 SamplingException- if the index is out of bounds
 - 
getA
Returnsavalue of a single sample.- Parameters:
 index- int; index- Returns:
 avalue of a single sample- Throws:
 SamplingException- if the index is out of bounds
 - 
getT
Returnstvalue of a single sample.- Parameters:
 index- int; index- Returns:
 tvalue of a single sample- Throws:
 SamplingException- if the index is out of bounds
 - 
getExtendedData
public <T, S> T getExtendedData(ExtendedDataType<T,?,S,?> extendedDataType, int index) throws SamplingExceptionReturns extended data type value of a single sample.- Type Parameters:
 T- scalar type of extended data typeS- storage type of extended data type- Parameters:
 extendedDataType- ExtendedDataType<T,?,S,?>; data type from which to retrieve the dataindex- int; index for which to retrieve the data- Returns:
 - extended data type value of a single sample
 - Throws:
 SamplingException- if the index is out of bounds
 - 
getPosition
- Returns:
 - strongly typed copy of position, position is relative to the start of the lane, also when trajectories have been truncated at a position x > 0
 
 - 
getSpeed
- Returns:
 - strongly typed copy of speed
 
 - 
getAcceleration
- Returns:
 - strongly typed copy of acceleration
 
 - 
getTime
- Returns:
 - strongly typed copy of time
 
 - 
getTotalLength
- Returns:
 - total length of this trajectory
 - Throws:
 java.lang.IllegalStateException- if trajectory is empty
 - 
getTotalDuration
- Returns:
 - total duration of this trajectory
 - Throws:
 java.lang.IllegalStateException- if trajectory is empty
 - 
contains
- Parameters:
 metaDataType- MetaDataType<?>; meta data type- Returns:
 - whether the trajectory contains the meta data of give type
 
 - 
getMetaData
- Type Parameters:
 T- class of meta data- Parameters:
 metaDataType- MetaDataType<T>; meta data type- Returns:
 - value of meta data
 
 - 
getMetaDataTypes
Returns the included meta data types.- Returns:
 - included meta data types
 
 - 
contains
- Parameters:
 extendedDataType- ExtendedDataType<?,?,?,?>; extended data type- Returns:
 - whether the trajectory contains the extended data of give type
 
 - 
getExtendedData
public <O, S> O getExtendedData(ExtendedDataType<?,O,S,?> extendedDataType) throws SamplingException- Type Parameters:
 O- output typeS- storage type- Parameters:
 extendedDataType- ExtendedDataType<?,O,S,?>; extended data type to return- Returns:
 - values of extended data type
 - Throws:
 SamplingException- if the extended data type is not in the trajectory
 - 
getExtendedDataTypes
Returns the included extended data types.- Returns:
 - included extended data types
 
 - 
getSpaceTimeView
public Trajectory.SpaceTimeView getSpaceTimeView(Length startPosition, Length endPosition, Time startTime, Time endTime)Returns a space-time view of this trajectory. This is much more efficient thansubSet()as no trajectory is copied. The limitation is that only distance and time (and mean speed) in the space-time view can be obtained.- Parameters:
 startPosition- Length; start positionendPosition- Length; end positionstartTime- Time; start timeendTime- Time; end time- Returns:
 - space-time view of this trajectory
 
 - 
subSet
Copies the trajectory but with a subset of the data. Longitudinal entry is only true if the original trajectory has true, and the subset is from the start.- Parameters:
 startPosition- Length; start positionendPosition- Length; end position- Returns:
 - subset of the trajectory
 - Throws:
 java.lang.NullPointerException- if an input is nulljava.lang.IllegalArgumentException- of minLength is smaller than maxLength
 - 
subSet
Copies the trajectory but with a subset of the data.- Parameters:
 startTime- Time; start timeendTime- Time; end time- Returns:
 - subset of the trajectory
 - Throws:
 java.lang.NullPointerException- if an input is nulljava.lang.IllegalArgumentException- of minTime is smaller than maxTime
 - 
subSet
public Trajectory<G> subSet(Length startPosition, Length endPosition, Time startTime, Time endTime)Copies the trajectory but with a subset of the data.- Parameters:
 startPosition- Length; start positionendPosition- Length; end positionstartTime- Time; start timeendTime- Time; end time- Returns:
 - subset of the trajectory
 - Throws:
 java.lang.NullPointerException- if an input is nulljava.lang.IllegalArgumentException- of minLength/Time is smaller than maxLength/Time
 - 
getTimeAtPosition
Returns an interpolated time at the given position.- Parameters:
 position- Length; position- Returns:
 - Time; interpolated time at the given position
 
 - 
getSpeedAtPosition
Returns an interpolated speed at the given position.- Parameters:
 position- Length; position- Returns:
 - Speed; interpolated speed at the given position
 
 - 
getAccelerationAtPosition
Returns an interpolated acceleration at the given position.- Parameters:
 position- Length; position- Returns:
 - Acceleration; interpolated acceleration at the given position
 
 - 
getPositionAtTime
Returns an interpolated position at the given time.- Parameters:
 time- Time; time- Returns:
 - Length; interpolated position at the given time
 
 - 
getSpeedAtTime
Returns an interpolated speed at the given time.- Parameters:
 time- Time; time- Returns:
 - Speed; interpolated speed at the given time
 
 - 
getAccelerationAtTime
Returns an interpolated acceleration at the given time.- Parameters:
 time- Time; time- Returns:
 - Acceleration; interpolated acceleration at the given time
 
 - 
hashCode
public int hashCode()- Overrides:
 hashCodein classjava.lang.Object
 - 
equals
public boolean equals(java.lang.Object obj)- Overrides:
 equalsin classjava.lang.Object
 - 
toString
public java.lang.String toString()- Overrides:
 toStringin classjava.lang.Object
 
 -