Package org.opentrafficsim.draw.graphs
Class ContourDataSource<G extends org.opentrafficsim.kpi.interfaces.GtuDataInterface>
- java.lang.Object
-
- org.opentrafficsim.draw.graphs.ContourDataSource<G>
-
- Type Parameters:
G
- gtu type data
public class ContourDataSource<G extends org.opentrafficsim.kpi.interfaces.GtuDataInterface> extends Object
Class that contains data for contour plots. One data source can be shared between contour plots, in which case the granularity, path, sampler, update interval, and whether the data is smoothed (EGTF) are equal between the plots.By default the source contains traveled time and traveled distance per cell.
Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version 5 okt. 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ContourDataSource.Axis
Class to store and determine axis information such as granularity, ticks, and range.static interface
ContourDataSource.ContourDataType<Z extends Number,I>
Interface for data types of which a contour plot can be made.static class
ContourDataSource.Dimension
Enum to refer to either the distance or time axis.
-
Field Summary
Fields Modifier and Type Field Description protected static Time
DEFAULT_LOWER_TIME_BOUND
Initial lower bound for the time scale.protected static double[]
DEFAULT_SPACE_GRANULARITIES
Space granularity values.protected static int
DEFAULT_SPACE_GRANULARITY_INDEX
Index of the initial space granularity.protected static double[]
DEFAULT_TIME_GRANULARITIES
Time granularity values.protected static int
DEFAULT_TIME_GRANULARITY_INDEX
Index of the initial time granularity.(package private) ContourDataSource.Axis
spaceAxis
Space axis.(package private) ContourDataSource.Axis
timeAxis
Time axis.
-
Constructor Summary
Constructors Constructor Description ContourDataSource(org.opentrafficsim.kpi.sampling.SamplerData<G> samplerData, Duration delay, GraphPath<org.opentrafficsim.kpi.sampling.KpiLaneDirection> path, double[] spaceGranularity, int initSpaceIndex, double[] timeGranularity, int initTimeIndex, Time start, Time initialEnd)
Constructor for non-default input.ContourDataSource(org.opentrafficsim.kpi.sampling.SamplerData<G> samplerData, GraphPath<org.opentrafficsim.kpi.sampling.KpiLaneDirection> path)
Constructor using default granularities.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
get(int item, ContourDataSource.ContourDataType<?,?> contourDataType)
Returns data of the givenContourDataType
for a specific item.(package private) int
getAxisBin(ContourDataSource.Dimension dimension, double value)
Returns the axis bin number of the given value.(package private) double
getAxisValue(ContourDataSource.Dimension dimension, int item)
Returns the value on the axis of an item.(package private) int
getBinCount(ContourDataSource.Dimension dimension)
Returns the bin count.(package private) double
getBinSize(ContourDataSource.Dimension dimension, int item)
Returns the size of a bin.(package private) Duration
getDelay()
Returns the delay for anAbstractContourPlot
using thisContourDataSource
.double[]
getGranularities(ContourDataSource.Dimension dimension)
Returns the available granularities that a linked plot may use.double
getGranularity(ContourDataSource.Dimension dimension)
Returns the selected granularity that a linked plot should use.(package private) GraphPath<org.opentrafficsim.kpi.sampling.KpiLaneDirection>
getPath()
Returns the path for anAbstractContourPlot
using thisContourDataSource
.org.opentrafficsim.kpi.sampling.SamplerData<G>
getSamplerData()
Returns the sampler data for anAbstractContourPlot
using thisContourDataSource
.double
getSpeed(int item)
Returns the speed of the cell pertaining to plot item.double
getTotalDistance(int item)
Returns the total distance traveled in the cell pertaining to plot item.double
getTotalTime(int item)
Returns the total time traveled in the cell pertaining to plot item.(package private) Duration
getUpdateInterval()
Returns the update interval for anAbstractContourPlot
using thisContourDataSource
.(package private) void
increaseTime(Time updateTime)
Called byAbstractContourPlot
to update the time.(package private) void
registerContourPlot(AbstractContourPlot<?> contourPlot)
Register a contour plot to this data pool.void
setGranularity(ContourDataSource.Dimension dimension, double granularity)
Sets the granularity of the plot.void
setInterpolate(boolean interpolate)
Sets bi-linear interpolation enabled or disabled.void
setSmooth(boolean smooth)
Sets the adaptive smoothing enabled or disabled.String
toString()
-
-
-
Field Detail
-
DEFAULT_SPACE_GRANULARITIES
protected static final double[] DEFAULT_SPACE_GRANULARITIES
Space granularity values.
-
DEFAULT_SPACE_GRANULARITY_INDEX
protected static final int DEFAULT_SPACE_GRANULARITY_INDEX
Index of the initial space granularity.- See Also:
- Constant Field Values
-
DEFAULT_TIME_GRANULARITIES
protected static final double[] DEFAULT_TIME_GRANULARITIES
Time granularity values.
-
DEFAULT_TIME_GRANULARITY_INDEX
protected static final int DEFAULT_TIME_GRANULARITY_INDEX
Index of the initial time granularity.- See Also:
- Constant Field Values
-
DEFAULT_LOWER_TIME_BOUND
protected static final Time DEFAULT_LOWER_TIME_BOUND
Initial lower bound for the time scale.
-
spaceAxis
final ContourDataSource.Axis spaceAxis
Space axis.
-
timeAxis
final ContourDataSource.Axis timeAxis
Time axis.
-
-
Constructor Detail
-
ContourDataSource
public ContourDataSource(org.opentrafficsim.kpi.sampling.SamplerData<G> samplerData, GraphPath<org.opentrafficsim.kpi.sampling.KpiLaneDirection> path)
Constructor using default granularities.- Parameters:
samplerData
- SamplerData<G>; sampler datapath
- GraphPath<KpiLaneDirection>; path
-
ContourDataSource
public ContourDataSource(org.opentrafficsim.kpi.sampling.SamplerData<G> samplerData, Duration delay, GraphPath<org.opentrafficsim.kpi.sampling.KpiLaneDirection> path, double[] spaceGranularity, int initSpaceIndex, double[] timeGranularity, int initTimeIndex, Time start, Time initialEnd)
Constructor for non-default input.- Parameters:
samplerData
- SamplerData<G>; sampler datadelay
- Duration; delay so critical future events have occurred, e.g. GTU's next move's to extend trajectoriespath
- GraphPath<KpiLaneDirection>; pathspaceGranularity
- double[]; granularity options for space dimensioninitSpaceIndex
- int; initial selected space granularitytimeGranularity
- double[]; granularity options for time dimensioninitTimeIndex
- int; initial selected time granularitystart
- Time; start timeinitialEnd
- Time; initial end time of plots, will be expanded if simulation time exceeds it
-
-
Method Detail
-
getSamplerData
public final org.opentrafficsim.kpi.sampling.SamplerData<G> getSamplerData()
Returns the sampler data for anAbstractContourPlot
using thisContourDataSource
.- Returns:
- SamplerData<G>; the sampler
-
getUpdateInterval
final Duration getUpdateInterval()
Returns the update interval for anAbstractContourPlot
using thisContourDataSource
.- Returns:
- Duration; update interval
-
getDelay
final Duration getDelay()
Returns the delay for anAbstractContourPlot
using thisContourDataSource
.- Returns:
- Duration; delay
-
getPath
final GraphPath<org.opentrafficsim.kpi.sampling.KpiLaneDirection> getPath()
Returns the path for anAbstractContourPlot
using thisContourDataSource
.- Returns:
- GraphPath<KpiLaneDirection>; the path
-
registerContourPlot
final void registerContourPlot(AbstractContourPlot<?> contourPlot)
Register a contour plot to this data pool. The contour constructor will do this.- Parameters:
contourPlot
- AbstractContourPlot<?>; contour plot
-
getBinCount
final int getBinCount(ContourDataSource.Dimension dimension)
Returns the bin count.- Parameters:
dimension
- Dimension; space or time- Returns:
- int; bin count
-
getBinSize
final double getBinSize(ContourDataSource.Dimension dimension, int item)
Returns the size of a bin. Usually this is equal to the granularity, except for the last which is likely smaller.- Parameters:
dimension
- Dimension; space or timeitem
- int; item number (cell number in contour plot)- Returns:
- double; the size of a bin
-
getAxisValue
final double getAxisValue(ContourDataSource.Dimension dimension, int item)
Returns the value on the axis of an item.- Parameters:
dimension
- Dimension; space or timeitem
- int; item number (cell number in contour plot)- Returns:
- double; the value on the axis of this item
-
getAxisBin
final int getAxisBin(ContourDataSource.Dimension dimension, double value)
Returns the axis bin number of the given value.- Parameters:
dimension
- Dimension; space or timevalue
- double; value- Returns:
- int; axis bin number of the given value
-
getGranularities
public final double[] getGranularities(ContourDataSource.Dimension dimension)
Returns the available granularities that a linked plot may use.- Parameters:
dimension
- Dimension; space or time- Returns:
- double[]; available granularities that a linked plot may use
-
getGranularity
public final double getGranularity(ContourDataSource.Dimension dimension)
Returns the selected granularity that a linked plot should use.- Parameters:
dimension
- Dimension; space or time- Returns:
- double; granularity that a linked plot should use
-
increaseTime
final void increaseTime(Time updateTime)
Called byAbstractContourPlot
to update the time. This will invalidate the plot triggering a redraw.- Parameters:
updateTime
- Time; current time
-
setGranularity
public final void setGranularity(ContourDataSource.Dimension dimension, double granularity)
Sets the granularity of the plot. This will invalidate the plot triggering a redraw.- Parameters:
dimension
- Dimension; space or timegranularity
- double; granularity in space or time (SI unit)
-
setInterpolate
public final void setInterpolate(boolean interpolate)
Sets bi-linear interpolation enabled or disabled. This will invalidate the plot triggering a redraw.- Parameters:
interpolate
- boolean; whether to enable interpolation
-
setSmooth
public final void setSmooth(boolean smooth)
Sets the adaptive smoothing enabled or disabled. This will invalidate the plot triggering a redraw.- Parameters:
smooth
- boolean; whether to smooth the plor
-
getSpeed
public double getSpeed(int item)
Returns the speed of the cell pertaining to plot item.- Parameters:
item
- int; plot item- Returns:
- double; speed of the cell, calculated as 'total distance' / 'total space'.
-
getTotalDistance
public double getTotalDistance(int item)
Returns the total distance traveled in the cell pertaining to plot item.- Parameters:
item
- int; plot item- Returns:
- double; total distance traveled in the cell
-
getTotalTime
public double getTotalTime(int item)
Returns the total time traveled in the cell pertaining to plot item.- Parameters:
item
- int; plot item- Returns:
- double; total time traveled in the cell
-
get
public double get(int item, ContourDataSource.ContourDataType<?,?> contourDataType)
Returns data of the givenContourDataType
for a specific item.- Parameters:
item
- int; plot itemcontourDataType
- ContourDataType<?, ?>; contour data type- Returns:
- data of the given
ContourDataType
for a specific item
-
-