Skip to content
Snippets Groups Projects
Commit d51cc5a1 authored by Jean-Yves Tinevez's avatar Jean-Yves Tinevez
Browse files

LabelingSource: allow to specify on what mipmap level to operate

parent f931a1e3
No related branches found
No related tags found
No related merge requests found
......@@ -35,12 +35,13 @@ import viewer.render.Source;
* @author Stephan Preibisch
*
*/
public class LabelingSource implements Source<ARGBType> {
public class LabelingSource< T > implements Source< ARGBType >
{
private int currentTimepoint;
private NativeImgLabeling< Integer, IntType > currentSource;
private final Source<?> imgSource;
private final Source< T > imgSource;
private final String name;
......@@ -66,9 +67,13 @@ public class LabelingSource implements Source<ARGBType> {
private final AffineTransform3D currentTranform = new AffineTransform3D();
private final int level;
@SuppressWarnings( "unchecked" )
public LabelingSource(final Source<?> imgSource) {
public LabelingSource( final Source< T > imgSource, final int level )
{
this.imgSource = imgSource;
this.level = level;
name = imgSource.getName() + " annotations";
converter = new LabelingTypeARGBConverter< Integer >( new HashMap< List< Integer >, ARGBType >() );
interpolatorFactories = new InterpolatorFactory[ numInterpolationMethods ];
......@@ -80,76 +85,124 @@ public class LabelingSource implements Source<ARGBType> {
loadTimepoint( 0 );
}
public LabelingSource( final Source< T > imgSource )
{
this( imgSource, 0 );
}
@Override
public boolean isPresent(final int t) {
public boolean isPresent( final int t )
{
return imgSource.isPresent( t );
}
@Override
public RandomAccessibleInterval<ARGBType> getSource(final int t, final int level) {
public RandomAccessibleInterval< ARGBType > getSource( final int t, final int level )
{
if ( t != currentTimepoint )
{
loadTimepoint( t );
}
if ( currentAlpha != oldAlpha )
{
updateColorTable();
}
return Converters.convert( ( RandomAccessibleInterval< LabelingType< Integer >> ) currentSource, converter, new ARGBType() );
}
@Override
public RealRandomAccessible<ARGBType> getInterpolatedSource(final int t, final int level, final Interpolation method) {
public RealRandomAccessible< ARGBType > getInterpolatedSource( final int t, final int level, final Interpolation method )
{
return Views.interpolate( Views.extendValue( getSource( t, level ), new ARGBType() ), interpolatorFactories[ method == Interpolation.NLINEAR ? iNLinearMethod : iNearestNeighborMethod ] );
}
@Override
public int getNumMipmapLevels() {
public int getNumMipmapLevels()
{
return 1;
}
private void loadTimepoint(final int timepoint) {
/**
* Returns the mipmap level of the img source this labeling is built upon.
*
* @return the mipmap level.
*/
public int getLevel()
{
return level;
}
/**
* Exposes the {@link Source} this labeling source is built on.
*
* @return a {@link Source}.
*/
public Source< T > getImgSource()
{
return imgSource;
}
private void loadTimepoint( final int timepoint )
{
currentTimepoint = timepoint;
if (isPresent(timepoint)) {
if ( isPresent( timepoint ) )
{
currentTranform.set(imgSource.getSourceTransform(timepoint, 0));
currentTranform.set( imgSource.getSourceTransform( timepoint, level ) );
NativeImgLabeling< Integer, IntType > labeling = labelings.get( Integer.valueOf( timepoint ) );
if (null == labeling) {
final Dimensions sourceDimensions = imgSource.getSource(timepoint, 0);
if ( null == labeling )
{
final Dimensions sourceDimensions = imgSource.getSource( timepoint, level );
labeling = newLabeling( sourceDimensions );
labelings.put( Integer.valueOf( timepoint ), labeling );
}
currentSource = labeling;
updateColorTable();
} else
}
else
{
currentSource = null;
}
}
@Override
public AffineTransform3D getSourceTransform(final int t, final int level) {
if (currentTimepoint != t) {
public AffineTransform3D getSourceTransform( final int t, final int level )
{
if ( currentTimepoint != t )
{
loadTimepoint( t );
}
return currentTranform;
}
@Override
public ARGBType getType() {
public ARGBType getType()
{
return new ARGBType();
}
@Override
public String getName() {
public String getName()
{
return name;
}
public NativeImgLabeling<Integer, IntType> getLabeling(final int t) {
public NativeImgLabeling< Integer, IntType > getLabeling( final int t )
{
NativeImgLabeling< Integer, IntType > target;
if (isPresent(t)) {
if ( isPresent( t ) )
{
target = labelings.get( Integer.valueOf( t ) );
if (null == target) {
final Dimensions sourceDimensions = imgSource.getSource(t, 0);
if ( null == target )
{
final Dimensions sourceDimensions = imgSource.getSource( t, level );
target = newLabeling( sourceDimensions );
labelings.put( Integer.valueOf( t ), target );
}
} else {
}
else
{
target = null;
}
return target;
......@@ -161,7 +214,8 @@ public class LabelingSource implements Source<ARGBType> {
* @param alpha
* an <code>int</code>, ranging from 0 to 255.
*/
public void setAlpha(final int alpha) {
public void setAlpha( final int alpha )
{
this.currentAlpha = alpha;
}
......@@ -170,17 +224,20 @@ public class LabelingSource implements Source<ARGBType> {
*
* @return an <code>int</code>, ranging from 0 to 255.
*/
public int getAlpha() {
public int getAlpha()
{
return currentAlpha;
}
public void updateColorTable() {
public void updateColorTable()
{
final int a = currentAlpha;
final HashMap< List< Integer >, ARGBType > colorTable = new HashMap< List< Integer >, ARGBType >();
final LabelingMapping< Integer > mapping = currentSource.getMapping();
final int numLists = mapping.numLists();
final Random random = new Random( 1 );
for (int i = 0; i < numLists; ++i) {
for ( int i = 0; i < numLists; ++i )
{
final List< Integer > list = mapping.listAtIndex( i );
final int r = random.nextInt( 256 );
final int g = random.nextInt( 256 );
......@@ -192,7 +249,8 @@ public class LabelingSource implements Source<ARGBType> {
oldAlpha = a;
}
private static final NativeImgLabeling<Integer, IntType> newLabeling(final Dimensions dimensions) {
private static final NativeImgLabeling< Integer, IntType > newLabeling( final Dimensions dimensions )
{
final NtreeImgFactory< IntType > factory = new NtreeImgFactory< IntType >();
final Img< IntType > img = factory.create( dimensions, new IntType() );
final NativeImgLabeling< Integer, IntType > labeling = new NativeImgLabeling< Integer, IntType >( img );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment