13 #ifndef OGLPLUS_IMAGES_FILTERED_1107121519_HPP
14 #define OGLPLUS_IMAGES_FILTERED_1107121519_HPP
31 template <
typename T,
unsigned CH>
38 "Number of channels must be between 1 and 4"
41 template <
typename Filter,
typename Sampler,
typename Extractor>
50 sampler.SetInput(input);
51 auto p = this->_begin<T>();
54 for(
unsigned k=0; k!=d; ++k)
55 for(
unsigned j=0; j!=h; ++j)
56 for(
unsigned i=0; i!=w; ++i)
58 sampler.SetOrigin(i, j, k);
62 for(
unsigned ci=0; ci!=CH; ++ci)
64 assert(p != this->_end<T>());
69 assert(p == this->_end<T>());
74 template <
typename Extractor,
typename Sampler>
76 const Extractor& extractor,
85 struct NoCoordTransform
87 void operator()(
int,
int,
int,
unsigned,
unsigned,
unsigned)
const
92 class MatrixCoordTransform
102 int& x,
int& y,
int& z,
103 double w,
double h,
double d
109 x = int(std::floor(out.x()*w));
110 y = int(std::floor(out.
y()*h));
111 z = int(std::floor(out.
z()*d));
127 if(xpos >=
int(width)) xpos %= width;
128 while(xpos < 0) xpos += width;
130 if(ypos >=
int(height)) ypos %= height;
131 while(ypos < 0) ypos += height;
133 if(zpos >=
int(depth)) zpos %= depth;
134 while(zpos < 0) zpos += depth;
136 assert((xpos >= 0) && (xpos <
int(width)));
137 assert((ypos >= 0) && (ypos <
int(height)));
138 assert((zpos >= 0) && (zpos <
int(depth)));
140 return image.
Pixel(xpos, ypos, zpos);
144 template <
typename Transform,
typename SampleFunc>
152 int _ori_x, _ori_y, _ori_z;
156 const SampleFunc& sample = SampleFunc()
165 void SetInput(
const Image& image)
198 assert(_image !=
nullptr);
211 template <
typename SampleFunc>
213 : SamplerTpl<NoCoordTransform, SampleFunc>
215 SimpleSampler(
const SampleFunc& sample = SampleFunc())
216 : SamplerTpl<NoCoordTransform, SampleFunc>(
223 struct DefaultSampler
224 : SimpleSampler<RepeatSample>
227 template <
typename SampleFunc>
228 struct MatrixTransformSampler
229 : SamplerTpl<MatrixCoordTransform, SampleFunc>
231 MatrixTransformSampler(
233 const SampleFunc& sample = SampleFunc()
234 ): SamplerTpl<MatrixCoordTransform, SampleFunc>(
235 MatrixCoordTransform(transf),
242 template <
unsigned I>
251 template <
unsigned N>
252 struct FirstNComponents
269 typedef FirstNComponents<3> FromRGB;
270 typedef FirstNComponents<4> FromRGBA;
272 template <
typename Filter,
typename Sampler,
typename Extractor>
280 _calculate(input, filter, sampler, extractor, this->_one((
T*)0));
287 #endif // include guard
Extractor that allows to specify which component to use as input.
Definition: filtered.hpp:243
Object< SamplerOps > Sampler
An oglplus_object encapsulating the OpenGL sampler functionality.
Definition: sampler.hpp:877
T At(const Vector &vector, std::size_t i) const T x(void) const
Returns the value of the i-th coordinate of the vector.
Definition: vector.hpp:221
FromComponentI< 0 > FromRed
Extractor selecting the Red component of the input image.
Definition: filtered.hpp:261
GLsizei Depth(void) const
Returns the depth of the image.
Definition: image.hpp:246
T z(void) const
Returns the 2-nd component.
Definition: vector.hpp:237
GLsizei Width(void) const
Returns the width of the image.
Definition: image.hpp:234
Base class for various image filters.
Definition: filtered.hpp:32
T y(void) const
Returns the 1-st component.
Definition: vector.hpp:231
Vector< double, 4 > Pixel(GLsizei width, GLsizei height, GLsizei depth) const
Returns the pixel at the specified coordinates.
Definition: image.hpp:319
GLsizei Height(void) const
Returns the height of the image.
Definition: image.hpp:240
Wrapper for (texture) image data.
Definition: image.hpp:45
Basic template for vector types.
Definition: fwd.hpp:43
FromComponentI< 2 > FromBlue
Extractor selecting the Blue component of the input image.
Definition: filtered.hpp:265
FromComponentI< 3 > FromAlpha
Extractor selecting the Alpha component of the input image.
Definition: filtered.hpp:267
FromComponentI< 1 > FromGreen
Extractor selecting the Green component of the input image.
Definition: filtered.hpp:263