Closed aaime closed 8 years ago
Sounds good Andrea. Are you working on it or do you want me to have a look ?
I'm not working on it right now. So if you feel bored go right ahead :-)
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 ?
I've seen it happening as one tries to get and use the image version of the roigeometry out of an empty geometry
Cool - I'll delve into that
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 :)
Stumbled into this one again... we need to check what ROIShape is doing in the same situation.
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
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)