Skip to content
Snippets Groups Projects
Commit c96d534a authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Receive compressFromMipmap level from server.

Also bunch of files are reformatted since we merged the source of the fork to stay up to date.
parent 93f64136
No related branches found
No related tags found
No related merge requests found
package azgracompress;
public class ViewerCompressionOptions {
private boolean enabled = false;
private int compressFromMipmapLevel = 0;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enable) {
this.enabled = enable;
}
public int getCompressFromMipmapLevel() {
return compressFromMipmapLevel;
}
public void setCompressFromMipmapLevel(final int compressFrom) {
this.compressFromMipmapLevel = compressFrom;
}
}
This diff is collapsed.
......@@ -28,7 +28,6 @@
*/
package bdv.img.remote;
import azgracompress.ViewerCompressionOptions;
import azgracompress.cache.ICacheFile;
import azgracompress.cache.QuantizationCacheManager;
import azgracompress.compression.ImageDecompressor;
......@@ -41,6 +40,7 @@ import bdv.img.hdf5.DimsAndExistence;
import bdv.img.hdf5.MipmapInfo;
import bdv.img.hdf5.ViewLevelId;
import bdv.util.ConstantRandomAccessible;
import bdv.viewer.ViewerOptions;
import com.google.gson.GsonBuilder;
import mpicbg.spim.data.generic.sequence.ImgLoaderHint;
import net.imglib2.FinalInterval;
......@@ -77,7 +77,7 @@ public class RemoteImageLoader implements ViewerImgLoader {
/**
* Flag whether we allow the server to send us compressed data.
*/
private ViewerCompressionOptions viewerCompressionOptions;
private ViewerOptions.CompressionOptions viewerCompressionOptions;
/**
......@@ -131,7 +131,7 @@ public class RemoteImageLoader implements ViewerImgLoader {
}
}
public void setViewerCompressionOptions(final ViewerCompressionOptions ops) {
public void setViewerCompressionOptions(final ViewerOptions.CompressionOptions ops) {
this.viewerCompressionOptions = ops;
}
......@@ -146,7 +146,9 @@ public class RemoteImageLoader implements ViewerImgLoader {
return;
}
final ArrayList<ICacheFile> cacheFiles = new ArrayList<>();
int compressFromMipmapLevel = 0;
try (final DataInputStream dis = new DataInputStream(connection.getInputStream())) {
compressFromMipmapLevel = dis.readByte();
final int codebookCount = dis.readByte();
for (int cbIndex = 0; cbIndex < codebookCount; cbIndex++) {
final ICacheFile readCacheFile = QuantizationCacheManager.readCacheFile(dis);
......@@ -160,13 +162,15 @@ public class RemoteImageLoader implements ViewerImgLoader {
}
}
ColorConsole.fprintf(ColorConsole.Target.stdout, ColorConsole.Color.Yellow, "Received %d cache files.", cacheFiles.size());
ColorConsole.fprintf(ColorConsole.Target.stdout, ColorConsole.Color.Yellow,
"Decompressing from mipmap level %d.", compressFromMipmapLevel);
final ImageDecompressor[] decompressors = new ImageDecompressor[cacheFiles.size()];
for (int i = 0; i < cacheFiles.size(); i++) {
decompressors[i] = new ImageDecompressor(cacheFiles.get(i));
}
shortLoader.setDataDecompressors(decompressors, metadata.maxNumLevels, viewerCompressionOptions.getCompressFromMipmapLevel());
shortLoader.setDataDecompressors(decompressors, metadata.maxNumLevels, compressFromMipmapLevel);
}
......
......@@ -28,9 +28,9 @@
*/
package bdv.spimdata;
import azgracompress.ViewerCompressionOptions;
import bdv.img.remote.RemoteImageLoader;
import bdv.spimdata.legacy.XmlIoSpimDataMinimalLegacy;
import bdv.viewer.ViewerOptions;
import mpicbg.spim.data.SpimDataException;
import mpicbg.spim.data.SpimDataIOException;
import mpicbg.spim.data.generic.XmlIoAbstractSpimData;
......@@ -49,7 +49,7 @@ import java.io.File;
import static mpicbg.spim.data.XmlKeys.SPIMDATA_TAG;
public class XmlIoSpimDataMinimal extends XmlIoAbstractSpimData<SequenceDescriptionMinimal, SpimDataMinimal> {
private ViewerCompressionOptions compressionOptions;
private ViewerOptions.CompressionOptions compressionOptions;
public XmlIoSpimDataMinimal() {
super(SpimDataMinimal.class,
......@@ -61,7 +61,7 @@ public class XmlIoSpimDataMinimal extends XmlIoAbstractSpimData<SequenceDescript
new XmlIoViewRegistrations());
}
public void setViewerCompressionOptions(final ViewerCompressionOptions ops) {
public void setViewerCompressionOptions(final ViewerOptions.CompressionOptions ops) {
this.compressionOptions = ops;
}
......
......@@ -6,13 +6,13 @@
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
......@@ -29,285 +29,274 @@
package bdv.viewer;
import bdv.TransformEventHandler3D;
import java.awt.event.KeyListener;
import org.scijava.ui.behaviour.KeyPressedManager;
import org.scijava.ui.behaviour.io.InputTriggerConfig;
import bdv.TransformEventHandlerFactory;
import bdv.viewer.animate.MessageOverlayAnimator;
import bdv.viewer.render.AccumulateProjector;
import bdv.viewer.render.AccumulateProjectorARGB;
import bdv.viewer.render.AccumulateProjectorFactory;
import bdv.viewer.render.MultiResolutionRenderer;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.ARGBType;
import bdv.TransformEventHandlerFactory;
import org.scijava.ui.behaviour.KeyPressedManager;
import org.scijava.ui.behaviour.io.InputTriggerConfig;
import java.awt.event.KeyListener;
/**
* Optional parameters for {@link ViewerPanel}.
*
* @author Tobias Pietzsch
*/
public class ViewerOptions
{
public final Values values = new Values();
/**
* Create default {@link ViewerOptions}.
* @return default {@link ViewerOptions}.
*/
public static ViewerOptions options()
{
return new ViewerOptions();
}
/**
* Set width of {@link ViewerPanel} canvas.
*/
public ViewerOptions width( final int w )
{
values.width = w;
return this;
}
/**
* Set height of {@link ViewerPanel} canvas.
*/
public ViewerOptions height( final int h )
{
values.height = h;
return this;
}
/**
* Set the number and scale factors for scaled screen images.
*
* @param s
* Scale factors from the viewer canvas to screen images of
* different resolutions. A scale factor of 1 means 1 pixel in
* the screen image is displayed as 1 pixel on the canvas, a
* scale factor of 0.5 means 1 pixel in the screen image is
* displayed as 2 pixel on the canvas, etc.
* @see MultiResolutionRenderer
*/
public ViewerOptions screenScales( final double[] s )
{
values.screenScales = s;
return this;
}
/**
* Set target rendering time in nanoseconds.
*
* @param t
* Target rendering time in nanoseconds. The rendering time for
* the coarsest rendered scale should be below this threshold.
* @see MultiResolutionRenderer
*/
public ViewerOptions targetRenderNanos( final long t )
{
values.targetRenderNanos = t;
return this;
}
/**
* Set how many threads to use for rendering.
*
* @param n
* How many threads to use for rendering.
* @see MultiResolutionRenderer
*/
public ViewerOptions numRenderingThreads( final int n )
{
values.numRenderingThreads = n;
return this;
}
/**
* Set how many source groups there are initially.
*
* @param n
* How many source groups to create initially.
*/
public ViewerOptions numSourceGroups( final int n )
{
values.numSourceGroups = n;
return this;
}
/**
* Set whether volatile versions of sources should be used if available.
*
* @param v
* whether volatile versions of sources should be used if
* available.
* @see MultiResolutionRenderer
*/
public ViewerOptions useVolatileIfAvailable( final boolean v )
{
values.useVolatileIfAvailable = v;
return this;
}
public ViewerOptions msgOverlay( final MessageOverlayAnimator o )
{
values.msgOverlay = o;
return this;
}
public ViewerOptions transformEventHandlerFactory( final TransformEventHandlerFactory f )
{
values.transformEventHandlerFactory = f;
return this;
}
/**
* Set the factory for creating {@link AccumulateProjector}. This can be
* used to customize how sources are combined.
*
* @param f
* factory for creating {@link AccumulateProjector}.
* @see MultiResolutionRenderer
*/
public ViewerOptions accumulateProjectorFactory( final AccumulateProjectorFactory< ARGBType > f )
{
values.accumulateProjectorFactory = f;
return this;
}
/**
* Set the {@link InputTriggerConfig} from which keyboard and mouse action mapping is loaded.
*
* @param c the {@link InputTriggerConfig} from which keyboard and mouse action mapping is loaded
*/
public ViewerOptions inputTriggerConfig( final InputTriggerConfig c )
{
values.inputTriggerConfig = c;
return this;
}
/**
* Set the {@link KeyPressedManager} to share
* {@link KeyListener#keyPressed(java.awt.event.KeyEvent)} events with other
* ui-behaviour windows.
* <p>
* The goal is to make keyboard click/drag behaviours work like mouse
* click/drag: When a behaviour is initiated with a key press, the window
* under the mouse receives focus and the behaviour is handled there.
* </p>
*
* @param manager
* @return
*/
public ViewerOptions shareKeyPressedEvents( final KeyPressedManager manager )
{
values.keyPressedManager = manager;
return this;
}
/**
* Read-only {@link ViewerOptions} values.
*/
public static class Values
{
private int width = 800;
private int height = 600;
private double[] screenScales = new double[] { 1, 0.75, 0.5, 0.25, 0.125 };
private long targetRenderNanos = 30 * 1000000l;
private int numRenderingThreads = 3;
private int numSourceGroups = 10;
private boolean useVolatileIfAvailable = true;
private MessageOverlayAnimator msgOverlay = new MessageOverlayAnimator( 800 );
private TransformEventHandlerFactory transformEventHandlerFactory = TransformEventHandler3D::new;
private AccumulateProjectorFactory< ARGBType > accumulateProjectorFactory = AccumulateProjectorARGB.factory;
private InputTriggerConfig inputTriggerConfig = null;
private KeyPressedManager keyPressedManager = null;
public ViewerOptions optionsFromValues()
{
return new ViewerOptions().
width( width ).
height( height ).
screenScales( screenScales ).
targetRenderNanos( targetRenderNanos ).
numRenderingThreads( numRenderingThreads ).
numSourceGroups( numSourceGroups ).
useVolatileIfAvailable( useVolatileIfAvailable ).
msgOverlay( msgOverlay ).
transformEventHandlerFactory( transformEventHandlerFactory ).
accumulateProjectorFactory( accumulateProjectorFactory ).
inputTriggerConfig( inputTriggerConfig );
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public double[] getScreenScales()
{
return screenScales;
}
public long getTargetRenderNanos()
{
return targetRenderNanos;
}
public int getNumRenderingThreads()
{
return numRenderingThreads;
}
public int getNumSourceGroups()
{
return numSourceGroups;
}
public boolean isUseVolatileIfAvailable()
{
return useVolatileIfAvailable;
}
public MessageOverlayAnimator getMsgOverlay()
{
return msgOverlay;
}
public TransformEventHandlerFactory getTransformEventHandlerFactory()
{
return transformEventHandlerFactory;
}
public AccumulateProjectorFactory< ARGBType > getAccumulateProjectorFactory()
{
return accumulateProjectorFactory;
}
public InputTriggerConfig getInputTriggerConfig()
{
return inputTriggerConfig;
}
public KeyPressedManager getKeyPressedManager()
{
return keyPressedManager;
}
}
public class ViewerOptions {
public static class CompressionOptions {
private boolean enabled = false;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enable) {
this.enabled = enable;
}
}
public final Values values = new Values();
/**
* Create default {@link ViewerOptions}.
*
* @return default {@link ViewerOptions}.
*/
public static ViewerOptions options() {
return new ViewerOptions();
}
/**
* Set width of {@link ViewerPanel} canvas.
*/
public ViewerOptions width(final int w) {
values.width = w;
return this;
}
public ViewerOptions compressionOptions(final CompressionOptions compressionOptions) {
values.compressionOptions = compressionOptions;
return this;
}
/**
* Set height of {@link ViewerPanel} canvas.
*/
public ViewerOptions height(final int h) {
values.height = h;
return this;
}
/**
* Set the number and scale factors for scaled screen images.
*
* @param s Scale factors from the viewer canvas to screen images of
* different resolutions. A scale factor of 1 means 1 pixel in
* the screen image is displayed as 1 pixel on the canvas, a
* scale factor of 0.5 means 1 pixel in the screen image is
* displayed as 2 pixel on the canvas, etc.
* @see MultiResolutionRenderer
*/
public ViewerOptions screenScales(final double[] s) {
values.screenScales = s;
return this;
}
/**
* Set target rendering time in nanoseconds.
*
* @param t Target rendering time in nanoseconds. The rendering time for
* the coarsest rendered scale should be below this threshold.
* @see MultiResolutionRenderer
*/
public ViewerOptions targetRenderNanos(final long t) {
values.targetRenderNanos = t;
return this;
}
/**
* Set how many threads to use for rendering.
*
* @param n How many threads to use for rendering.
* @see MultiResolutionRenderer
*/
public ViewerOptions numRenderingThreads(final int n) {
values.numRenderingThreads = n;
return this;
}
/**
* Set how many source groups there are initially.
*
* @param n How many source groups to create initially.
*/
public ViewerOptions numSourceGroups(final int n) {
values.numSourceGroups = n;
return this;
}
/**
* Set whether volatile versions of sources should be used if available.
*
* @param v whether volatile versions of sources should be used if
* available.
* @see MultiResolutionRenderer
*/
public ViewerOptions useVolatileIfAvailable(final boolean v) {
values.useVolatileIfAvailable = v;
return this;
}
public ViewerOptions msgOverlay(final MessageOverlayAnimator o) {
values.msgOverlay = o;
return this;
}
public ViewerOptions transformEventHandlerFactory(final TransformEventHandlerFactory f) {
values.transformEventHandlerFactory = f;
return this;
}
/**
* Set the factory for creating {@link AccumulateProjector}. This can be
* used to customize how sources are combined.
*
* @param f factory for creating {@link AccumulateProjector}.
* @see MultiResolutionRenderer
*/
public ViewerOptions accumulateProjectorFactory(final AccumulateProjectorFactory<ARGBType> f) {
values.accumulateProjectorFactory = f;
return this;
}
/**
* Set the {@link InputTriggerConfig} from which keyboard and mouse action mapping is loaded.
*
* @param c the {@link InputTriggerConfig} from which keyboard and mouse action mapping is loaded
*/
public ViewerOptions inputTriggerConfig(final InputTriggerConfig c) {
values.inputTriggerConfig = c;
return this;
}
/**
* Set the {@link KeyPressedManager} to share
* {@link KeyListener#keyPressed(java.awt.event.KeyEvent)} events with other
* ui-behaviour windows.
* <p>
* The goal is to make keyboard click/drag behaviours work like mouse
* click/drag: When a behaviour is initiated with a key press, the window
* under the mouse receives focus and the behaviour is handled there.
* </p>
*
* @param manager
* @return
*/
public ViewerOptions shareKeyPressedEvents(final KeyPressedManager manager) {
values.keyPressedManager = manager;
return this;
}
/**
* Read-only {@link ViewerOptions} values.
*/
public static class Values {
private int width = 800;
private int height = 600;
private double[] screenScales = new double[]{1, 0.75, 0.5, 0.25, 0.125};
private long targetRenderNanos = 30 * 1000000l;
private int numRenderingThreads = 3;
private int numSourceGroups = 10;
private boolean useVolatileIfAvailable = true;
private MessageOverlayAnimator msgOverlay = new MessageOverlayAnimator(800);
private TransformEventHandlerFactory transformEventHandlerFactory = TransformEventHandler3D::new;
private AccumulateProjectorFactory<ARGBType> accumulateProjectorFactory = AccumulateProjectorARGB.factory;
private InputTriggerConfig inputTriggerConfig = null;
private KeyPressedManager keyPressedManager = null;
private CompressionOptions compressionOptions = new CompressionOptions();
public ViewerOptions optionsFromValues() {
return new ViewerOptions().
width(width).
height(height).
screenScales(screenScales).
targetRenderNanos(targetRenderNanos).
numRenderingThreads(numRenderingThreads).
numSourceGroups(numSourceGroups).
useVolatileIfAvailable(useVolatileIfAvailable).
msgOverlay(msgOverlay).
transformEventHandlerFactory(transformEventHandlerFactory).
accumulateProjectorFactory(accumulateProjectorFactory).
inputTriggerConfig(inputTriggerConfig).
compressionOptions(compressionOptions);
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public double[] getScreenScales() {
return screenScales;
}
public long getTargetRenderNanos() {
return targetRenderNanos;
}
public int getNumRenderingThreads() {
return numRenderingThreads;
}
public int getNumSourceGroups() {
return numSourceGroups;
}
public boolean isUseVolatileIfAvailable() {
return useVolatileIfAvailable;
}
public MessageOverlayAnimator getMsgOverlay() {
return msgOverlay;
}
public TransformEventHandlerFactory getTransformEventHandlerFactory() {
return transformEventHandlerFactory;
}
public AccumulateProjectorFactory<ARGBType> getAccumulateProjectorFactory() {
return accumulateProjectorFactory;
}
public InputTriggerConfig getInputTriggerConfig() {
return inputTriggerConfig;
}
public KeyPressedManager getKeyPressedManager() {
return keyPressedManager;
}
public CompressionOptions getCompressionOptions() {
return compressionOptions;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment