Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::SampleGenerator Class Referenceabstract

Generates samples in [0, 1]. Generators of different types produces samples with different properties. Depending on the implementation, the samples can be fully random, quasi random, or even fully deterministic. Sample generators in Photon have their life cycles. Life cycle begins when the sample generator start producing sample batches, and ends when all sample batches are exhausted. More...

#include <SampleGenerator.h>

Inheritance diagram for ph::SampleGenerator:
ph::SGHalton ph::SGStratified ph::SGUniformRandom

Public Member Functions

 SampleGenerator (std::size_t numSampleBatches, std::size_t maxCachedBatches)
 
 SampleGenerator (std::size_t numSampleBatches)
 
virtual ~SampleGenerator ()=default
 
virtual std::unique_ptr< SampleGeneratormakeNewborn (std::size_t numSampleBatches) const =0
 Make a new generator.
 
virtual void rebirth ()
 Reset this generator to its initial state, reviving it from dead state. Calling this method starts a new life cycle–all existing sample stages and values are lost, and references to them are invalidated. New declarations can be made after, and new sample values can be generated.
 
void genSplitted (std::size_t numSplits, std::vector< std::unique_ptr< SampleGenerator > > &out_sgs) const
 
bool prepareSampleBatch ()
 Generates sample values for current sample batch. Advances all sample values in all stages to the next batch. Will potentially generate sample values for more than one batch at once (cached).
 
SamplesNDHandle declareStageND (std::size_t numDims, std::size_t numSamples)
 Similar to declareStageND(), with default size hints.
 
SamplesNDHandle declareStageND (std::size_t numDims, std::size_t numSamples, std::vector< std::size_t > dimSizeHints)
 Declares a N-dimensional sample stage. A sample stage contains information for how the samples will be used, number of samples, etc. These information can help the sample generator to produce sample values of better quality. This method can only be called before sample batches are generated (before any call to prepareSampleBatch()).
 
SamplesNDStream getSamplesND (const SamplesNDHandle &handle) const
 Gets generated N-dimensional sample values in a stage. This method can only be called after sample batches are generated (after any call to prepareSampleBatch()).
 
std::size_t numSampleBatches () const
 
std::size_t maxCachedBatches () const
 
std::size_t numRemainingBatches () const
 
bool hasMoreBatches () const
 

Detailed Description

Generates samples in [0, 1]. Generators of different types produces samples with different properties. Depending on the implementation, the samples can be fully random, quasi random, or even fully deterministic. Sample generators in Photon have their life cycles. Life cycle begins when the sample generator start producing sample batches, and ends when all sample batches are exhausted.

Constructor & Destructor Documentation

◆ SampleGenerator() [1/2]

ph::SampleGenerator::SampleGenerator ( std::size_t numSampleBatches,
std::size_t maxCachedBatches )

◆ SampleGenerator() [2/2]

ph::SampleGenerator::SampleGenerator ( std::size_t numSampleBatches)
explicit

◆ ~SampleGenerator()

virtual ph::SampleGenerator::~SampleGenerator ( )
virtualdefault

Member Function Documentation

◆ declareStageND() [1/2]

SamplesNDHandle ph::SampleGenerator::declareStageND ( std::size_t numDims,
std::size_t numSamples )

Similar to declareStageND(), with default size hints.

◆ declareStageND() [2/2]

SamplesNDHandle ph::SampleGenerator::declareStageND ( std::size_t numDims,
std::size_t numSamples,
std::vector< std::size_t > dimSizeHints )

Declares a N-dimensional sample stage. A sample stage contains information for how the samples will be used, number of samples, etc. These information can help the sample generator to produce sample values of better quality. This method can only be called before sample batches are generated (before any call to prepareSampleBatch()).

◆ genSplitted()

void ph::SampleGenerator::genSplitted ( std::size_t numSplits,
std::vector< std::unique_ptr< SampleGenerator > > & out_sgs ) const

◆ getSamplesND()

SamplesNDStream ph::SampleGenerator::getSamplesND ( const SamplesNDHandle & handle) const

Gets generated N-dimensional sample values in a stage. This method can only be called after sample batches are generated (after any call to prepareSampleBatch()).

◆ hasMoreBatches()

bool ph::SampleGenerator::hasMoreBatches ( ) const
inline
Returns
Whether the generator has more batches to generate. If true, prepareSampleBatch() will return true also. If false, the generator's life cycle has ended–all samples are exhausted and cannot produce new samples.

◆ makeNewborn()

virtual std::unique_ptr< SampleGenerator > ph::SampleGenerator::makeNewborn ( std::size_t numSampleBatches) const
pure virtual

Make a new generator.

Returns
The new generator. Newborn generator may not have the same internal state as its ancestor.

Implemented in ph::SGHalton, ph::SGStratified, and ph::SGUniformRandom.

◆ maxCachedBatches()

std::size_t ph::SampleGenerator::maxCachedBatches ( ) const
inline

◆ numRemainingBatches()

std::size_t ph::SampleGenerator::numRemainingBatches ( ) const
inline

◆ numSampleBatches()

std::size_t ph::SampleGenerator::numSampleBatches ( ) const
inline

◆ prepareSampleBatch()

bool ph::SampleGenerator::prepareSampleBatch ( )

Generates sample values for current sample batch. Advances all sample values in all stages to the next batch. Will potentially generate sample values for more than one batch at once (cached).

Returns
Whether sample values are generated.

◆ rebirth()

void ph::SampleGenerator::rebirth ( )
virtual

Reset this generator to its initial state, reviving it from dead state. Calling this method starts a new life cycle–all existing sample stages and values are lost, and references to them are invalidated. New declarations can be made after, and new sample values can be generated.

Note
The initial state of a generator may be different each time rebirth() is called. This depends on the actual settings used for the generator.

The documentation for this class was generated from the following files: