Class VidMap

java.lang.Object
paletai.mapping.VidMap

public class VidMap extends Object
Handles homography transformations for video mapping with interactive calibration. Provides UI for point adjustment and real-time perspective correction.

This class combines MathHomography calculations with Processing's OpenGL rendering pipeline to create perspective-corrected video mappings. It supports:

  • Interactive calibration with draggable control points
  • Real-time homography updates
  • Serialization of mapping configurations
  • Visual feedback during calibration
  • Preview area integration for UI display
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
     
    processing.core.PVector[]
     
    processing.core.PVector[]
     
    processing.core.PVector[]
    Normalized coordinates for shader (0-1 range)
    processing.core.PVector[]
    Pixel coordinates for Processing display
  • Constructor Summary

    Constructors
    Constructor
    Description
    VidMap(processing.core.PApplet p, String name)
    Constructs a new VidMap instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assignToDisplay(int w, int h)
    Assigns this VidMap to a display with specific dimensions.
    void
    checkHover(float mousex, float mousey)
    Checks hover state for calibration points and image dragging.
    processing.opengl.PGraphics2D
    Returns the transformed media canvas after homography processing.
    void
    Handles mouse release events for calibration interaction.
    void
    moveHoverPoint(float x, float y)
    Moves hover points or drags the entire image during calibration.
    processing.core.PVector
    Normal2Pixel(processing.core.PVector in)
    Converts normalized coordinates back to pixel space.
    void
    Turns off calibration mode.
    void
    Turns on calibration mode.
    processing.core.PVector
    Pixel2Nornal(processing.core.PVector in)
    Converts pixel coordinates to normalized shader coordinates.
    void
    render(processing.core.PImage input)
    Renders a PImage with homography transformation applied.
    void
    render(processing.opengl.PGraphics2D input)
    Renders the input image with homography transformation applied.
    void
    Resets the homography to identity transformation.
    void
    setPreviewArea(float px, float py, float pw, float ph)
    Sets the preview area for calibration point display.
    void
    Toggles calibration mode on/off.
    void
    Toggles input checking mode for calibration.
    void
    updateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew)
    Updates the homography transformation from normalized coordinates.
    void
    updateHomographyFromPixel(processing.core.PVector[] xyPP, processing.core.PVector[] uvPP)
    Updates the homography matrix from pixel-space coordinates.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • xyN

      public processing.core.PVector[] xyN
      Normalized coordinates for shader (0-1 range)
    • uvN

      public processing.core.PVector[] uvN
    • xyP

      public processing.core.PVector[] xyP
      Pixel coordinates for Processing display
    • uvP

      public processing.core.PVector[] uvP
    • checkInput

      public boolean checkInput
  • Constructor Details

    • VidMap

      public VidMap(processing.core.PApplet p, String name)
      Constructs a new VidMap instance. Initializes the homography shader, display buffers, and mathematical utilities.
      Parameters:
      p - The parent Processing applet
      name - Unique identifier for this mapping
      See Also:
  • Method Details

    • assignToDisplay

      public void assignToDisplay(int w, int h)
      Assigns this VidMap to a display with specific dimensions. Creates graphics buffers and configures the shader for the target resolution.
      Parameters:
      w - The width of the target display
      h - The height of the target display
      See Also:
      • PGraphics2D
      • PShader.set(String, float, float)
    • setPreviewArea

      public void setPreviewArea(float px, float py, float pw, float ph)
      Sets the preview area for calibration point display. Defines the screen region where calibration points and grids will be rendered.
      Parameters:
      px - Preview area x-coordinate
      py - Preview area y-coordinate
      pw - Preview area width
      ph - Preview area height
    • resetHomography

      public void resetHomography()
      Resets the homography to identity transformation. Initializes all points to the corners of the display and updates the homography matrix accordingly.
      See Also:
    • updateHomographyFromPixel

      public void updateHomographyFromPixel(processing.core.PVector[] xyPP, processing.core.PVector[] uvPP)
      Updates the homography matrix from pixel-space coordinates. Converts pixel coordinates to normalized coordinates and updates the transformation accordingly.
      Parameters:
      xyPP - Source points in pixel coordinates
      uvPP - Destination points in pixel coordinates
      Throws:
      IllegalArgumentException - If arrays don't contain exactly 4 points
      See Also:
    • updateHomography

      public void updateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew)
      Updates the homography transformation from normalized coordinates. Calculates the homography matrix and its inverse, then configures the shader with the transformed coordinates.
      Parameters:
      xyNew - Source points in normalized coordinates (0-1)
      uvNew - Destination points in normalized coordinates (0-1)
      See Also:
    • toggleInput

      public void toggleInput()
      Toggles input checking mode for calibration. Switches between input (source) and output (destination) point manipulation.
    • render

      public void render(processing.opengl.PGraphics2D input)
      Renders the input image with homography transformation applied. Processes the input through the homography shader and draws calibration visuals if calibration mode is active.
      Parameters:
      input - The input graphics to transform
      See Also:
      • makeGrid(PVector[], boolean)
      • drawCalibrationOnPreview()
      • PGraphics.filter(PShader)
    • render

      public void render(processing.core.PImage input)
      Renders a PImage with homography transformation applied. Wrapper method that converts PImage to PGraphics2D before processing.
      Parameters:
      input - The input image to transform
      See Also:
    • getMediaCanvas

      public processing.opengl.PGraphics2D getMediaCanvas()
      Returns the transformed media canvas after homography processing.
      Returns:
      PGraphics2D containing the transformed output
    • Pixel2Nornal

      public processing.core.PVector Pixel2Nornal(processing.core.PVector in)
      Converts pixel coordinates to normalized shader coordinates. Normalizes coordinates to 0-1 range and inverts Y-axis for shader compatibility.
      Parameters:
      in - Input point in pixel coordinates
      Returns:
      Point in normalized coordinates (0-1, Y inverted)
    • Normal2Pixel

      public processing.core.PVector Normal2Pixel(processing.core.PVector in)
      Converts normalized coordinates back to pixel space. Denormalizes coordinates and inverts Y-axis back to Processing coordinate system.
      Parameters:
      in - Input point in normalized coordinates
      Returns:
      Point in pixel coordinates
    • toggleCalibration

      public void toggleCalibration()
      Toggles calibration mode on/off. Enables or disables the interactive calibration interface.
    • offCalibration

      public void offCalibration()
      Turns off calibration mode. Disables the interactive calibration interface.
    • onCalibration

      public void onCalibration()
      Turns on calibration mode. Enables the interactive calibration interface.
    • checkHover

      public void checkHover(float mousex, float mousey)
      Checks hover state for calibration points and image dragging. Determines if mouse is hovering over calibration points or inside the transformable image area in the preview.
      Parameters:
      mousex - The current x-coordinate of the mouse
      mousey - The current y-coordinate of the mouse
      See Also:
      • normalizedToPreview(PVector)
      • isMouseInsideImage(PVector, PVector[])
    • moveHoverPoint

      public void moveHoverPoint(float x, float y)
      Moves hover points or drags the entire image during calibration. Updates homography points based on mouse movement in preview space. Supports individual point movement and whole-image translation.
      Parameters:
      x - The current x-coordinate of the mouse
      y - The current y-coordinate of the mouse
      See Also:
    • mouseReleased

      public void mouseReleased()
      Handles mouse release events for calibration interaction. Completes dragging operations and resets movement states.