Skip to content

Commit

Permalink
fixed format
Browse files Browse the repository at this point in the history
  • Loading branch information
tvcastillod committed Sep 20, 2024
1 parent ca9ec16 commit 69f3819
Show file tree
Hide file tree
Showing 36 changed files with 108 additions and 103 deletions.
5 changes: 4 additions & 1 deletion fury/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4022,9 +4022,11 @@ def uncertainty_cone(
return double_cone(centers, evecs, angles, colors, scales, opacity)


@warn_on_args_to_kwargs()
def odf(
centers,
coeffs,
*,
sh_basis='descoteaux',
scales=1.0,
opacity=1.0
Expand Down Expand Up @@ -4073,7 +4075,8 @@ def odf(

coeffs_given = coeffs.shape[-1]
degree = int((np.sqrt(8 * coeffs_given + 1) - 3) / 2)
if (degree%2 != 0): degree -= 1
if (degree%2 != 0):
degree -= 1
coeffs = coeffs[:, :int(((degree + 1) * (degree + 2)) / 2)]
if not isinstance(scales, np.ndarray):
scales = np.array(scales)
Expand Down
31 changes: 17 additions & 14 deletions fury/actors/odf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
attribute_to_actor(odf_actor, big_minmax, "minmax")

odf_actor_pd = odf_actor.GetMapper().GetInput()

n_glyphs = coeffs.shape[0]
# Coordinates to locate the data of each glyph in the texture.
uv_vals = np.array(uv_calculations(n_glyphs))
num_pnts = uv_vals.shape[0]

# Definition of texture coordinates to be associated with the actor.
t_coords = FloatArray()
t_coords.SetNumberOfComponents(2)
t_coords.SetNumberOfTuples(num_pnts)
[t_coords.SetTuple(i, uv_vals[i]) for i in range(num_pnts)]

set_polydata_tcoords(odf_actor_pd, t_coords)

# The coefficient data is stored in a texture to be passed to the shaders.

# Data is normalized to a range of 0 to 1.
Expand All @@ -92,7 +92,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
max_sh_degree = int((np.sqrt(8 * max_num_coeffs + 1) - 3) / 2)
max_poly_degree = 2 * max_sh_degree + 2
viz_sh_degree = max_sh_degree

# The number of coefficients is associated to the order of the SH
odf_actor.GetShaderProperty().GetFragmentCustomUniforms().SetUniformf(
"shDegree", viz_sh_degree
Expand All @@ -103,7 +103,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
vs_dec = \
"""
uniform float shDegree;
in vec3 center;
in vec2 minmax;
Expand Down Expand Up @@ -185,11 +185,13 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
eval_sh_composed = ""
for i in range(2, max_sh_degree + 1, 2):
eval_sh = import_fury_shader(
os.path.join("rt_odfs", sh_basis, "eval_sh_" + str(i) + ".frag")
os.path.join("ray_tracing", "odf", sh_basis, "eval_sh_" + str(i) +
".frag")
)
eval_sh_grad = import_fury_shader(
os.path.join(
"rt_odfs", sh_basis, "eval_sh_grad_" + str(i) + ".frag"
"ray_tracing", "odf", sh_basis, "eval_sh_grad_" + str(i) +
".frag"
)
)
eval_sh_composed = compose_shader(
Expand Down Expand Up @@ -230,18 +232,18 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
# SH_DEGREE in this order.
# param point The point on the unit sphere where the basis should be
# evaluated.
eval_sh = import_fury_shader(os.path.join("rt_odfs", "eval_sh.frag"))
eval_sh = import_fury_shader(os.path.join("ray_tracing", "odf", "eval_sh.frag"))

# Evaluates the gradient of each basis function given by eval_sh() and the
# basis itself
eval_sh_grad = import_fury_shader(
os.path.join("rt_odfs", "eval_sh_grad.frag")
os.path.join("ray_tracing", "odf", "eval_sh_grad.frag")
)

# Outputs a matrix that turns equidistant samples on the unit circle of a
# homogeneous polynomial into coefficients of that polynomial.
get_inv_vandermonde = import_fury_shader(
os.path.join("rt_odfs", "get_inv_vandermonde.frag")
os.path.join("ray_tracing", "odf", "get_inv_vandermonde.frag")
)

# Determines all intersections between a ray and a spherical harmonics
Expand All @@ -255,7 +257,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
# param ray_origin The origin of the ray, relative to the glyph center.
# param ray_dir The normalized direction vector of the ray.
ray_sh_glyph_intersections = import_fury_shader(
os.path.join("rt_odfs", "ray_sh_glyph_intersections.frag")
os.path.join("ray_tracing", "odf", "ray_sh_glyph_intersections.frag")
)

# Provides a normalized normal vector for a spherical harmonics glyph.
Expand All @@ -266,7 +268,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
#
# return A normalized surface normal pointing away from the origin.
get_sh_glyph_normal = import_fury_shader(
os.path.join("rt_odfs", "get_sh_glyph_normal.frag")
os.path.join("ray_tracing", "odf", "get_sh_glyph_normal.frag")
)

# Applies the non-linearity that maps linear RGB to sRGB
Expand All @@ -290,7 +292,7 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
)

# Logarithmic tonemapping operator. Input and output are linear RGB.
tonemap = import_fury_shader(os.path.join("rt_odfs", "tonemap.frag"))
tonemap = import_fury_shader(os.path.join("lighting", "tonemap.frag"))

# Blinn-Phong illumination model
blinn_phong_model = import_fury_shader(
Expand Down Expand Up @@ -368,7 +370,8 @@ def sh_odf(centers, coeffs, degree, sh_basis, scales, opacity):
vec3 color = vec3(1.);
if (firstRayParam != NO_INTERSECTION) {
vec3 intersection = ro - centerMCVSOutput + firstRayParam * rd;
vec3 normal = getShGlyphNormal(shCoeffs, intersection, int(shDegree), int(numCoeffsVSOutput));
vec3 normal = getShGlyphNormal(shCoeffs, intersection,
int(shDegree), int(numCoeffsVSOutput));
vec3 colorDir = srgbToLinearRgb(abs(normalize(intersection)));
float attenuation = dot(ld, normal);
color = blinnPhongIllumModel(
Expand Down
5 changes: 5 additions & 0 deletions fury/shaders/lighting/tonemap.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vec3 tonemap(vec3 linear)
{
float maxChannel = max(max(1.0, linear.r), max(linear.g, linear.b));
return linear * ((1.0 - 0.02 * log2(maxChannel)) / maxChannel);
}
57 changes: 57 additions & 0 deletions fury/shaders/ray_tracing/odf/eval_sh.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
void evalSH(out float outSH[SH_COUNT], vec3 point, int shDegree, int numCoeffs)
{
if (shDegree == 2)
{
float tmpOutSH[6];
#if SH_DEGREE == 2
evalSH2(tmpOutSH, point);
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];
}
else if (shDegree == 4)
{
float tmpOutSH[15];
#if SH_DEGREE == 4
evalSH4(tmpOutSH, point);
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];
}
else if (shDegree == 6)
{
float tmpOutSH[28];
#if SH_DEGREE == 6
evalSH6(tmpOutSH, point);
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];
}
else if (shDegree == 8)
{
float tmpOutSH[45];
#if SH_DEGREE == 8
evalSH8(tmpOutSH, point);
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];
}
else if (shDegree == 10)
{
float tmpOutSH[66];
#if SH_DEGREE == 10
evalSH10(tmpOutSH, point);
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];
}
else if (shDegree == 12)
{
float tmpOutSH[91];
#if SH_DEGREE == 12
evalSH12(tmpOutSH, point);
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void evalShGrad(out float outSH[SH_COUNT], out vec3 outGrads[SH_COUNT], vec3 poi
#endif
for (int i = 0; i != numCoeffs; ++i)
outSH[i] = tmpOutSH[i];

}
else if (shDegree == 4)
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void eval_sh_10(out float outSH[66], vec3 point)
void evalSH10(out float outSH[66], vec3 point)
{
float x, y, z, z2, c0, s0, c1, s1, d, a, b;
x = point[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void eval_sh_12(out float outSH[91], vec3 point)
void evalSH12(out float outSH[91], vec3 point)
{
float x, y, z, z2, c0, s0, c1, s1, d, a, b;
x = point[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void eval_sh_2(out float outSH[6], vec3 point)
void evalSH2(out float outSH[6], vec3 point)
{
float x, y, z, z2, c0, s0, c1, s1, d, a;
x = point[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void eval_sh_4(out float outSH[15], vec3 point)
void evalSH4(out float outSH[15], vec3 point)
{
float x, y, z, z2, c0, s0, c1, s1, d, a, b;
x = point[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void eval_sh_6(out float outSH[28], vec3 point)
void evalSH6(out float outSH[28], vec3 point)
{
float x, y, z, z2, c0, s0, c1, s1, d, a, b;
x = point[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void eval_sh_8(out float outSH[45], vec3 point)
void evalSH8(out float outSH[45], vec3 point)
{
float x, y, z, z2, c0, s0, c1, s1, d, a, b;
x = point[0];
Expand Down
58 changes: 0 additions & 58 deletions fury/shaders/rt_odfs/eval_sh.frag

This file was deleted.

5 changes: 0 additions & 5 deletions fury/shaders/rt_odfs/tonemap.frag

This file was deleted.

26 changes: 13 additions & 13 deletions fury/shaders/utils/find_roots.frag
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ void findRoots(out float outRoots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], f
// Compute its two roots using the quadratic formula
float discriminant = derivative[1] * derivative[1] - 4.0 * derivative[0] * derivative[2];
if (discriminant >= 0.0) {
float sqrt_discriminant = sqrt(discriminant);
float scaled_root = derivative[1] + ((derivative[1] > 0.0) ? sqrt_discriminant : (-sqrt_discriminant));
float root_0 = clamp(-2.0 * derivative[0] / scaled_root, begin, end);
float root_1 = clamp(-0.5 * scaled_root / derivative[2], begin, end);
outRoots[maxPolyDegree - 2] = min(root_0, root_1);
outRoots[maxPolyDegree - 1] = max(root_0, root_1);
float sqrtDiscriminant = sqrt(discriminant);
float scaledRoot = derivative[1] + ((derivative[1] > 0.0) ? sqrtDiscriminant : (-sqrtDiscriminant));
float root0 = clamp(-2.0 * derivative[0] / scaledRoot, begin, end);
float root1 = clamp(-0.5 * scaledRoot / derivative[2], begin, end);
outRoots[maxPolyDegree - 2] = min(root0, root1);
outRoots[maxPolyDegree - 1] = max(root0, root1);
}
else {
// Indicate that the cubic derivative has a single root
Expand All @@ -45,30 +45,30 @@ void findRoots(out float outRoots[MAX_DEGREE + 1], float poly[MAX_DEGREE + 1], f
for (int degree = 3; degree != maxPolyDegree + 1; ++degree) {
// Take the integral of the previous derivative (scaled such that the
// constant coefficient can still be copied directly from poly)
float prev_derivative_order = float(maxPolyDegree + 1 - degree);
float prevDerivativeOrder = float(maxPolyDegree + 1 - degree);
_unroll_
for (int i = maxPolyDegree; i != 0; --i)
derivative[i] = derivative[i - 1] * (prev_derivative_order * (1.0 / float(i)));
derivative[i] = derivative[i - 1] * (prevDerivativeOrder * (1.0 / float(i)));
// Copy the constant coefficient without causing spilling. This part
// would be harder if the derivative were not scaled the way it is.
_unroll_
for (int i = 0; i != maxPolyDegree - 2; ++i)
derivative[0] = (degree == maxPolyDegree - i) ? poly[i] : derivative[0];
// Determine the value of this derivative at begin
float begin_value = derivative[maxPolyDegree];
float beginValue = derivative[maxPolyDegree];
_unroll_
for (int i = maxPolyDegree - 1; i != -1; --i)
begin_value = begin_value * begin + derivative[i];
beginValue = beginValue * begin + derivative[i];
// Iterate over the intervals where roots may be found
_unroll_
for (int i = 0; i != maxPolyDegree; ++i) {
if (i < maxPolyDegree - degree)
continue;
float current_begin = outRoots[i];
float current_end = outRoots[i + 1];
float currentBegin = outRoots[i];
float currentEnd = outRoots[i + 1];
// Try to find a root
float root;
if (newtonBisection(root, begin_value, derivative, current_begin, current_end, begin_value, tolerance, maxPolyDegree))
if (newtonBisection(root, beginValue, derivative, currentBegin, currentEnd, beginValue, tolerance, maxPolyDegree))
outRoots[i] = root;
else if (degree < maxPolyDegree)
// Create an empty interval for the next iteration
Expand Down
10 changes: 5 additions & 5 deletions fury/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,13 +1645,13 @@ def minmax_norm(data, axis=1):
if data.ndim == 1:
data = np.array([data])
elif data.ndim > 2:
raise ValueError('the dimension of the array must be 2.')
raise ValueError("the dimension of the array dimension must be 2.")

minimum = data.min(axis=axis)
maximum = data.max(axis=axis)
if np.array_equal(minimum, maximum):
return data
if (axis == 0):
return (data - minimum)/(maximum - minimum)
if (axis == 1):
return (data - minimum[:, None])/(maximum - minimum)[:, None]
if axis == 0:
return (data - minimum) / (maximum - minimum)
if axis == 1:
return (data - minimum[:, None]) / (maximum - minimum)[:, None]

0 comments on commit 69f3819

Please sign in to comment.