imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
17 stars 25 forks source link

Improvements in wrapping RealPointCollections #310

Closed gselzer closed 2 weeks ago

gselzer commented 2 weeks ago

With this immediate fix, the following SciJava script now runs (where before I got the same error described in #299):

The question now is whether we should further improve the type variables within RealPoint -> PointRoi conversions to be more correct.

#@ Dataset i
#@output Dataset out

from java.util import ArrayList
from net.imglib2 import RealPoint
from net.imagej.roi import DefaultROITree
from net.imglib2.roi.geom.real import DefaultWritableRealPointCollection

arr = ArrayList([RealPoint([10, 10])])
pc = DefaultWritableRealPointCollection(arr)

tree = DefaultROITree()
tree.addROIs(ArrayList([pc]))
i.getProperties().put("rois", tree)

out = i

Closes #299

gselzer commented 2 weeks ago

But this still doesn't work - if you run the script, you'll get a point ROI on the input image. Then any call to RealPointCollectionWrapper.synchronize() (including closing the image) throws the following error.

(Fiji Is Just) ImageJ 2.14.0/1.54f; Java 1.8.0_322 [64-bit]; Windows 10 10.0; 361MB of 48709MB (<1%)

java.lang.ClassCastException: net.imglib2.RealPoint cannot be cast to net.imglib2.roi.util.RealLocalizableRealPositionable
    at net.imagej.legacy.convert.roi.point.RealPointCollectionWrapper.synchronize(RealPointCollectionWrapper.java:99)
    at net.imagej.legacy.convert.roi.MaskPredicateWrapper.getUpdatedSource(MaskPredicateWrapper.java:63)
    at net.imagej.legacy.convert.roi.AbstractMaskPredicateUnwrapConverter.convert(AbstractMaskPredicateUnwrapConverter.java:74)
    at org.scijava.convert.ConvertService.convert(ConvertService.java:68)
    at net.imagej.legacy.convert.OverlayToROITreeConverter.convert(OverlayToROITreeConverter.java:82)
    at org.scijava.convert.ConvertService.convert(ConvertService.java:68)
    at net.imagej.legacy.LegacyImageMap.synchronizeAttachmentsToDataset(LegacyImageMap.java:611)
    at net.imagej.legacy.LegacyImageMap.synchronizeAttachmentsToDataset(LegacyImageMap.java:583)
    at net.imagej.legacy.LegacyImageMap.lookupDisplay(LegacyImageMap.java:197)
    at net.imagej.legacy.DefaultLegacyHooks.unregisterImage(DefaultLegacyHooks.java:190)
    at ij.gui.ImageWindow.close(ImageWindow.java)
    at ij.ImagePlus.close(ImagePlus.java:476)
    at ij.plugin.Commands.closeImage(Commands.java:138)
    at ij.plugin.Commands.close(Commands.java:91)
    at ij.plugin.Commands.run(Commands.java:29)
    at ij.IJ.runPlugIn(IJ.java:216)
    at ij.Executer.runCommand(Executer.java:152)
    at ij.Executer.run(Executer.java:70)
    at java.lang.Thread.run(Thread.java:750)

...maybe we have to do better 😆

imagesc-bot commented 2 weeks ago

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/12

gselzer commented 2 weeks ago

Update on current improvements:

ctrueden commented 2 weeks ago

Thanks @gselzer! This is definitely a step forward.

imagesc-bot commented 1 week ago

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/17