-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage.h
91 lines (77 loc) · 2.52 KB
/
image.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include "math.h"
#include <boost/multi_array.hpp>
class Image {
struct Sample {
Vec2 position;
Vec color;
Sample() : position(0, 0), color(0, 0, 0) {}
};
typedef boost::multi_array<Sample, 3> SampleArray;
typedef boost::multi_array<Vec4, 2> PixelArray;
/** The samples from the current iteration. */
SampleArray currentIteration;
/** The raw sampled colors and weights. */
PixelArray rawData;
/** The array used for writing to an OpenEXR file. */
std::vector<float> channelR;
std::vector<float> channelG;
std::vector<float> channelB;
public:
/**
* Default width (radius) of the filter kernel.
*/
static constexpr float DEFAULT_FILTER_WIDTH = 2.0f;
/**
* The default number of samples to take per pixel per iteration.
*/
static constexpr int DEFAULT_SAMPLES_PER_PIXEL = 4;
const int w; /**< The width of the output image. */
const int h; /**< The height of the output image. */
const int samplesPerPixel; /**< Samples per pixel per iteration. */
const float filterWidth; /**< The width (radius) of the filter kernel. */
/**
* Constructs a new image.
*
* @param ww the width of the image
* @param hh the height of the image
* @param spp the number of samples per pixel per iteration
* @param fw the width (radius) of the filter kernel
*/
Image(
int ww,
int hh,
int spp = DEFAULT_SAMPLES_PER_PIXEL,
float fw = DEFAULT_FILTER_WIDTH
);
/**
* Sets the specified sample for the current iteration. The sample will
* not be applied to the image until Image::commitSamples is called.
* This is thread-safe if no two threads call this function with the same
* arguments (x, y, idx) at the same time. Otherwise, it is NOT thread-safe.
*
* @param x the x-coordinate of the pixel for which the sample was taken
* @param y the y-coordinate of the pixel for which the sample was taken
* @param ptX the actual x-position of the sample, if jittered
* @param ptY the actual y-position of the sample, if jittered
* @param idx the index of the sample, 0 <= idx < samplesPerPixel
* @param color the color of the sample
*/
void setSample(
int x,
int y,
float ptX,
float ptY,
int idx,
const Vec& color
);
/**
* Takes the currently-set samples, filters their values, and adds them to
* the image. This is NOT thread-safe.
*/
void commitSamples();
/**
* Writes the currently-committed image to an OpenEXR file on disk.
*/
void writeToEXR(std::string fileName);
};