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

Fix immediate ClassCastExceptions in wrapping RealPointCollections #310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gselzer
Copy link
Contributor

@gselzer gselzer commented Nov 4, 2024

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
Copy link
Contributor Author

gselzer commented Nov 4, 2024

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 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImgPlus images with a new ROITree that contains a RealPointCollection can't be displayed
1 participant