LinearGradient( GLsizei width, GLsizei height, const Vector<T, N>& background, const std::map<P, Vector<T, N>>& x_points, const std::map<P, Vector<T, N>>& y_points, Combine combine ): Image(width, height, 1, N, (GLubyte*)0) { std::vector<Vector<T, N>> y_gradient(height); _make_gradient( background, height, y_points, y_gradient ); std::vector<Vector<T, N>> x_gradient(width); _make_gradient( background, width, x_points, x_gradient ); _apply_gradient( combine, y_gradient, x_gradient, _begin_ub(), _end_ub() ); }
bool _apply_sphere(const Vec3f& center, GLfloat radius) { assert(radius > 0.0f); bool something_updated = false; Vec3f c = center*0.5f + Vec3f(0.5f, 0.5f, 0.5f); GLfloat r = radius*0.5f; GLsizei w = Width(), h = Height(), d = Depth(); GLubyte* data = _begin_ub(); for(GLsizei k=(c.z()-r)*d, ke=(c.z()+r)*d; k!=ke; ++k) for(GLsizei j=(c.y()-r)*h, je=(c.y()+r)*h; j!=je; ++j) for(GLsizei i=(c.x()-r)*w, ie=(c.x()+r)*w; i!=ie; ++i) { assert(k >= 0 && k < d); assert(j >= 0 && j < h); assert(i >= 0 && i < w); GLsizei n = k*w*h + j*w + i; GLubyte b = data[n]; if(b != 0xFF) { GLfloat cd = GLfloat(b)/GLfloat(0xFF); Vec3f p(GLfloat(i)/w, GLfloat(j)/h, GLfloat(k)/d); GLfloat nd = (r - Distance(c, p))/r; if(nd < 0.0f) nd = 0.0f; nd = std::sqrt(nd); nd += cd; if(nd > 1.0f) nd = 1.0f; data[n] = GLubyte(0xFF * nd); something_updated = true; } } return something_updated; }
LinearGradient( GLsizei width, const Vector<T, N>& background, const std::map<P, Vector<T, N>>& x_points ): Image(width, 1, 1, N, (GLubyte*0)) { std::vector<Vector<T, N>> x_gradient(width); _make_gradient( background, width, x_points, x_gradient ); _apply_gradient(x_gradient, _begin_ub(), _end_ub()); }