13 #ifndef OGLPLUS_IMAGES_CELL_1107121519_HPP
14 #define OGLPLUS_IMAGES_CELL_1107121519_HPP
24 template <
typename T,
unsigned CH>
39 assert(!
"Invalid number of channels!");
54 assert(!
"Invalid number of channels!");
68 GLdouble result = 0.0;
69 for(std::size_t d=0; d!=dims; ++d)
71 GLdouble dist = (tc[d]-(cc[d]+co[d]/is[d]))*is[d];
74 return std::sqrt(result);
78 template <
typename GetDistance,
typename GetValue>
84 GetDistance get_distance,
87 input.
Width() *cell_w,
89 input.
Depth() *cell_d,
91 _fmt(CH), _ifmt((
T*)nullptr, CH)
94 const T one = this->_one((
T*)0);
96 const GLdouble i_w = 1.0/
Width();
97 const GLdouble i_h = 1.0/
Height();
98 const GLdouble i_d = 1.0/
Depth();
100 const GLsizei iw = input.Width();
101 const GLsizei ih = input.Height();
102 const GLsizei
id = input.Depth();
104 std::size_t dims = 1;
105 if(ih*cell_h > 1) dims = 2;
106 if(
id*cell_d > 1) dims = 3;
108 const GLsizei kmin = (dims == 3)?-1:0;
109 const GLsizei kmax = (dims == 3)?+2:1;
110 const GLsizei jmin = (dims >= 2)?-1:0;
111 const GLsizei jmax = (dims >= 2)?+2:1;
112 const GLsizei imin = -1;
113 const GLsizei imax = +2;
118 const Vec3d is(iw, ih,
id);
120 auto pos = this->_begin<T>();
122 for(GLsizei z=0; z!=
Depth(); ++z)
124 GLsizei cz = z/cell_d;
126 for(GLsizei y=0; y!=
Height(); ++y)
128 GLsizei cy = y/cell_h;
130 for(GLsizei x=0; x!=
Width(); ++x)
132 GLsizei cx = x/cell_w;
138 for(GLsizei k=kmin; k<kmax; ++k)
139 for(GLsizei j=jmin; j<jmax; ++j)
140 for(GLsizei i=imin; i<imax; ++i)
156 colors[l] = input.Pixel(ccx, ccy, ccz).xyz();
157 Vec3d co = colors[l];
159 dists[l] = get_distance(dims, tc, cc, co, is);
164 Vector<GLdouble, CH> value = get_value(dists, colors, l);
166 for(std::size_t c=0; c!=CH; ++c)
168 assert(pos != this->_end<T>());
169 GLdouble vc = value.At(c);
175 assert(pos == this->_end<T>());
180 :
public CellImageGen<GLubyte, 1>
183 typedef CellImageGen<GLubyte, 1> Base;
185 template <
typename ValueCalc>
188 ValueCalc _calc_value;
189 const unsigned _order;
190 std::vector<GLdouble> _d;
192 DistanceValue(ValueCalc calc_value,
unsigned order)
193 : _calc_value(calc_value)
199 const GLdouble* dists,
204 for(
unsigned o=0; o!=_order; ++o)
207 for(GLsizei c=0; c<count; ++c)
209 for(
unsigned o=0; o!=_order; ++o)
222 GLfloat result = _calc_value(_d);
223 if(result > 1) result = 1;
224 if(result < 0) result = 0;
225 return Vec1d(result);
229 template <
typename ValueCalc>
235 ValueCalc calc_value,
237 ): CellImageGen<GLubyte, 1>(
238 cell_w, cell_h, cell_d,
240 Base::EulerDistance(),
241 DistanceValue<ValueCalc>(calc_value, order)
248 #endif // include guard
Vector< GLdouble, 1 > Vec1d
1D double-precision (degenerate) vector
Definition: vector.hpp:93
PixelDataInternalFormat
OpenGL pixel data internal format enumeration.
Definition: pixel_data.hpp:79
Vector< GLdouble, 3 > Vec3d
3D double-precision vector
Definition: vector.hpp:105
GLsizei Width(void) const
Returns the width of the image.
Definition: image.hpp:234
PixelDataFormat
OpenGL pixel data format enumeration.
Definition: pixel_data.hpp:50
GLsizei Height(void) const
Returns the height of the image.
Definition: image.hpp:240