cz.cuni.jagrlib.piece
Class MonteCarloFF

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.MonteCarloFF
All Implemented Interfaces:
Breakable, Property, RadiosityBasisFunctions, Template

public class MonteCarloFF
extends Piece
implements RadiosityBasisFunctions

This module provides stochastic Monte Carlo methods (hemisphere sampling, area sampling, area-to-area sampling) for form-factor solving.

See Also:
MonteCarloFF.java, RadiosityBasisFunctions, Brep, BitSet, MicroFacet

Nested Class Summary
static class MonteCarloFF.Sampling
          Supported sampling methods.
 
Field Summary
protected  double[] area
          Element areas.
protected  int attrNormal
          Actual vertex-normal attribute.
protected  Brep brep
          Accelerator: input B-rep database.
static java.lang.String CACHE_SIZE
           
protected  int cacheSize
          How many rows will be cached?
protected static java.lang.String CATEGORY
          Object category.
protected  int ctx
          Actual Brep context.
protected  double[][] fullCache
          Full row-cache in case of cacheSize >= num.
protected  GeometrySearch geom
          Accelerator: scene optimalization.
protected  boolean isInit
          Accelerators are initialized?
static java.lang.String NUMBER_RAYS
           
protected  int numRays
          Number of rays, which are shooted from one element.
static RegPiece reg
          Static registration instance for this class.
protected  RandomJames rnd
          Random number generator.
protected  LRUCache<double[]> rowCache
          FF row cache.
protected  MonteCarloFF.Sampling sampling
          Actual sampling method.
static java.lang.String SAMPLING
           
protected  Solid solid
          Accelerator: intersection computing.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Constructor Summary
MonteCarloFF()
           
 
Method Summary
protected  void assertAreas()
          Computes areas of all elements (if necessary).
 int coefficientsFromElement(int elem, int[] result)
          Returns coefficient indexes defining the given element.
 java.util.BitSet coefficientsFromElements(java.util.BitSet elements, java.util.BitSet result)
          Returns set of coefficients defining the given set of elements.
 double[] distribute(int elem, double[] coords, double[] result)
          Computes distribution coefficients for the single point of the element.
 double elementArea(int i)
          Computes area of the given element (triangle is presumed) .
 int elementsFromCoefficient(int coeff, int[] result)
          Returns elements which are affected by the given single coefficient.
 java.util.BitSet elementsFromCoefficients(java.util.BitSet coefficients, java.util.BitSet result)
          Returns set of elements which are affected by the given set of coefficients.
 double formFactor(int from, int to)
          Computes single form-factor (F_{from,to}).
 int formFactorsFrom(int coeff, int[] ind, double[] ff)
          Computes "shooting" form-factors (single source coefficient is fixed).
 int formFactorsTo(int coeff, int[] ind, double[] ff)
          Computes "gathering" form-factors (single target coefficient is fixed).
protected  double[] generateRays(int coeff, double[][] origin, double[][] direction)
          Generates required number of rays for shooting throught the hemisphere.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int getOrder()
          Order of the approximation (for information purposes only).
protected  double[][] getVertices(int handle, double[][] vertex)
          Return coords of all vertices of the triangle.
protected  boolean init()
          Initialize accelerators..
protected  double[] randomWeighted(double[][] v, double[][] dir)
          Generate uniform random directions by random generating numbers.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 int totalCoefficients()
          Total number of coefficients.
 int totalElements()
          Total number of elements in the scene.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rowCache

protected LRUCache<double[]> rowCache
FF row cache.


fullCache

protected double[][] fullCache
Full row-cache in case of cacheSize >= num.


cacheSize

protected int cacheSize
How many rows will be cached? (0 for none)


sampling

protected MonteCarloFF.Sampling sampling
Actual sampling method.


brep

protected Brep brep
Accelerator: input B-rep database.


solid

protected Solid solid
Accelerator: intersection computing.


geom

protected GeometrySearch geom
Accelerator: scene optimalization.


ctx

protected int ctx
Actual Brep context.


attrNormal

protected int attrNormal
Actual vertex-normal attribute.


rnd

protected final RandomJames rnd
Random number generator.


numRays

protected int numRays
Number of rays, which are shooted from one element.


area

protected double[] area
Element areas.


isInit

protected boolean isInit
Accelerators are initialized?


SAMPLING

public static final java.lang.String SAMPLING
See Also:
Constant Field Values

NUMBER_RAYS

public static final java.lang.String NUMBER_RAYS
See Also:
Constant Field Values

CACHE_SIZE

public static final java.lang.String CACHE_SIZE
See Also:
Constant Field Values

TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

