cz.cuni.jagrlib.testing
Class PhotonMap

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.testing.PhotonMap
All Implemented Interfaces:
Breakable, LightMap, Property, Template

public class PhotonMap
extends Piece
implements LightMap

Module for photon storing. Primary intended for photon mapping application.

Since:
0.26
See Also:
PhotonMap.java

Nested Class Summary
protected static class PhotonMap.Filter
          Supported filters used in a radiance/irradiance estimation.
protected static class PhotonMap.Type
          Types of searching of nearest photons.
protected static class PhotonMap.Volume
          Volumes used for finding photons.
 
Field Summary
protected static double ALPHA
          For Gaussian filte.
protected  double[] bboxMax
          Maximals of bounding box.
protected  double[] bboxMin
          Minimals of bounding box.
protected static double BETA
          For Gaussian filter.
protected static java.lang.String CATEGORY
          Object category.
protected  float[] cosphi
          Cosinus of angle phi.
protected  float[] costheta
          Cosinus of angle theta.
static java.lang.String DIR_ERROR
           
protected  double dirError
          Maximal error of normal and direction of photon is radiance/irradiance estimate.
protected  int estimate
          Maximal number of photons which can be used for radiosity estimate.
static java.lang.String ESTIMATE
           
protected  PhotonMap.Filter filter
          Actual filter for radiance/irradiance estimate.
static java.lang.String FILTER
           
protected  int halfStoredPhotons
          Half of stored photons.
protected  boolean isBalanced
          Was the photon map balanced?
protected  boolean isInit
          Was the photon map initialized?
protected  double k
          Filter constant characterizing the cone filter.
static java.lang.String K
           
static java.lang.String LOG_ESTIMATE
           
static java.lang.String LOG_PHOTONS
           
protected  boolean logEstimate
          Log information about estimates?
protected  boolean logPhotons
          Log all photons stored in photon map?
static java.lang.String MAX_PHOTONS
           
protected  int maxPhotons
          Maximal number of stored photons.
protected  cz.cuni.jagrlib.testing.PhotonMap.Photon[] photon
          The list of photons stored in the photon map.
protected  int prevScale
          Number of already scaled photons.
protected  double radius
          Maximal radius of the sphere/circle (maximal distance between estimate point and a photon).
static java.lang.String RADIUS
           
static RegPiece reg
          Static registration instance for this class.
protected  float[] sinphi
          Sinus of angle phi.
protected  float[] sintheta
          Sinus of angle theta.
protected  int storedPhotons
          Number of stored photons.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
protected  PhotonMap.Type type
          Actual type of searching nearest photons.
static java.lang.String TYPE
           
protected  PhotonMap.Volume volume
          Actual volume used for finding photons.
static java.lang.String VOLUME
           
 
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
PhotonMap()
           
 
Method Summary
 void addPencil(double[] center, double[][] dir, float[] radiance, double distance)
          Add single pencil.
 void addPhoton(double[] origin, double[] dir, float[] power)
          Add single photon.
 void addRadiosity(int handle, float[] amount)
          Add single contribution of energy to the some element.
 void addRays(double[] origin, double[] dir)
          Add single ray.
protected  void balance()
          Creates a left-balanced KD-tree from the flat photon array.
protected  void balanceSegment(int index, int start, int end, cz.cuni.jagrlib.testing.PhotonMap.Photon[] organiz, cz.cuni.jagrlib.testing.PhotonMap.Photon[] balance)
          Recursively balances KD-tree.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int getNumberElements()
          Returns number of saved elements.
 int getNumberPencils()
          Returns number of saved pencils.
 int getNumberPhotons()
          Returns number of saved photons.
 int getNumberRays()
          Returns number of saved rays.
 double[] irradiance(double[] position, double[] normal, double[] irrad)
          Computes irradiance at some point.
 boolean isFull()
          Is light map full?
protected  cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons locatePhotons(int index, cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons np)
          Finds the nearest photons in the photon map under the given conditions (np).
protected  cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons locatePhotons(cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons np)
          Finds the nearest photons in the photon map under the given conditions (np).
protected  void medianSplit(int start, int end, int median, int axis, cz.cuni.jagrlib.testing.PhotonMap.Photon[] p)
          Splits photon array into two separates pieces around the median, with all photons below the median in the lower half and all photons above the median in the upper half.
protected  double[] photonDir(cz.cuni.jagrlib.testing.PhotonMap.Photon p, double[] dir)
          Returns the direction of a photon.
protected  void prepare()
           
 double[] radiance(double[] position, double[] dir, double[] rad)
          Computes irradiance at some point.
 float[] radiosity(int handle)
          Computes the radiosity of the single element.
 void scalePhotonPower(float scale)
          Scales the power of all photons in the once they have been emitted from the light source.
 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.
protected  void swap(cz.cuni.jagrlib.testing.PhotonMap.Photon[] ph, int a, int b)
          Swap two photons (a, b) in the list.
 
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

volume

protected PhotonMap.Volume volume
Actual volume used for finding photons.


filter

protected PhotonMap.Filter filter
Actual filter for radiance/irradiance estimate.


type

protected PhotonMap.Type type
Actual type of searching nearest photons.


maxPhotons

protected int maxPhotons
Maximal number of stored photons.


storedPhotons

protected int storedPhotons
Number of stored photons.


halfStoredPhotons

protected int halfStoredPhotons
Half of stored photons.


photon

protected cz.cuni.jagrlib.testing.PhotonMap.Photon[] photon
The list of photons stored in the photon map.


sintheta

protected float[] sintheta
Sinus of angle theta.


costheta

protected float[] costheta
Cosinus of angle theta.


sinphi

protected float[] sinphi
Sinus of angle phi.


cosphi

protected float[] cosphi
Cosinus of angle phi.


bboxMin

protected double[] bboxMin
Minimals of bounding box.


bboxMax

protected double[] bboxMax
Maximals of bounding box.


prevScale

protected int prevScale
Number of already scaled photons.


estimate

protected int estimate
Maximal number of photons which can be used for radiosity estimate.


radius

protected double radius
Maximal radius of the sphere/circle (maximal distance between estimate point and a photon).


dirError

protected double dirError
Maximal error of normal and direction of photon is radiance/irradiance estimate. If it's used sphere, values should be between -1.0 and 0.0. 0.0 means that every photon on the surface which is directed towards the object (dot product of normal and direction is negative) is used. This could cause some visual problems in the corners, that's why should be this coefficient smaller than 0.0. On the other hand, if it's used disc, this coefficient has to be positive. Maximal value should be something about 0.1 (greater value cause same problems as sphere).


k

protected double k
Filter constant characterizing the cone filter. Must be equal or greater than one.


isInit

protected boolean isInit
Was the photon map initialized?


isBalanced

protected boolean isBalanced
Was the photon map balanced?


logEstimate

protected boolean logEstimate
Log information about estimates?


logPhotons

protected boolean logPhotons
Log all photons stored in photon map?


ALPHA

protected static final double ALPHA
For Gaussian filte.

See Also:
Constant Field Values

BETA

protected static final double BETA
For Gaussian filter.

See Also:
Constant Field Values

VOLUME

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

TYPE

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

FILTER

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

MAX_PHOTONS

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

ESTIMATE

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

RADIUS

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

DIR_ERROR

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

K

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

LOG_ESTIMATE

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

LOG_PHOTONS

public static final java.lang.String LOG_PHOTONS
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

PhotonMap

public PhotonMap()
Method Detail

prepare

protected void prepare()

locatePhotons

protected cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons locatePhotons(int index,
                                                                         cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons np)
Finds the nearest photons in the photon map under the given conditions (np).

Parameters:
index - Index of starting photon.
np - NearestPhotons class as a photon-store.

