Skip to content

Commit 1db7ae7

Browse files
committed
Adapt API changes introduced by imglib/imglib2-roi#71
1 parent 83eaa1e commit 1db7ae7

File tree

11 files changed

+55
-36
lines changed

11 files changed

+55
-36
lines changed

src/main/java/sc/fiji/labkit/ui/actions/AddLabelingIoAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void addLabel(Labeling labeling, Label label,
8484
.stream().map(Label::name).collect(Collectors.toList()));
8585
if (newLabelName == null) return;
8686
Label newLabel = labeling.addLabel(newLabelName);
87-
Cursor<Void> cursor = region.cursor();
87+
Cursor<Void> cursor = region.inside().cursor();
8888
RandomAccess<LabelingType<Label>> ra = labeling.randomAccess();
8989
while (cursor.hasNext()) {
9090
cursor.fwd();

src/main/java/sc/fiji/labkit/ui/labeling/Labeling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static Labeling fromMap(Map<String, IterableRegion<BitType>> regions) {
142142
new SparseRandomAccessIntType(interval));
143143
RandomAccess<LabelingType<Label>> ra = imgLabeling.randomAccess();
144144
regions.forEach((label, region) -> {
145-
Cursor<Void> cursor = region.cursor();
145+
Cursor<Void> cursor = region.inside().cursor();
146146
while (cursor.hasNext()) {
147147
cursor.fwd();
148148
ra.setPosition(cursor);

src/main/java/sc/fiji/labkit/ui/labeling/LabelingSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private JsonElement regionToJson(Gson gson,
266266
IterableRegion<BitType> region)
267267
{
268268
JsonArray result = new JsonArray();
269-
Cursor<Void> cursor = region.cursor();
269+
Cursor<Void> cursor = region.inside().cursor();
270270
long[] coords = new long[cursor.numDimensions()];
271271
while (cursor.hasNext()) {
272272
cursor.fwd();

src/main/java/sc/fiji/labkit/ui/models/ColoredLabelsModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void localizeLabel(final Label label) {
141141

142142
private static Interval getBoundingBox(IterableRegion<BitType> region) {
143143
int numDimensions = region.numDimensions();
144-
Cursor<?> cursor = region.cursor();
144+
Cursor<?> cursor = region.inside().cursor();
145145
if (!cursor.hasNext()) return null;
146146
long[] min = new long[numDimensions];
147147
long[] max = new long[numDimensions];

src/main/java/sc/fiji/labkit/ui/plugin/MeasureConnectedComponents.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static void addAction(Extensible extensible, LabelingModel model) {
114114

115115
static List<Long> connectedComponetsSizes(IterableRegion<BitType> region) {
116116
List<Long> sizes = new ArrayList<>();
117-
Cursor<Void> cursor = region.cursor();
117+
Cursor<Void> cursor = region.inside().cursor();
118118
SparseRandomAccessIntType visitedImage = new SparseRandomAccessIntType(
119119
region);
120120
RandomAccess<IntType> visited = visitedImage.randomAccess();
@@ -124,12 +124,12 @@ static List<Long> connectedComponetsSizes(IterableRegion<BitType> region) {
124124
visited.setPosition(cursor);
125125
if (visited.get().get() == 0) {
126126
currentIndex++;
127-
long countBefore = visitedImage.sparsityPattern().size();
127+
long countBefore = visitedImage.sparsityPattern().inside().size();
128128
Filter<Pair<BitType, IntType>, Pair<BitType, IntType>> filter = (
129129
current, seed) -> current.getA().get() && current.getB().get() == 0;
130130
FloodFill.fill(region, visitedImage, cursor, new IntType(currentIndex),
131131
new DiamondShape(1), filter);
132-
long countAfter = visitedImage.sparsityPattern().size();
132+
long countAfter = visitedImage.sparsityPattern().inside().size();
133133
sizes.add(countAfter - countBefore);
134134
}
135135
}

src/main/java/sc/fiji/labkit/ui/segmentation/weka/TrainableSegmentationSegmenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private void trainFrame(Training training, List<String> classes, Labeling labeli
260260
ImgPlus<?> image, FeatureCalculator featuresCalculator)
261261
{
262262
SparseRandomAccessIntType classIndices = getClassIndices(labeling, classes);
263-
if (classIndices.sparsityPattern().size() == 0)
263+
if (classIndices.sparsityPattern().inside().size() == 0)
264264
return;
265265
DiskCachedCellImg<FloatType, ?> cachedFeatureBlock = cachedFeatureBlock(featuresCalculator,
266266
image);

src/main/java/sc/fiji/labkit/ui/utils/sparse/SparseIterableRegion.java

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import net.imglib2.AbstractWrappedInterval;
3636
import net.imglib2.Cursor;
3737
import net.imglib2.Interval;
38+
import net.imglib2.IterableInterval;
3839
import net.imglib2.Localizable;
3940
import net.imglib2.Point;
4041
import net.imglib2.RandomAccess;
@@ -56,6 +57,8 @@ public class SparseIterableRegion extends AbstractWrappedInterval<Interval>
5657

5758
final private IntervalIndexer2 indexer;
5859

60+
private final InsideIterable inside;
61+
5962
public SparseIterableRegion(Interval interval) {
6063
this(interval, new TLongHashSet());
6164
}
@@ -64,6 +67,7 @@ public SparseIterableRegion(Interval interval, TLongSet positions) {
6467
super(interval);
6568
this.codes = positions;
6669
this.indexer = new IntervalIndexer2(interval);
70+
this.inside = new InsideIterable();
6771
}
6872

6973
public void add(Localizable position) {
@@ -79,43 +83,58 @@ private boolean contains(Localizable position) {
7983
}
8084

8185
@Override
82-
public Cursor<Void> cursor() {
83-
return new SparseRoiCursor();
86+
public RandomAccess<BitType> randomAccess() {
87+
return new SparseRoiRandomAccess();
8488
}
8589

8690
@Override
87-
public Cursor<Void> localizingCursor() {
88-
return cursor();
91+
public RandomAccess<BitType> randomAccess(Interval interval) {
92+
return randomAccess();
8993
}
9094

9195
@Override
92-
public long size() {
93-
return codes.size();
96+
public IterableInterval< Void > inside()
97+
{
98+
return inside;
9499
}
95100

96-
@Override
97-
public Void firstElement() {
98-
return null;
99-
}
101+
private class InsideIterable extends AbstractWrappedInterval< Interval > implements IterableInterval< Void >
102+
{
103+
InsideIterable()
104+
{
105+
super( SparseIterableRegion.this );
106+
}
100107

101-
@Override
102-
public Object iterationOrder() {
103-
return null;
104-
}
108+
@Override
109+
public Cursor<Void> cursor() {
110+
return new SparseRoiCursor();
111+
}
105112

106-
@Override
107-
public Iterator<Void> iterator() {
108-
return cursor();
109-
}
113+
@Override
114+
public Cursor<Void> localizingCursor() {
115+
return cursor();
116+
}
110117

111-
@Override
112-
public RandomAccess<BitType> randomAccess() {
113-
return new SparseRoiRandomAccess();
118+
@Override
119+
public long size() {
120+
return codes.size();
121+
}
122+
123+
@Override
124+
public Void firstElement() {
125+
return null;
126+
}
127+
128+
@Override
129+
public Object iterationOrder() {
130+
return this;
131+
}
114132
}
115133

116134
@Override
117-
public RandomAccess<BitType> randomAccess(Interval interval) {
118-
return randomAccess();
135+
public BitType getType()
136+
{
137+
return new BitType();
119138
}
120139

121140
private class SparseRoiCursor extends AbstractCursor<Void> implements

src/main/java/sc/fiji/labkit/ui/utils/sparse/SparseRandomAccessIntType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public RandomAccess<IntType> randomAccess(Interval interval) {
7878
}
7979

8080
public Cursor<IntType> sparseCursor() {
81-
return new MappingCursor<>(sparsityPattern().cursor(), randomAccess());
81+
return new MappingCursor<>(sparsityPattern().inside().cursor(), randomAccess());
8282
}
8383

8484
public IterableRegion<? extends BooleanType<?>> sparsityPattern() {

src/test/java/demo/custom_segmenter/MeanCalculator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MeanCalculator {
4545
public void addSample(RandomAccessibleInterval<?> image,
4646
IterableRegion<BitType> region)
4747
{
48-
Cursor<Void> cursor = region.cursor();
48+
Cursor<Void> cursor = region.inside().cursor();
4949
RandomAccess<RealType<?>> randomAccess = Cast.unchecked(image.randomAccess());
5050
while (cursor.hasNext()) {
5151
cursor.fwd();

src/test/java/sc/fiji/labkit/ui/labeling/SparseIterableRegionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testSize() {
6969
RandomAccess<BitType> ra = roi.randomAccess();
7070
ra.setPosition(positionA);
7171
ra.get().set(true);
72-
assertEquals(1, roi.size());
72+
assertEquals(1, roi.inside().size());
7373
}
7474

7575
@Test
@@ -78,7 +78,7 @@ public void testCursor() {
7878
RandomAccess<BitType> ra = roi.randomAccess();
7979
ra.setPosition(positionA);
8080
ra.get().set(true);
81-
Cursor<Void> cursor = roi.cursor();
81+
Cursor<Void> cursor = roi.inside().cursor();
8282
assertTrue(cursor.hasNext());
8383
cursor.fwd();
8484
assertEquals(positionA[1], cursor.getLongPosition(1));

0 commit comments

Comments
 (0)