Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.batik.ext.awt.image.rendered
Class TurbulencePatternRed  view TurbulencePatternRed download TurbulencePatternRed.java

java.lang.Object
  extended byorg.apache.batik.ext.awt.image.rendered.AbstractRed
      extended byorg.apache.batik.ext.awt.image.rendered.TurbulencePatternRed
All Implemented Interfaces:
CachableRed, java.awt.image.RenderedImage

public final class TurbulencePatternRed
extends AbstractRed

This class creates a RenderedImage in conformance to the one defined for the feTurbulence filter of the SVG specification. What follows is my high-level description of how the noise is generated. This is not contained in the SVG spec, just the algorithm for doing it. This is provided in the hope that someone will figure out a clever way to accelerate parts of the function. gradient contains a long list of random unit vectors. For each point we are to generate noise for we do two things. first we use the latticeSelector to 'co-mingle' the integer portions of x and y (this allows us to have a one-dimensional array of gradients that appears 2 dimensional, by using the co-mingled index). We do this for [x,y], [x+1,y], [x,y+1], and [x+1, y+1], this gives us the four gradient vectors that surround the point (b00, b10, ...) Next we construct the four vectors from the grid points (where the gradient vectors are defined) [these are rx0, rx1, ry0, ry1]. We then take the dot product between the gradient vectors and the grid point vectors (this gives the portion of the grid point vector that projects along the gradient vector for each grid point). These four dot projects are then combined with linear interpolation. The weight factor for the linear combination is the result of applying the 's' curve function to the fractional part of x and y (rx0, ry0). The S curve function get's it's name because it looks a bit like as 'S' from 0->1.

Version:
$Id: TurbulencePatternRed.java,v 1.4 2004/10/30 18:38:05 deweese Exp $

Nested Class Summary
(package private) static class TurbulencePatternRed.StitchInfo
          Inner class to store tile stitching info.
 
Field Summary
private  double baseFrequencyX
          x-axis base frequency for the noise function along the x-axis
private  double baseFrequencyY
          y-axis base frequency for the noise function along the y-axis
private static int BM
           
private static int BSize
           
private  int[] channels
          List of channels that the generator produces.
private  double[] gradient
           
private static java.awt.geom.AffineTransform IDENTITY
          Identity transform, default used when null input in generatePattern
private  boolean isFractalNoise
          Defines whether the filter performs a fractal noise or a turbulence function
private  int[] latticeSelector
           
private static int NM
           
private static int NP
           
private  int numOctaves
          Number of octaves in the noise function
private static double PerlinN
           
private static int RAND_a
           
private static int RAND_m
          Produces results in the range [1, 2**31 - 2].
private static int RAND_q
           
private static int RAND_r
           
private  int seed
          Starting number for the pseudo random number generator
private  TurbulencePatternRed.StitchInfo stitchInfo
          Used when stitching is on
private  java.awt.geom.Rectangle2D tile
          Defines the tile for the turbulence function, if non-null turns on stitching, so frequencies are adjusted to avoid discontinuities in case frequencies do not match tile boundaries.
(package private)  double[] tx
           
private  java.awt.geom.AffineTransform txf
          Defines the tile for the turbulence function
(package private)  double[] ty
           
 
Fields inherited from class org.apache.batik.ext.awt.image.rendered.AbstractRed
bounds, cm, minTileX, minTileY, numXTiles, numYTiles, props, sm, srcs, tileGridXOff, tileGridYOff, tileHeight, tileWidth
 
Constructor Summary
TurbulencePatternRed(double baseFrequencyX, double baseFrequencyY, int numOctaves, int seed, boolean isFractalNoise, java.awt.geom.Rectangle2D tile, java.awt.geom.AffineTransform txf, java.awt.Rectangle devRect, java.awt.color.ColorSpace cs, boolean alpha)
           
 
Method Summary
 java.awt.image.WritableRaster copyData(java.awt.image.WritableRaster dest)
          Generates a Perlin noise pattern into dest Raster.
 double getBaseFrequencyX()
           
 double getBaseFrequencyY()
           
 boolean[] getChannels()
           
 int getNumOctaves()
           
 int getSeed()
           
 java.awt.geom.Rectangle2D getTile()
           
private  void initLattice(int seed)
           
 boolean isFractalNoise()
           
private static double lerp(double t, double a, double b)
           
private  void noise2(double[] noise, double vec0, double vec1)
          Generate a pixel of noise corresponding to the point vec0,vec1.
private  void noise2Stitch(double[] noise, double vec0, double vec1, TurbulencePatternRed.StitchInfo stitchInfo)
          This version of the noise function implements stitching.
 int random(int seed)
           
private static double s_curve(double t)
           
 int setupSeed(int seed)
           
private  int turbulence_4(double pointX, double pointY, double[] fSum)
          This is the heart of the turbulence calculation.
private  void turbulence(int[] rgb, double pointX, double pointY, double[] fSum, double[] noise)
          This is the heart of the turbulence calculation.
private  int turbulenceFractal_4(double pointX, double pointY, double[] fSum)
          This is the heart of the turbulence calculation.
private  void turbulenceFractal(int[] rgb, double pointX, double pointY, double[] fSum, double[] noise)
          This is the heart of the turbulence calculation.
private  void turbulenceFractalStitch(int[] rgb, double pointX, double pointY, double[] fSum, double[] noise, TurbulencePatternRed.StitchInfo stitchInfo)
          This is the heart of the turbulence calculation.
private  void turbulenceStitch(int[] rgb, double pointX, double pointY, double[] fSum, double[] noise, TurbulencePatternRed.StitchInfo stitchInfo)
          This is the heart of the turbulence calculation.
 
Methods inherited from class org.apache.batik.ext.awt.image.rendered.AbstractRed
copyBand, copyToRaster, getBounds, getColorModel, getData, getData, getDependencyRegion, getDirtyRegion, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getProperty, getPropertyNames, getSampleModel, getSources, getTile, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, getXTile, getYTile, init, init, makeTile, updateTileGridInfo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stitchInfo

private TurbulencePatternRed.StitchInfo stitchInfo
Used when stitching is on


IDENTITY

private static final java.awt.geom.AffineTransform IDENTITY
Identity transform, default used when null input in generatePattern

See Also:
#generatePattern

baseFrequencyX

private double baseFrequencyX
x-axis base frequency for the noise function along the x-axis


baseFrequencyY

private double baseFrequencyY
y-axis base frequency for the noise function along the y-axis


numOctaves

private int numOctaves
Number of octaves in the noise function


seed

private int seed
Starting number for the pseudo random number generator


tile

private java.awt.geom.Rectangle2D tile
Defines the tile for the turbulence function, if non-null turns on stitching, so frequencies are adjusted to avoid discontinuities in case frequencies do not match tile boundaries.


txf

private java.awt.geom.AffineTransform txf
Defines the tile for the turbulence function


isFractalNoise

private boolean isFractalNoise
Defines whether the filter performs a fractal noise or a turbulence function


channels

private int[] channels
List of channels that the generator produces.


tx

double[] tx

ty

double[] ty

RAND_m

private static final int RAND_m
Produces results in the range [1, 2**31 - 2]. Algorithm is: r = (a * r) mod m where a = 16807 and m = 2**31 - 1 = 2147483647 See [Park & Miller], CACM vol. 31 no. 10 p. 1195, Oct. 1988 To test: the algorithm should produce the result 1043618065 as the 10,000th generated number if the original seed is 1.

See Also:
Constant Field Values

RAND_a

private static final int RAND_a
See Also:
Constant Field Values

RAND_q

private static final int RAND_q
See Also:
Constant Field Values

RAND_r

