Skip to content

Commit 43eebfe

Browse files
authored
Merge pull request #115, update to imglib2-7.1
Addition of getType() API
2 parents 343417f + 32bdfb5 commit 43eebfe

File tree

13 files changed

+78
-58
lines changed

13 files changed

+78
-58
lines changed

pom.xml

+8-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>34.1.0</version>
8+
<version>38.0.1</version>
99
</parent>
1010

1111
<groupId>sc.fiji</groupId>
@@ -85,24 +85,16 @@
8585
<license.licenseName>bsd_2</license.licenseName>
8686
<license.copyrightOwners>Matthias Arzt</license.copyrightOwners>
8787

88-
<imglib2.version>6.1.0</imglib2.version>
89-
<imglib2-cache.version>1.0.0-beta-17</imglib2-cache.version>
90-
<bigdataviewer-core.version>10.4.6</bigdataviewer-core.version>
91-
<bigdataviewer-vistools.version>1.0.0-beta-32</bigdataviewer-vistools.version>
92-
9388
<!-- NB: Deploy releases to the SciJava Maven repository. -->
9489
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
9590

96-
<bigdataviewer-core.version>10.4.6</bigdataviewer-core.version>
97-
<imagej-deprecated.version>0.2.0</imagej-deprecated.version>
98-
<imagej-ops.version>2.0.0</imagej-ops.version>
99-
<imglib2.version>6.1.0</imglib2.version>
100-
<imglib2-algorithm.version>0.13.2</imglib2-algorithm.version>
101-
<imglib2-algorithm-gpl.version>0.3.1</imglib2-algorithm-gpl.version>
102-
<imglib2-cache.version>1.0.0-beta-17</imglib2-cache.version>
103-
<imglib2-realtransform.version>4.0.1</imglib2-realtransform.version>
104-
<imglib2-roi.version>0.14.0</imglib2-roi.version>
105-
<scifio.version>0.45.0</scifio.version>
91+
<imglib2.version>7.1.0</imglib2.version>
92+
<imglib2-realtransform.version>4.0.3</imglib2-realtransform.version>
93+
<imglib2-roi.version>0.15.0</imglib2-roi.version>
94+
<imglib2-cache.version>1.0.0-beta-18</imglib2-cache.version>
95+
<imglib2-algorithm.version>0.15.3</imglib2-algorithm.version>
96+
<bigdataviewer-core.version>10.6.0</bigdataviewer-core.version>
97+
<labkit-pixel-classification.version>0.1.18</labkit-pixel-classification.version>
10698
</properties>
10799

108100
<dependencies>
@@ -198,10 +190,6 @@
198190
<groupId>sc.fiji</groupId>
199191
<artifactId>bigdataviewer-core</artifactId>
200192
</dependency>
201-
<dependency>
202-
<groupId>sc.fiji</groupId>
203-
<artifactId>bigdataviewer-vistools</artifactId>
204-
</dependency>
205193
<dependency>
206194
<groupId>net.imglib2</groupId>
207195
<artifactId>imglib2-realtransform</artifactId>

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

+1-1
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/brush/LabelBrushController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import net.imglib2.roi.IterableRegion;
4141
import net.imglib2.roi.Regions;
4242
import net.imglib2.type.logic.BitType;
43+
import net.imglib2.util.Intervals;
4344
import org.scijava.ui.behaviour.*;
4445
import sc.fiji.labkit.ui.ActionsAndBehaviours;
4546
import sc.fiji.labkit.ui.brush.neighborhood.Ellipsoid;
@@ -248,8 +249,8 @@ private List<Label> getVisibleLabels() {
248249
private RandomAccessible<LabelingType<Label>> extendLabelingType(
249250
RandomAccessibleInterval<LabelingType<Label>> slice)
250251
{
251-
LabelingType<Label> variable = Util.getTypeFromInterval(slice)
252-
.createVariable();
252+
LabelingType<Label> variable = slice.randomAccess()
253+
.setPositionAndGet(Intervals.minAsLongArray(slice)).createVariable();
253254
variable.clear();
254255
return Views.extendValue(slice, variable);
255256
}

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

+7-1
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);
@@ -303,6 +303,12 @@ public void setLabelOrder(Comparator<? super Label> comparator) {
303303
labels.sort(comparator);
304304
}
305305

306+
@Override
307+
public LabelingType< Label > getType()
308+
{
309+
return randomAccess().getType();
310+
}
311+
306312
public static class SetEntryAsBitType<T> extends BitType {
307313

308314
private Set<T> set = null;

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

+1-1
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

+1-1
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

+3-3
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

+1-1
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

+42-23
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

+7-1
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() {
@@ -124,6 +124,12 @@ private void set(MyRandomAccess position, int value) {
124124
}
125125
}
126126

127+
@Override
128+
public IntType getType()
129+
{
130+
return new IntType();
131+
}
132+
127133
// -- Helper classes --
128134

129135
private class MyRandomAccess extends Point implements RandomAccess<IntType> {

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

+1-1
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

+2-2
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));

src/test/java/sc/fiji/labkit/ui/utils/sparse/SparseRandomAccessIntTypeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public void testNoEntryValue() {
4949
noEntryValue);
5050
Views.iterable(image).forEach(x -> x.setInteger(noEntryValue));
5151
// test
52-
assertFalse(image.sparsityPattern().cursor().hasNext());
52+
assertFalse(image.sparsityPattern().inside().cursor().hasNext());
5353
}
5454
}

0 commit comments

Comments
 (0)