This is a random sampling algorithm, the effect of feeling like a general.
Class declaration:
#pragma once #ifndef __PURERANDOM_HEADER__ #define __PURERANDOM_HEADER__ #include "sampler.h" class PureRandom :public Sampler { public: PureRandom(); ~PureRandom(); PureRandom(const integer samps); PureRandom(const integer samps, const integer sets); PureRandom(const PureRandom& pr); PureRandom& operator=(const PureRandom& pr); virtual Sampler* clone() const; virtual void generate_samples(); }; #endif
Class implementation:
#include "pch.h" #include "purerandom.h" PureRandom::PureRandom() :Sampler() { generate_samples(); } PureRandom::~PureRandom() {} PureRandom::PureRandom(const integer samps) :Sampler(samps) { generate_samples(); } PureRandom::PureRandom(const integer samps, const integer sets) : Sampler(samps, sets) { generate_samples(); } PureRandom::PureRandom(const PureRandom& pr) : Sampler(pr) { generate_samples(); } PureRandom& PureRandom::operator=(const PureRandom& pr) { if (this == &pr) return *this; Sampler::operator=(pr); return *this; } Sampler* PureRandom::clone() const { return new PureRandom(*this); } void PureRandom::generate_samples() { for (integer i=0;i<nsets;i++) for (integer j = 0; j < nsamples; j++) { Point2 sp(random_ldouble(), random_ldouble()); samples.push_back(sp); } }
World class need to modify the build function, before modifying remain effective, will not be repeated
World :: Build void () { vp.set_hres (200 is); vp.set_vres (100); vp.set_sampler (new new PureRandom ()); // herein PureRandom samples after line of code that are modified to each of the test seed sampling algorithm. = new new MultiSphere tracer_ptr (the this); Geometrics * obj = new new Sphere (0, 0.5); obj-> SET_COLOR (the RGBColor (. 1, 0, 0)); add_object (obj); obj = new new Sphere (Point3 (0, - 100.5, 0), 100); obj-> SET_COLOR (the RGBColor (0, 0,. 1)); add_object (obj); }
Test results and pictures: