Skip to content

Commit

Permalink
Fix depth in MIP and MINIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aganders3 committed Mar 28, 2023
1 parent 9e61444 commit 3cb973a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions vispy/visuals/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@
_MIP_SNIPPETS = dict(
before_loop="""
float maxval = u_mip_cutoff; // The maximum encountered value
int maxi = -2; // Where the maximum value was encountered
int maxi = -1; // Where the maximum value was encountered
bool refine = true; // Whether to refine the frag with smaller steps
""",
in_loop="""
if ( val > maxval ) {
Expand All @@ -375,13 +376,13 @@
if ( maxval >= clim.y ) {
// stop if no chance of finding a higher maxval
iter = nsteps;
maxi = -1;
refine = false;
}
}
""",
after_loop="""
// Refine search for max value, but only if anything was found
if ( maxi > -1 ) {
if ( maxi > -1 && refine) {
// Calculate starting location of ray for sampling
vec3 start_loc_refine = start_loc + step * (float(maxi) - 0.5);
loc = start_loc_refine;
Expand All @@ -400,9 +401,9 @@
}
frag_depth_point = max_loc_tex * u_shape;
gl_FragColor = applyColormap(maxval);
} else if ( maxi == -1 ) {
} else if ( maxi > -1 ) {
// skip refinement if already minimum wrt contrast
frag_depth_point = start_loc + step * float(maxi);
frag_depth_point = (start_loc + step * float(maxi)) * u_shape;
gl_FragColor = applyColormap(maxval);
} else {
discard;
Expand Down Expand Up @@ -447,7 +448,8 @@
_MINIP_SNIPPETS = dict(
before_loop="""
float minval = u_minip_cutoff; // The minimum encountered value
int mini = -2; // Where the minimum value was encountered
int mini = -1; // Where the minimum value was encountered
bool refine = true;
""",
in_loop="""
if ( val < minval ) {
Expand All @@ -456,13 +458,13 @@
if ( minval <= clim.x ) {
// stop if no chance of finding a lower minval
iter = nsteps;
mini = -1;
refine = false;
}
}
""",
after_loop="""
// Refine search for min value, but only if anything was found
if ( mini > -1 ) {
if ( mini > -1 && refine ) {
// Calculate starting location of ray for sampling
vec3 start_loc_refine = start_loc + step * (float(mini) - 0.5);
loc = start_loc_refine;
Expand All @@ -482,9 +484,9 @@
frag_depth_point = min_loc_tex * u_shape;
gl_FragColor = applyColormap(minval);
}
else if ( mini == -1 ) {
else if ( mini > -1 ) {
// skip refinement if already minimum wrt contrast
frag_depth_point = start_loc + step * float(mini);
frag_depth_point = (start_loc + step * float(mini)) * u_shape;
gl_FragColor = applyColormap(minval);
} else {
discard;
Expand Down

0 comments on commit 3cb973a

Please sign in to comment.