cz.cuni.jagrlib.testing
Class MonteCarlo

java.lang.Object
  extended by cz.cuni.jagrlib.testing.MonteCarlo

public class MonteCarlo
extends java.lang.Object

Monte Carlo methods.

Since:
0.24
See Also:
MonteCarlo.java

Field Summary
protected static RandomJames rnd
          Random number generator.
 
Constructor Summary
MonteCarlo()
           
 
Method Summary
static double balanceHeuristic(double f, double pdfF, double g, double pdfG)
          Balance heuristic.
static double[] concentricSampleDisk(double ksi1, double ksi2, double[] result)
          Samples concentric disk.
static double[] cosineSampleHemisphere(double ksi1, double ksi2, double[] result)
          Samples hemisphere according to the cosine-distribution.
static double lerp(double t, double v1, double v2)
           
static double powerHeuristic(double f, double pdfF, double g, double pdfG)
          Power heuristic.
static double[] randomPointFromTriangle(double u, double v, double[] a, double[] b, double[] c, double[] result)
          Generates random point in the given triangle.
static boolean sameHemisphere(double[] in, double[] normal, double[] out)
          Are these directions on the same side of hemisphere.
static double[] sampleSquare(double u, double v, double[] vertUR, double[] vertUL, double[] vertLL, double[] vertLR, double[] pos)
          Generates point on the light.
static double[] uniformSampleCone(double u, double v, double cosThetaMax, double[] result)
          Uniformly samples cone.
static double[] uniformSampleHemisphere(double ksi1, double ksi2, double[] result)
          Samples hemisphere uniformly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rnd

protected static final RandomJames rnd
Random number generator.

Constructor Detail

MonteCarlo

public MonteCarlo()
Method Detail

uniformSampleHemisphere

public static double[] uniformSampleHemisphere(double ksi1,
                                               double ksi2,
                                               double[] result)
Samples hemisphere uniformly.


cosineSampleHemisphere

public static double[] cosineSampleHemisphere(double ksi1,
                                              double ksi2,
                                              double[] result)
Samples hemisphere according to the cosine-distribution.


concentricSampleDisk

public static double[] concentricSampleDisk(double ksi1,
                                            double ksi2,
                                            double[] result)
Samples concentric disk.


sampleSquare

public static double[] sampleSquare(double u,
                                    double v,
                                    double[] vertUR,
                                    double[] vertUL,
                                    double[] vertLL,
                                    double[] vertLR,
                                    double[] pos)
Generates point on the light.


randomPointFromTriangle

public static final double[] randomPointFromTriangle(double u,
                                                     double v,
                                                     double[] a,
                                                     double[] b,
                                                     double[] c,
                                                     double[] result)
Generates random point in the given triangle. Works in either dimension (2D, 3D).

Parameters:
a - Triangle vertex A.
b - Triangle vertex B.
c - Triangle vertex C.
result - Pre-allocated result array (can be null).
Returns:
Random point or null in case of failure.

uniformSampleCone

public static double[] uniformSampleCone(double u,
                                         double v,
                                         double cosThetaMax,
                                         double[] result)
Uniformly samples cone.

Parameters:
u - Uniform random number.
v - Uniform random number.
cosThetaMax - Maximal possible cosinus of angle theta.
dir - Pre-allocated array to hold result.
Returns:
Point on the cone.

sameHemisphere

public static boolean sameHemisphere(double[] in,
                                     double[] normal,
                                     double[] out)
Are these directions on the same side of hemisphere.


lerp

public static double lerp(double t,
                          double v1,
                          double v2)

balanceHeuristic

public static double balanceHeuristic(double f,
                                      double pdfF,
                                      double g,
                                      double pdfG)
Balance heuristic.

Parameters:
f - Function f.
pdfF - Underlying probability density function of f.
g - Function g.
pdfG - Underlying probability density function of g.
Returns:
Weight of the f function.

powerHeuristic

public static double powerHeuristic(double f,
                                    double pdfF,
                                    double g,
                                    double pdfG)
Power heuristic.

Parameters:
f - Function f.
pdfF - Underlying probability density function of f.
g - Function g.
pdfG - Underlying probability density function of g.
Returns:
Weight of the f function.