All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentrafficsim.draw.road.ConflictAnimation Maven / Gradle / Ivy

The newest version!
package org.opentrafficsim.draw.road;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Path2D;
import java.awt.image.ImageObserver;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Set;

import javax.naming.NamingException;

import org.djunits.unit.LengthUnit;
import org.djunits.value.vdouble.scalar.Length;
import org.djutils.draw.point.Point2d;
import org.opentrafficsim.draw.PaintPolygons;
import org.opentrafficsim.draw.road.AbstractLineAnimation.LaneBasedObjectData;
import org.opentrafficsim.draw.road.ConflictAnimation.ConflictData;

import nl.tudelft.simulation.naming.context.Contextualized;

/**
 * Animate a conflict.
 * 

* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel */ public class ConflictAnimation extends AbstractLineAnimation { /** */ private static final long serialVersionUID = 20161207L; /** Drawable paths. */ private final Set paths; /** * @param source ConflictData; the conflict to draw * @param contextualized Contextualized; context provider * @throws NamingException in case of registration failure of the animation * @throws RemoteException on communication failure */ public ConflictAnimation(final ConflictData source, final Contextualized contextualized) throws NamingException, RemoteException { super(source, contextualized, .9, new Length(0.5, LengthUnit.SI)); // geometry of area (not the line) is absolute; pre-transform geometry to fit rotation of source this.paths = this.getSource().getContour() == null ? null : PaintPolygons.getPaths(getSource().getLocation(), getSource().getContour()); } /** {@inheritDoc} */ @Override public final void paint(final Graphics2D graphics, final ImageObserver observer) { // paint the bar that represents the line where the conflict starts, like any other AbstractLineAnimation Color fillColor = getSource().getColor(); graphics.setColor(fillColor); super.paint(graphics, observer); // paint the additional area with dashed lines Stroke oldStroke = graphics.getStroke(); BasicStroke stroke; float factor = getSource().isPermitted() ? .5f : 1f; if (getSource().isCrossing()) { stroke = new BasicStroke(.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {factor * 1.0f, factor * 2.0f}, 0.0f); } else { stroke = new BasicStroke(.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {factor * 1.0f, factor * 0.95f, factor * 0.1f, factor * 0.95f}, 0.0f); } graphics.setStroke(stroke); if (this.paths != null) { setRendering(graphics); PaintPolygons.paintPaths(graphics, fillColor, this.paths, false); resetRendering(graphics); } graphics.setStroke(oldStroke); } /** {@inheritDoc} */ @Override public final String toString() { return "ConflictAnimation [getSource()=" + getSource() + "]"; } /** * ConflictData provides the information required to draw a conflict. *

* Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. *
* BSD-style license. See OpenTrafficSim License. *

* @author Wouter Schakel */ public interface ConflictData extends LaneBasedObjectData { /** * Returns the conflict color. * @return Color; conflict color. */ Color getColor(); /** * Returns the contour. * @return List<Point2d>; points. */ List getContour(); /** * Whether the conflict is a crossing. * @return boolean; whether the conflict is a crossing. */ boolean isCrossing(); /** * Whether the conflict is a permitted conflict. * @return boolean; whether the conflict is a permitted conflict. */ boolean isPermitted(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy