Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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, java.io.Serializable

public class FastValueGridPortrayal2D
extends ValueGridPortrayal2D

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
  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.

See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class sim.portrayal.FieldPortrayal
`FieldPortrayal.CustomInspector`

Field Summary

Fields inherited from class sim.portrayal.grid.ValueGridPortrayal2D
`map, valueName`

Fields inherited from class sim.portrayal.FieldPortrayal2D
`DEFAULT, DONT_USE_BUFFER, USE_BUFFER`

Fields inherited from class sim.portrayal.FieldPortrayal
`classPortrayals, dirtyField, field, immutableField, portrayalForAll, portrayalForNull, portrayalForRemainder, portrayals`

Constructor Summary
`FastValueGridPortrayal2D()`
`FastValueGridPortrayal2D(boolean immutableField)` If immutableField is true, we presume that the grid doesn't change.
`FastValueGridPortrayal2D(java.lang.String valueName)`
`FastValueGridPortrayal2D(java.lang.String valueName, boolean immutableField)` If immutableField is true, we presume that the grid doesn't change.

Method Summary
`void` | `draw(java.lang.Object object, java.awt.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].
`void` | `reset()`

Methods inherited from class sim.portrayal.grid.ValueGridPortrayal2D
`getDefaultPortrayal, getMap, getValueName, getWrapper, hitOrDraw, newValue, setField, setMap`

Methods inherited from class sim.portrayal.FieldPortrayal2D
`getBuffering, getSelectedObjects, hitObjects, move, setBuffering, setSelected`

Methods inherited from class sim.portrayal.FieldPortrayal
`getDefaultNullPortrayal, getField, getInspector, getName, getPortrayalForAll, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isImmutableField, setImmutableField, setPortrayalForAll, setPortrayalForClass, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, 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 Detail

### FastValueGridPortrayal2D

    public FastValueGridPortrayal2D(java.lang.String valueName,
                                    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(java.lang.String valueName)

### 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 Detail

### reset

    public void reset()

### draw

    public void draw(java.lang.Object object,
                     java.awt.Graphics2D graphics,
                     DrawInfo2D info)

  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 interface `Portrayal2D`
  Overrides:
    `draw` in class `FieldPortrayal2D`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD