cz.cuni.jagrlib
Class Formula

java.lang.Object
  extended by cz.cuni.jagrlib.Formula

public class Formula
extends java.lang.Object

Mathematical support (excluding geometric stuff - see Geometry class).

Since:
0.24
See Also:
Formula.java

Field Summary
static int BLUE_WEIGHT
          Blue importance weight.
protected static int[] exp
           
static int FIRST_PRIMES
          Number of prime numbers in smallPrimes array.
static java.text.NumberFormat fmtDouble
           
static java.text.NumberFormat fmtInt
           
static int GREEN_WEIGHT
          Green importance weight.
static HashFunction hashFunction
          Hash-function instance (accelerator).
static java.lang.String LINE_SEPARATOR
          Line separator string.
static byte[] LINE_SEPARATOR_BYTES
          Line separator as byte array.
protected static int[] primes
          Prime numbers - approximately geometric sequence.
protected static int PRIMES_MAX
           
static int RED_WEIGHT
          Red importance weight.
static int[] smallPrimes
          First prime numbers for hashing steps.
static double WEIGHT_INVERSE
          Importance weight total inverse.
static int WEIGHT_SHIFT
          Importance weight shift.
static int WEIGHT_TOTAL
          Importance weight total.
 
Constructor Summary
Formula()
           
 
Method Summary
static int argMax(double[] array)
          Return index of array item with maximum absolute value.
static int bits(long n)
          Computes number of bits to represent the given number of possibilities (log_2{n} rounded up).
static double clamp(double source, double min, double max)
          Clamps the source value to the given range.
static float clamp(float source, float min, float max)
          Clamps the source value to the given range.
static int clamp(int source, int min, int max)
          Clamps the source value to the given range.
static long clamp(long source, long min, long max)
          Clamps the source value to the given range.
static double[] cloneArray(double[] arr)
          Clone the given array of doubles.
static float[] cloneArray(float[] arr)
          Clone the given array of floats.
static int[] cloneArray(int[] arr)
          Clone the given array of integers.
static double[] colorRamp(double x, double[] color)
          Computes double[3] color from the visualization color-ramp.
static float[] colorRamp(double x, float[] color)
          Computes float[3] color from the visualization color-ramp.
static int[] colorRamp(double x, int[] color)
          Computes color from the visualization color-ramp.
static java.lang.String colorToString(java.awt.Color c)
          Returns String representation of the given Color.
static double diagonal(double x, double y, double z)
          Computes diagonal of the rectangle block.
static int findPrime(int from)
          Returns prime number from the predefined sequence.
static double frexp(double x, int[] exp)
          Function for C[++] compatibility: computes normalized mantissa (0.5 to 1.0) and binary exponent from the given floating-point number.
static float frexp(float x, int[] exp)
          Function for C[++] compatibility: computes normalized mantissa (0.5 to 1.0) and binary exponent from the given floating-point number.
static int gcd(int u, int v)
          Computes greates common divisor of two unsigned integers.
static int getSmallPrime(int key)
          Returns small prime number based on the given key (hash).
static int granularity(int value, int granul)
          Returns the given value rounded up to the given granularity.
static int hashClassName(java.lang.Object object)
          Returns hash-number computed from class name of the given instance.
static double[] hsvToRgb(double h, double s, double v, double[] rgb)
          HSV (HSB) to RGB conversion.
static org.nfunk.jep.JEP initExpression(java.lang.String expr)
          Initializes expression to be repeatedly evaluated.
static boolean isIntFormat(java.lang.String fmt)
          Checks format string for numeric type class (integer / floating-point).
static double ldexp(double mant, int exp)
          Function for C[++] compatibility: composes floating-point number from the mantissa and binary exponent.
static float ldexp(float mant, int exp)
          Function for C[++] compatibility: composes floating-point number from the mantissa and binary exponent.
static float loadFloat(byte[] array, int index)
          Reads a float-number from byte-array (used in serialization, PersistentParamsBinary, ..).
static int loadUnsigned16(byte[] array, int index)
          Reads a 16-bit unsigned integer from byte-array (used in serialization, PersistentParamsBinary, ..).
static java.awt.Color parseColor(java.lang.String s)
          Parse textual color representation.
static double[] parseColorDouble(java.lang.String s)
          Parse textual color representation (components are from range [ 0.0, 1.0 ]).
static java.lang.String[] parseStringList(java.lang.String str)
          Parse sequence of (comma, semicolon)-separated quoted strings.
static int percent(long part, long total)
          Returns integer percent value.
static long permutationsWithRepetition(int[] freq)
          freq[] array can contain zeroes..
static double power(double a, int e)
          Computes double-precision number powered to integer exponent.
static java.lang.String relativePath(java.lang.String path)
          Returns path relative to current directory.
static double remainder(double a, double b)
          Computes floating-point remainder which is periodic and positive unlike the Math.IEEEremainder(double, double).
static void RGBeToRGB(byte[] rgbe, int startRgbe, double[] rgb, int startRgb)
          Conversion from Radiance's RGBe 32-bit format into HDR floating-point RGB format.
static double rgbToGray(double r, double g, double b)
          RGB -> gray value convertor.
static int rgbToGray(int r, int g, int b)
          RGB -> gray value convertor.
static double[] rgbToHsv(double r, double g, double b, double[] hsv)
          RGB to HSV (HSB) conversion.
static void RGBToRGBe(byte[] rgbe, int startRgbe, double R, double G, double B)
          Conversion from HDR floating-point RGB format to Radiance's RGBe 32-bit format.
static int round(double a)
          Rounds double number to the nearest integer.
static int storeFloat(byte[] array, int index, float f)
          Converts a float number into four bytes (used in serialization, PersistentParamsBinary, ..).
static int storeUnsigned16(byte[] array, int index, int s)
          Converts a 16-bit unsigned integer into two bytes (used in serialization, PersistentParamsBinary, ..).
static java.lang.String stringValue(java.lang.Object value)
          Converts arbitrary object instance to String representation (for persistance).
static long swapBytes(long a, int bits)
          Swaps the given number (containing multiple of 8 bits).
static java.lang.String timeHMS(double time)
          Converts number of seconds to readable (HH:MM:SS) format.
static double toMega(long n)
          Converts integer number into binary million (Mega) units.
static java.lang.String vectorToString(double[] v)
          Converts double[] vector to readable form.
static java.lang.String vectorToString(int[] v)
          Converts int[] vector to readable form.
static long vlc(int a)
          Returns Variable-length code for the given integer number.
static int vlcInv(long code)
          Returns original signed number from its Variable-length code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static final java.lang.String LINE_SEPARATOR
Line separator string.


LINE_SEPARATOR_BYTES

public static final byte[] LINE_SEPARATOR_BYTES
Line separator as byte array.


fmtInt

public static final java.text.NumberFormat fmtInt

fmtDouble

public static final java.text.NumberFormat fmtDouble

RED_WEIGHT

public static final int RED_WEIGHT
Red importance weight.

See Also:
Constant Field Values

GREEN_WEIGHT

public static final int GREEN_WEIGHT
Green importance weight.

See Also:
Constant Field Values

BLUE_WEIGHT

public static final int BLUE_WEIGHT
Blue importance weight.

See Also:
Constant Field Values

WEIGHT_SHIFT

public static final int WEIGHT_SHIFT
Importance weight shift.

See Also:
Constant Field Values

WEIGHT_TOTAL

public static final int WEIGHT_TOTAL
Importance weight total.

See Also:
Constant Field Values

WEIGHT_INVERSE

public static final double WEIGHT_INVERSE
Importance weight total inverse.

See Also:
Constant Field Values

exp

protected static int[] exp

primes

protected static final int[] primes
Prime numbers - approximately geometric sequence.


PRIMES_MAX

protected static final int PRIMES_MAX

smallPrimes

public static final int[] smallPrimes
First prime numbers for hashing steps.


FIRST_PRIMES

public static final int FIRST_PRIMES
Number of prime numbers in smallPrimes array. Has to be power of two!

See Also:
Constant Field Values

hashFunction

public static HashFunction hashFunction
Hash-function instance (accelerator).

Constructor Detail

Formula

public Formula()
Method Detail

power

public static final double power(double a,
                                 int e)
Computes double-precision number powered to integer exponent.

Parameters:
a - Base.
e - Exponent (all integer values are handled correctly).
Returns:
a to the power of e.

diagonal

public static final double diagonal(double x,
                                    double y,
                                    double z)
Computes diagonal of the rectangle block.


remainder

public static final double remainder(double a,
                                     double b)
Computes floating-point remainder which is periodic and positive unlike the Math.IEEEremainder(double, double).


gcd

public static final int gcd(int u,
                            int v)
Computes greates common divisor of two unsigned integers.


bits

public static final int bits(long n)
Computes number of bits to represent the given number of possibilities (log_2{n} rounded up).


clamp

public static final int clamp(int source,
                              int min,
                              int max)
Clamps the source value to the given range.


clamp

public static final long clamp(long source,
                               long min,
                               long max)
Clamps the source value to the given range.


clamp

public static final float clamp(float source,
                                float min,
                                float max)
Clamps the source value to the given range.


clamp

public static final double clamp(double source,
                                 double min,
                                 double max)
Clamps the source value to the given range.


argMax

public static final int argMax(double[] array)
Return index of array item with maximum absolute value.


round

public static final int round(double a)
Rounds double number to the nearest integer.

For double -> long rounding, use Math.round(double),
for float -> int rounding, use Math.round(float).


vlc

public static final long vlc(int a)
Returns Variable-length code for the given integer number.

0 .. 0, 1 .. 1, -1 .. 2, 2 .. 3, -2 .. 4, etc.


vlcInv

public static final int vlcInv(long code)
Returns original signed number from its Variable-length code.

0 .. 0, 1 .. 1, 2 .. -1, 3 .. 2, 4 .. -2, etc.


percent

public static final int percent(long part,
                                long total)
Returns integer percent value.


granularity

public static final int granularity(int value,
                                    int granul)
Returns the given value rounded up to the given granularity.


ldexp

public static final double ldexp(double mant,
                                 int exp)
Function for C[++] compatibility: composes floating-point number from the mantissa and binary exponent.

See Also:
frexp(double,int[])

ldexp

public static final float ldexp(float mant,
                                int exp)
Function for C[++] compatibility: composes floating-point number from the mantissa and binary exponent.

See Also:
frexp(float,int[])

frexp

public static final double frexp(double x,
                                 int[] exp)
Function for C[++] compatibility: computes normalized mantissa (0.5 to 1.0) and binary exponent from the given floating-point number.

See Also:
ldexp(double,int)

frexp

public static final float frexp(float x,
                                int[] exp)
Function for C[++] compatibility: computes normalized mantissa (0.5 to 1.0) and binary exponent from the given floating-point number.

See Also:
ldexp(float,int)

storeUnsigned16

public static final int storeUnsigned16(byte[] array,
                                        int index,
                                        int s)
Converts a 16-bit unsigned integer into two bytes (used in serialization, PersistentParamsBinary, ..).

Parameters:
array - Target of the conversion.
index - Start index.
s - Number to convert.
Returns:
Index pointing after used space.
See Also:
loadUnsigned16(byte[], int)

loadUnsigned16

public static final int loadUnsigned16(byte[] array,
                                       int index)
Reads a 16-bit unsigned integer from byte-array (used in serialization, PersistentParamsBinary, ..).

Parameters:
array - Source array.
index - Start index.
Returns:
Result read from the array.
See Also:
storeUnsigned16(byte[], int, int)

storeFloat

public static final int storeFloat(byte[] array,
                                   int index,
                                   float f)
Converts a float number into four bytes (used in serialization, PersistentParamsBinary, ..).

Parameters:
array - Target of the conversion.
index - Start index.
f - Floating number to convert.
Returns:
Index pointing after used space.
See Also:
loadFloat(byte[], int)

loadFloat

public static final float loadFloat(byte[] array,
                                    int index)
Reads a float-number from byte-array (used in serialization, PersistentParamsBinary, ..).

Parameters:
array - Source array.
index - Start index.
Returns:
Result read from the array.
See Also:
storeFloat(byte[], int, float)

toMega

public static final double toMega(long n)
Converts integer number into binary million (Mega) units.


permutationsWithRepetition

public static long permutationsWithRepetition(int[] freq)
freq[] array can contain zeroes..


swapBytes

public static long swapBytes(long a,
                             int bits)
Swaps the given number (containing multiple of 8 bits).


initExpression

public static org.nfunk.jep.JEP initExpression(java.lang.String expr)
Initializes expression to be repeatedly evaluated.

Parameters:
expr - String representation of the expression.
Returns:
Expression to be evaluated afterwards.
See Also:
JEP.addVariable(String,double), JEP.getValue()

parseStringList

public static java.lang.String[] parseStringList(java.lang.String str)
Parse sequence of (comma, semicolon)-separated quoted strings.


isIntFormat

public static boolean isIntFormat(java.lang.String fmt)
Checks format string for numeric type class (integer / floating-point). Finds String.format()-like sequence and returns whether it needs integer numeric value.


timeHMS

public static java.lang.String timeHMS(double time)
Converts number of seconds to readable (HH:MM:SS) format.


rgbToGray

public static final int rgbToGray(int r,
                                  int g,
                                  int b)
RGB -> gray value convertor. Keeps original data amplitude..


rgbToGray

public static final double rgbToGray(double r,
                                     double g,
                                     double b)
RGB -> gray value convertor. Keeps original data amplitude..


colorToString

public static final java.lang.String colorToString(java.awt.Color c)
Returns String representation of the given Color.

See Also:
parseColor(java.lang.String)

parseColor

public static final java.awt.Color parseColor(java.lang.String s)
Parse textual color representation. Input format: "[Red;Green;Blue]"

Parameters:
s - Input string in "[Red;Green;Blue]" format.
Returns:
Color object.

parseColorDouble

public static final double[] parseColorDouble(java.lang.String s)
Parse textual color representation (components are from range [ 0.0, 1.0 ]). Input format: "[Red;Green;Blue]"

Parameters:
s - Input string in "[Red;Green;Blue]" format.
Returns:
Color object.

colorRamp

public static final int[] colorRamp(double x,
                                    int[] color)
Computes color from the visualization color-ramp.

Parameters:
x - Ramp position from 0.0 to 1.0.
color - Pre-allocated array to hold result.
Returns:
RGB[A] color.

colorRamp

public static final double[] colorRamp(double x,
                                       double[] color)
Computes double[3] color from the visualization color-ramp.

Parameters:
x - Ramp position from 0.0 to 1.0.
color - Pre-allocated array to hold result.
Returns:
RGB[A] color.

colorRamp

public static final float[] colorRamp(double x,
                                      float[] color)
Computes float[3] color from the visualization color-ramp.

Parameters:
x - Ramp position from 0.0f to 1.0f.
color - Pre-allocated array to hold result.
Returns:
RGB[A] color.

RGBeToRGB

public static final void RGBeToRGB(byte[] rgbe,
                                   int startRgbe,
                                   double[] rgb,
                                   int startRgb)
Conversion from Radiance's RGBe 32-bit format into HDR floating-point RGB format.


RGBToRGBe

public static final void RGBToRGBe(byte[] rgbe,
                                   int startRgbe,
                                   double R,
                                   double G,
                                   double B)
Conversion from HDR floating-point RGB format to Radiance's RGBe 32-bit format.


rgbToHsv

public static final double[] rgbToHsv(double r,
                                      double g,
                                      double b,
                                      double[] hsv)
RGB to HSV (HSB) conversion. RGB values are arbitrary (nonnegative), 0.0 <= H < 360.0, 0.0 <= S <= 1.0 , V has the same magnitude as RGB.


hsvToRgb

public static final double[] hsvToRgb(double h,
                                      double s,
                                      double v,
                                      double[] rgb)
HSV (HSB) to RGB conversion. RGB values are arbitrary (nonnegative), 0.0 <= H < 360.0, 0.0 <= S <= 1.0 , V has the same magnitude as RGB result.


findPrime

public static final int findPrime(int from)
Returns prime number from the predefined sequence.

Parameters:
from - Lower bound (inclusive) for the prime.
Returns:
Prime number greater or equal to from.

getSmallPrime

public static final int getSmallPrime(int key)
Returns small prime number based on the given key (hash).


cloneArray

public static final float[] cloneArray(float[] arr)
Clone the given array of floats.


cloneArray

public static final double[] cloneArray(double[] arr)
Clone the given array of doubles.


cloneArray

public static final int[] cloneArray(int[] arr)
Clone the given array of integers.


vectorToString

public static final java.lang.String vectorToString(int[] v)
Converts int[] vector to readable form.


vectorToString

public static final java.lang.String vectorToString(double[] v)
Converts double[] vector to readable form.


hashClassName

public static final int hashClassName(java.lang.Object object)
Returns hash-number computed from class name of the given instance.


relativePath

public static java.lang.String relativePath(java.lang.String path)
Returns path relative to current directory.


stringValue

public static final java.lang.String stringValue(java.lang.Object value)
Converts arbitrary object instance to String representation (for persistance).