MonteCarloFF

public MonteCarloFF()
Method Detail

getOrder

public int getOrder()
Order of the approximation (for information purposes only). Number of coefficients defining radiosity distribution on single element.

Specified by:
getOrder in interface RadiosityBasisFunctions

coefficientsFromElement

public int coefficientsFromElement(int elem,
                                   int[] result)
Returns coefficient indexes defining the given element.

Specified by:
coefficientsFromElement in interface RadiosityBasisFunctions
Parameters:
elem - Element handle.
result - Pre-allocated integer array to hold result (can be null).
Returns:
Size of result array.

elementsFromCoefficient

public int elementsFromCoefficient(int coeff,
                                   int[] result)
Returns elements which are affected by the given single coefficient.

Specified by:
elementsFromCoefficient in interface RadiosityBasisFunctions
Parameters:
coeff - Coefficient index.
result - Pre-allocated integer array to hold result (can be null).
Returns:
Size of result array.

coefficientsFromElements

public java.util.BitSet coefficientsFromElements(java.util.BitSet elements,
                                                 java.util.BitSet result)
Returns set of coefficients defining the given set of elements.

Specified by:
coefficientsFromElements in interface RadiosityBasisFunctions
Parameters:
elements - Set of elements.
result - Non-mandatory object to be filled.
Returns:
Set of coefficient indices.

elementsFromCoefficients

public java.util.BitSet elementsFromCoefficients(java.util.BitSet coefficients,
                                                 java.util.BitSet result)
Returns set of elements which are affected by the given set of coefficients.

Specified by:
elementsFromCoefficients in interface RadiosityBasisFunctions
Parameters:
coefficients - Set of coefficients.
result - Non-mandatory object to be filled.
Returns:
Set of element handles.

distribute

public double[] distribute(int elem,
                           double[] coords,
                           double[] result)
Computes distribution coefficients for the single point of the element.

Specified by:
distribute in interface RadiosityBasisFunctions
Parameters:
elem - Element handle.
coords - World-space (?) coordinates of the point lying on the given element.
result - Non-mandatory pre-allocated array to hold result.
Returns:
Distribution multiplicators (coefficient indices match the result of coefficientsFromElement(int, int[])).

totalElements

public int totalElements()
Total number of elements in the scene.

Specified by:
totalElements in interface RadiosityBasisFunctions

totalCoefficients

public int totalCoefficients()
Total number of coefficients.

Specified by:
totalCoefficients in interface RadiosityBasisFunctions

formFactorsFrom

public int formFactorsFrom(int coeff,
                           int[] ind,
                           double[] ff)
Computes "shooting" form-factors (single source coefficient is fixed).

Specified by:
formFactorsFrom in interface RadiosityBasisFunctions
Parameters:
coeff - Source-coefficient index.
ind - Array to hold affected (lit) coefficient indices (can be null).
ff - Array to hold respective form-factors (can be null).
Returns:
Number of coefficients lit.

formFactorsTo

public int formFactorsTo(int coeff,
                         int[] ind,
                         double[] ff)
Computes "gathering" form-factors (single target coefficient is fixed).

Specified by:
formFactorsTo in interface RadiosityBasisFunctions
Parameters:
coeff - Target-coefficient index.
ind - Array to hold relevant (visible) coefficient indices (can be null).
ff - Array to hold respective form-factors (can be null).
Returns:
Number of relevant coefficients.

formFactor

public double formFactor(int from,
                         int to)
Computes single form-factor (F_{from,to}). Works only with triangle faces..

Specified by:
formFactor in interface RadiosityBasisFunctions

init

protected boolean init()
Initialize accelerators..


elementArea

public double elementArea(int i)
Computes area of the given element (triangle is presumed) .


getVertices

protected double[][] getVertices(int handle,
                                 double[][] vertex)
Return coords of all vertices of the triangle.


assertAreas

protected void assertAreas()
Computes areas of all elements (if necessary).


generateRays

protected double[] generateRays(int coeff,
                                double[][] origin,
                                double[][] direction)
Generates required number of rays for shooting throught the hemisphere.

Parameters:
coeff - ID of element, which is shooting ray.
origin - Pre-allocated array to hold sampling points on element in world coordinates.
direction - Pre-allocated array to hold sampling points on hemisphere or area in world coordinates.

randomWeighted

protected double[] randomWeighted(double[][] v,
                                  double[][] dir)
Generate uniform random directions by random generating numbers.

Parameters:
v - World-space coordinates of the triangle vertices.
dir - Pre-allocated array to hold normalized direction of ray in tangent space.
Returns:
Weight vector or null if all rays are equally important.

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.