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

Use ClassCopyProvider to instantiate RealARGBColorConverter

Before, two class "copies" were hard-coded (Imp0, Imp1) and used for
volatile respectively non-volatile Types. This would still cause slow-down
if for example IntType and ShortType were mixed. Now, every Type gets its
own class copy.
parent 2fcad967
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer-core</artifactId>
<version>6.0.3-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
<name>BigDataViewer Core</name>
<description>BigDataViewer core classes with minimal dependencies.</description>
......
......
......@@ -174,14 +174,17 @@ public class BigDataViewer
initSetupRealTypeNonVolatile( spimData, setup, type, converterSetups, sources );
return;
}
final int setupId = setup.getId();
final V volatileType = ( ( ViewerSetupImgLoader< T, V > ) spimData.getSequenceDescription().getImgLoader().getSetupImgLoader( setupId ) ).getVolatileImageType();
final double typeMin = Math.max( 0, Math.min( type.getMinValue(), 65535 ) );
final double typeMax = Math.max( 0, Math.min( type.getMaxValue(), 65535 ) );
final RealARGBColorConverter< V > vconverter = new RealARGBColorConverter.Imp0<>( typeMin, typeMax );
final RealARGBColorConverter< V > vconverter = RealARGBColorConverter.create( volatileType, typeMin, typeMax );
vconverter.setColor( new ARGBType( 0xffffffff ) );
final RealARGBColorConverter< T > converter = new RealARGBColorConverter.Imp1<>( typeMin, typeMax );
final RealARGBColorConverter< T > converter = RealARGBColorConverter.create( type, typeMin, typeMax );
converter.setColor( new ARGBType( 0xffffffff ) );
final int setupId = setup.getId();
final String setupName = createSetupName( setup );
final VolatileSpimSource< T, V > vs = new VolatileSpimSource<>( spimData, setupId, setupName );
final SpimSource< T > s = vs.nonVolatile();
......@@ -207,7 +210,7 @@ public class BigDataViewer
{
final double typeMin = type.getMinValue();
final double typeMax = type.getMaxValue();
final RealARGBColorConverter< T > converter = new RealARGBColorConverter.Imp1<>( typeMin, typeMax );
final RealARGBColorConverter< T > converter = RealARGBColorConverter.create( type, typeMin, typeMax );
converter.setColor( new ARGBType( 0xffffffff ) );
final int setupId = setup.getId();
......
......
......@@ -129,7 +129,7 @@ public class BoundingBoxDialog extends JDialog
};
// set up a converter from the source type (UnsignedShortType in this case) to ARGBType
final RealARGBColorConverter< UnsignedShortType > converter = new RealARGBColorConverter.Imp1<>( 0, 3000 );
final RealARGBColorConverter< UnsignedShortType > converter = RealARGBColorConverter.create( new UnsignedShortType(), 0, 3000 );
converter.setColor( new ARGBType( 0x00994499 ) ); // set bounding box color to magenta
// create a ConverterSetup (can be used by the brightness dialog to adjust the converter settings)
......
......
......@@ -30,34 +30,62 @@
package net.imglib2.display;
import net.imglib2.converter.Converter;
import net.imglib2.loops.ClassCopyProvider;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.RealType;
public abstract class RealARGBColorConverter< R extends RealType< ? > > implements ColorConverter, Converter< R, ARGBType >
public interface RealARGBColorConverter< R extends RealType< ? > > extends ColorConverter, Converter< R, ARGBType >
{
protected double min = 0;
public static < R extends RealType< ? > > RealARGBColorConverter< R > create( final R type, final double min, final double max )
{
return Instances.create( type, min, max );
}
}
protected double max = 1;
class Instances
{
@SuppressWarnings( "rawtypes" )
private static ClassCopyProvider< RealARGBColorConverter > provider;
@SuppressWarnings( "unchecked" )
public static < R extends RealType< ? > > RealARGBColorConverter< R > create( final R type, final double min, final double max )
{
if ( provider == null )
{
synchronized ( Instances.class )
{
if ( provider == null )
provider = new ClassCopyProvider<>( Imp.class, RealARGBColorConverter.class, double.class, double.class );
}
}
return provider.newInstanceForKey( type, min, max );
}
protected final ARGBType color = new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) );
public static class Imp< R extends RealType< ? > > implements RealARGBColorConverter< R >
{
private double min = 0;
protected int A;
private double max = 1;
protected double scaleR;
private final ARGBType color = new ARGBType( ARGBType.rgba( 255, 255, 255, 255 ) );
protected double scaleG;
private int A;
protected double scaleB;
private double scaleR;
public RealARGBColorConverter( final double min, final double max )
private double scaleG;
private double scaleB;
private int black;
public Imp( final double min, final double max )
{
this.min = min;
this.max = max;
update();
}
protected int black;
@Override
public ARGBType getColor()
{
......@@ -114,41 +142,6 @@ public abstract class RealARGBColorConverter< R extends RealType< ? > > implemen
black = ARGBType.rgba( 0, 0, 0, A );
}
public static class Imp0< R extends RealType< ? > > extends RealARGBColorConverter< R >
{
public Imp0( final double min, final double max )
{
super( min, max );
}
@Override
public void convert( final R input, final ARGBType output )
{
final double v = input.getRealDouble() - min;
if ( v < 0 )
{
output.set( black );
}
else
{
final int r0 = ( int ) ( scaleR * v + 0.5 );
final int g0 = ( int ) ( scaleG * v + 0.5 );
final int b0 = ( int ) ( scaleB * v + 0.5 );
final int r = Math.min( 255, r0 );
final int g = Math.min( 255, g0 );
final int b = Math.min( 255, b0 );
output.set( ARGBType.rgba( r, g, b, A) );
}
}
}
public static class Imp1< R extends RealType< ? > > extends RealARGBColorConverter< R >
{
public Imp1( final double min, final double max )
{
super( min, max );
}
@Override
public void convert( final R input, final ARGBType output )
{
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment