本文整理汇总了C++中Sampler类的典型用法代码示例。如果您正苦于以下问题:C++ Sampler类的具体用法?C++ Sampler怎么用?C++ Sampler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sampler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Sample
Spectrum GridDensityMedium::Sample(const Ray &rWorld, Sampler &sampler,
MemoryArena &arena,
MediumInteraction *mi) const {
Ray ray = WorldToMedium(
Ray(rWorld.o, Normalize(rWorld.d), rWorld.tMax * rWorld.d.Length()));
// Compute $[\tmin, \tmax]$ interval of _ray_'s overlap with medium bounds
const Bounds3f b(Point3f(0, 0, 0), Point3f(1, 1, 1));
Float tMin, tMax;
if (!b.IntersectP(ray, &tMin, &tMax)) return Spectrum(1.f);
// Run delta-tracking iterations to sample a medium interaction
Float t = tMin;
while (true) {
t -= std::log(1 - sampler.Get1D()) * invMaxDensity;
if (t >= tMax) break;
if (Density(ray(t)) * invMaxDensity * sigma_t > sampler.Get1D()) {
// Populate _mi_ with medium interaction information and return
PhaseFunction *phase = ARENA_ALLOC(arena, HenyeyGreenstein)(g);
*mi = MediumInteraction(rWorld(t), -rWorld.d, rWorld.time, this,
phase);
return sigma_s / sigma_t;
}
}
return Spectrum(1.f);
}
示例2: getReward
double BAUCT::SimulateQ(uint state, QNODE& qnode, uint action)
{
uint observation;
double immediateReward, delayedReward = 0;
uint ii = state*SA+action*S;
Sampler* nextSSampler = SampFact.getTransitionSampler(pcounts+ii,state,action,S);
observation = nextSSampler->getNextStateSample();
immediateReward = getReward(state,action,observation);
delete nextSSampler;
pcounts[state*SA+action*S+observation] += 1;
bool terminal = false; //FIXME Assumes non-episodic tasks...
History.Add(action, observation);
VNODE*& vnode = qnode.Child(observation);
if (!vnode && !terminal && qnode.Value.GetCount() >= Params.ExpandCount)
vnode = ExpandNode(); //&state);
if (!terminal)
{
TreeDepth++;
if (vnode)
delayedReward = SimulateV(observation, vnode);
else{
delayedReward = Rollout(observation);
}
TreeDepth--;
}
double totalReward = immediateReward + Simulator.GetDiscount() * delayedReward;
qnode.Value.Add(totalReward);
return totalReward;
}
示例3: sample_value
Value sample_value(
const Shared & shared,
rng_t & rng) const {
Sampler sampler;
sampler.init(shared, *this, rng);
return sampler.eval(shared, rng);
}
示例4: Sample
Spectrum GridDensityMedium::Sample(const Ray &_ray, Sampler &sampler,
MemoryArena &arena,
MediumInteraction *mi) const {
// Transform the ray into local coordinates and determine overlap interval
// [_tMin, tMax_]
const Bounds3f dataBounds(Point3f(0.f, 0.f, 0.f), Point3f(1.f, 1.f, 1.f));
Ray ray = WorldToMedium(
Ray(_ray.o, Normalize(_ray.d), _ray.tMax * _ray.d.Length()));
Float tMin, tMax;
if (!dataBounds.IntersectP(ray, &tMin, &tMax)) return Spectrum(1.f);
tMin = std::max(tMin, (Float)0.f);
tMax = std::min(tMax, ray.tMax);
if (tMin >= tMax) return Spectrum(1.f);
// Run Delta-Tracking iterations to sample a medium interaction
Float t = tMin;
while (true) {
t -= std::log(1 - sampler.Get1D()) * invMaxDensity;
if (t >= tMax) break;
Float density = Density(ray(t));
if (density * invMaxDensity * sigma_t > sampler.Get1D()) {
// Populate _mi_ with medium interaction information and return
PhaseFunction *phase = ARENA_ALLOC(arena, HenyeyGreenstein)(g);
*mi = MediumInteraction(_ray(t), -_ray.d, _ray.time, this, phase);
return sigma_s / sigma_t;
}
}
return Spectrum(1.0f);
}
示例5: integrate_sampling
double integrate_sampling(
const MDF& mdf,
const Sampler& sampler,
const size_t sample_count)
{
double integral = 0.0;
for (size_t i = 0; i < sample_count; ++i)
{
static const size_t Bases[] = { 2 };
const Vector2d s = hammersley_sequence<double, 2>(Bases, i, sample_count);
const Vector3d w = sampler.sample(s);
const double pdf = sampler.pdf(w);
const double cos_theta = w.y;
const double value = mdf.evaluate(cos_theta);
const double sample = value / pdf;
integral += sample * cos_theta;
}
integral /= static_cast<double>(sample_count);
return integral;
}
示例6: set_stack
bool SamplerScript::set_stack(ScriptObject* self, ClassFactoryClass* cf, const Sample& sample, SampleObject* sam)
{
if (sample.stack.depth > 0)
{
Toplevel* toplevel = self->toplevel();
AvmCore* core = toplevel->core();
Sampler* s = core->get_sampler();
StackFrameClass* sfcc = (StackFrameClass*)cf->get_StackFrameClass();
ArrayObject* stack = toplevel->arrayClass()->newArray(sample.stack.depth);
StackTrace::Element* e = (StackTrace::Element*)sample.stack.trace;
for(uint32_t i=0; i < sample.stack.depth; i++, e++)
{
StackFrameObject* sf = sfcc->constructObject();
// at every allocation the sample buffer could overflow and the samples could be deleted
// the StackTrace::Element pointer is a raw pointer into that buffer so we need to check
// that its still around before dereferencing e
uint32_t num;
if (s->getSamples(num) == NULL)
return false;
sf->setconst_name(e->name()); // NOT e->info()->name() because e->name() can be a fake name
sf->setconst_file(e->filename());
sf->setconst_line(e->linenum());
sf->setconst_scriptID(static_cast<double>(e->functionId()));
stack->setUintProperty(i, sf->atom());
}
sam->setconst_stack(stack);
}
return true;
}
示例7: DispatchProgramChange
void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) {
if (!pDevice || !pDevice->pSampler) {
std::cerr << "MidiInputPort: ERROR, no sampler instance to handle program change."
<< "This is a bug, please report it!\n" << std::flush;
return;
}
Sampler* pSampler = (Sampler*) pDevice->pSampler;
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(Program);
if (!pSamplerChannel) return;
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
if (!pEngineChannel) return;
// disconnect from the engine channel which was connected by the last PC event
if (pPreviousProgramChangeEngineChannel)
Disconnect(pPreviousProgramChangeEngineChannel);
// now connect to the new engine channel and remember it
try {
Connect(pEngineChannel, (midi_chan_t) MidiChannel);
pPreviousProgramChangeEngineChannel = pEngineChannel;
}
catch (...) { /* NOOP */ }
}
示例8: render_tile
void SampleRenderer::render_tile(CtxG&, Recti tile_rect,
Recti tile_film_rect, Film& tile_film, Sampler& sampler) const
{
StatTimer t(TIMER_RENDER_TILE);
Vec2 film_res(float(this->film->x_res), float(this->film->y_res));
for(int32_t y = tile_rect.p_min.y; y < tile_rect.p_max.y; ++y) {
for(int32_t x = tile_rect.p_min.x; x < tile_rect.p_max.x; ++x) {
sampler.start_pixel();
for(uint32_t s = 0; s < sampler.samples_per_pixel; ++s) {
sampler.start_pixel_sample();
Vec2 pixel_pos = sampler.get_sample_2d(this->pixel_pos_idx);
Vec2 film_pos = Vec2(float(x), float(y)) + pixel_pos;
Ray ray(this->scene->camera->cast_ray(film_res, film_pos));
Spectrum radiance = this->get_radiance(*this->scene, ray, 0, sampler);
assert(is_finite(radiance));
assert(is_nonnegative(radiance));
if(is_finite(radiance) && is_nonnegative(radiance)) {
Vec2 tile_film_pos = film_pos -
Vec2(float(tile_film_rect.p_min.x), float(tile_film_rect.p_min.y));
tile_film.add_sample(tile_film_pos, radiance);
}
}
}
}
}
示例9: UniformSampleAllLights
// Integrator Utility Functions
Spectrum UniformSampleAllLights(const Interaction &it, const Scene &scene,
MemoryArena &arena, Sampler &sampler,
const std::vector<int> &nLightSamples,
bool handleMedia) {
ProfilePhase p(Prof::DirectLighting);
Spectrum L(0.f);
for (size_t j = 0; j < scene.lights.size(); ++j) {
// Accumulate contribution of _j_th light to _L_
const std::shared_ptr<Light> &light = scene.lights[j];
int nSamples = nLightSamples[j];
const Point2f *uLightArray = sampler.Get2DArray(nSamples);
const Point2f *uScatteringArray = sampler.Get2DArray(nSamples);
if (!uLightArray || !uScatteringArray) {
// Use a single sample for illumination from _light_
Point2f uLight = sampler.Get2D();
Point2f uScattering = sampler.Get2D();
L += EstimateDirect(it, uScattering, *light, uLight, scene, sampler,
arena, handleMedia);
} else {
// Estimate direct lighting using sample arrays
Spectrum Ld(0.f);
for (int k = 0; k < nSamples; ++k)
Ld += EstimateDirect(it, uScatteringArray[k], *light,
uLightArray[k], scene, sampler, arena,
handleMedia);
L += Ld / nSamples;
}
}
return L;
}
示例10: main
int main(int argc, char** argv)
{
CommandLineOptions options(argc, argv);
Data::get_instance().load(options.get_data_file().c_str());
Sampler<MyModel> sampler = setup<MyModel>(options);
sampler.run();
return 0;
}
示例11: Sampler
void ResourceManager::checkSamplerAllocation(GLuint sampler)
{
if (sampler != 0 && !getSampler(sampler))
{
Sampler *samplerObject = new Sampler(sampler);
mSamplerMap[sampler] = samplerObject;
samplerObject->addRef();
}
}
示例12: main
int main(int argc, char** argv)
{
Data::get_instance().load("data.txt");
Sampler<MyModel> sampler = setup<MyModel>(argc, argv);
sampler.run();
return 0;
}
示例13: Sampler
unsigned int App::addSampler()
{
samplers_.push_back(std::tr1::shared_ptr<Sampler>(new Sampler()));
unsigned int index = samplers_.size() - 1;
Sampler *sampler = samplers_[index].get();
clutter_container_add_actor(CLUTTER_CONTAINER(stage_), sampler->getGenerator()->getRoot());
return samplers_.size() - 1;
}
示例14: updateSpeed
void App::updateSpeed()
{
std::vector<std::tr1::shared_ptr<Sampler> >::iterator iter;
for (iter = samplers_.begin(); iter < samplers_.end(); ++iter)
{
Sampler *sampler = (*iter).get();
sampler->getPlayer()->setSpeed(speed_);
}
}
示例15: TEST
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(SamplerTest, Defaults)
{
Sampler s;
EXPECT_EQ(Sampler::REPEAT, s.wrapModeS());
EXPECT_EQ(Sampler::REPEAT, s.wrapModeT());
EXPECT_EQ(Sampler::NEAREST_MIPMAP_LINEAR, s.minFilter());
EXPECT_EQ(Sampler::LINEAR, s.magFilter());
}