Class Clip

java.lang.Object
skyview.geometry.Sampler
skyview.geometry.sampler.Clip
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Component

public class Clip
extends Sampler
The class implements a fast flux conserving resampling based on the Sutherland-Hodgman clipping algorithm.

Consider an original image of data in some projection and a new map of an overlapping region with some projection, coordinate system, etc. Assume that the flux within a given pixel in the original image is constant over the area of the pixel. The flux within each pixel in the new map should be the integral of the flux in the region occupied by each pixel in the map.

  • Find all of the corners of the pixels in resampled map and project the positions of these corners into the projection of the original image. These should be scaled such that the coordinates run from 0 to inWidth and inHeight where inWidth and inHeight are the dimensions of the original image. I.e., in these coordinate each pixel in the original image is a unit square. This step is done prior to call the primary Clip sampler methods in this class. Note that the corners of the pixels are required rather than the pixel centers.
  • For each pixel in the resampled map, find a bounding box in the original image's coordinates. This is used to find a rectangle of candidate pixels in the original image that may contribute flux to this pixel in the resampled map.
  • For each candidate image pixel clip the resampled pixel to the image pixels boundaries.
  • Calculate the area of the clipped region. This is easy since the clipped region is a convex polygon and we have the vertices. Triangulating the polygon allows us to calculate its area.
  • Add a flux to the resampled pixel equal to the area of the clipped resampled pixel times the flux in the original map pixel
  • Repeat for all candidate original pixels
  • Go to the next resampling pixel.

The instance methods of this class are not thread-safe, however it is possible to generate a separate Clip sampler object for each thread to resample the same input image.

Developed by Tom McGlynn, NASA/GSFC October 3, 2002

See Also:
Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected double drizzArea
    Drizzle Area
    protected double drizzOffset
    Drizzle offset
    protected int recurse  

    Fields inherited from class skyview.geometry.Sampler

    bounds, inDepth, inHeight, inImage, inWidth, outDepth, outHeight, outImage, outWidth, trans
  • Constructor Summary

    Constructors 
    Constructor Description
    Clip()  
  • Method Summary

    Modifier and Type Method Description
    double clipRectPoly​(double xmin, double ymin, double xmax, double ymax, double[] polyx, double[] polyy)
    This method provides an interface to the simplified Sutherland-Hodges clipper for use outside the sampling context.
    static double convexArea​(int n, double[] x, double[] y)
    Calculate the area of a convex polygon.
    java.lang.String getDescription()
    Get the description of this component.
    java.lang.String getName()
    Get the name of this component.
    double[] lastX()  
    double[] lastY()  
    protected static void printVert​(int n, double[] x, double[] y, java.lang.String label)
    Debugging routine that prints a list of vertices.
    int rectClip​(int n, double[] x, double[] y, double[] nx, double[] ny, double minX, double minY, double maxX, double maxY)
    Clip a polygon by a non-rotated rectangle.
    void sample​(int pix)
    Implement the sample function of the Sampler class.
    void samplePixel​(int pix, double[] x, double[] y)
    Sample a single map pixel.
    void setDrizzle​(double drizzle)
    Set the drizzle factor for sampling
    void setInput​(Image in)
    Set the input image for the sampling
    void setIntensive​(boolean intensive)  
    void setOutput​(Image outImage)
    Set the output image for the sampling
    double weight()
    Return the weight associated with the last sampling.

    Methods inherited from class skyview.geometry.Sampler

    clone, factory, setBounds, setOrder, setTransform

    Methods inherited from class java.lang.Object

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

    • recurse

      protected int recurse
    • drizzOffset

      protected double drizzOffset
      Drizzle offset
    • drizzArea

      protected double drizzArea
      Drizzle Area
  • Constructor Details

    • Clip

      public Clip()
  • Method Details

    • setOutput

      public void setOutput​(Image outImage)
      Description copied from class: Sampler
      Set the output image for the sampling
      Overrides:
      setOutput in class Sampler
    • getName

      public java.lang.String getName()
      Description copied from interface: Component
      Get the name of this component.
    • getDescription

      public java.lang.String getDescription()
      Description copied from interface: Component
      Get the description of this component.
    • setIntensive

      public void setIntensive​(boolean intensive)
    • setInput

      public void setInput​(Image in)
      Description copied from class: Sampler
      Set the input image for the sampling
      Overrides:
      setInput in class Sampler
    • setDrizzle

      public void setDrizzle​(double drizzle)
      Set the drizzle factor for sampling
      Parameters:
      drizzle - The drizzle factor should range from 0 to 1 and indicates the length of the side of the pixel inside the original image pixel in which the flux is assumed to be contained.
    • convexArea

      public static double convexArea​(int n, double[] x, double[] y)
      Calculate the area of a convex polygon. This function calculates the area of a convex polygon by deconvolving the polygon into triangles and summing the areas of the constituents. The user provides the coordinates of the vertices of the polygon in sequence along the circumference (in either direction and starting at any point). Only distinct vertices should be given, i.e., the first vertex should not be repeated at the end of the list. *
      Parameters:
      n - The number of vertices in the polygon.
      x - The x coordinates of the vertices
      y - The y coordinates of teh vertices
      Returns:
      The area of the polygon.
    • rectClip

      public int rectClip​(int n, double[] x, double[] y, double[] nx, double[] ny, double minX, double minY, double maxX, double maxY)
      Clip a polygon by a non-rotated rectangle. This uses a simplified version of the Sutherland-Hodgeman polygon clipping method. We assume that the region to be clipped is convex. This implies that we will not need to worry about the clipping breaking the input region into multiple disconnected areas. [Proof: Suppose the resulting region is not convex. Then there is a line between two points in the region that crosses the boundary of the clipped region. However the clipped boundaries are all lines from one of the two figures we are intersecting. This would imply that this line crosses one of the boundaries in the original image. Hence either the original polygon or the clipping region would need to be non-convex.] Private arrays are used for intermediate results to minimize allocation costs.
      Parameters:
      n - Number of vertices in the polygon.
      x - X values of vertices
      y - Y values of vertices
      nx - X values of clipped polygon
      ny - Y values of clipped polygon
      minX - Minimum X-value
      minY - Minimum Y-value
      maxX - MAximum X-value
      maxY - Maximum Y-value
      Returns:
      Number of vertices in clipped polygon.
    • printVert

      protected static void printVert​(int n, double[] x, double[] y, java.lang.String label)
      Debugging routine that prints a list of vertices.
      Parameters:
      n - The number of vertices in the polygon
      x - X coordinates
      y - Y coordinates
    • sample

      public void sample​(int pix)
      Implement the sample function of the Sampler class. This function samples a single pixel.
      Specified by:
      sample in class Sampler
      Parameters:
      pix - The index of the pixel.
    • weight

      public double weight()
      Return the weight associated with the last sampling. For the Clip sampler, the weight can be associated with the 'area' of the pixel.
    • samplePixel

      public void samplePixel​(int pix, double[] x, double[] y)
      Sample a single map pixel.
      Parameters:
      x - The x values of the corners of the pixel [4]
      y - The y values of the corners of the pixel [4]
    • clipRectPoly

      public double clipRectPoly​(double xmin, double ymin, double xmax, double ymax, double[] polyx, double[] polyy)
      This method provides an interface to the simplified Sutherland-Hodges clipper for use outside the sampling context.
      Parameters:
      polyx - The vertices of an (assumed convex) polygon.
      polyy - The vertices of an (assumed convex) polygon.
      Returns:
      The area of the overlap.
    • lastX

      public double[] lastX()
    • lastY

      public double[] lastY()