18 #ifndef PIC_UTIL_RASTERIZER_HPP 19 #define PIC_UTIL_RASTERIZER_HPP 24 #include "../base.hpp" 25 #include "../image.hpp" 26 #include "../util/vec.hpp" 27 #include "../util/math.hpp" 29 #ifndef PIC_EIGEN_NOT_BUNDLED 30 #include "../externals/Eigen/Dense" 32 #include <Eigen/Dense> 46 if(img == NULL || color == NULL) {
55 float *data = img->
data;
61 int dx = v1[0] - v0[0];
62 int dy = v1[1] - v0[1];
70 for(
int y = v0[1]; y < v1[1]; y++) {
73 for(
int k = 0; k < img->channels; k++) {
74 data[ind + k] = color[k];
82 int ind_y = v0[1] * img->
width;
84 for(
int x = v0[0]; x < v1[0]; x++) {
85 int ind = (x + ind_y) * img->
channels;
87 for(
int k = 0; k < img->channels; k++) {
88 data[ind + k] = color[k];
94 if(std::abs(dy) < std::abs(dx)) {
106 for(
int x = v0[0]; x <= v1[0]; x++) {
109 for(
int k = 0; k < img->channels; k++) {
110 data[ind + k] = color[k];
139 for(
int y = v0[1]; y <= v1[1]; y++) {
143 for(
int k = 0; k < img->channels; k++) {
144 data[ind + k] = color[k];
161 #ifndef PIC_DISABLE_EIGEN 170 for(
int i = 0; i < img->
channels; i++) {
175 for(
size_t i = 0; i < points.size(); i++) {
176 int x = int(points[i][0]);
177 int y = int(points[i][1]);
178 float *pixel = (*img)(x, y);
180 for(
int j = 0; j < img->
channels; j++) {
196 bool bNormTerm =
false)
206 float sigma2 = (sigma * sigma * 2.0f);
208 int halfWidth = img->
width >> 1;
209 int halfHeight = img->
height >> 1;
211 float normTerm = bNormTerm ? sigma * sqrtf(
C_PI) : 1.0f ;
213 #pragma omp parallel for 215 for(
int j = 0; j < img->
height; j++) {
216 int j_squared = j - halfHeight;
217 j_squared = j_squared * j_squared;
219 for(
int i = 0; i < img->
width; i++) {
220 int i_squared = i - halfWidth;
221 i_squared = i_squared * i_squared;
223 float gaussVal = expf(-
float(i_squared + j_squared) / sigma2) / normTerm;
225 float *tmp_data = (*img)(i, j);
227 for(
int k = 0; k < img->
channels; k++) {
228 tmp_data[k] = gaussVal;
244 int halfWidth = img->
width >> 1;
245 int halfHeight = img->
height >> 1;
247 int radius_squared = (halfWidth * halfWidth + halfHeight * halfHeight) >> 1;
249 #pragma omp parallel for 251 for(
int j = 0; j < img->
height; j++) {
252 int j_squared = j - halfHeight;
253 j_squared = j_squared * j_squared;
255 for(
int i = 0; i < img->
width; i++) {
256 int i_squared = i - halfWidth;
257 i_squared = i_squared * i_squared;
261 if((i_squared + j_squared) < radius_squared) {
265 float *tmp_data = (*img)(i, j);
267 for(
int k = 0; k < img->
channels; k++) {
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
const float C_PI
Definition: math.hpp:50
PIC_INLINE void drawPoints(Image *img, std::vector< Eigen::Vector2f > &points, float *color)
drawPoints
Definition: rasterizer.hpp:162
PIC_INLINE void drawLine(Image *img, Vec2i v0, Vec2i v1, float *color)
drawLine renders a line (v0, v1) with color into img.
Definition: rasterizer.hpp:44
#define PIC_INLINE
Definition: base.hpp:33
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
PIC_INLINE void evaluateGaussian(Image *img, float sigma=-1.0f, bool bNormTerm=false)
evaluateGaussian renders a Gaussian function which is centred in the image.
Definition: rasterizer.hpp:195
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
int width
Definition: image.hpp:80
PIC_INLINE void evaluateSolid(Image *img)
evaluateSolid renders a centred circle.
Definition: rasterizer.hpp:238
int height
Definition: image.hpp:80
The Vec class.
Definition: vec.hpp:35