Skip to content
Snippets Groups Projects
Commit 0ee593b5 authored by Tobias Pietzsch's avatar Tobias Pietzsch
Browse files

WIP move targetRenderNanos to ScreenScales

parent 266160b8
No related branches found
No related tags found
No related merge requests found
...@@ -122,14 +122,6 @@ public class MultiResolutionRenderer ...@@ -122,14 +122,6 @@ public class MultiResolutionRenderer
*/ */
private final RenderStorage renderStorage; private final RenderStorage renderStorage;
/**
* Target rendering time in nanoseconds. The rendering time for the coarsest
* rendered scale should be below this threshold. After the coarsest scale,
* increasingly finer scales are rendered, but these render passes may be
* canceled (while the coarsest may not).
*/
private final long targetRenderNanos;
/** /**
* Estimate of the time it takes to render one screen pixel from one source, * Estimate of the time it takes to render one screen pixel from one source,
* in nanoseconds. * in nanoseconds.
...@@ -157,8 +149,7 @@ public class MultiResolutionRenderer ...@@ -157,8 +149,7 @@ public class MultiResolutionRenderer
/** /**
* Whether the current rendering operation may be cancelled (to start a new * Whether the current rendering operation may be cancelled (to start a new
* one). Rendering may be cancelled unless we are rendering at the * one). Rendering may be cancelled unless we are rendering at the
* (estimated) coarsest screen scale meeting the rendering time * (estimated) coarsest screen scale meeting the rendering time threshold.
* {@link #targetRenderNanos threshold}.
*/ */
private boolean renderingMayBeCancelled; private boolean renderingMayBeCancelled;
...@@ -244,10 +235,9 @@ public class MultiResolutionRenderer ...@@ -244,10 +235,9 @@ public class MultiResolutionRenderer
this.painterThread = painterThread; this.painterThread = painterThread;
projector = null; projector = null;
currentScreenScaleIndex = -1; currentScreenScaleIndex = -1;
screenScales = new ScreenScales( screenScaleFactors ); screenScales = new ScreenScales( screenScaleFactors, targetRenderNanos );
renderStorage = new RenderStorage(); renderStorage = new RenderStorage();
this.targetRenderNanos = targetRenderNanos;
renderNanosPerPixelAndSource = new MovingAverage( 3 ); renderNanosPerPixelAndSource = new MovingAverage( 3 );
renderNanosPerPixelAndSource.init( 500 ); renderNanosPerPixelAndSource.init( 500 );
...@@ -310,7 +300,7 @@ public class MultiResolutionRenderer ...@@ -310,7 +300,7 @@ public class MultiResolutionRenderer
currentViewerState = viewerState.snapshot(); currentViewerState = viewerState.snapshot();
currentNumVisibleSources = currentViewerState.getVisibleAndPresentSources().size(); currentNumVisibleSources = currentViewerState.getVisibleAndPresentSources().size();
final double renderNanosPerPixel = renderNanosPerPixelAndSource.getAverage() * currentNumVisibleSources; final double renderNanosPerPixel = renderNanosPerPixelAndSource.getAverage() * currentNumVisibleSources;
requestedScreenScaleIndex = screenScales.suggestScreenScale( renderNanosPerPixel, targetRenderNanos ); requestedScreenScaleIndex = screenScales.suggestScreenScale( renderNanosPerPixel );
} }
final boolean createProjector = newFrame || ( requestedScreenScaleIndex != currentScreenScaleIndex ); final boolean createProjector = newFrame || ( requestedScreenScaleIndex != currentScreenScaleIndex );
...@@ -520,7 +510,7 @@ public class MultiResolutionRenderer ...@@ -520,7 +510,7 @@ public class MultiResolutionRenderer
{ {
cacheControl.prepareNextFrame(); cacheControl.prepareNextFrame();
final double renderNanosPerPixel = renderNanosPerPixelAndSource.getAverage() * currentNumVisibleSources; final double renderNanosPerPixel = renderNanosPerPixelAndSource.getAverage() * currentNumVisibleSources;
requestedIntervalScaleIndex = screenScales.suggestIntervalScreenScale( renderNanosPerPixel, targetRenderNanos, currentScreenScaleIndex ); requestedIntervalScaleIndex = screenScales.suggestIntervalScreenScale( renderNanosPerPixel, currentScreenScaleIndex );
} }
createProjector = newInterval || ( requestedIntervalScaleIndex != currentIntervalScaleIndex ); createProjector = newInterval || ( requestedIntervalScaleIndex != currentIntervalScaleIndex );
......
...@@ -2,12 +2,21 @@ package bdv.viewer.render; ...@@ -2,12 +2,21 @@ package bdv.viewer.render;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.imglib2.Interval; import net.imglib2.Interval;
import net.imglib2.realtransform.AffineTransform3D; import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.util.Intervals; import net.imglib2.util.Intervals;
public class ScreenScales public class ScreenScales
{ {
/**
* Target rendering time in nanoseconds. The rendering time for the coarsest
* rendered scale should be below this threshold. After the coarsest scale,
* increasingly finer scales are rendered, but these render passes may be
* canceled (while the coarsest may not).
*/
private final double targetRenderNanos;
private final List< ScreenScale > screenScales; private final List< ScreenScale > screenScales;
private int screenW = 0; private int screenW = 0;
...@@ -16,16 +25,19 @@ public class ScreenScales ...@@ -16,16 +25,19 @@ public class ScreenScales
/** /**
* @param screenScaleFactors * @param screenScaleFactors
* Scale factors from the viewer canvas to screen images of * Scale factors from the viewer canvas to screen images of different
* different resolutions. A scale factor of 1 means 1 pixel in * resolutions. A scale factor of 1 means 1 pixel in the screen image is
* the screen image is displayed as 1 pixel on the canvas, a * displayed as 1 pixel on the canvas, a scale factor of 0.5 means 1
* scale factor of 0.5 means 1 pixel in the screen image is * pixel in the screen image is displayed as 2 pixel on the canvas, etc.
* displayed as 2 pixel on the canvas, etc. * @param targetRenderNanos
* Target rendering time in nanoseconds. The rendering time for the
* coarsest rendered scale should be below this threshold.
*/ */
public ScreenScales( final double[] screenScaleFactors ) public ScreenScales( final double[] screenScaleFactors, final double targetRenderNanos )
{ {
this.targetRenderNanos = targetRenderNanos;
screenScales = new ArrayList<>(); screenScales = new ArrayList<>();
for ( double scale : screenScaleFactors ) for ( final double scale : screenScaleFactors )
screenScales.add( new ScreenScale( scale ) ); screenScales.add( new ScreenScale( scale ) );
} }
...@@ -46,17 +58,23 @@ public class ScreenScales ...@@ -46,17 +58,23 @@ public class ScreenScales
return false; return false;
} }
/**
* @return the screen scale at {@code index}
*/
public ScreenScale get( final int index ) public ScreenScale get( final int index )
{ {
return screenScales.get( index ); return screenScales.get( index );
} }
/**
* @return number of screen scales.
*/
public int size() public int size()
{ {
return screenScales.size(); return screenScales.size();
} }
public int suggestScreenScale( final double renderNanosPerPixel, final double targetRenderNanos ) public int suggestScreenScale( final double renderNanosPerPixel )
{ {
for ( int i = 0; i < screenScales.size() - 1; i++ ) for ( int i = 0; i < screenScales.size() - 1; i++ )
{ {
...@@ -67,7 +85,7 @@ public class ScreenScales ...@@ -67,7 +85,7 @@ public class ScreenScales
return screenScales.size() - 1; return screenScales.size() - 1;
} }
public int suggestIntervalScreenScale( final double renderNanosPerPixel, final double targetRenderNanos, final int minScreenScaleIndex ) public int suggestIntervalScreenScale( final double renderNanosPerPixel, final int minScreenScaleIndex )
{ {
for ( int i = minScreenScaleIndex; i < screenScales.size() - 1; i++ ) for ( int i = minScreenScaleIndex; i < screenScales.size() - 1; i++ )
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment