Skip to content

Commit

Permalink
Merge pull request #2465 from aganders3/attenuated-mip-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Apr 24, 2023
2 parents 44afcb6 + fc5539a commit adc14c3
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions vispy/visuals/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,13 @@
int maxi = -1; // Where the maximum value was encountered
""",
in_loop="""
if( val > maxval ) {
if ( val > maxval ) {
maxval = val;
maxi = iter;
if ( maxval >= clim.y ) {
// stop if no chance of finding a higher maxval
iter = nsteps;
}
}
""",
after_loop="""
Expand All @@ -395,8 +399,7 @@
}
frag_depth_point = max_loc_tex * u_shape;
gl_FragColor = applyColormap(maxval);
}
else {
} else {
discard;
}
""",
Expand All @@ -406,7 +409,7 @@
before_loop="""
float maxval = u_mip_cutoff; // The maximum encountered value
float sumval = 0.0; // The sum of the encountered values
float scaled = 0.0; // The scaled value
float scale = 0.0; // The cumulative attenuation
int maxi = -1; // Where the maximum value was encountered
vec3 max_loc_tex = vec3(0.0); // Location where the maximum value was encountered
""",
Expand All @@ -415,9 +418,12 @@
// * attenuation value does not depend on data values
// * negative values do not amplify instead of attenuate
sumval = sumval + clamp((val - clim.x) / (clim.y - clim.x), 0.0, 1.0);
scaled = val * exp(-u_attenuation * (sumval - 1) / u_relative_step_size);
if( scaled > maxval ) {
maxval = scaled;
scale = exp(-u_attenuation * (sumval - 1) / u_relative_step_size);
if( maxval > scale * clim.y ) {
// stop if no chance of finding a higher maxval
iter = nsteps;
} else if( val * scale > maxval ) {
maxval = val * scale;
maxi = iter;
max_loc_tex = loc;
}
Expand All @@ -439,9 +445,13 @@
int mini = -1; // Where the minimum value was encountered
""",
in_loop="""
if( val < minval ) {
if ( val < minval ) {
minval = val;
mini = iter;
if ( minval <= clim.x ) {
// stop if no chance of finding a lower minval
iter = nsteps;
}
}
""",
after_loop="""
Expand All @@ -465,8 +475,7 @@
}
frag_depth_point = min_loc_tex * u_shape;
gl_FragColor = applyColormap(minval);
}
else {
} else {
discard;
}
""",
Expand Down

0 comments on commit adc14c3

Please sign in to comment.