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

ROIGeometry must handle the emtpy geometry case #225

Closed
aaime opened this issue Jan 7, 2014 · 8 comments
Closed

ROIGeometry must handle the emtpy geometry case #225

aaime opened this issue Jan 7, 2014 · 8 comments

Comments

@aaime
Copy link
Collaborator

aaime commented Jan 7, 2014

While working with imagery it may happen that a call to intersect results in an empty geometry, but ROIGeometry fails if passed an empty one. We should behave normally with it too (it's just a case in which the ROI is empty)

@mbedward
Copy link
Owner

mbedward commented Jan 8, 2014

Sounds good Andrea. Are you working on it or do you want me to have a look ?

@aaime
Copy link
Collaborator Author

aaime commented Jan 8, 2014

I'm not working on it right now. So if you feel bored go right ahead :-)

@mbedward
Copy link
Owner

I've been adding some unit tests in which ROIGeometry is passed an empty Geometry but haven't seen any failures yet. Can you give me an example that provokes an error ?

@aaime
Copy link
Collaborator Author

aaime commented Jan 12, 2014

I've seen it happening as one tries to get and use the image version of the roigeometry out of an empty geometry

@mbedward
Copy link
Owner

Cool - I'll delve into that

@mbedward
Copy link
Owner

OK - so I see the problem now. How best to handle it ? JAI doesn't seem to like creating empty images (ImageLayout constructor throws an exception if passed zero width / height). Maybe add a new ImageOp for an empty image which could be used by VectorBinarize when the geometry is empty ? Would that work with your use cases Andrea ? Other ideas also welcome :)

@aaime
Copy link
Collaborator Author

aaime commented Dec 15, 2015

Stumbled into this one again... we need to check what ROIShape is doing in the same situation.

@aaime
Copy link
Collaborator Author

aaime commented Jan 5, 2016

Ok, tested it with ROIShape, and it just fails:

@Test
    public void testEmptyIntersection() {
        ROIShape rs1 = new ROIShape(new Rectangle2D.Double(0, 0, 10, 10));
        ROIShape rs2 = new ROIShape(new Rectangle2D.Double(20, 0, 10, 10));
        ROI intersection = rs1.intersect(rs2);
        intersection.getAsImage();
    }

results in:

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
    at java.awt.image.SampleModel.<init>(SampleModel.java:126)
    at java.awt.image.MultiPixelPackedSampleModel.<init>(MultiPixelPackedSampleModel.java:147)
    at java.awt.image.MultiPixelPackedSampleModel.<init>(MultiPixelPackedSampleModel.java:107)
    at java.awt.image.Raster.createPackedRaster(Raster.java:846)
    at java.awt.image.Raster.createPackedRaster(Raster.java:588)
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:442)
    at javax.media.jai.ROIShape.getAsImage(ROIShape.java:1129)
    at org.jaitools.imageutils.ROIGeometryTest.testEmptyIntersection(ROIGeometryTest.java:356)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Sooo... I must have been seeing things! Closing for the moment, until I have a new vision :-p

@aaime aaime closed this as completed Jan 5, 2016
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

No branches or pull requests

2 participants