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 Details

    • depth

      public int depth
      recursion depth
    • doXYSwap

      private boolean doXYSwap
    • description

      public static final String description
      See Also:
  • Constructor Details

    • HilbertGen

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

      public HilbertGen(int width, int height)
    • HilbertGen

      public HilbertGen(int depth)
    • HilbertGen

      public HilbertGen(int depth, AffineTransformType type)
  • 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)
    • 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()
    • generateHilbertCoordinates

      private ArrayList<int[]> generateHilbertCoordinates(int n)
      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)
    • 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