Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label region cursor bug #74

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/main/java/net/imglib2/roi/labeling/LabelRegionCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,4 @@ public LabelRegionCursor copy()
{
return new LabelRegionCursor( this );
}

@Override
public LabelRegionCursor copyCursor()
{
return copy();
}
}
27 changes: 14 additions & 13 deletions src/main/java/net/imglib2/roi/labeling/LabelRegions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
*/
package net.imglib2.roi.labeling;

import gnu.trove.list.array.TIntArrayList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import gnu.trove.list.array.TIntArrayList;
import net.imglib2.AbstractEuclideanSpace;
import net.imglib2.Cursor;
import net.imglib2.Localizable;
Expand Down Expand Up @@ -72,12 +73,12 @@ public class LabelRegions< T > extends AbstractEuclideanSpace implements Iterabl

private final LabelingType< T > type;

protected final ArrayList< FragmentProperties > indexToFragmentProperties;
protected final List< FragmentProperties > indexToFragmentProperties;

/**
* Maps labels to {@link LabelRegionProperties} for all currently non-empty labels in the labeling.
*/
private final HashMap< T, LabelRegionProperties > labelToLabelRegionProperties;
private final Map< T, LabelRegionProperties > labelToLabelRegionProperties;

/**
* Maps labels to {@link LabelRegionProperties} for all labels that were
Expand All @@ -89,7 +90,7 @@ public class LabelRegions< T > extends AbstractEuclideanSpace implements Iterabl
* into the live map, meaning that {@link LabelRegion}s that reference it
* will be updated correctly.
*/
private final HashMap< T, LabelRegionProperties > allLabelToLabelRegionProperties;
private final Map< T, LabelRegionProperties > allLabelToLabelRegionProperties;

/**
* maintains "canonical" {@link LabelRegion}s that were created by
Expand All @@ -101,19 +102,19 @@ public class LabelRegions< T > extends AbstractEuclideanSpace implements Iterabl
* to always create new {@link LabelRegion}s, which are not re-positioned or
* have had their origin changed.
*/
private final HashMap< T, LabelRegion< T > > labelToLabelRegion;
private final Map< T, LabelRegion< T > > labelToLabelRegion;

private int expectedGeneration;

public LabelRegions( final RandomAccessibleInterval< LabelingType< T > > labeling )
{
super( labeling.numDimensions() );
this.labeling = labeling;
type = Views.iterable( labeling ).firstElement();
indexToFragmentProperties = new ArrayList< FragmentProperties >();
labelToLabelRegionProperties = new HashMap< T, LabelRegionProperties >();
allLabelToLabelRegionProperties = new HashMap< T, LabelRegionProperties >();
labelToLabelRegion = new HashMap< T, LabelRegion< T > >();
type = labeling.getType();
indexToFragmentProperties = new ArrayList<>();
labelToLabelRegionProperties = new HashMap<>();
allLabelToLabelRegionProperties = new HashMap<>();
labelToLabelRegion = new HashMap<>();
expectedGeneration = type.getGeneration() - 1;
}

Expand All @@ -123,7 +124,7 @@ public LabelRegion< T > getLabelRegion( final T label )
LabelRegion< T > labelRegion = labelToLabelRegion.get( label );
if ( labelRegion == null )
{
labelRegion = new LabelRegion< T >( this, labelToLabelRegionProperties.get( label ), label );
labelRegion = new LabelRegion<>(this, labelToLabelRegionProperties.get(label), label);
labelToLabelRegion.put( label, labelRegion );
}
return labelRegion;
Expand Down Expand Up @@ -159,7 +160,7 @@ public LabelRegion< T > next()
LabelRegion< T > labelRegion = labelToLabelRegion.get( label );
if ( labelRegion == null )
{
labelRegion = new LabelRegion< T >( LabelRegions.this, labelToLabelRegionProperties.get( label ), label );
labelRegion = new LabelRegion<>(LabelRegions.this, labelToLabelRegionProperties.get(label), label);
labelToLabelRegion.put( label, labelRegion );
}
return labelRegion;
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/net/imglib2/roi/util/SamplingCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public T getType()
@Override
public SamplingCursor< T > copy()
{
return new SamplingCursor< T >( source.copyCursor(), target.copyRandomAccess() );
}

@Override
public SamplingCursor< T > copyCursor()
{
return copy();
return new SamplingCursor<>( source.copy(), target.copy() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IterationCodeCursor( final TIntArrayList itcode, final long[] offset )

protected IterationCodeCursor( final IterationCodeCursor c )
{
super( c.position );
super( c.position.clone() );
iter = new IterationCodeIterator<>( c.iter, Point.wrap( position ) );
}

Expand Down Expand Up @@ -111,10 +111,4 @@ public IterationCodeCursor copy()
{
return new IterationCodeCursor( this );
}

@Override
public IterationCodeCursor copyCursor()
{
return copy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IterationCodeListCursor( final ArrayList< TIntArrayList > itcodesList, fi

protected IterationCodeListCursor( final IterationCodeListCursor c )
{
super( c.position );
super( c.position.clone() );
iter = new IterationCodeListIterator<>( c.iter, Point.wrap( position ) );
}

Expand Down Expand Up @@ -111,10 +111,4 @@ public IterationCodeListCursor copy()
{
return new IterationCodeListCursor( this );
}

@Override
public IterationCodeListCursor copyCursor()
{
return copy();
}
}
Loading