10#ifndef FSSR_BASIS_FUNCTION_HEADER
11#define FSSR_BASIS_FUNCTION_HEADER
69 double* value,
double* weight,
114 double const gaussian_value =
gaussian(scale, pos);
117 if (deriv !=
nullptr)
119 double const deriv_norm = value_norm * T(2) *
MATH_POW2(scale);
121 * gaussian_value / deriv_norm;
122 (*deriv)[1] = (-T(2) * pos[0] * pos[1]) * gaussian_value / deriv_norm;
123 (*deriv)[2] = (-T(2) * pos[0] * pos[2]) * gaussian_value / deriv_norm;
126 return pos[0] * gaussian_value / value_norm;
131#if FSSR_NEW_WEIGHT_FUNCTION
139 if (square_radius >= T(9))
141 if (deriv !=
nullptr)
146 if (deriv !=
nullptr)
148 T
const deriv_factor = -T(4) / T(3)
149 + T(48) / T(54) * std::sqrt(square_radius)
150 - T(4) / T(27) * square_radius;
152 (*deriv)[0] = deriv_factor * pos[0] / scale;
153 (*deriv)[1] = deriv_factor * pos[1] / scale;
154 (*deriv)[2] = deriv_factor * pos[2] / scale;
161 return T(1) - T(2) / T(3) * square_radius
162 + T(8) / T(27) * std::pow(square_radius, T(1.5))
163 - T(1) / T(27) *
MATH_POW2(square_radius);
173 T
const x = pos[0] / scale;
174 T
const y = pos[1] / scale;
175 T
const z = pos[2] / scale;
183 if (x > T(-3) && x < T(0))
189 else if (x >= T(0) && x < T(3))
200 if (square_radius < T(9))
203 - T(1) / T(3) * square_radius
204 + T(2) / T(27) * std::pow(square_radius, T(1.5));
207 if (deriv !=
nullptr)
214 if (x > T(-3) && x <= T(0))
216 deriv_x = (T(2) / T(3) + T(2) / T(9) * x) / scale;
218 else if (x > T(0) && x < T(3))
220 deriv_x = (-T(2) / T(3) * x + T(6) / T(27) *
MATH_POW2(x)) / scale;
230 if (square_radius < T(9))
232 T
const factor = (T(12) / (T(54) * scale)
235 deriv_y = factor * pos[1];
236 deriv_z = factor * pos[2];
239 (*deriv)[0] = deriv_x * weight_yz;
240 (*deriv)[1] = deriv_y * weight_x;
241 (*deriv)[2] = deriv_z * weight_x;
244 return weight_x * weight_yz;
256 return rot * (pos - sample.
pos);
271 return (pos - sample.pos).dot(sample.normal);
280weighting_function_mpu (T
const& x)
282 if (x <= T(-3) || x >= T(3))
285 T xf = (x + T(3)) / T(2);
289 return (T(-2) *
MATH_POW2(xf) + T(6) * xf - T(3)) / T(2);
302 return weighting_function_mpu(pos.
norm() / sample_scale);
Matrix class for arbitrary dimensions and types.
Vector class for arbitrary dimensions and types.
T square_norm(void) const
Computes the squared norm of the vector (much cheaper).
T norm(void) const
Computes the norm (length) of the vector.
T dot(Vector< T, N > const &other) const
Dot (or scalar) product between self and another vector.
Vector< T, N > & fill(T const &value)
Fills all vector elements with the given value.
#define FSSR_NAMESPACE_END
#define FSSR_NAMESPACE_BEGIN
T gaussian(T const &sigma, math::Vector< T, 3 > const &x)
The Gaussian function in 3D.
T fssr_weight(T const &scale, math::Vector< T, 3 > const &pos, math::Vector< T, 3 > *deriv=nullptr)
Evaluates the FSSR weight function and directional derivatives (optional).
T gaussian_normalized(T const &sigma, math::Vector< T, 3 > const &x)
The normalized Gaussian function in 3D.
math::Vec3f transform_position(math::Vec3f const &pos, Sample const &sample)
Transforms 'pos' according to the samples position and normal.
void rotation_from_normal(math::Vec3f const &normal, math::Matrix3f *rot)
Generates a rotation matrix that transforms in the FSSR LCS.
T fssr_basis(T const &scale, math::Vector< T, 3 > const &pos, math::Vector< T, 3 > *deriv=nullptr)
Evaluates the FSSR basis function and directional derivatives (optional).
void evaluate(math::Vec3f const &pos, Sample const &sample, double *value, double *weight, math::Vector< double, 3 > *value_deriv, math::Vector< double, 3 > *weight_deriv)
Rotates the given point in the LCS of the sample, evaluates the basis and weight functions and their ...
Representation of a point sample.