mpicbg icon indicating copy to clipboard operation
mpicbg copied to clipboard

ClassCastException

Open nanthony21 opened this issue 3 years ago • 1 comments

This is what I get when trying to run the "Landmark Correspondences" plugin in "Perspective" mode.

(Fiji Is Just) ImageJ 2.3.0/1.53f51; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 146MB of 24463MB (<1%)
 
java.lang.ClassCastException: mpicbg.models.HomographyModel2D cannot be cast to mpicbg.models.Affine2D
	at Transform_Roi.run(Transform_Roi.java:184)
	at ij.IJ.runUserPlugIn(IJ.java:241)
	at ij.IJ.runPlugIn(IJ.java:204)
	at ij.Executer.runCommand(Executer.java:150)
	at ij.Executer.run(Executer.java:68)
	at java.lang.Thread.run(Thread.java:748)

nanthony21 avatar Oct 25 '21 21:10 nanthony21

According to the plugins.config the "Landmark Correspondences" plugin is implemented by the Transform_Roi class.

Looking into the Transform_Roi.java file at like 210, we read:

				case 4:
					IJ.error( "Perspective transformation is not yet supported for Moving Least Squares.  Using Affine instead." );
					//t.setModel( HomographyModel2D.class );
					t.setModel( AffineModel2D.class );
					break;

Looks like a perspective transform was never implemented for Moving Least Squares.

In line 284 we read that:

			if ( showMatrix )
			{
				final double[] flatmatrix = new double[6];
				( ( Affine2D< ? > )model ).toArray( flatmatrix );
				IJ.log("Matrix: " + Arrays.toString(flatmatrix));
			}

Note the Affine2D and not AffineModel2D is used. It's possible that's the error: above at line 213 perhaps it should have been t.setModel( Affine2D.class ); instead, or perhaps the opposite: the cast ought to be to AffineModel2D.

Thankfully this error is easy to fix (submit a one-line fix from github itself), and also, note the error doesn't occur if one doesn't choose to show (print) the matrix.

acardona avatar May 24 '22 13:05 acardona