private static final int RAND_r
See Also:
Constant Field Values

BSize

private static final int BSize
See Also:
Constant Field Values

BM

private static final int BM
See Also:
Constant Field Values

PerlinN

private static final double PerlinN
See Also:
Constant Field Values

NP

private static final int NP
See Also:
Constant Field Values

NM

private static final int NM
See Also:
Constant Field Values

latticeSelector

private final int[] latticeSelector

gradient

private final double[] gradient
Constructor Detail

TurbulencePatternRed

public TurbulencePatternRed(double baseFrequencyX,
                            double baseFrequencyY,
                            int numOctaves,
                            int seed,
                            boolean isFractalNoise,
                            java.awt.geom.Rectangle2D tile,
                            java.awt.geom.AffineTransform txf,
                            java.awt.Rectangle devRect,
                            java.awt.color.ColorSpace cs,
                            boolean alpha)
Method Detail

getBaseFrequencyX

public double getBaseFrequencyX()

getBaseFrequencyY

public double getBaseFrequencyY()

getNumOctaves

public int getNumOctaves()

getSeed

public int getSeed()

getTile

public java.awt.geom.Rectangle2D getTile()

isFractalNoise

public boolean isFractalNoise()

getChannels

public boolean[] getChannels()

setupSeed

public final int setupSeed(int seed)

random

public final int random(int seed)

initLattice

private void initLattice(int seed)

s_curve

private static final double s_curve(double t)

lerp

private static final double lerp(double t,
                                 double a,
                                 double b)

noise2

private final void noise2(double[] noise,
                          double vec0,
                          double vec1)
Generate a pixel of noise corresponding to the point vec0,vec1. See class description for a high level discussion of method. This handles cases where channels <= 4.


noise2Stitch

private final void noise2Stitch(double[] noise,
                                double vec0,
                                double vec1,
                                TurbulencePatternRed.StitchInfo stitchInfo)
This version of the noise function implements stitching. If any of the lattice is on the right or bottom edge, the function uses the the latice on the other side of the tile, i.e., the left or right edge.


turbulence_4

private final int turbulence_4(double pointX,
                               double pointY,
                               double[] fSum)
This is the heart of the turbulence calculation. It returns 'turbFunctionResult', as defined in the spec. This is special case for 4 bands of output.


turbulence

private final void turbulence(int[] rgb,
                              double pointX,
                              double pointY,
                              double[] fSum,
                              double[] noise)
This is the heart of the turbulence calculation. It returns 'turbFunctionResult', as defined in the spec.


turbulenceStitch

private final void turbulenceStitch(int[] rgb,
                                    double pointX,
                                    double pointY,
                                    double[] fSum,
                                    double[] noise,
                                    TurbulencePatternRed.StitchInfo stitchInfo)
This is the heart of the turbulence calculation. It returns 'turbFunctionResult', as defined in the spec.


turbulenceFractal_4

private final int turbulenceFractal_4(double pointX,
                                      double pointY,
                                      double[] fSum)
This is the heart of the turbulence calculation. It returns 'turbFunctionResult', as defined in the spec. This handles the case where we are generating 4 channels of noise.


turbulenceFractal

private final void turbulenceFractal(int[] rgb,
                                     double pointX,
                                     double pointY,
                                     double[] fSum,
                                     double[] noise)
This is the heart of the turbulence calculation. It returns 'turbFunctionResult', as defined in the spec.


turbulenceFractalStitch

private final void turbulenceFractalStitch(int[] rgb,
                                           double pointX,
                                           double pointY,
                                           double[] fSum,
                                           double[] noise,
                                           TurbulencePatternRed.StitchInfo stitchInfo)
This is the heart of the turbulence calculation. It returns 'turbFunctionResult', as defined in the spec.


copyData

public java.awt.image.WritableRaster copyData(java.awt.image.WritableRaster dest)
Generates a Perlin noise pattern into dest Raster.