vanetsim.map
Class Map

java.lang.Object
  extended by vanetsim.map.Map

public final class Map
extends java.lang.Object

The map. The coordinate system is 2-dimensional with each axis allowing values from 0 to Integer.MAXVALUE (2147483647). Negative values are not allowed. The scale is 1:1cm which means that about 21474km x 21474km is the maximum size of a map (should be more than enough for all cases). The map is divided into several rectangular Regions in order to improve performance. All vehicles, nodes and streets are stored in these regions. Because of the regions, for example rendering and distance calculations only need to be done on a limited amount of vehicles/streets/nodes which helps handling large maps a lot.


Field Summary
static int LANE_WIDTH
          The width of a single lane (3m).
 
Method Summary
 void addMixZone(Node node, int radius)
          Add a new mix zone to the correct region.
 Node addNode(Node node)
          Add a new node to the correct region.
 void addRSU(RSU rsu)
          Add a new Road-Side-Unit to the correct region.
 void addStreet(Street street)
          Add a new street to the correct region(s).
 void addVehicle(Vehicle vehicle)
          Add a new vehicle to the correct start region.
 void autoTrimMap(int minX, int minY, int maxX, int maxY)
          Function to trim a map.
 void clearMixZones()
          Delete every Mix Zone on this map
 void clearRSUs()
          Delete every RSU on this map
 void clearTrafficLights()
          Delete every turn-off lane on this map
 void clearVehicles()
          Delete every Vehicle on this map
 void deleteMixZone(Node node)
          Delete a mix zone in the correct region.
 void delNode(Node node)
          Delete a node from it's region.
 void delRSU(int x, int y)
          Delete a Road-Side-Unit from it's region.
 void delStreet(Street street)
          Delete a street from all region(s) it's in.
 void delVehicle(Vehicle vehicle)
          Deletes a vehicle from it's region.
static Map getInstance()
          Gets the single instance of this map.
 int getMapHeight()
          Gets the map height.
 int getMapWidth()
          Gets the map width.
 boolean getReadyState()
          Returns if a map is currently in the process of being loaded.
 int getRegionCountX()
          Gets the amount of regions in x direction.
 int getRegionCountY()
          Gets the amount of regions in y direction.
 Region getRegionOfPoint(int x, int y)
          Calculates the Region of a point.
 Region[][] getRegions()
          Gets all regions.
 void initNewMap(int width, int height, int regionWidth, int regionHeight)
          Initializes a new map.
 void load(java.io.File file, boolean zip)
          Load a map.
 void save(java.io.File file, boolean zip)
          Save the map.
 void saveReloadMap()
          Helper function to save and reload a map after editing
 void signalMapLoaded()
          This function needs to be called to signal that the loading process of the map has finished.
 int trimStreet(int streetXInside, int streetYInside, int streetXOutside, int streetYOutside, int border)
           
 void writeSilentPeriodHeader()
          write silent period header to log file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LANE_WIDTH

public static final int LANE_WIDTH
The width of a single lane (3m). Used in various other places in this program!

See Also:
Constant Field Values
Method Detail

getInstance

public static Map getInstance()
Gets the single instance of this map.

Returns:
single instance of this map

initNewMap

public void initNewMap(int width,
                       int height,
                       int regionWidth,
                       int regionHeight)
Initializes a new map.

Parameters:
width - the width
height - the height
regionWidth - the width of a region
regionHeight - the height of a region

signalMapLoaded

public void signalMapLoaded()
This function needs to be called to signal that the loading process of the map has finished.


load

public void load(java.io.File file,
                 boolean zip)
Load a map.

Parameters:
file - the file to load
zip - true if the file given is zipped, else false

save

public void save(java.io.File file,
                 boolean zip)
Save the map.

Parameters:
file - the file in which to save
zip - if true, file is saved in a compressed zip file (extension .zip is added to file!). If false, no compression is made.

addNode

public Node addNode(Node node)
Add a new node to the correct region. A node can only be in one region.

Parameters:
node - the node to add
Returns:
the added node (might be different if already existing!)

delNode

public void delNode(Node node)
Delete a node from it's region.

Parameters:
node - the node to remove

addRSU

public void addRSU(RSU rsu)
Add a new Road-Side-Unit to the correct region. A RSU can only be in one region.

Parameters:
rsu - the RSU to add

delRSU

public void delRSU(int x,
                   int y)
Delete a Road-Side-Unit from it's region.

Parameters:
x - the x coordinate of the rsu
y - the y coordinate of the rsu

addVehicle

public void addVehicle(Vehicle vehicle)
Add a new vehicle to the correct start region. A vehicle can only be in one region and may move to other regions during the simulation. Although a vehicle is part of a scenario, it's added here as the map knows everything about how to correctly put it into a region.

Parameters:
vehicle - the vehicle to add

delVehicle

public void delVehicle(Vehicle vehicle)
Deletes a vehicle from it's region.

Parameters:
vehicle - the vehicle to delete

addStreet

public void addStreet(Street street)
Add a new street to the correct region(s). Note that a street can be in multiple regions and so we must determine all here! This makes rendering and calculations a lot easier later!

Parameters:
street - the street to add

delStreet

public void delStreet(Street street)
Delete a street from all region(s) it's in.

Parameters:
street - the street to delete

addMixZone

public void addMixZone(Node node,
                       int radius)
Add a new mix zone to the correct region. A mix zone can only be in one region.

Parameters:
node - the mix zone node to add
radius - the mix zone radius

deleteMixZone

public void deleteMixZone(Node node)
Delete a mix zone in the correct region.


clearMixZones

public void clearMixZones()
Delete every Mix Zone on this map


clearRSUs

public void clearRSUs()
Delete every RSU on this map


clearVehicles

public void clearVehicles()
Delete every Vehicle on this map


autoTrimMap

public void autoTrimMap(int minX,
                        int minY,
                        int maxX,
                        int maxY)
Function to trim a map. If no coordinates are chosen the map will be trimmed to its borders (Only empty space will be removed). Otherwise the map will be trimmed according to the coordinates.

Parameters:
minX - the minimum x coordinate
maxX - the maximum x coordinate
minY - the minimum y coordinate
maxY - the maximum y coordinate

trimStreet

public int trimStreet(int streetXInside,
                      int streetYInside,
                      int streetXOutside,
                      int streetYOutside,
                      int border)

saveReloadMap

public void saveReloadMap()
Helper function to save and reload a map after editing


clearTrafficLights

public void clearTrafficLights()
Delete every turn-off lane on this map


getMapWidth

public int getMapWidth()
Gets the map width.

Returns:
the map width

getMapHeight

public int getMapHeight()
Gets the map height.

Returns:
the map height

getRegionOfPoint

public Region getRegionOfPoint(int x,
                               int y)
Calculates the Region of a point.

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point
Returns:
the region in which this point is located or null if there was a problem

writeSilentPeriodHeader

public void writeSilentPeriodHeader()
write silent period header to log file


getRegions

public Region[][] getRegions()
Gets all regions.

Returns:
all regions

getRegionCountX

public int getRegionCountX()
Gets the amount of regions in x direction.

Returns:
the amount of regions in x direction

getRegionCountY

public int getRegionCountY()
Gets the amount of regions in y direction.

Returns:
the amount of regions in y direction

getReadyState

public boolean getReadyState()
Returns if a map is currently in the process of being loaded. While loading, simulation and rendering should not be done because not all map elements are already existing!

Returns:
true if loading has finished, else false