Top Description Inners Fields Constructors Methods
javafx.scene.effect

public Class DisplacementMap

extends Effect
Class Inheritance
Imports
javafx.beans.Observable, javafx.beans.property.BooleanProperty, .BooleanPropertyBase, .DoubleProperty, .DoublePropertyBase, .ObjectProperty, .ObjectPropertyBase, javafx.scene.Node, com.sun.javafx.effect.EffectDirtyBits, com.sun.javafx.geom.BaseBounds, com.sun.javafx.geom.transform.BaseTransform, com.sun.javafx.scene.BoundsAccessor

An effect that shifts each pixel by a distance specified by the first two bands of of the specified FloatMap. For each pixel in the output, the corresponding data from the mapData is retrieved, scaled and offset by the scale and offset attributes, scaled again by the size of the source input image and used as an offset from the destination pixel to retrieve the pixel data from the source input.

dst[x, y] = src[(x, y) + (offset + scale * map[x, y]) * (srcw, srch)]

A value of (0.0, 0.0) would specify no offset for the pixel data whereas a value of (0.5, 0.5) would specify an offset of half of the source image size.

Note

that the mapping is the offset from a destination pixel to the source pixel location from which it is sampled which means that filling the map with all values of 0.5 would displace the image by half of its size towards the upper left since each destination pixel would contain the data that comes from the source pixel below and to the right of it.

Also note that this effect does not adjust the coordinates of input events or any methods that measure containment on a Node. The results of mouse picking and the containment methods are undefined when a Node has a DisplacementMap effect in place.

Example:

int width = 220;
int height = 100;

FloatMap floatMap = new FloatMap();
floatMap.setWidth(width);
floatMap.setHeight(height);

for (int i = 0; i < width; i++) {
    double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0;
    for (int j = 0; j < height; j++) {
        floatMap.setSamples(i, j, 0.0f, (float) v);
    }
}

DisplacementMap displacementMap = new DisplacementMap();
displacementMap.setMapData(floatMap);

Text text = new Text();
text.setX(40.0);
text.setY(80.0);
text.setText("Wavy Text");
text.setFill(Color.web("0x3b596d"));
text.setFont(Font.font(null, FontWeight.BOLD, 50));
text.setEffect(displacementMap);

The code above produces the following:

The visual effect of
DisplacementMap on text

Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final FloatMap
private ObjectProperty<Effect>
input

The input for this Effect.

private ObjectProperty<FloatMap>
mapData

The map data for this Effect.

private final DisplacementMap.MapDataChangeListener
private DoubleProperty
offsetX

The offset by which all x coordinate offset values in the FloatMap are displaced after they are scaled.

private DoubleProperty
offsetY

The offset by which all y coordinate offset values in the FloatMap are displaced after they are scaled.

private DoubleProperty
scaleX

The scale factor by which all x coordinate offset values in the FloatMap are multiplied.

private DoubleProperty
scaleY

The scale factor by which all y coordinate offset values in the FloatMap are multiplied.

private BooleanProperty
wrap

Defines whether values taken from outside the edges of the map "wrap around" or not.

Constructor Summary

AccessConstructor and Description
public
DisplacementMap()

Creates a new instance of DisplacementMap with default parameters.

public
DisplacementMap(FloatMap
the map data for this displacement map effect
mapData
)

Creates a new instance of DisplacementMap with the specified mapData.

public
DisplacementMap(FloatMap
the map data for this displacement map effect
mapData
,
double
the offset by which all x coordinate offset values in the FloatMap are displaced after they are scaled
offsetX
,
double
the offset by which all y coordinate offset values in the FloatMap are displaced after they are scaled
offsetY
,
double
the scale factor by which all x coordinate offset values in the FloatMap are multiplied
scaleX
,
double
the scale factor by which all y coordinate offset values in the FloatMap are multiplied
scaleY
)

Creates a new instance of DisplacementMap with the specified mapData, offsetX, offsetY, scaleX, and scaleY.

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv Effect
copy()

Implements abstract javafx.scene.effect.Effect.copy.

pack-priv DisplacementMap
pack-priv BaseBounds
getBounds(BaseBounds bounds, BaseTransform tx, Node node, BoundsAccessor boundsAccessor)

Implements abstract javafx.scene.effect.Effect.getBounds.

Returns bounds of given node with applied effect.

public final Effect
public final FloatMap
public final double
public final double
public final double
public final double
public final ObjectProperty<Effect>
public final boolean
public final ObjectProperty<FloatMap>
public final DoubleProperty
public final DoubleProperty
public final DoubleProperty
public final DoubleProperty
public final void
public final void
public final void
setOffsetX(double value)

public final void
setOffsetY(double value)

public final void
setScaleX(double value)

public final void
setScaleY(double value)

public final void
setWrap(boolean value)

pack-priv void
public final BooleanProperty
Inherited from javafx.scene.effect.Effect:
containsCycleseffectBoundsChangedgetInputBoundsgetKernelSizegetPeergetShadowBoundsmarkDirtysynctransformBounds

Field Detail

defaultMapback to summary
private final FloatMap defaultMap
inputback to summary
private ObjectProperty<Effect> input

The input for this Effect. If set to null, or left unspecified, a graphical image of the Node to which the Effect is attached will be used as the input.

Default Value
null
mapDataback to summary
private ObjectProperty<FloatMap> mapData

The map data for this Effect.

Default Value
an empty map
mapDataChangeListenerback to summary
private final DisplacementMap.MapDataChangeListener mapDataChangeListener
offsetXback to summary
private DoubleProperty offsetX

The offset by which all x coordinate offset values in the FloatMap are displaced after they are scaled.

      Min: n/a
      Max: n/a
  Default: 0.0
 Identity: 0.0
Default Value
0.0
offsetYback to summary
private DoubleProperty offsetY

The offset by which all y coordinate offset values in the FloatMap are displaced after they are scaled.

      Min: n/a
      Max: n/a
  Default: 0.0
 Identity: 0.0
Default Value
0.0
scaleXback to summary
private DoubleProperty scaleX

The scale factor by which all x coordinate offset values in the FloatMap are multiplied.

      Min: n/a
      Max: n/a
  Default: 1.0
 Identity: 1.0
Default Value
1.0
scaleYback to summary
private DoubleProperty scaleY

The scale factor by which all y coordinate offset values in the FloatMap are multiplied.

      Min: n/a
      Max: n/a
  Default: 1.0
 Identity: 1.0
Default Value
1.0
wrapback to summary
private BooleanProperty wrap

Defines whether values taken from outside the edges of the map "wrap around" or not.

      Min:  n/a
      Max:  n/a
  Default: false
 Identity:  n/a
Default Value
false

Constructor Detail

DisplacementMapback to summary
public DisplacementMap()

Creates a new instance of DisplacementMap with default parameters.

DisplacementMapback to summary
public DisplacementMap(FloatMap mapData)

Creates a new instance of DisplacementMap with the specified mapData.

Parameters
mapData:FloatMap

the map data for this displacement map effect

Since
JavaFX 2.1
DisplacementMapback to summary
public DisplacementMap(FloatMap mapData, double offsetX, double offsetY, double scaleX, double scaleY)

Creates a new instance of DisplacementMap with the specified mapData, offsetX, offsetY, scaleX, and scaleY.

Parameters
mapData:FloatMap

the map data for this displacement map effect

offsetX:double

the offset by which all x coordinate offset values in the FloatMap are displaced after they are scaled

offsetY:double

the offset by which all y coordinate offset values in the FloatMap are displaced after they are scaled

scaleX:double

the scale factor by which all x coordinate offset values in the FloatMap are multiplied

scaleY:double

the scale factor by which all y coordinate offset values in the FloatMap are multiplied

Since
JavaFX 2.1

Method Detail

checkChainContainsback to summary
pack-priv boolean checkChainContains(Effect e)

Implements abstract javafx.scene.effect.Effect.checkChainContains.

Annotations
@Override
copyback to summary
pack-priv Effect copy()

Implements abstract javafx.scene.effect.Effect.copy.

Annotations
@Override
createPeerback to summary
pack-priv DisplacementMap createPeer()

Implements abstract javafx.scene.effect.Effect.createPeer.

Annotations
@Override
getBoundsback to summary
pack-priv BaseBounds getBounds(BaseBounds bounds, BaseTransform tx, Node node, BoundsAccessor boundsAccessor)

Implements abstract javafx.scene.effect.Effect.getBounds.

Doc from javafx.scene.effect.Effect.getBounds.

Returns bounds of given node with applied effect. We *never* pass null in as a bounds. This method will NOT take a null bounds object. The returned value may be the same bounds object passed in, or it may be a new object.

Annotations
@Override
getInputback to summary
public final Effect getInput()
getMapDataback to summary
public final FloatMap getMapData()
getOffsetXback to summary
public final double getOffsetX()
getOffsetYback to summary
public final double getOffsetY()
getScaleXback to summary
public final double getScaleX()
getScaleYback to summary
public final double getScaleY()
inputPropertyback to summary
public final ObjectProperty<Effect> inputProperty()
isWrapback to summary
public final boolean isWrap()
mapDataPropertyback to summary
public final ObjectProperty<FloatMap> mapDataProperty()
offsetXPropertyback to summary
public final DoubleProperty offsetXProperty()
offsetYPropertyback to summary
public final DoubleProperty offsetYProperty()
scaleXPropertyback to summary
public final DoubleProperty scaleXProperty()
scaleYPropertyback to summary
public final DoubleProperty scaleYProperty()
setInputback to summary
public final void setInput(Effect value)
setMapDataback to summary
public final void setMapData(FloatMap value)
setOffsetXback to summary
public final void setOffsetX(double value)
setOffsetYback to summary
public final void setOffsetY(double value)
setScaleXback to summary
public final void setScaleX(double value)
setScaleYback to summary
public final void setScaleY(double value)
setWrapback to summary
public final void setWrap(boolean value)
updateback to summary
pack-priv void update()

Implements abstract javafx.scene.effect.Effect.update.

Annotations
@Override
wrapPropertyback to summary
public final BooleanProperty wrapProperty()
javafx.scene.effect back to summary

private Class DisplacementMap.MapDataChangeListener

extends EffectChangeListener
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv FloatMap
Inherited from javafx.scene.effect.EffectChangeListener:
registredOn

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
invalidated(Observable
The Observable that became invalid
valueModel
)

Implements javafx.beans.InvalidationListener.invalidated.

This method needs to be provided by an implementation of InvalidationListener.

public void
Inherited from javafx.scene.effect.EffectChangeListener:
register

Field Detail

mapDataback to summary
pack-priv FloatMap mapData

Constructor Detail

MapDataChangeListenerback to summary
private MapDataChangeListener()

Method Detail

invalidatedback to summary
public void invalidated(Observable valueModel)

Implements javafx.beans.InvalidationListener.invalidated.

Doc from javafx.beans.InvalidationListener.invalidated.

This method needs to be provided by an implementation of InvalidationListener. It is called if an Observable becomes invalid.

In general, it is considered bad practice to modify the observed value in this method.

Parameters
valueModel:Observable

The Observable that became invalid

Annotations
@Override
registerback to summary
public void register(FloatMap value)