Class PointSample<T>

All Implemented Interfaces:
EuclideanSpace, Localizable, Positionable, RandomAccess<T>, RealLocalizable, Sampler<T>, Typed<T>

public class PointSample<T> extends AbstractLocalizable implements RandomAccess<T>
A simple default implementation of RandomAccess that can be used to combine a real location and a sample instance, e.g. as output of a FunctionRandomAccessible.
  • Field Details

    • sampleSupplier

      protected final Supplier<T> sampleSupplier
  • Constructor Details

    • PointSample

      protected PointSample(Supplier<T> sampleSupplier, long[] position, boolean copy)
      Protected constructor that can re-use the passed position array.
      Parameters:
      sampleSupplier - a supplier to create the sample instance (can be () -> t) for instances that are re-used (like Type).
      position - array used to store the position.
      copy - flag indicating whether position array should be duplicated.
    • PointSample

      public PointSample(Supplier<T> sampleSupplier, int n)
      Create a point in nDimensional space initialized to 0,0,...
      Parameters:
      sampleSupplier - a supplier to create the sample instance (can be () -> t) for instances that are re-used (like Type).
      n - number of dimensions of the space
    • PointSample

      public PointSample(Supplier<T> sampleSupplier, long... position)
      Create a point at a definite location in a space of the dimensionality of the position.
      Parameters:
      sampleSupplier - a supplier to create the sample instance (can be () -> t) for instances that are re-used (like Type).
      position - the initial position. The length of the array determines the dimensionality of the space.
    • PointSample

      public PointSample(Supplier<T> sampleSupplier, int... position)
      Create a point at a definite location in a space of the dimensionality of the position.
      Parameters:
      sampleSupplier - a supplier to create the sample instance (can be () -> t) for instances that are re-used (like Type).
      position - the initial position. The length of the array determines the dimensionality of the space.
    • PointSample

      public PointSample(Supplier<T> sampleSupplier, Localizable localizable)
      Create a point using the position and dimensionality of a Localizable
      Parameters:
      sampleSupplier - a supplier to create the sample instance (can be () -> t) for instances that are re-used (like Type).
      localizable - the initial position. Its dimensionality determines the dimensionality of the space.
  • Method Details

    • fwd

      public void fwd(int d)
      Description copied from interface: Positionable
      Move by 1 in one dimension.
      Specified by:
      fwd in interface Positionable
      Parameters:
      d - dimension
    • bck

      public void bck(int d)
      Description copied from interface: Positionable
      Move by -1 in one dimension.
      Specified by:
      bck in interface Positionable
      Parameters:
      d - dimension
    • move

      public void move(int distance, int d)
      Description copied from interface: Positionable
      Move the element in one dimension for some distance.
      Specified by:
      move in interface Positionable
      Parameters:
      distance - relative offset in dimension d
      d - dimension
    • move

      public void move(long distance, int d)
      Description copied from interface: Positionable
      Move the element in one dimension for some distance.
      Specified by:
      move in interface Positionable
      Parameters:
      distance - relative offset in dimension d
      d - dimension
    • move

      public void move(Localizable localizable)
      Description copied from interface: Positionable
      Move the element relative to its current location using an Localizable as distance vector.
      Specified by:
      move in interface Positionable
      Parameters:
      localizable - relative offset, EuclideanSpace.numDimensions() must be ≥ EuclideanSpace.numDimensions()
    • move

      public void move(int[] distance)
      Description copied from interface: Positionable
      Move the element relative to its current location using an int[] as distance vector.
      Specified by:
      move in interface Positionable
      Parameters:
      distance - relative offset, length must be ≥ EuclideanSpace.numDimensions()
    • move

      public void move(long[] distance)
      Description copied from interface: Positionable
      Move the element relative to its current location using a long[] as distance vector.
      Specified by:
      move in interface Positionable
      Parameters:
      distance - relative offset, length must be ≥ EuclideanSpace.numDimensions()
    • setPosition

      public void setPosition(Localizable localizable)
      Description copied from interface: Positionable
      Place the element at the same location as a given Localizable
      Specified by:
      setPosition in interface Positionable
      Parameters:
      localizable - absolute position, EuclideanSpace.numDimensions() must be ≥ EuclideanSpace.numDimensions()
    • setPosition

      public void setPosition(int[] position)
      Description copied from interface: Positionable
      Set the position of the element.
      Specified by:
      setPosition in interface Positionable
      Parameters:
      position - absolute position, length must be ≥ EuclideanSpace.numDimensions()
    • setPosition

      public void setPosition(long[] position)
      Description copied from interface: Positionable
      Set the position of the element.
      Specified by:
      setPosition in interface Positionable
      Parameters:
      position - absolute position, length must be ≥ EuclideanSpace.numDimensions()
    • setPosition

      public void setPosition(int position, int d)
      Description copied from interface: Positionable
      Set the position of the element for one dimension.
      Specified by:
      setPosition in interface Positionable
      Parameters:
      position - absolute position in dimension d
      d - dimension
    • setPosition

      public void setPosition(long position, int d)
      Description copied from interface: Positionable
      Set the position of the element for one dimension.
      Specified by:
      setPosition in interface Positionable
      Parameters:
      position - absolute position in dimension d
      d - dimension
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • wrap

      public static <T> PointSample<T> wrap(T sample, long[] position)
      Create a PointSample that carries the provided sample and stores its coordinates in the provided position array.
      Parameters:
      sample - the re-usable sample instance that is used by this PointSample (like Type)
      position - array to use for storing the position.
    • wrapSupplier

      public static <T> PointSample<T> wrapSupplier(Supplier<T> sampleSupplier, long[] position)
      Create a PointSample that carries the provided sample and stores its coordinates in the provided position array.
      Parameters:
      sampleSupplier - a supplier to create the sample instance (can be () -> t) for instances that are re-used (like Type).
      position - array to use for storing the position.
    • get

      public T get()
      Description copied from interface: Sampler
      Access the actual T instance providing access to a pixel, sub-pixel or integral region value the Sampler points at.
      Specified by:
      get in interface Sampler<T>
    • getType

      public T getType()
      Description copied from interface: Typed
      Get an instance of T.

      It should not be assumed that the returned T instance is an independent copy. In particular, repeated calls to getType() may return the same instance.

      Specified by:
      getType in interface Sampler<T>
      Specified by:
      getType in interface Typed<T>
      Returns:
      an instance of T
    • copy

      public PointSample<T> copy()
      Specified by:
      copy in interface RandomAccess<T>
      Specified by:
      copy in interface Sampler<T>
      Returns:
      - A new Sampler in the same state accessing the same values. It does NOT copy T, just the state of the Sampler. Otherwise use T.copy() if available. Sampler.copy().get() == Sampler.get(), i.e. both hold the same value, not necessarily the same instance (this is the case for an ArrayCursor for example)