Class MFImage

All Implemented Interfaces:
MField, MFImage, X3DField

public class MFImage extends X3DConcreteField implements MFImage
This utility class provides a concrete implementation corresponding to MFImage X3D field type.

Warning: this is an abstract interface that cannot be instantiated as a concrete object. Java programmers typically only need to use concrete objects provided by the org.web3d.x3d.jsail classes.
Package hint: This specification class is defined by the X3D Java Language Binding Specification for the Scene Authoring Interface (SAI). MFImage is an array of SFImage values.

Related field object: SFImage
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int[]
    Default value for this field type is an empty array.
    static final String
    Default string value for this field type is "".
    static final String
    String constant NAME provides name of this element: MFImage
    static final Pattern
    Precompiled regular expression (regex) pattern for this field type using default REGEX value.
    static final String
    Default regular expression (regex) pattern for this field type is \s*(([+]?
    static final int
    Default tuple size for this field type is 1 (i.e. number of component values making up a single-field SF object).

    Fields inherited from class org.web3d.x3d.jsail.fields.X3DConcreteField

    validationResult
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for MFImage performs value initialization.
    MFImage(int[] newValue)
    Constructor for MFImage using a corresponding Java primitive int[] array as new initial value.
    MFImage(MFImage newValue)
    Constructor to copy an MFImage value as initial value for this new field object.
    MFImage(SFImage newValue)
    Utility constructor for MFImage to assign a single SFImage as new initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(RenderedImage[] newValue)
    Places a new SFImage value at the end of the existing value array, increasing the field length accordingly.
    void
    Removes all values in the field array, changing the array size to zero.
    boolean
    equals(MFImage comparisonMFImage)
    Determine whether two objects contain equal values.
    int
    getHeight(int imageIndex)
    Get the height of the image array.
    getImage(int imageIndex)
    Fetch the Java representation of the underlying image from these pixels.
    int
    getNumberComponents(int imageIndex)
    Get the number of color components in the image.
    void
    getPixels(int imageIndex, int[] pixels)
    Get the image pixel value in the given eventOut.
    int[]
    Provides current value of the field as a Java primitive type.
    int
    getWidth(int imageIndex)
    Get the width of the image array.
    final void
    Initialization for MFImage applies default initial value.
    void
    insertValue(int index, RenderedImage newValue)
    Insert a new value prior to the index location in the existing value array, increasing the field length accordingly.
    static final boolean
    Whether or not this field type is an array (true)
    boolean
    Determine whether current value matches DEFAULT_VALUE
    final boolean
    Test PATTERN match via regular expression (regex) check of current object's toString() value.
    static final boolean
    matches(String value)
    Test PATTERN match with regular expression (regex) of provided value.
    void
    remove(int index)
    Remove one SFImage element of the field array at index position, if found.
    void
    set1Value(int imageIndex, int newValue)
    Replace a single value at the appropriate location in the existing value array.
    void
    set1Value(int imageIndex, int width, int height, int components, int[] pixels)
     
    void
    setImage(int imageIndex, RenderedImage image)
    Set the image value in the given writable field to the new image defined by a set of pixels.
    void
     
    void
    setSubImage(int imageIndex, RenderedImage image, int sourceWidth, int sourceHeight, int sourceXOffset, int sourceYOffset, int destinationXOffset, int destinationYOffset)
    Copy a region of the argument RenderedImage to replace a portion of the current SFimage.
    void
    setValue(int[] newValue)
    Assign a new value array; can be an SFImage primive array containing width, height, and components count, followed by array of pixels.
    setValue(MFImage newValue)
    Apply an MFImage value to this field.
    void
    setValue(SFImage newValue)
    Assign a new value array; can be an SFImage primive array containing width, height, and components count, followed by array of pixels.
    Utility accessor for MFImage using String value (which must pass parsing validation checks).
    int
    Get the size of the underlying data array.
    Provides current value as a String.
    static String
    toString(int[] value)
    Static utility method to provide String representation of a correctly typed input value.
    Provide pixel values in decimal format.
    Provide pixel values in hexadecimal format.
    final String
    Validate current value via get/set comparison tests
    final String
    Validate current value via regular expression (regex) check of current object's toString() value, reporting errors only if found.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • MFImage

      public MFImage()
      Constructor for MFImage performs value initialization.
    • MFImage

      public MFImage(MFImage newValue)
      Constructor to copy an MFImage value as initial value for this new field object.
      Parameters:
      newValue - The newValue to apply
    • MFImage

      public MFImage(int[] newValue)
      Constructor for MFImage using a corresponding Java primitive int[] array as new initial value.
      Parameters:
      newValue - is new value to assign setContainerFieldOverride(containerFieldName); // apply checksConcreteField#getTupleSize(String)
    • MFImage

      public MFImage(SFImage newValue)
      Utility constructor for MFImage to assign a single SFImage as new initial value.
      Parameters:
      newValue - is new value to assign
  • Method Details

    • isArray

      public static final boolean isArray()
      Whether or not this field type is an array (true)
      Returns:
      true if array type
    • initialize

      public final void initialize()
      Initialization for MFImage applies default initial value. Static initializer also provided to verify that the regex pattern compiles and matches that default value.
      Specified by:
      initialize in class X3DConcreteField
      See Also:
    • equals

      public boolean equals(MFImage comparisonMFImage)
      Determine whether two objects contain equal values.
      Parameters:
      comparisonMFImage - field type to compare
      Returns:
      true if equivalent, false otherwise
    • validate

      public final String validate()
      Validate current value via get/set comparison tests
      Returns:
      empty string if get/set testing passes, warning otherwise
      See Also:
    • validateRegex

      public final String validateRegex()
      Validate current value via regular expression (regex) check of current object's toString() value, reporting errors only if found.
      Returns:
      empty string if PATTERN matches, warning otherwise
      See Also:
    • matches

      public final boolean matches()
      Test PATTERN match via regular expression (regex) check of current object's toString() value.
      Returns:
      true if PATTERN matches, false otherwise
      See Also:
    • matches

      public static final boolean matches(String value)
      Test PATTERN match with regular expression (regex) of provided value.
      Parameters:
      value - String to check against regex pattern for successful match
      Returns:
      true if PATTERN matches, false otherwise
      See Also:
    • setValueByString

      public MFImage setValueByString(String newValue) throws InvalidFieldValueException
      Utility accessor for MFImage using String value (which must pass parsing validation checks).

      Warning: this method is not type safe at compile time! Best practice for X3DJSAIL programmers is to use strongly typed methods instead, in order to avoid potential for run-time errors.
      Parameters:
      newValue - is new value to assign, if empty then assign DEFAULT_VALUE
      Returns:
      MFMatrix4d - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same node object).
      Throws:
      InvalidFieldValueException
      See Also:
    • toString

      public static String toString(int[] value)
      Static utility method to provide String representation of a correctly typed input value.
      Parameters:
      value - The value to convert to a String
      Returns:
      String version of the provided value
      See Also:
    • getPrimitiveValue

      public int[] getPrimitiveValue()
      Provides current value of the field as a Java primitive type.
      Returns:
      current value
    • toString

      public String toString()
      Provides current value as a String.
      Overrides:
      toString in class Object
      Returns:
      String version of the provided value, with pixels in hexadecimal or decimal format.
      See Also:
    • toStringDecimal

      public String toStringDecimal()
      Provide pixel values in decimal format.
      Returns:
      String version of the provided value in decimal format
      See Also:
    • toStringHexadecimal

      public String toStringHexadecimal()
      Provide pixel values in hexadecimal format.
      Returns:
      String version of the provided value in hexadecimal format
      See Also:
    • getWidth

      public int getWidth(int imageIndex)
      Get the width of the image array.
      Specified by:
      getWidth in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      Returns:
      The width of the image in pixels
    • getHeight

      public int getHeight(int imageIndex)
      Get the height of the image array.
      Specified by:
      getHeight in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      Returns:
      The height of the image in pixels
    • getNumberComponents

      public int getNumberComponents(int imageIndex)
      Get the number of color components in the image. The value will always be between 0 and 4 indicating the number of components of the color specification to be read from the image pixel data.
      Specified by:
      getNumberComponents in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      Returns:
      The number of components
    • getPixels

      public void getPixels(int imageIndex, int[] pixels)
      Get the image pixel value in the given eventOut.

      The number of items in the pixels array will be width * height. If there are less items than this an ArrayIndexOutOfBoundsException will be generated. The integer values are represented according to the number of components.

      1 Component Images
      The integer has the intensity value stored in the lowest byte and can be obtained:

          intensity = (pixel[i]     ) &0xFF;
        

      2 Component Images
      The integer has the transparency value stored in the lowest byte and the intensity in the next byte:

          intensity = (pixel[i] >> 8) &0xFF;
          alpha     = (pixel[i]     ) &0xFF;
        

      3 Component Images
      The three color components are stored in the integer array as follows:

          red   = (pixel[i] >> 16) &0xFF;
          green = (pixel[i] >>  8) &0xFF;
          blue  = (pixel[i]      ) &0xFF;
        

      4 Component Images
      The integer has the value stored in the array as follows:

          red   = (pixel[i] >> 24) &0xFF;
          green = (pixel[i] >> 16) &0xFF;
          blue  = (pixel[i] >>  8) &0xFF;
          alpha = (pixel[i]      ) &0xFF;
        

      The width and height values must be greater than or equal to zero. The number of components is between 1 and 4. Any value outside of these bounds will generate an IllegalArgumentException.

      Specified by:
      getPixels in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      pixels - The array to copy pixel values into
    • getImage

      public WritableRenderedImage getImage(int imageIndex)
      Fetch the Java representation of the underlying image from these pixels. This is the same copy that the browser uses to generate texture information from.
      Specified by:
      getImage in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      Returns:
      The image reference representing the current state
    • setImage

      public void setImage(int imageIndex, RenderedImage image)
      Set the image value in the given writable field to the new image defined by a set of pixels.
      Specified by:
      setImage in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      image - The new image to use as the source
    • setSubImage

      public void setSubImage(int imageIndex, RenderedImage image, int sourceWidth, int sourceHeight, int sourceXOffset, int sourceYOffset, int destinationXOffset, int destinationYOffset)
      Copy a region of the argument RenderedImage to replace a portion of the current SFimage.

      The sub image set shall not resize the base image representation and therefore performs an intersection clip of the provided image. The user provided image shall be of the same format (pixel depth, pixel representation) as the original image obtained through the getImage() method.

      RenderedImages are row order from top to bottom. A 4x8 RenderImage is indexed as follows:

      
       X >01234567
         ----------
       0 |********|
       1 |********|
       2 |********|
       3 |********|
       ^ ----------
       Y
      
        
      SFImages are row order from bottom to top. A 4x8 RenderImage is indexed as follows:
      
       X >01234567
         ----------
       3 |********|
       2 |********|
       1 |********|
       0 |********|
       ^ ----------
       Y
      
        

      Note: The parameter srcYOffset is referenced to the RenderedImage object (indexed top to bottom).
      The parameter destYOffset is referenced to the SFImage object (indexed bottom to top).

      Specified by:
      setSubImage in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      image - The new image to use as the source
      sourceWidth - The width of the argument sub-image region to copy
      sourceHeight - The height of the argument sub-image region to copy
      sourceXOffset - The initial x dimension (width) offset into the argument sub-image that begins the region to copy
      sourceYOffset - The initial y dimension (height) offset into the argument sub-image that begins the region to copy
      destinationXOffset - The initial x dimension (width) offset in the SFimage object that begins the region to receive the copy
      destinationYOffset - The initial y dimension (height) offset in the SFimage object that begins the region to receive the copy
    • set1Value

      public void set1Value(int imageIndex, int newValue)
      Replace a single value at the appropriate location in the existing value array. Size of the current underlying value array does not change.
      Specified by:
      set1Value in interface MFImage
      Parameters:
      imageIndex - the index of the selected image
      newValue - provides new value to apply
    • set1Value

      public void set1Value(int imageIndex, int width, int height, int components, int[] pixels)
      Specified by:
      set1Value in interface MFImage
    • setValue

      public void setValue(int[] newValue)
      Assign a new value array; can be an SFImage primive array containing width, height, and components count, followed by array of pixels.
      Specified by:
      setValue in interface MFImage
      Parameters:
      newValue - the newValue to set
    • setValue

      public void setValue(SFImage newValue)
      Assign a new value array; can be an SFImage primive array containing width, height, and components count, followed by array of pixels.
      Parameters:
      newValue - the newValue to set
    • setImage

      public void setImage(RenderedImage[] image)
      Specified by:
      setImage in interface MFImage
    • append

      public void append(RenderedImage[] newValue)
      Places a new SFImage value at the end of the existing value array, increasing the field length accordingly.
      Specified by:
      append in interface MFImage
      Parameters:
      newValue - The newValue to append
    • insertValue

      public void insertValue(int index, RenderedImage newValue)
      Insert a new value prior to the index location in the existing value array, increasing the field length accordingly.
      Specified by:
      insertValue in interface MFImage
      Parameters:
      index - The position for the inserted value in the current array
      newValue - The newValue to insert
    • remove

      public void remove(int index)
      Remove one SFImage element of the field array at index position, if found. Initial element is at index 0.
      Specified by:
      remove in interface MField
      Parameters:
      index - position of element in field array that gets removed
    • clear

      public void clear()
      Removes all values in the field array, changing the array size to zero.
      Specified by:
      clear in interface MField
    • size

      public int size()
      Get the size of the underlying data array. The size is the number of elements for that data type. So for an MFFloat the size would be the number of float values, but for an MFVec3f, it is the number of vectors in the returned array (where a vector is 3 consecutive array indexes in a flat array).
      Specified by:
      size in interface MField
      Returns:
      The number of elements in this field array.
    • setValue

      public MFImage setValue(MFImage newValue)
      Apply an MFImage value to this field.
      Parameters:
      newValue - The newValue to apply
      Returns:
      MFImage - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • isDefaultValue

      public boolean isDefaultValue()
      Determine whether current value matches DEFAULT_VALUE
      Returns:
      whether current value matches DEFAULT_VALUE
      See Also: