Package sim.portrayal.grid
Class FastValueGridPortrayal2D
java.lang.Object
sim.portrayal.FieldPortrayal
sim.portrayal.FieldPortrayal2D
sim.portrayal.grid.ValueGridPortrayal2D
sim.portrayal.grid.FastValueGridPortrayal2D
- All Implemented Interfaces:
Portrayal
,Portrayal2D
This class works like a ValueGridPortrayal2D, except that it doesn't use an underlying Portrayal for the object
(instead it always draws a rectangle), and may ignore the getColor() method, so you shouldn't override that method to customize
the color function in nonlinear ways any more. setColorTable() and setLevels() are still supported.
Use this class instead of
ValueGridPortrayal2D unless you need to customize how the values are drawn (other than the color range or lookup table).
Additionally, FastValueGridPortrayal2D is useful if your grid never changes past its first drawing. For example, if you're drawing static obstacles, cities, etc., which never change in value during the invocation of the simulation, then FastValueGridPortrayal2D can draw them efficiently by just drawing once into its buffer and re-displaying the buffer over and over again. Just pass in true in the constructor.
If your grid does change but only occasionally, you can also use this technique as well; just manually call reset() whenever the grid changes to inform the FastValueGridPortrayal2D that it needs to re-compute the buffer. reset() is threadsafe.
Important Note on Drawing Methods
FastValueGridPortrayal2D can draw a grid in two ways. First, it can draw each of the rects individually ("USE_BUFFER"). Second, it can create a bitmap the size of the grid (one pixel per grid location), poke the colors into the bitmap, then stretch the bitmap over the area and draw it ("DONT_USE_BUFFER"). You can specify the method by calling the setBuffering() method; optionally you can just let FastValueGridPortrayal2D guess which to use ("DEFAULT"). But you should know what you're doing, as methods can be much faster than each other depending on the situation. Use the following as guides- MacOS X and X Windows
- USE_BUFFER is much faster than DONT_USE_BUFFER in all cases, but can draw incorrectly aliased ("fuzzed out") rectangles when writing to media (a movie or a snapshot). The DEFAULT is for MacOS X is set to USE_BUFFER in ordinary drawing, and DONT_USE_BUFFER when writing to media.
- Windows and X Windows
- If you're not using any transparency (alpha), then DONT_USE_BUFFER is a tad faster than USE_BUFFER. But if you're using transparency, then DONT_USE_BUFFER is very slow -- in this case, try USE_BUFFER. Note however that in any case USE_BUFFER requires a lot of memory on Windows and X Windows due to poor implementation by Sun. You'll want to increase the default memory capacity, and expect occasional pauses for full garbage collection. You can test how often full garbage collection by running with java -verbose:gc ... and looking at how often the FULL GC printouts happen. Ordinary GC you shouldn't worry about. You can increase the default memory capacity to 50 Megabytes, for example (the default is about 20) by running with java -Xms50M ... The DEFAULT is for XWindows and Windows to use DONT_USE_BUFFER. You'll want to change this for sure if you're doing any transparency.
-
Field Summary
Fields inherited from class sim.portrayal.grid.ValueGridPortrayal2D
locationToPass, valueToPass
Fields inherited from class sim.portrayal.FieldPortrayal2D
DEFAULT, DONT_USE_BUFFER, USE_BUFFER
Fields inherited from class sim.portrayal.FieldPortrayal
classPortrayals, field, immutableField, portrayalForAll, portrayalForNonNull, portrayalForNull, portrayalForRemainder, portrayals
-
Constructor Summary
ConstructorDescriptionFastValueGridPortrayal2D
(boolean immutableField) If immutableField is true, we presume that the grid doesn't change.FastValueGridPortrayal2D
(String valueName) FastValueGridPortrayal2D
(String valueName, boolean immutableField) If immutableField is true, we presume that the grid doesn't change. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(Object object, Graphics2D graphics, DrawInfo2D info) Draws the field with its origin at [info.draw.x,info.draw.y], relative to the scaled coordinate system defined by [info.draw.width,info.draw.height].Methods inherited from class sim.portrayal.grid.ValueGridPortrayal2D
getDefaultPortrayal, getLocationPosition, getMap, getPositionLocation, getScale, getValueName, getWrapper, hitOrDraw, newValue, setBorder, setBorderColor, setBorderLineFraction, setBorderLineMinMaxWidth, setField, setGridColor, setGridLineFraction, setGridLineMinMaxWidth, setGridLines, setGridMinSpacing, setGridModulus, setMap, setValueName
Methods inherited from class sim.portrayal.FieldPortrayal2D
getBuffering, getClipLocation, getObjectPosition, getRelativeObjectPosition, hitObjects, setBuffering, setObjectPosition
Methods inherited from class sim.portrayal.FieldPortrayal
getAlternatePortrayalOrdering, getDefaultNullPortrayal, getField, getInspector, getName, getObjectLocation, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setAlternatePortrayalOrdering, setDirtyField, setImmutableField, setObjectLocation, setPortrayalForAll, setPortrayalForClass, setPortrayalForNonNull, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, setSelected, setSelected
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface sim.portrayal.Portrayal
getInspector, getName, getStatus, setSelected
-
Constructor Details
-
FastValueGridPortrayal2D
If immutableField is true, we presume that the grid doesn't change. This allows us to just re-splat the buffer. -
FastValueGridPortrayal2D
-
FastValueGridPortrayal2D
public FastValueGridPortrayal2D(boolean immutableField) If immutableField is true, we presume that the grid doesn't change. This allows us to just re-splat the buffer. -
FastValueGridPortrayal2D
public FastValueGridPortrayal2D()
-
-
Method Details
-
draw
Description copied from class:FieldPortrayal2D
Draws the field with its origin at [info.draw.x,info.draw.y], relative to the scaled coordinate system defined by [info.draw.width,info.draw.height]. The only parts that need be drawn are those which fall within the [info.clip] rectangle. Since your draw and hitObjects methods are likely to be nearly identical, you can choose instead to override the hitOrDraw method to handle both of them. By default this method simply calls hitOrDraw. FieldPortrayals will receive null for the object; they should just draw their own fields.- Specified by:
draw
in interfacePortrayal2D
- Overrides:
draw
in classFieldPortrayal2D
-