jpview
Class Utils

java.lang.Object
  extended by jpview.Utils

public class Utils
extends java.lang.Object

The Utils class provides static convenience methods

Author:
Default

Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String asString(double[] a)
          Return a string representation of a double array
static java.lang.String asString(float[] a)
          Returns a string representation of an array of floats
static java.lang.String asString(int[] a)
          Returns a string representation of an array of ints
static java.awt.image.BufferedImage blurImageSimple(java.awt.image.BufferedImage image, int kSize)
          Applies a simple blur to an image
static int clamp(int i)
          clamp to 8-bit int
static java.awt.image.BufferedImage createBufferedImage(int[] pixels, int scanline)
          Creates a buffered image from an array of pixels
static java.awt.image.BufferedImage createBufferedImage(Vec3f[] pixels, int scanline)
          Creates a buffered image from an array of Vec3f objects
static double dot3(double[] a, double[] b)
          Calulates the dot product of two 3 element double arrays
static float dot3(float[] a, float[] b)
          Calulates the dot product of two 3 element float arrays
static java.awt.image.BufferedImage gaussianBlur(java.awt.image.BufferedImage image, int kSize, float sigma)
          Applies a gaussian blur to a buffered image
static int[] grabPixels(java.awt.image.BufferedImage image)
          Returns a reference to the data buffer for the buffered image
static int indexOfMax(double[] a)
          Finds the element in an array with the maximum value
static Vec3f[] intToVec(int[] a)
          Creates an array of Vec3f (rgb) values from a pixel buffer
static void main(java.lang.String[] args)
          Main method for testing
static float[] normalize(float x, float y, float z)
          normalize three float values - divide by euclidean length
static double[] normalize3(double[] a)
          normalize an array of three doubles - divide by euclidean length
static float[] normalize3(float[] a)
          normalize an array of three floats - divide by euclidean length
static java.awt.image.BufferedImage readUnbuffered(java.io.InputStream is)
          Reads an input stream into a byte array without any buffering.
static double[] reflect(double[] normal, double[] incedent)
          Calculates the reflection vector based on the input normal and incedent
static float[] reflect(float[] normal, float[] incedent)
          Calculates the reflection vector based on the input normal and incedent
static double[] scalarMult3(double[] a, double s)
          Multiplies a vector of 3 doubles by a scalar value
static float[] scalarMult3(float[] a, float s)
          Multiplies a vector of 3 floats by a scalar value
static int unsignedByteToInt(byte b)
          create an integer representation of an unsigned byte
static double[] vecSum3(double[] a, double[] b)
          Returns the sum of two 3 component double vectors
static float[] vecSum3(float[] a, float[] b)
          Returns the sum of two 3 component float vectors
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

indexOfMax

public static int indexOfMax(double[] a)
Finds the element in an array with the maximum value

Parameters:
a - The array to search
Returns:
the index of the maximum value

clamp

public static int clamp(int i)
clamp to 8-bit int

Parameters:
i - the integer to clamp
Returns:
the clamped value

normalize3

public static float[] normalize3(float[] a)
normalize an array of three floats - divide by euclidean length

Parameters:
a - the array of floats
Returns:
a normalized array

normalize3

public static double[] normalize3(double[] a)
normalize an array of three doubles - divide by euclidean length

Parameters:
a - the array of three doubles (x, y, z)
Returns:
a normalized array

normalize

public static float[] normalize(float x,
                                float y,
                                float z)
normalize three float values - divide by euclidean length

Parameters:
x - value for x
y - value for y
z - value for z
Returns:
an array of float representing the normalized (x,y,z) values

asString

public static java.lang.String asString(double[] a)
Return a string representation of a double array

Parameters:
a - the array of doubles
Returns:
a string representation of the array

asString

public static java.lang.String asString(float[] a)
Returns a string representation of an array of floats

Parameters:
a - the array of floats for input
Returns:
a string representation of the input array

asString

public static java.lang.String asString(int[] a)
Returns a string representation of an array of ints

Parameters:
a - the array of ints for input
Returns:
string representation of the input

unsignedByteToInt

public static int unsignedByteToInt(byte b)
create an integer representation of an unsigned byte

Parameters:
b - the unsigned byte
Returns:
the integer representation

reflect

public static float[] reflect(float[] normal,
                              float[] incedent)
Calculates the reflection vector based on the input normal and incedent

Parameters:
normal - the normal vector
incedent - the incedenct vector
Returns:
the reflection vector

reflect

public static double[] reflect(double[] normal,
                               double[] incedent)
Calculates the reflection vector based on the input normal and incedent

Parameters:
normal - the normal vector
incedent - the incedent vector
Returns:
the reflection vector

vecSum3

public static float[] vecSum3(float[] a,
                              float[] b)
Returns the sum of two 3 component float vectors

Parameters:
a - the first vector
b - the second vector
Returns:
sum of the first and second vector

vecSum3

public static double[] vecSum3(double[] a,
                               double[] b)
Returns the sum of two 3 component double vectors

Parameters:
a - the first vector
b - the second vector
Returns:
the sum of the first and the second vector

scalarMult3

public static float[] scalarMult3(float[] a,
                                  float s)
Multiplies a vector of 3 floats by a scalar value

Parameters:
a - the vector of three floats
s - the scalar value
Returns:
the product of the vector and the scalar

scalarMult3

public static double[] scalarMult3(double[] a,
                                   double s)
Multiplies a vector of 3 doubles by a scalar value

Parameters:
a - the vector of 3 doubles
s - the scalar value
Returns:
product of the vector and the scalar

dot3

public static float dot3(float[] a,
                         float[] b)
Calulates the dot product of two 3 element float arrays

Parameters:
a - the first float array
b - the second float array
Returns:
the dot product of a and b

dot3

public static double dot3(double[] a,
                          double[] b)
Calulates the dot product of two 3 element double arrays

Parameters:
a - the first double array
b - the second double array
Returns:
the dot product

readUnbuffered

public static java.awt.image.BufferedImage readUnbuffered(java.io.InputStream is)
                                                   throws java.io.IOException
Reads an input stream into a byte array without any buffering. Had some trouble with Java's built-ins.

Parameters:
is - the input stream to read
Returns:
a byte array of what was read
Throws:
java.io.IOException - if the input stream can not be read

grabPixels

public static int[] grabPixels(java.awt.image.BufferedImage image)
Returns a reference to the data buffer for the buffered image

Parameters:
image - the buffered image source
Returns:
an array of pixels

gaussianBlur

public static java.awt.image.BufferedImage gaussianBlur(java.awt.image.BufferedImage image,
                                                        int kSize,
                                                        float sigma)
Applies a gaussian blur to a buffered image

Parameters:
image - the image source
kSize - the kernel size
sigma - the sigma value for the blur procedure
Returns:
a new blurred copy of the source image

blurImageSimple

public static java.awt.image.BufferedImage blurImageSimple(java.awt.image.BufferedImage image,
                                                           int kSize)
Applies a simple blur to an image

Parameters:
image - the input image
kSize - the kernel size
Returns:
a blurred copy of the original image

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(int[] pixels,
                                                               int scanline)
Creates a buffered image from an array of pixels

Parameters:
pixels - the array of pixels
scanline - the size of the scanline (width)
Returns:
a new buffered image created from the input

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(Vec3f[] pixels,
                                                               int scanline)
Creates a buffered image from an array of Vec3f objects

Parameters:
pixels - the input array
scanline - the scanline size (width)
Returns:
a new buffered image created from the input array

intToVec

public static Vec3f[] intToVec(int[] a)
Creates an array of Vec3f (rgb) values from a pixel buffer

Parameters:
a - the pixel buffer
Returns:
the Vec3f representation

main

public static void main(java.lang.String[] args)
Main method for testing

Parameters:
args - user defined