include/sampler.h
branchpyrit
changeset 47 320d5d466864
child 48 a4913301c626
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/sampler.h	Wed Mar 26 14:29:21 2008 +0100
@@ -0,0 +1,92 @@
+/*
+ * sampler.h: screen sample generation and image reconstruction
+ *
+ * This file is part of Pyrit Ray Tracer.
+ *
+ * Copyright 2008  Radek Brich
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef SAMPLER_H
+#define SAMPLER_H
+
+#include "common.h"
+#include "vector.h"
+
+using namespace std;
+
+/**
+ * sample
+ */
+class Sample
+{
+public:
+	Float x,y;
+};
+
+/**
+ * A abstract sampler.
+ * It generates screen samples in coordinates between [-1..1] for height
+ * and [-w/h..w/h] for width. It works in phases: initSampleSet returns
+ * number of samples for each phase, then samples can be generated using
+ * nextSample method. The resulting colour of each sample should be returned
+ * via saveSample method. The sampler should save the results to given buffer
+ * and decide if other phase is needed. When the picture is complete,
+ * initSampleSet returns zero and picture can be read from buffer.
+ */
+class Sampler
+{
+public:
+	Float *buffer;
+	int w,h;
+
+	Sampler(Float *abuffer, int &aw, int &ah): buffer(abuffer), w(aw), h(ah) {};
+	virtual ~Sampler() {};
+	void resetBuffer(Float *abuffer, int &aw, int &ah) { buffer = abuffer; w = aw; h = ah; };
+	virtual void init() = 0;
+	virtual int initSampleSet() = 0;
+	virtual Sample *nextSample(Sample *prev) = 0;
+	virtual void saveSample(Sample *samp, Colour &col) = 0;
+};
+
+/**
+ * default sample
+ */
+class DefaultSample: public Sample
+{
+	friend class DefaultSampler;
+	int sx,sy;
+};
+
+/**
+ * Default sampler.
+ */
+class DefaultSampler: public Sampler
+{
+	int phase;
+public:
+	DefaultSampler(Float *abuffer, int &aw, int &ah): Sampler(abuffer, aw, ah), phase(-1) {};
+	void init() { phase = 0; };
+	int initSampleSet();
+	Sample *nextSample(Sample *prev);
+	void saveSample(Sample *samp, Colour &col);
+};
+
+#endif