package org.opentrafficsim.road.test; import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D.Double; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import javax.naming.NamingException; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.xml.parsers.ParserConfigurationException; import nl.javel.gisbeans.io.esri.CoordinateTransform; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.animation.D2.GisRenderable2D; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import nl.tudelft.simulation.jstats.distributions.DistConstant; import nl.tudelft.simulation.jstats.distributions.DistExponential; import nl.tudelft.simulation.jstats.streams.MersenneTwister; import nl.tudelft.simulation.jstats.streams.StreamInterface; import nl.tudelft.simulation.language.io.URLResource; import org.djunits.unit.AccelerationUnit; import org.djunits.unit.LengthUnit; import org.djunits.unit.SpeedUnit; import org.djunits.unit.TimeUnit; import org.djunits.value.vdouble.scalar.Acceleration; import org.djunits.value.vdouble.scalar.DoubleScalar; import org.djunits.value.vdouble.scalar.Length; import org.djunits.value.vdouble.scalar.Speed; import org.djunits.value.vdouble.scalar.Time; import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface; import org.opentrafficsim.core.dsol.OTSModelInterface; import org.opentrafficsim.core.dsol.OTSSimTimeDouble; import org.opentrafficsim.core.geometry.OTSGeometryException; import org.opentrafficsim.core.gtu.GTUDirectionality; import org.opentrafficsim.core.gtu.GTUException; import org.opentrafficsim.core.gtu.GTUType; import org.opentrafficsim.core.gtu.animation.AccelerationGTUColorer; import org.opentrafficsim.core.gtu.animation.GTUColorer; import org.opentrafficsim.core.gtu.animation.IDGTUColorer; import org.opentrafficsim.core.gtu.animation.SwitchableGTUColorer; import org.opentrafficsim.core.gtu.animation.VelocityGTUColorer; import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner; import org.opentrafficsim.core.network.NetworkException; import org.opentrafficsim.core.network.OTSNetwork; import org.opentrafficsim.core.units.distributions.ContinuousDistDoubleScalar; import org.opentrafficsim.road.gtu.generator.GTUGeneratorIndividual; import org.opentrafficsim.road.gtu.lane.LaneBasedIndividualGTU; import org.opentrafficsim.road.gtu.lane.driver.LaneBasedBehavioralCharacteristics; import org.opentrafficsim.road.gtu.lane.perception.LanePerceptionFull; import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedGTUFollowingTacticalPlanner; import org.opentrafficsim.road.gtu.lane.tactical.following.GTUFollowingModelOld; import org.opentrafficsim.road.gtu.lane.tactical.following.IDMPlusOld; import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner; import org.opentrafficsim.road.gtu.strategical.route.LaneBasedStrategicalRoutePlanner; import org.opentrafficsim.road.network.factory.xml.XmlNetworkLaneParser; import org.opentrafficsim.road.network.lane.CrossSectionLink; import org.opentrafficsim.road.network.lane.Lane; import org.opentrafficsim.road.test.TestGMParser.WGS84ToRDNewTransform.Coords; import org.opentrafficsim.simulationengine.AbstractWrappableAnimation; import org.opentrafficsim.simulationengine.OTSSimulationException; import org.opentrafficsim.simulationengine.properties.AbstractProperty; import org.xml.sax.SAXException; /** *
* Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $,
* initial version Oct 17, 2014
* Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.
* $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $,
* initial version un 27, 2015
* Copyright (c) 2011 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. The
* source code and binary code of this software is proprietary information of Delft University of Technology. Specific
* MathTransform for WGS84 WGS84 (EPSG:4326) to RD_new (EPSG:28992) conversions. Code based on C code by Peter Knoppers as
* applied here, which is based on this paper.
* @author Gert-Jan Stolk
**/
public static class WGS84ToRDNewTransform
{
//@formatter:off
private static final double r[][] = { /* p down, q right */
{ 155000.00, 190094.945, -0.008, -32.391, 0.0 , },
{ -0.705, -11832.228, 0.0 , 0.608, 0.0 , },
{ 0.0 , -114.221, 0.0 , 0.148, 0.0 , },
{ 0.0 , 2.340, 0.0 , 0.0 , 0.0 , },
{ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , }};
private static final double s[][] = { /* p down, q right */
{ 463000.00 , 0.433, 3638.893, 0.0 , 0.092, },
{ 309056.544, -0.032, -157.984, 0.0 , -0.054, },
{ 73.077, 0.0 , -6.439, 0.0 , 0.0 , },
{ 59.788, 0.0 , 0.0 , 0.0 , 0.0 , },
{ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , }};
//@formatter:on
public static void transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts)
throws Exception
{
int offsetDelta = dstOff - srcOff;
for (int i = srcOff; i < srcOff + numPts && i + 1 < srcPts.length && i + offsetDelta + 1 < dstPts.length; i +=
2)
{
Coords transformedCoords = ellipswgs842rd(srcPts[i], srcPts[i + 1]);
dstPts[i + offsetDelta] = transformedCoords.x;
dstPts[i + offsetDelta + 1] = transformedCoords.y;
}
}
private static Coords ellipswgs842rd(double EW, double NS)
{
Coords result = new Coords(0, 0);
int p;
double pown = 1;
double dn = 0.36 * (NS - 52.15517440);
double de = 0.36 * (EW - 5.38720621);
if (NS <= 50 || NS >= 54 || EW <= 3 || (EW >= 8))
{
System.err.println("Error: ellipswgs842rd input out of range (" + EW + ", " + NS + ")");
}
for (p = 0; p < 5; p++)
{
double powe = 1;
int q;
for (q = 0; q < 5; q++)
{
result.x += r[p][q] * powe * pown;
result.y += s[p][q] * powe * pown;
powe *= de;
}
pown *= dn;
}
return result;
}
static class Coords
{
public double x, y;
public Coords(double x, double y)
{
this.x = x;
this.y = y;
}
}
}
}
* @author Alexander Verbraeck
*/
public class TestGMParser extends AbstractWrappableAnimation
{
/**
* Main program.
* @param args String[]; the command line arguments (not used)
* @throws SimRuntimeException should never happen
*/
public static void main(final String[] args) throws SimRuntimeException
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
try
{
TestGMParser xmlModel = new TestGMParser();
// 1 hour simulation run for testing
xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND),
new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList
* All rights reserved. BSD-style license. See OpenTrafficSim
* License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
*/
class TestGMModel implements OTSModelInterface
{
/** */
private static final long serialVersionUID = 20141121L;
/** The simulator. */
private OTSDEVSSimulatorInterface simulator;
/** {@inheritDoc} */
@Override
public final
void
constructModel(
final SimulatorInterface