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

Addition of getType() API #115

Merged
merged 6 commits into from
Aug 29, 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
28 changes: 8 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>34.1.0</version>
<version>38.0.1</version>
</parent>

<groupId>sc.fiji</groupId>
Expand Down Expand Up @@ -85,24 +85,16 @@
<license.licenseName>bsd_2</license.licenseName>
<license.copyrightOwners>Matthias Arzt</license.copyrightOwners>

<imglib2.version>6.1.0</imglib2.version>
<imglib2-cache.version>1.0.0-beta-17</imglib2-cache.version>
<bigdataviewer-core.version>10.4.6</bigdataviewer-core.version>
<bigdataviewer-vistools.version>1.0.0-beta-32</bigdataviewer-vistools.version>

<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<bigdataviewer-core.version>10.4.6</bigdataviewer-core.version>
<imagej-deprecated.version>0.2.0</imagej-deprecated.version>
<imagej-ops.version>2.0.0</imagej-ops.version>
<imglib2.version>6.1.0</imglib2.version>
<imglib2-algorithm.version>0.13.2</imglib2-algorithm.version>
<imglib2-algorithm-gpl.version>0.3.1</imglib2-algorithm-gpl.version>
<imglib2-cache.version>1.0.0-beta-17</imglib2-cache.version>
<imglib2-realtransform.version>4.0.1</imglib2-realtransform.version>
<imglib2-roi.version>0.14.0</imglib2-roi.version>
<scifio.version>0.45.0</scifio.version>
<imglib2.version>7.1.0</imglib2.version>
<imglib2-realtransform.version>4.0.3</imglib2-realtransform.version>
<imglib2-roi.version>0.15.0</imglib2-roi.version>
<imglib2-cache.version>1.0.0-beta-18</imglib2-cache.version>
<imglib2-algorithm.version>0.15.3</imglib2-algorithm.version>
<bigdataviewer-core.version>10.6.0</bigdataviewer-core.version>
<labkit-pixel-classification.version>0.1.18</labkit-pixel-classification.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -198,10 +190,6 @@
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer-core</artifactId>
</dependency>
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer-vistools</artifactId>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-realtransform</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void addLabel(Labeling labeling, Label label,
.stream().map(Label::name).collect(Collectors.toList()));
if (newLabelName == null) return;
Label newLabel = labeling.addLabel(newLabelName);
Cursor<Void> cursor = region.cursor();
Cursor<Void> cursor = region.inside().cursor();
RandomAccess<LabelingType<Label>> ra = labeling.randomAccess();
while (cursor.hasNext()) {
cursor.fwd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.imglib2.roi.IterableRegion;
import net.imglib2.roi.Regions;
import net.imglib2.type.logic.BitType;
import net.imglib2.util.Intervals;
import org.scijava.ui.behaviour.*;
import sc.fiji.labkit.ui.ActionsAndBehaviours;
import sc.fiji.labkit.ui.brush.neighborhood.Ellipsoid;
Expand Down Expand Up @@ -248,8 +249,8 @@ private List<Label> getVisibleLabels() {
private RandomAccessible<LabelingType<Label>> extendLabelingType(
RandomAccessibleInterval<LabelingType<Label>> slice)
{
LabelingType<Label> variable = Util.getTypeFromInterval(slice)
.createVariable();
LabelingType<Label> variable = slice.randomAccess()
.setPositionAndGet(Intervals.minAsLongArray(slice)).createVariable();
variable.clear();
return Views.extendValue(slice, variable);
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/sc/fiji/labkit/ui/labeling/Labeling.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static Labeling fromMap(Map<String, IterableRegion<BitType>> regions) {
new SparseRandomAccessIntType(interval));
RandomAccess<LabelingType<Label>> ra = imgLabeling.randomAccess();
regions.forEach((label, region) -> {
Cursor<Void> cursor = region.cursor();
Cursor<Void> cursor = region.inside().cursor();
while (cursor.hasNext()) {
cursor.fwd();
ra.setPosition(cursor);
Expand Down Expand Up @@ -303,6 +303,12 @@ public void setLabelOrder(Comparator<? super Label> comparator) {
labels.sort(comparator);
}

@Override
public LabelingType< Label > getType()
{
return randomAccess().getType();
}

public static class SetEntryAsBitType<T> extends BitType {

private Set<T> set = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private JsonElement regionToJson(Gson gson,
IterableRegion<BitType> region)
{
JsonArray result = new JsonArray();
Cursor<Void> cursor = region.cursor();
Cursor<Void> cursor = region.inside().cursor();
long[] coords = new long[cursor.numDimensions()];
while (cursor.hasNext()) {
cursor.fwd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void localizeLabel(final Label label) {

private static Interval getBoundingBox(IterableRegion<BitType> region) {
int numDimensions = region.numDimensions();
Cursor<?> cursor = region.cursor();
Cursor<?> cursor = region.inside().cursor();
if (!cursor.hasNext()) return null;
long[] min = new long[numDimensions];
long[] max = new long[numDimensions];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void addAction(Extensible extensible, LabelingModel model) {

static List<Long> connectedComponetsSizes(IterableRegion<BitType> region) {
List<Long> sizes = new ArrayList<>();
Cursor<Void> cursor = region.cursor();
Cursor<Void> cursor = region.inside().cursor();
SparseRandomAccessIntType visitedImage = new SparseRandomAccessIntType(
region);
RandomAccess<IntType> visited = visitedImage.randomAccess();
Expand All @@ -124,12 +124,12 @@ static List<Long> connectedComponetsSizes(IterableRegion<BitType> region) {
visited.setPosition(cursor);
if (visited.get().get() == 0) {
currentIndex++;
long countBefore = visitedImage.sparsityPattern().size();
long countBefore = visitedImage.sparsityPattern().inside().size();
Filter<Pair<BitType, IntType>, Pair<BitType, IntType>> filter = (
current, seed) -> current.getA().get() && current.getB().get() == 0;
FloodFill.fill(region, visitedImage, cursor, new IntType(currentIndex),
new DiamondShape(1), filter);
long countAfter = visitedImage.sparsityPattern().size();
long countAfter = visitedImage.sparsityPattern().inside().size();
sizes.add(countAfter - countBefore);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void trainFrame(Training training, List<String> classes, Labeling labeli
ImgPlus<?> image, FeatureCalculator featuresCalculator)
{
SparseRandomAccessIntType classIndices = getClassIndices(labeling, classes);
if (classIndices.sparsityPattern().size() == 0)
if (classIndices.sparsityPattern().inside().size() == 0)
return;
DiskCachedCellImg<FloatType, ?> cachedFeatureBlock = cachedFeatureBlock(featuresCalculator,
image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.imglib2.AbstractWrappedInterval;
import net.imglib2.Cursor;
import net.imglib2.Interval;
import net.imglib2.IterableInterval;
import net.imglib2.Localizable;
import net.imglib2.Point;
import net.imglib2.RandomAccess;
Expand All @@ -56,6 +57,8 @@ public class SparseIterableRegion extends AbstractWrappedInterval<Interval>

final private IntervalIndexer2 indexer;

private final InsideIterable inside;

public SparseIterableRegion(Interval interval) {
this(interval, new TLongHashSet());
}
Expand All @@ -64,6 +67,7 @@ public SparseIterableRegion(Interval interval, TLongSet positions) {
super(interval);
this.codes = positions;
this.indexer = new IntervalIndexer2(interval);
this.inside = new InsideIterable();
}

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

@Override
public Cursor<Void> cursor() {
return new SparseRoiCursor();
public RandomAccess<BitType> randomAccess() {
return new SparseRoiRandomAccess();
}

@Override
public Cursor<Void> localizingCursor() {
return cursor();
public RandomAccess<BitType> randomAccess(Interval interval) {
return randomAccess();
}

@Override
public long size() {
return codes.size();
public IterableInterval< Void > inside()
{
return inside;
}

@Override
public Void firstElement() {
return null;
}
private class InsideIterable extends AbstractWrappedInterval< Interval > implements IterableInterval< Void >
{
InsideIterable()
{
super( SparseIterableRegion.this );
}

@Override
public Object iterationOrder() {
return null;
}
@Override
public Cursor<Void> cursor() {
return new SparseRoiCursor();
}

@Override
public Iterator<Void> iterator() {
return cursor();
}
@Override
public Cursor<Void> localizingCursor() {
return cursor();
}

@Override
public RandomAccess<BitType> randomAccess() {
return new SparseRoiRandomAccess();
@Override
public long size() {
return codes.size();
}

@Override
public Void firstElement() {
return null;
}

@Override
public Object iterationOrder() {
return this;
}
}

@Override
public RandomAccess<BitType> randomAccess(Interval interval) {
return randomAccess();
public BitType getType()
{
return new BitType();
}

private class SparseRoiCursor extends AbstractCursor<Void> implements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public RandomAccess<IntType> randomAccess(Interval interval) {
}

public Cursor<IntType> sparseCursor() {
return new MappingCursor<>(sparsityPattern().cursor(), randomAccess());
return new MappingCursor<>(sparsityPattern().inside().cursor(), randomAccess());
}

public IterableRegion<? extends BooleanType<?>> sparsityPattern() {
Expand Down Expand Up @@ -124,6 +124,12 @@ private void set(MyRandomAccess position, int value) {
}
}

@Override
public IntType getType()
{
return new IntType();
}

// -- Helper classes --

private class MyRandomAccess extends Point implements RandomAccess<IntType> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/demo/custom_segmenter/MeanCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MeanCalculator {
public void addSample(RandomAccessibleInterval<?> image,
IterableRegion<BitType> region)
{
Cursor<Void> cursor = region.cursor();
Cursor<Void> cursor = region.inside().cursor();
RandomAccess<RealType<?>> randomAccess = Cast.unchecked(image.randomAccess());
while (cursor.hasNext()) {
cursor.fwd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testSize() {
RandomAccess<BitType> ra = roi.randomAccess();
ra.setPosition(positionA);
ra.get().set(true);
assertEquals(1, roi.size());
assertEquals(1, roi.inside().size());
}

@Test
Expand All @@ -78,7 +78,7 @@ public void testCursor() {
RandomAccess<BitType> ra = roi.randomAccess();
ra.setPosition(positionA);
ra.get().set(true);
Cursor<Void> cursor = roi.cursor();
Cursor<Void> cursor = roi.inside().cursor();
assertTrue(cursor.hasNext());
cursor.fwd();
assertEquals(positionA[1], cursor.getLongPosition(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public void testNoEntryValue() {
noEntryValue);
Views.iterable(image).forEach(x -> x.setInteger(noEntryValue));
// test
assertFalse(image.sparsityPattern().cursor().hasNext());
assertFalse(image.sparsityPattern().inside().cursor().hasNext());
}
}
Loading