Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

toxic::PhotonMap Class Reference

#include <photonmap.h>

List of all members.

Public Member Functions

 PhotonMap ()
 ~PhotonMap ()
int GetSizeInMemory () const
 Returns the size (in bytes) of the photon map in memory.

void StorePhoton (const sheep::Point3 &position, const Color3 &power, const sheep::Vector3 &direction, const sheep::Vector3 &normal)
void ScalePhotonPower (sheep::Real scale)
void Balance ()
Color3 ComputeRadiance (const Context &context, const sheep::Point3 &point, const sheep::Vector3 &normal, const sheep::Vector3 &outgoing, const ShadingData &shadingdata, sheep::Real max_dist, int max_photons) const
Color3 ApproximateRadiance (const sheep::Point3 &point, const sheep::Vector3 &normal, const ShadingData &shadingdata, sheep::Real max_dist, int max_photons) const
void PrecomputeRadiances (int spacing, sheep::Real max_dist, int max_photons, sheep::ProgressMonitor *progmon=0)
Color3 GetPrecomputedRadiance (const sheep::Point3 &point, const sheep::Vector3 &normal, const ShadingData &shadingdata, sheep::Real max_dist) const
void BuildPhotonDirectionHistogram (const sheep::Point3 &position, const SurfaceBasis &surfacebasis, sheep::Real max_dist, int max_photons, sheep::Real *histogram, int m, int n, sheep::Real *total_power) const
bool WriteToFile (const std::string &filename, sheep::ProgressMonitor *progmon=0) const
 Writes the photon map to disk. Returns true if writing was successful.

int GetPhotonCount () const
const PhotonGetPhoton (int i) const

Static Public Member Functions

PhotonMapCreateFromFile (const std::string &filename, sheep::ProgressMonitor *progmon=0)

Private Types

enum  { BUF_SIZE = 10000 }
 Some buffers used by the IrradianceEstimate() method. More...


Private Member Functions

void median_split (Photon **p, int start, int end, int median, int axis) const
void balance_segment (Photon **pbal, Photon **porg, int index, int start, int end)
void locate_photons (nearest_photons *np, int index) const
void locate_nearest_photon_with_irradiance (const sheep::Vector3 &normal, nearest_photons *np, int index) const

Private Attributes

int m_stored_photons
int m_half_stored_photons
int m_prev_scale
std::vector< Photonm_photons
 The array of photons.

sheep::float32 m_bbox_min [3]
 Bounding box of the photon array.

sheep::float32 m_bbox_max [3]
sheep::float32 * m_dist2_buf
const Photon ** m_index_buf

Static Private Attributes

const std::string m_photon_map_sig = "toxic photon map file version 1"
 Signature string identifying photon map files.


Detailed Description

The photon map implementation is based on the reference implementation provided by Henrik Wann Jensen in his book "Realistic Image Synthesis Using Photon Mapping".

Definition at line 49 of file photonmap.h.


Member Enumeration Documentation

anonymous enum [private]
 

Some buffers used by the IrradianceEstimate() method.

Enumeration values:
BUF_SIZE 

Definition at line 171 of file photonmap.h.


Constructor & Destructor Documentation

PhotonMap::PhotonMap  ) 
 

Definition at line 46 of file photonmap.cpp.

References BUF_SIZE, m_bbox_max, m_bbox_min, m_dist2_buf, m_index_buf, and m_photons.

Referenced by CreateFromFile().

PhotonMap::~PhotonMap  ) 
 

Definition at line 62 of file photonmap.cpp.

References m_dist2_buf, and m_index_buf.


Member Function Documentation

Color3 PhotonMap::ApproximateRadiance const sheep::Point3 point,
const sheep::Vector3 normal,
const ShadingData shadingdata,
sheep::Real  max_dist,
int  max_photons
const
 

Same as the ComputeRadiance() method, except that the surface is considered as a perfect lambertian surface. This method is faster than the ComputeRadiance() method, but it is also less accurate. The point and the surface normal are expressed in world space. The returned value is a radiance (W.m^-2.sr^-1).

Todo:
Let THRESHOLD be a user setting.

Move out of the loop.

Definition at line 235 of file photonmap.cpp.

References BUF_SIZE, fnz(), toxic::Photon::GetIncidentDirection(), toxic::Photon::GetPower(), toxic::Photon::GetSurfaceNormal(), locate_photons(), toxic::PhotonMap::nearest_photons::m_dist2, m_dist2_buf, toxic::PhotonMap::nearest_photons::m_found, toxic::PhotonMap::nearest_photons::m_got_heap, toxic::PhotonMap::nearest_photons::m_index, m_index_buf, toxic::PhotonMap::nearest_photons::m_max, toxic::PhotonMap::nearest_photons::m_position, toxic::ShadingData::m_reflectance, and sheep::PI.

Referenced by PrecomputeRadiances().

void PhotonMap::Balance  ) 
 

Creates a left-balanced kd-tree from the flat array of photons. This function must be called prior to calling any of the ComputeRadiance(), ApproximateRadiance(), PrecomputeRadiances() and GetPrecomputedRadiance() methods.

Todo:
Warning: this is not portable.

Definition at line 113 of file photonmap.cpp.

References balance_segment(), m_half_stored_photons, m_photons, and m_stored_photons.

Referenced by main().

void PhotonMap::balance_segment Photon **  pbal,
Photon **  porg,
int  index,
int  start,
int  end
[private]
 

See "Realistic Image Synthesis Using Photon Mapping" chapter 6 for an explanation of this function.

Definition at line 617 of file photonmap.cpp.

References m_bbox_max, m_bbox_min, toxic::Photon::m_position, median_split(), and toxic::Photon::SetSplittingPlaneAxis().

Referenced by Balance().

void PhotonMap::BuildPhotonDirectionHistogram const sheep::Point3 position,
const SurfaceBasis surfacebasis,
sheep::Real  max_dist,
int  max_photons,
sheep::Real histogram,
int  m,
int  n,
sheep::Real total_power
const
 

Definition at line 365 of file photonmap.cpp.

References toxic::Color3::Average(), BUF_SIZE, toxic::Photon::GetIncidentDirection(), toxic::SurfaceBasis::GetNormal(), toxic::Photon::GetPower(), toxic::Photon::GetSurfaceNormal(), sheep::Vector3::IsUnitLength(), locate_photons(), toxic::PhotonMap::nearest_photons::m_dist2, m_dist2_buf, toxic::PhotonMap::nearest_photons::m_found, toxic::PhotonMap::nearest_photons::m_got_heap, toxic::PhotonMap::nearest_photons::m_index, m_index_buf, toxic::PhotonMap::nearest_photons::m_max, toxic::PhotonMap::nearest_photons::m_position, sheep::Vector3::m_y, min(), sheep::PI, toxic::SurfaceBasis::TransformToLocal(), and toxic::VectorToSphericalCoords().

Color3 PhotonMap::ComputeRadiance const Context context,
const sheep::Point3 point,
const sheep::Vector3 normal,
const sheep::Vector3 outgoing,
const ShadingData shadingdata,
sheep::Real  max_dist,
int  max_photons
const
 

Computes the radiance reflected toward a given direction due to the photon density on a given surface, around a given point. This is the slowest but the most accurate method to compute the reflected radiance in a given direction. The point, the surface normal and the outgoing direction are expressed in world space. The outgoing direction is such that it leaves the surface, and it is unit-length. The returned value is a radiance (W.m^-2.sr^-1).

Todo:
Let THRESHOLD be a user setting.

Missing cosine factor?

Definition at line 161 of file photonmap.cpp.

References BUF_SIZE, toxic::IBDF::Evaluate(), fnz(), toxic::Photon::GetIncidentDirection(), toxic::Photon::GetPower(), toxic::Photon::GetSurfaceNormal(), locate_photons(), toxic::ShadingData::m_bdf, toxic::PhotonMap::nearest_photons::m_dist2, m_dist2_buf, toxic::PhotonMap::nearest_photons::m_found, toxic::PhotonMap::nearest_photons::m_got_heap, toxic::PhotonMap::nearest_photons::m_index, m_index_buf, toxic::PhotonMap::nearest_photons::m_max, toxic::PhotonMap::nearest_photons::m_position, toxic::ShadingData::m_reflectance, sheep::PI, and toxic::SurfaceBasis::TransformToLocal().

Referenced by toxic::Renderer::compute_caustics(), and toxic::Renderer::compute_indirect_illumination().

PhotonMap * PhotonMap::CreateFromFile const std::string &  filename,
sheep::ProgressMonitor progmon = 0
[static]
 

Creates a photon map by reading it from disk. Returns a pointer to the newly created photon map if successful, and 0 otherwise.

Definition at line 511 of file photonmap.cpp.

References sheep::BinaryStream::IsOpen(), m_bbox_max, m_bbox_min, m_half_stored_photons, m_photon_map_sig, m_photons, m_stored_photons, PhotonMap(), PHOTONMAP_IO_BUFFER_SIZE, sheep::BinaryStream::Read(), toxic::Photon::ReadFromStream(), and sheep::BinaryStream::SetBufferSize().

Referenced by main().

const Photon & PhotonMap::GetPhoton int  i  )  const [inline]
 

Definition at line 250 of file photonmap.h.

int PhotonMap::GetPhotonCount  )  const [inline]
 

Definition at line 245 of file photonmap.h.

Referenced by main().

Color3 PhotonMap::GetPrecomputedRadiance const sheep::Point3 point,
const sheep::Vector3 normal,
const ShadingData shadingdata,
sheep::Real  max_dist
const
 

Same as the ApproximateRadiance() method, but several times faster. The point and the surface normal are expressed in world space. The returned value is a radiance (W.m^-2.sr^-1). Be sure to call the PrecomputeRadiances() method prior to calling this method.

Definition at line 337 of file photonmap.cpp.

References toxic::Photon::GetPrecomputedRadiance(), locate_nearest_photon_with_irradiance(), toxic::PhotonMap::nearest_photons::m_dist2, m_dist2_buf, toxic::PhotonMap::nearest_photons::m_index, m_index_buf, toxic::PhotonMap::nearest_photons::m_position, and toxic::ShadingData::m_reflectance.

Referenced by toxic::Renderer::compute_indirect_illumination().

int PhotonMap::GetSizeInMemory  )  const
 

Returns the size (in bytes) of the photon map in memory.

Definition at line 67 of file photonmap.cpp.

References BUF_SIZE, and m_photons.

Referenced by main().

void PhotonMap::locate_nearest_photon_with_irradiance const sheep::Vector3 normal,
nearest_photons np,
int  index
const [private]
 

Definition at line 785 of file photonmap.cpp.

References toxic::Photon::GetSplittingPlaneAxis(), toxic::Photon::GetSurfaceNormal(), toxic::Photon::HasPrecomputedRadiance(), toxic::PhotonMap::nearest_photons::m_dist2, m_half_stored_photons, toxic::PhotonMap::nearest_photons::m_index, m_photons, toxic::Photon::m_position, and toxic::PhotonMap::nearest_photons::m_position.

Referenced by GetPrecomputedRadiance().

void PhotonMap::locate_photons nearest_photons np,
int  index
const [private]
 

locate_photons() finds the nearest photons in the photon map given the parameters in np.

Todo:
The 'pane' global illumination renderer (http://www.csit.fsu.edu/~beason/pane) does a check here. Check whether or not this is relevant.

Definition at line 677 of file photonmap.cpp.

References toxic::Photon::GetSplittingPlaneAxis(), toxic::PhotonMap::nearest_photons::m_dist2, toxic::PhotonMap::nearest_photons::m_found, toxic::PhotonMap::nearest_photons::m_got_heap, m_half_stored_photons, toxic::PhotonMap::nearest_photons::m_index, toxic::PhotonMap::nearest_photons::m_max, m_photons, toxic::Photon::m_position, and toxic::PhotonMap::nearest_photons::m_position.

Referenced by ApproximateRadiance(), BuildPhotonDirectionHistogram(), and ComputeRadiance().

void PhotonMap::median_split Photon **  p,
int  start,
int  end,
int  median,
int  axis
const [private]
 

median_split() splits the photon array into two separate pieces around the median, with all photons below the median in the lower half and all photons above the median in the upper half. The comparison criteria is the axis (indicated by the axis parameter). Inspired by routine in "Algorithms in C++" by Sedgewick.

Definition at line 583 of file photonmap.cpp.

References toxic::Photon::m_position.

Referenced by balance_segment().

void PhotonMap::PrecomputeRadiances int  spacing,
sheep::Real  max_dist,
int  max_photons,
sheep::ProgressMonitor progmon = 0
 

Precomputes the reflected radiance at photons location. This method calls the ApproximateRadiance() to compute the reflected radiance at a given photon's location, thus the surface carrying the photon is considered as a perfect lambertian surface. Be sure to call the Balance() method prior to calling this method, and be sure to call this method prior to the first call of the GetPrecomputedRadiance() method.

Definition at line 302 of file photonmap.cpp.

References ApproximateRadiance(), toxic::Photon::GetPosition(), toxic::Photon::GetSurfaceNormal(), m_photons, toxic::ShadingData::m_reflectance, m_stored_photons, and toxic::Photon::SetPrecomputedRadiance().

Referenced by main().

void PhotonMap::ScalePhotonPower sheep::Real  scale  ) 
 

