Package net.paulhertz.pixelaudio

# Class HilbertGen

java.lang.Object
net.paulhertz.pixelaudio.PixelMapGen
net.paulhertz.pixelaudio.HilbertGen

public class HilbertGen extends PixelMapGen
Generates coordinates and LUTs for a Hilbert curve over a square bitmap starting at (0,0) and ending at (width-1, 0). Width and height must be equal powers of 2. You can also call HilbertGen(int depth) and width and height will equal Math.pow(2, depth). See abstract class `PixelMapGen` for instance variables shared by all child classes.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `int`
  `depth`
  recursion depth
  `static final String`
  `description`
  `private boolean`
  `doXYSwap`

  ### Fields inherited from class net.paulhertz.pixelaudio.PixelMapGen

  `coords, flipx, flipy, fx270, fx90, h, nada, pixelMap, r180, r270, r90, sampleMap, size, transArray, transformType, w`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HilbertGen(int depth)`
  `HilbertGen(int width, int height)`
  `HilbertGen(int width, int height, AffineTransformType type)`
  `HilbertGen(int depth, AffineTransformType type)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `private int[]`
  `d2xy(int n, int pos)`
  Calculates coordinate positions within a Hilbert curve.
  `String`
  `describe()`
  `int[]`
  `generate()`
  Initialization method that sets `this.coords`, and then `this.pixelMap` and `this.sampleMap`: `this.coords` is a list of coordinate pairs representing the signal path, the (x,y) pixel locations along a path that visits every pixel in a bitmap exactly once.
  `private ArrayList<int[]>`
  `generateCoordinates()`
  `private ArrayList<int[]>`
  `generateHilbertCoordinates(int n)`
  Handles the generation of coordinates for a HilbertGen.
  `static MultiGen`
  `hilbertLoop3x2(int genW, int genH)`
  Generates a looping fractal signal path consisting of 6 HilbertGens, arranged 3 wide and 2 tall, to fit a 3 * genW by 2 * genH image.
  `static MultiGen`
  `hilbertMultigenLoop(int columns, int rows, int genEdge)`
  `static MultiGen`
  `hilbertRowOrtho(int cols, int rows, int genW, int genH)`
  This method creates rows of HilbertGens, starting each row from the left and adding gens.
  `static MultiGen`
  `hilbertVerticalStackBou(int stacks, int rows, int units, int genW, int genH)`
  This method creates a vertical stacks of rows of HilbertGens.
  `static MultiGen`
  `hilbertVerticalStackOrtho(int stacks, int rows, int units, int genW, int genH)`
  This method creates a vertical stacks of rows of HilbertGens.
  `static boolean`
  `prevalidate(int width, int height)`
  static version of `validate()` that we use to throw meaningful errors (or so we hope)
  `boolean`
  `validate(int width, int height)`

  ### Methods inherited from class net.paulhertz.pixelaudio.PixelMapGen

  `findNearestPowerOfTwoLessThan, findPowerOfTwo, getCoordinates, getCoordinatesCopy, getHeight, getInversMapFromPixelArray, getPixelMap, getPixelMapCopy, getPixelMapFromCoordinates, getSampleMap, getSampleMapCopy, getSize, getTransformType, getWidth, isPowerOfTwo, loadIndexMaps, randomTransform, setMapsFromCoords, setTransformType, transformCoords`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### depth

    public int depth
    recursion depth

  - ### doXYSwap

    private boolean doXYSwap

  - ### description

    public static final String description
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### HilbertGen

    public HilbertGen(int width, int height, AffineTransformType type)

  - ### HilbertGen

    public HilbertGen(int width, int height)

  - ### HilbertGen

    public HilbertGen(int depth)
    Parameters:
      `depth` - depth of recursion of HIlbert curve, where 2^depth produces the width and height of the HilbertGen

  - ### HilbertGen

    public HilbertGen(int depth, AffineTransformType type)
    Parameters:
      `depth` - depth of recursion of HIlbert curve, where 2^depth produces the width and height of the HilbertGen
      `type` - AfineTransformType to apply to the HilbertGen coordinates

- ## Method Details

  - ### describe

    public String describe()
    Specified by:
      `describe` in class `PixelMapGen`
    Returns:
      A String describing the mapping generated by your class and any initialization requirements.

  - ### validate

    public boolean validate(int width, int height)
    Specified by:
      `validate` in class `PixelMapGen`
    Returns:
      true if the width and height parameters are valid for creating a mapping with this generator, otherwise, false.

  - ### prevalidate

    public static boolean prevalidate(int width, int height)
    static version of `validate()` that we use to throw meaningful errors (or so we hope)
    Parameters:
      `width` - width of the HilbertGen
      `height` - height of the HilbertGen
    Returns:
      true if width and height are legitimate values for a Hilbert curve: equal powers of 2

  - ### generate

    public int[] generate()
    Description copied from class: `PixelMapGen`

    Initialization method that sets `this.coords`, and then `this.pixelMap` and `this.sampleMap`: `this.coords` is a list of coordinate pairs representing the signal path, the (x,y) pixel locations along a path that visits every pixel in a bitmap exactly once. Once you have created it, you can call `setMapsFromCoords()` to set `this.pixelMap` and `this.sampleMap` automatically.

    `generate()` must be called from your class, so that you can initialize any local variables before generating coordinates and LUTs. The best place to call it is typically on the last line of the constructor for your class, after calling super() on the first line and after initializing any local variables needed to generate your coordinates and LUTs. You must initialize `this.coords`, `this.pixelMap`, and `this.sampleMap` within generate(). See `DiagonalZigzagGen` or `HilbertGen` for sample code.

    Specified by:
      `generate` in class `PixelMapGen`
    Returns:
      this.pixelMap, the value for PixelAudioMapper.signalToImageLUT.

  - ### generateCoordinates

    private ArrayList<int[]> generateCoordinates()
    Returns:
      array of coordinates for the HilbertGen

  - ### generateHilbertCoordinates

    private ArrayList<int[]> generateHilbertCoordinates(int n)
    Handles the generation of coordinates for a HilbertGen.
    Parameters:
      `n` - size of the array of Hilbert curve coordinates, necessarily a power of 4
    Returns:
      an ArrayList of integer pairs {x,y} representing the coordinates of a Hilbert curve

  - ### d2xy

    private int[] d2xy(int n, int pos)
    Calculates coordinate positions within a Hilbert curve.
    Parameters:
      `n` - size of the array of Hilbert curve coordinates
      `pos` - index position within the Hilbert curve coordinates
    Returns:

  - ### hilbertMultigenLoop

    public static MultiGen hilbertMultigenLoop(int columns, int rows, int genEdge)
    Parameters:
      `columns` - number of columns of gens wide
      `rows` - number of rows of gens high
      `genEdge` - number of pixels for the edge of each Hilbert curve, must be a power of 2
    Returns:
      a MultiGen consisting of rows rows and cols columns of Hilbert curves check for null return value

  - ### hilbertLoop3x2

    public static MultiGen hilbertLoop3x2(int genW, int genH)
    Generates a looping fractal signal path consisting of 6 HilbertGens, arranged 3 wide and 2 tall, to fit a 3 * genW by 2 * genH image. This particular MultiGen configuration was used so extensively in my sample code that I've given it its own method. Note that genH must equal genW and both must be powers of 2. For the image size we're using in this example, genW = image width / 3 and genH = image height / 2.
    Parameters:
      `genW` - width of each HilbertGen
      `genH` - height of each HilbertGen
    Returns:
      a Multigen composed of 6 HilbertGens on a 3 x 2 grid

  - ### hilbertVerticalStackOrtho

    public static MultiGen hilbertVerticalStackOrtho(int stacks, int rows, int units, int genW, int genH)
    This method creates a vertical stacks of rows of HilbertGens. Each row begins genH pixels down from the previous row, back at the beginning of the previous row (i.e., in "row major" order, like a bitmap). This method pairs nicely with an image with 3 columns of with 8 rows of words, using the image as a control surface for sampling an audio file with words recorded at the appropriate locations to match the screen order. I used it for a performance work, DeadBodyWorkFlow, which is included in the The signal path jumps from the end of the last gen in each row to the beginning of the first gen int he next row. The path in each row is continuous, which provides some interesting optical effects.
    Parameters:
      `stacks` - the number of stacks
      `rows` - the number of rows in each stack
      `units` - the number of gens in each row
      `genW` - the width of each gen, a power of 2
      `genH` - the height of each gen, equal to genW
    Returns:
      a Multigen consisting of stacks * rows * units PixelMapGens

  - ### hilbertVerticalStackBou

    public static MultiGen hilbertVerticalStackBou(int stacks, int rows, int units, int genW, int genH)
    This method creates a vertical stacks of rows of HilbertGens. Each row begins genH pixels down from the previous row. Alternating rows add units in opposite directions. This means path continuity is possible in each stack by changing the orientation of the gens; however, it isn't fully implemented in this example. Hint: choosing the right orientation for each gen will assure path continuity.
    Parameters:
      `stacks` - the number of stacks
      `rows` - the number of rows in each stack
      `units` - the number of gens in each row
      `genW` - the width of each gen, a power of 2
      `genH` - the height of each gen, equal to genW
    Returns:
      a Multigen consisting of stacks * rows * units PixelMapGens

  - ### hilbertRowOrtho

    public static MultiGen hilbertRowOrtho(int cols, int rows, int genW, int genH)
    This method creates rows of HilbertGens, starting each row from the left and adding gens. The odd rows are flipped vertically and the even rows are unchanged. The unchanged HilbertGen starts at upper left corner and ends at upper right corner, so this provides some possibilities of symmetry between rows. The path is not continuous.
    Parameters:
      `cols` - number of columns of gens wide
      `rows` - number of rows of gens high
      `genW` - width of each gen (same as genH and a power of 2)
      `genH` - height of each gen
    Returns:
      a MultiGen composed of cols * rows PixelMapGens