locatePhotons

protected cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons locatePhotons(cz.cuni.jagrlib.testing.PhotonMap.NearestPhotons np)
Finds the nearest photons in the photon map under the given conditions (np).

Parameters:
index - Index of starting photon.
np - NearestPhotons class as a photon-store.

photonDir

protected double[] photonDir(cz.cuni.jagrlib.testing.PhotonMap.Photon p,
                             double[] dir)
Returns the direction of a photon.


scalePhotonPower

public void scalePhotonPower(float scale)
Scales the power of all photons in the once they have been emitted from the light source.

Specified by:
scalePhotonPower in interface LightMap

balance

protected void balance()
Creates a left-balanced KD-tree from the flat photon array. These functions should be called before the photon map is used for rendering.


medianSplit

protected void medianSplit(int start,
                           int end,
                           int median,
                           int axis,
                           cz.cuni.jagrlib.testing.PhotonMap.Photon[] p)
Splits photon array into two separates pieces around the median, with all photons below the median in the lower half and all photons above the median in the upper half.

Parameters:
start - Start of photon block in array.
end - End of photon block in array.
median - Desired median number.
axis - Axis to split along.
p - Photons for splitting.

balanceSegment

protected void balanceSegment(int index,
                              int start,
                              int end,
                              cz.cuni.jagrlib.testing.PhotonMap.Photon[] organiz,
                              cz.cuni.jagrlib.testing.PhotonMap.Photon[] balance)
Recursively balances KD-tree.

Parameters:
index -
start - Start of photon block in array.
end - End of photon block in array.
organiz - Array for organization of photons which is used when splitting comes up (input variable).
balance - Balanced array of photons (output variable).

swap

protected void swap(cz.cuni.jagrlib.testing.PhotonMap.Photon[] ph,
                    int a,
                    int b)
Swap two photons (a, b) in the list.


addPhoton

public void addPhoton(double[] origin,
                      double[] dir,
                      float[] power)
Add single photon.

Specified by:
addPhoton in interface LightMap

addRays

public void addRays(double[] origin,
                    double[] dir)
Add single ray.

Specified by:
addRays in interface LightMap

addPencil

public void addPencil(double[] center,
                      double[][] dir,
                      float[] radiance,
                      double distance)
Add single pencil.

Specified by:
addPencil in interface LightMap

addRadiosity

public void addRadiosity(int handle,
                         float[] amount)
Add single contribution of energy to the some element.

Specified by:
addRadiosity in interface LightMap

radiance

public double[] radiance(double[] position,
                         double[] dir,
                         double[] rad)
Computes irradiance at some point.

Specified by:
radiance in interface LightMap
Parameters:
position - Position of point in which is irradiance computing.
direction -
rad - Pre-allocated array to hold resulting irradiance.
Returns:
Resulting irradiance.

irradiance

public double[] irradiance(double[] position,
                           double[] normal,
                           double[] irrad)
Computes irradiance at some point.

Specified by:
irradiance in interface LightMap
Parameters:
position - Position of point in which is irradiance computing.
irrad - Pre-allocated array to hold resulting irradiance.
Returns:
Resulting irradiance.

radiosity

public float[] radiosity(int handle)
Computes the radiosity of the single element.

Specified by:
radiosity in interface LightMap

getNumberPhotons

public int getNumberPhotons()
Returns number of saved photons.

Specified by:
getNumberPhotons in interface LightMap

getNumberRays

public int getNumberRays()
Returns number of saved rays.

Specified by:
getNumberRays in interface LightMap

getNumberPencils

public int getNumberPencils()
Returns number of saved pencils.

Specified by:
getNumberPencils in interface LightMap

getNumberElements

public int getNumberElements()
Returns number of saved elements.

Specified by:
getNumberElements in interface LightMap

isFull

public boolean isFull()
Is light map full?

Specified by:
isFull in interface LightMap

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.