This method is used to scale the power of all photons once they have been emitted from the light source. scale = 1 / (#emitted photons) Call this function after each light source is processed.

Definition at line 106 of file photonmap.cpp.

References m_photons, m_prev_scale, and m_stored_photons.

Referenced by toxic::IPhotonTracer::BuildPhotonMap().

void PhotonMap::StorePhoton const sheep::Point3 position,
const Color3 power,
const sheep::Vector3 direction,
const sheep::Vector3 normal
 

Creates and stores a photon into the photon map. 'direction' must be unit-length. Both 'position' and 'direction' must be expressed in world space. The power is expressed in W.

Definition at line 75 of file photonmap.cpp.

References m_bbox_max, m_bbox_min, m_photons, m_stored_photons, toxic::Photon::SetIncidentDirection(), toxic::Photon::SetPosition(), toxic::Photon::SetPower(), and toxic::Photon::SetSurfaceNormal().

Referenced by toxic::GlobalPhotonTracer::trace_photon(), and toxic::CausticsPhotonTracer::trace_photon().

bool PhotonMap::WriteToFile const std::string &  filename,
sheep::ProgressMonitor progmon = 0
const
 

Writes the photon map to disk. Returns true if writing was successful.

Definition at line 455 of file photonmap.cpp.

References sheep::BinaryStream::IsOpen(), m_bbox_max, m_bbox_min, m_half_stored_photons, m_photon_map_sig, m_photons, m_stored_photons, PHOTONMAP_IO_BUFFER_SIZE, sheep::BinaryStream::SetBufferSize(), and sheep::BinaryStream::Write().

Referenced by main().


Member Data Documentation

sheep::float32 toxic::PhotonMap::m_bbox_max[3] [private]
 

Definition at line 168 of file photonmap.h.

Referenced by balance_segment(), CreateFromFile(), PhotonMap(), StorePhoton(), and WriteToFile().

sheep::float32 toxic::PhotonMap::m_bbox_min[3] [private]
 

Bounding box of the photon array.

Definition at line 167 of file photonmap.h.

Referenced by balance_segment(), CreateFromFile(), PhotonMap(), StorePhoton(), and WriteToFile().

sheep::float32* toxic::PhotonMap::m_dist2_buf [private]
 

Definition at line 172 of file photonmap.h.

Referenced by ApproximateRadiance(), BuildPhotonDirectionHistogram(), ComputeRadiance(), GetPrecomputedRadiance(), PhotonMap(), and ~PhotonMap().

int toxic::PhotonMap::m_half_stored_photons [private]
 

Definition at line 160 of file photonmap.h.

Referenced by Balance(), CreateFromFile(), locate_nearest_photon_with_irradiance(), locate_photons(), and WriteToFile().

const Photon** toxic::PhotonMap::m_index_buf [private]
 

Definition at line 173 of file photonmap.h.

Referenced by ApproximateRadiance(), BuildPhotonDirectionHistogram(), ComputeRadiance(), GetPrecomputedRadiance(), PhotonMap(), and ~PhotonMap().

const string PhotonMap::m_photon_map_sig = "toxic photon map file version 1" [static, private]
 

Signature string identifying photon map files.

Signature string identifying photon map files. Increment version number each time the file structure change.

Definition at line 41 of file photonmap.cpp.

Referenced by CreateFromFile(), and WriteToFile().

std::vector<Photon> toxic::PhotonMap::m_photons [private]
 

The array of photons.

Definition at line 164 of file photonmap.h.

Referenced by Balance(), CreateFromFile(), GetSizeInMemory(), locate_nearest_photon_with_irradiance(), locate_photons(), PhotonMap(), PrecomputeRadiances(), ScalePhotonPower(), StorePhoton(), and WriteToFile().

int toxic::PhotonMap::m_prev_scale [private]
 

Definition at line 161 of file photonmap.h.

Referenced by ScalePhotonPower().

int toxic::PhotonMap::m_stored_photons [private]
 

Definition at line 159 of file photonmap.h.

Referenced by Balance(), CreateFromFile(), PrecomputeRadiances(), ScalePhotonPower(), StorePhoton(), and WriteToFile().


The documentation for this class was generated from the following files:
Generated on Tue May 11 01:31:57 2004 for toxic by doxygen 1.3.6