TypedEgtf.java

  1. package org.opentrafficsim.draw.egtf.typed;

  2. import org.djunits.unit.SpeedUnit;
  3. import org.djunits.unit.Unit;
  4. import org.djunits.value.base.Scalar;
  5. import org.djunits.value.vdouble.matrix.base.DoubleMatrix;
  6. import org.djunits.value.vdouble.scalar.Duration;
  7. import org.djunits.value.vdouble.scalar.Length;
  8. import org.djunits.value.vdouble.scalar.Speed;
  9. import org.djunits.value.vdouble.vector.DurationVector;
  10. import org.djunits.value.vdouble.vector.LengthVector;
  11. import org.djunits.value.vdouble.vector.base.DoubleVector;
  12. import org.opentrafficsim.draw.egtf.DataStream;
  13. import org.opentrafficsim.draw.egtf.Egtf;
  14. import org.opentrafficsim.draw.egtf.KernelShape;
  15. import org.opentrafficsim.draw.egtf.Quantity;

  16. /**
  17.  * Typed version of the EGTF.
  18.  * <p>
  19.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  20.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  21.  * </p>
  22.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  23.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  24.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  25.  */
  26. public class TypedEgtf extends Egtf
  27. {

  28.     /**
  29.      * Constructor using cCong = -18km/h, cFree = 80km/h, deltaV = 10km/h and vc = 80km/h. A default kernel is set.
  30.      */
  31.     public TypedEgtf()
  32.     {
  33.     }

  34.     /**
  35.      * Constructor defining global settings. A default kernel is set.
  36.      * @param cCong Speed; shock wave speed in congestion
  37.      * @param cFree Speed; shock wave speed in free flow
  38.      * @param deltaV Speed; speed range between congestion and free flow
  39.      * @param vc Speed; flip-over speed below which we have congestion
  40.      */
  41.     public TypedEgtf(final Speed cCong, final Speed cFree, final Speed deltaV, final Speed vc)
  42.     {
  43.         super(cCong.getInUnit(SpeedUnit.KM_PER_HOUR), cFree.getInUnit(SpeedUnit.KM_PER_HOUR),
  44.                 deltaV.getInUnit(SpeedUnit.KM_PER_HOUR), vc.getInUnit(SpeedUnit.KM_PER_HOUR));
  45.     }

  46.     /**
  47.      * Convenience constructor that also sets a specified kernel.
  48.      * @param cCong Speed; shock wave speed in congestion
  49.      * @param cFree Speed; shock wave speed in free flow
  50.      * @param deltaV Speed; speed range between congestion and free flow
  51.      * @param vc Speed; flip-over speed below which we have congestion
  52.      * @param sigma Length; spatial kernel size
  53.      * @param tau Duration; temporal kernel size
  54.      * @param xMax Length; maximum spatial range
  55.      * @param tMax Duration; maximum temporal range
  56.      */
  57.     @SuppressWarnings("parameternumber")
  58.     public TypedEgtf(final Speed cCong, final Speed cFree, final Speed deltaV, final Speed vc, final Length sigma,
  59.             final Duration tau, final Length xMax, final Duration tMax)
  60.     {
  61.         super(cCong.getInUnit(SpeedUnit.KM_PER_HOUR), cFree.getInUnit(SpeedUnit.KM_PER_HOUR),
  62.                 deltaV.getInUnit(SpeedUnit.KM_PER_HOUR), vc.getInUnit(SpeedUnit.KM_PER_HOUR), sigma.si, tau.si, xMax.si,
  63.                 tMax.si);
  64.     }

  65.     /**
  66.      * Adds point data.
  67.      * @param quantity Quantity&lt;Z, ?&gt;; quantity of the data
  68.      * @param location Length; location
  69.      * @param time Duration; time
  70.      * @param value Z; data value
  71.      * @param <U> unit of type
  72.      * @param <Z> value type
  73.      * @throws IllegalStateException if data was added with a data stream previously
  74.      */
  75.     public synchronized <U extends Unit<U>, Z extends Scalar<U, Z>> void addPointData(final Quantity<Z, ?> quantity,
  76.             final Length location, final Duration time, final Z value)
  77.     {
  78.         addPointDataSI(quantity, location.si, time.si, value.doubleValue());
  79.     }

  80.     /**
  81.      * Adds point data.
  82.      * @param dataStream DataStream&lt;Z&gt;; data stream of the data
  83.      * @param location Length; location
  84.      * @param time Duration; time
  85.      * @param value Z; data value
  86.      * @param <U> unit of type
  87.      * @param <Z> value type
  88.      * @throws IllegalStateException if data was added with a quantity previously
  89.      */
  90.     public synchronized <U extends Unit<U>, Z extends Scalar<U, Z>> void addPointData(final DataStream<Z> dataStream,
  91.             final Length location, final Duration time, final Z value)
  92.     {
  93.         addPointDataSI(dataStream, location.si, time.si, value.doubleValue());
  94.     }

  95.     /**
  96.      * Adds vector data.
  97.      * @param quantity Quantity&lt;Z, ?&gt;; quantity of the data
  98.      * @param location LengthVector; locations
  99.      * @param time DurationVector; times
  100.      * @param values DoubleVectorInterface&lt;U&gt;; data values
  101.      * @param <U> unit of type
  102.      * @param <Z> value type
  103.      * @throws IllegalStateException if data was added with a data stream previously
  104.      */
  105.     public synchronized <U extends Unit<U>, Z extends Scalar<U, Z>> void addVectorData(final Quantity<Z, ?> quantity,
  106.             final LengthVector location, final DurationVector time, final DoubleVector<U, ?, ?> values)
  107.     {
  108.         addVectorDataSI(quantity, location.getValuesSI(), time.getValuesSI(), values.getValuesSI());
  109.     }

  110.     /**
  111.      * Adds vector data.
  112.      * @param dataStream DataStream&lt;Z&gt;; data stream of the data
  113.      * @param location LengthVector; locations
  114.      * @param time DurationVector; times
  115.      * @param values DoubleVectorInterface&lt;U&gt;; data values
  116.      * @param <U> unit of type
  117.      * @param <Z> value type
  118.      * @throws IllegalStateException if data was added with a quantity previously
  119.      */
  120.     public synchronized <U extends Unit<U>, Z extends Scalar<U, Z>> void addVectorData(final DataStream<Z> dataStream,
  121.             final LengthVector location, final DurationVector time, final DoubleVector<U, ?, ?> values)
  122.     {
  123.         addVectorDataSI(dataStream, location.getValuesSI(), time.getValuesSI(), values.getValuesSI());
  124.     }

  125.     /**
  126.      * Adds grid data.
  127.      * @param quantity Quantity&lt;Z, ?&gt;; quantity of the data
  128.      * @param location LengthVector; locations
  129.      * @param time DurationVector; times
  130.      * @param values DoubleMatrixInterface&lt;U&gt;; data values
  131.      * @param <U> unit of type
  132.      * @param <Z> value type
  133.      * @throws IllegalStateException if data was added with a data stream previously
  134.      */
  135.     public synchronized <U extends Unit<U>, Z extends Scalar<U, Z>> void addGridData(final Quantity<Z, ?> quantity,
  136.             final LengthVector location, final DurationVector time, final DoubleMatrix<U, ?, ?, ?> values)
  137.     {
  138.         addGridDataSI(quantity, location.getValuesSI(), time.getValuesSI(), values.getValuesSI());
  139.     }

  140.     /**
  141.      * Adds grid data.
  142.      * @param dataStream DataStream&lt;Z&gt;; data stream of the data
  143.      * @param location LengthVector; locations
  144.      * @param time DurationVector; times
  145.      * @param values DoubleMatrixInterface&lt;U&gt;; data values
  146.      * @param <U> unit of type
  147.      * @param <Z> value type
  148.      * @throws IllegalStateException if data was added with a quantity previously
  149.      */
  150.     public synchronized <U extends Unit<U>, Z extends Scalar<U, Z>> void addGridData(final DataStream<Z> dataStream,
  151.             final LengthVector location, final DurationVector time, final DoubleMatrix<U, ?, ?, ?> values)
  152.     {
  153.         addGridDataSI(dataStream, location.getValuesSI(), time.getValuesSI(), values.getValuesSI());
  154.     }

  155.     /**
  156.      * Removes all data from before the given time. This is useful in live usages of this class, where older data is no longer
  157.      * required.
  158.      * @param time Duration; time before which all data can be removed
  159.      */
  160.     public void clearDataBefore(final Duration time)
  161.     {
  162.         clearDataBefore(time.si);
  163.     }

  164.     /**
  165.      * Sets an exponential kernel with infinite range.
  166.      * @param sigma Length; spatial kernel size
  167.      * @param tau Duration; temporal kernel size
  168.      */
  169.     public void setKernel(final Length sigma, final Duration tau)
  170.     {
  171.         setKernelSI(sigma.si, tau.si);
  172.     }

  173.     /**
  174.      * Returns an exponential kernel with limited range.
  175.      * @param sigma Length; spatial kernel size in [m]
  176.      * @param tau Duration; temporal kernel size in [s]
  177.      * @param xMax Length; maximum spatial range in [m]
  178.      * @param tMax Duration; maximum temporal range in [s]
  179.      */
  180.     public void setKernel(final Length sigma, final Duration tau, final Length xMax, final Duration tMax)
  181.     {
  182.         setKernelSI(sigma.si, tau.si, xMax.si, tMax.si);
  183.     }

  184.     /**
  185.      * Sets a Gaussian kernel with infinite range.
  186.      * @param sigma Length; spatial kernel size
  187.      * @param tau Duration; temporal kernel size
  188.      */
  189.     public void setGaussKernel(final Length sigma, final Duration tau)
  190.     {
  191.         setGaussKernelSI(sigma.si, tau.si);
  192.     }

  193.     /**
  194.      * Returns a Gaussian kernel with limited range.
  195.      * @param sigma Length; spatial kernel size in [m]
  196.      * @param tau Duration; temporal kernel size in [s]
  197.      * @param xMax Length; maximum spatial range in [m]
  198.      * @param tMax Duration; maximum temporal range in [s]
  199.      */
  200.     public void setGaussKernel(final Length sigma, final Duration tau, final Length xMax, final Duration tMax)
  201.     {
  202.         setGaussKernelSI(sigma.si, tau.si, xMax.si, tMax.si);
  203.     }

  204.     /**
  205.      * Sets a kernel with limited range and provided shape. The shape allows using non-exponential kernels.
  206.      * @param xMax Length; maximum spatial range
  207.      * @param tMax Duration; maximum temporal range
  208.      * @param shape KernelShape; shape of the kernel
  209.      */
  210.     public void setKernel(final Length xMax, final Duration tMax, final KernelShape shape)
  211.     {
  212.         setKernelSI(xMax.si, tMax.si, shape);
  213.     }

  214.     /**
  215.      * Returns filtered data.
  216.      * @param location LengthVector; location of output grid
  217.      * @param time DurationVector; time of output grid
  218.      * @param quantities Quantity&lt;?, ?&gt;...; quantities to calculate filtered data of
  219.      * @return Filter; filtered data, {@code null} when interrupted
  220.      */
  221.     public TypedFilter filter(final LengthVector location, final DurationVector time, final Quantity<?, ?>... quantities)
  222.     {
  223.         return new TypedFilter(filterSI(location.getValuesSI(), time.getValuesSI(), quantities));
  224.     }

  225.     /** {@inheritDoc} */
  226.     @Override
  227.     public String toString()
  228.     {
  229.         return "TypedEGTF []";
  230.     }

  231. }