include/sampler.h
branchpyrit
changeset 88 f7edb3b90816
parent 87 1081e3dd3f3e
child 90 f6a72eb99631
equal deleted inserted replaced
87:1081e3dd3f3e 88:f7edb3b90816
    27 #ifndef SAMPLER_H
    27 #ifndef SAMPLER_H
    28 #define SAMPLER_H
    28 #define SAMPLER_H
    29 
    29 
    30 #include "common.h"
    30 #include "common.h"
    31 #include "vector.h"
    31 #include "vector.h"
       
    32 #include "pixmap.h"
    32 
    33 
    33 using namespace std;
    34 using namespace std;
    34 
    35 
    35 /**
    36 /**
    36  * sample
    37  * sample
    54  * initSampleSet returns zero and picture can be read from buffer.
    55  * initSampleSet returns zero and picture can be read from buffer.
    55  */
    56  */
    56 class Sampler
    57 class Sampler
    57 {
    58 {
    58 protected:
    59 protected:
    59 	Float *buffer;
    60 
    60 	int w,h;
    61 	Pixmap pixmap;
    61 	bool packetable;
    62 	bool packetable;
    62 public:
    63 public:
    63 	Sampler(Float *abuffer, int &aw, int &ah):
    64 	Sampler(Float *buffer, const int &w, const int &h):
    64 		buffer(abuffer), w(aw), h(ah), packetable(false) {};
    65 		pixmap(buffer, w, h), packetable(false) {};
       
    66 	Sampler(const int &w, const int &h):
       
    67 		pixmap(w, h), packetable(false) {};
    65 	virtual ~Sampler() {};
    68 	virtual ~Sampler() {};
    66 	void resetBuffer(Float *abuffer, int &aw, int &ah) { buffer = abuffer; w = aw; h = ah; };
    69 	void resetBuffer(Float *buffer, int &w, int &h)
       
    70 		{ pixmap.setData(buffer, w, h); };
    67 	virtual void init() = 0;
    71 	virtual void init() = 0;
    68 	virtual int initSampleSet() = 0;
    72 	virtual int initSampleSet() = 0;
    69 	virtual bool nextSample(Sample *s) = 0;
    73 	virtual bool nextSample(Sample *s) = 0;
    70 	virtual void saveSample(Sample &samp, Colour &col) = 0;
    74 	virtual void saveSample(Sample &samp, Colour &col) = 0;
    71 	bool packetableSamples() { return packetable; };
    75 	bool packetableSamples() { return packetable; };
       
    76 	const Pixmap &getPixmap() { return pixmap; };
    72 };
    77 };
    73 
    78 
    74 /**
    79 /**
    75  * Default sampler.
    80  * Default sampler.
    76  * Implements basic adaptive subsampling and oversampling.
    81  * Implements basic adaptive subsampling and oversampling.
    80 	int phase;
    85 	int phase;
    81 	int subsample;  // 0,1 = no, 1+ = size of sampling grid
    86 	int subsample;  // 0,1 = no, 1+ = size of sampling grid
    82 	int oversample; // 0 = no, 1 = 4x, 2 = 9x, 3 = 16x
    87 	int oversample; // 0 = no, 1 = 4x, 2 = 9x, 3 = 16x
    83 	int sx,sy,osa_samp; // current sample properties
    88 	int sx,sy,osa_samp; // current sample properties
    84 public:
    89 public:
    85 	DefaultSampler(Float *abuffer, int &aw, int &ah):
    90 	DefaultSampler(Float *buffer, const int &w, const int &h):
    86 		Sampler(abuffer, aw, ah), phase(-1), subsample(0), oversample(0) {};
    91 		Sampler(buffer, w, h), phase(-1), subsample(0), oversample(0) {};
       
    92 	DefaultSampler(const int &w, const int &h):
       
    93 		Sampler(w, h), phase(-1), subsample(0), oversample(0) {};
    87 	void init();
    94 	void init();
    88 	int initSampleSet();
    95 	int initSampleSet();
    89 	bool nextSample(Sample *s);
    96 	bool nextSample(Sample *s);
    90 	void saveSample(Sample &samp, Colour &col);
    97 	void saveSample(Sample &samp, Colour &col);
    91 
    98