public class DisplacementMap extends Effect
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:
Modifier and Type | Class and Description |
---|---|
private class |
DisplacementMap.MapDataChangeListener |
Effect.EffectInputChangeListener, Effect.EffectInputProperty
Modifier and Type | Field and Description |
---|---|
private FloatMap |
defaultMap |
private ObjectProperty<Effect> |
input
The input for this
Effect . |
private ObjectProperty<FloatMap> |
mapData
The map data for this
Effect . |
private DisplacementMap.MapDataChangeListener |
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 and Description |
---|
DisplacementMap()
Creates a new instance of DisplacementMap with default parameters.
|
DisplacementMap(FloatMap mapData)
Creates a new instance of DisplacementMap with the specified mapData.
|
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.
|
Modifier and Type | Method and Description |
---|---|
Effect |
getInput() |
FloatMap |
getMapData() |
double |
getOffsetX() |
double |
getOffsetY() |
double |
getScaleX() |
double |
getScaleY() |
(package private) boolean |
impl_checkChainContains(Effect e) |
Effect |
impl_copy()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
(package private) DisplacementMap |
impl_createImpl() |
BaseBounds |
impl_getBounds(BaseBounds bounds,
BaseTransform tx,
Node node,
BoundsAccessor boundsAccessor)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
(package private) void |
impl_update() |
ObjectProperty<Effect> |
inputProperty() |
boolean |
isWrap() |
ObjectProperty<FloatMap> |
mapDataProperty() |
DoubleProperty |
offsetXProperty() |
DoubleProperty |
offsetYProperty() |
DoubleProperty |
scaleXProperty() |
DoubleProperty |
scaleYProperty() |
void |
setInput(Effect value) |
void |
setMapData(FloatMap value) |
void |
setOffsetX(double value) |
void |
setOffsetY(double value) |
void |
setScaleX(double value) |
void |
setScaleY(double value) |
void |
setWrap(boolean value) |
BooleanProperty |
wrapProperty() |
effectBoundsChanged, getInputBounds, getKernelSize, getShadowBounds, impl_containsCycles, impl_effectDirtyProperty, impl_getImpl, impl_isEffectDirty, impl_sync, markDirty, transformBounds
private ObjectProperty<Effect> input
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.private final FloatMap defaultMap
private ObjectProperty<FloatMap> mapData
Effect
.private final DisplacementMap.MapDataChangeListener mapDataChangeListener
private DoubleProperty scaleX
FloatMap
are multiplied.
Min: n/a Max: n/a Default: 1.0 Identity: 1.0
private DoubleProperty scaleY
FloatMap
are multiplied.
Min: n/a Max: n/a Default: 1.0 Identity: 1.0
private DoubleProperty offsetX
FloatMap
are displaced after they are scaled.
Min: n/a Max: n/a Default: 0.0 Identity: 0.0
private DoubleProperty offsetY
FloatMap
are displaced after they are scaled.
Min: n/a Max: n/a Default: 0.0 Identity: 0.0
private BooleanProperty wrap
Min: n/a Max: n/a Default: false Identity: n/a
public DisplacementMap()
public DisplacementMap(FloatMap mapData)
mapData
- the map data for this displacement map effectpublic DisplacementMap(FloatMap mapData, double offsetX, double offsetY, double scaleX, double scaleY)
mapData
- the map data for this displacement map effectoffsetX
- the offset by which all x coordinate offset values in the
FloatMap
are displaced after they are scaledoffsetY
- the offset by which all y coordinate offset values in the
FloatMap
are displaced after they are scaledscaleX
- the scale factor by which all x coordinate offset values in the
FloatMap
are multipliedscaleY
- the scale factor by which all y coordinate offset values in the
FloatMap
are multipliedDisplacementMap impl_createImpl()
impl_createImpl
in class Effect
public final void setInput(Effect value)
public final Effect getInput()
public final ObjectProperty<Effect> inputProperty()
boolean impl_checkChainContains(Effect e)
impl_checkChainContains
in class Effect
public final void setMapData(FloatMap value)
public final FloatMap getMapData()
public final ObjectProperty<FloatMap> mapDataProperty()
public final void setScaleX(double value)
public final double getScaleX()
public final DoubleProperty scaleXProperty()
public final void setScaleY(double value)
public final double getScaleY()
public final DoubleProperty scaleYProperty()
public final void setOffsetX(double value)
public final double getOffsetX()
public final DoubleProperty offsetXProperty()
public final void setOffsetY(double value)
public final double getOffsetY()
public final DoubleProperty offsetYProperty()
public final void setWrap(boolean value)
public final boolean isWrap()
public final BooleanProperty wrapProperty()
void impl_update()
impl_update
in class Effect
@Deprecated public BaseBounds impl_getBounds(BaseBounds bounds, BaseTransform tx, Node node, BoundsAccessor boundsAccessor)
Effect
impl_getBounds
in class Effect