include/sampler.h
branchpyrit
changeset 47 320d5d466864
child 48 a4913301c626
equal deleted inserted replaced
46:6493fb65f0b1 47:320d5d466864
       
     1 /*
       
     2  * sampler.h: screen sample generation and image reconstruction
       
     3  *
       
     4  * This file is part of Pyrit Ray Tracer.
       
     5  *
       
     6  * Copyright 2008  Radek Brich
       
     7  *
       
     8  * Permission is hereby granted, free of charge, to any person obtaining a copy
       
     9  * of this software and associated documentation files (the "Software"), to deal
       
    10  * in the Software without restriction, including without limitation the rights
       
    11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       
    12  * copies of the Software, and to permit persons to whom the Software is
       
    13  * furnished to do so, subject to the following conditions:
       
    14  *
       
    15  * The above copyright notice and this permission notice shall be included in
       
    16  * all copies or substantial portions of the Software.
       
    17  *
       
    18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
       
    19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
       
    20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
       
    21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
       
    22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
       
    23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
       
    24  * THE SOFTWARE.
       
    25  */
       
    26 
       
    27 #ifndef SAMPLER_H
       
    28 #define SAMPLER_H
       
    29 
       
    30 #include "common.h"
       
    31 #include "vector.h"
       
    32 
       
    33 using namespace std;
       
    34 
       
    35 /**
       
    36  * sample
       
    37  */
       
    38 class Sample
       
    39 {
       
    40 public:
       
    41 	Float x,y;
       
    42 };
       
    43 
       
    44 /**
       
    45  * A abstract sampler.
       
    46  * It generates screen samples in coordinates between [-1..1] for height
       
    47  * and [-w/h..w/h] for width. It works in phases: initSampleSet returns
       
    48  * number of samples for each phase, then samples can be generated using
       
    49  * nextSample method. The resulting colour of each sample should be returned
       
    50  * via saveSample method. The sampler should save the results to given buffer
       
    51  * and decide if other phase is needed. When the picture is complete,
       
    52  * initSampleSet returns zero and picture can be read from buffer.
       
    53  */
       
    54 class Sampler
       
    55 {
       
    56 public:
       
    57 	Float *buffer;
       
    58 	int w,h;
       
    59 
       
    60 	Sampler(Float *abuffer, int &aw, int &ah): buffer(abuffer), w(aw), h(ah) {};
       
    61 	virtual ~Sampler() {};
       
    62 	void resetBuffer(Float *abuffer, int &aw, int &ah) { buffer = abuffer; w = aw; h = ah; };
       
    63 	virtual void init() = 0;
       
    64 	virtual int initSampleSet() = 0;
       
    65 	virtual Sample *nextSample(Sample *prev) = 0;
       
    66 	virtual void saveSample(Sample *samp, Colour &col) = 0;
       
    67 };
       
    68 
       
    69 /**
       
    70  * default sample
       
    71  */
       
    72 class DefaultSample: public Sample
       
    73 {
       
    74 	friend class DefaultSampler;
       
    75 	int sx,sy;
       
    76 };
       
    77 
       
    78 /**
       
    79  * Default sampler.
       
    80  */
       
    81 class DefaultSampler: public Sampler
       
    82 {
       
    83 	int phase;
       
    84 public:
       
    85 	DefaultSampler(Float *abuffer, int &aw, int &ah): Sampler(abuffer, aw, ah), phase(-1) {};
       
    86 	void init() { phase = 0; };
       
    87 	int initSampleSet();
       
    88 	Sample *nextSample(Sample *prev);
       
    89 	void saveSample(Sample *samp, Colour &col);
       
    90 };
       
    91 
       
    92 #endif