Skip to content
Snippets Groups Projects
Commit 63fee3cf authored by Céline  TREBEAU's avatar Céline TREBEAU
Browse files

Bug fix : NPE when the first SurfaceLine of a Surface is null in getZMap() method in Surface class.

Replacement of surfaceLines.length and surfaceLines[0].length by GetWidth() and getHeight() methods
parent 4d4423e5
No related branches found
No related tags found
2 merge requests!10Surface reconstruction Refactoring,!6Bug fix : NPE when the first SurfaceLine of a Surface is null in getZMap() method in Surface class.
Pipeline #41344 passed
...@@ -147,7 +147,7 @@ public class Surface ...@@ -147,7 +147,7 @@ public class Surface
* *
* @return the identical transposed {@link Surface} * @return the identical transposed {@link Surface}
*/ */
public Surface transpose(int length) public Surface transpose( int length )
{ {
Surface surface = new Surface( Math.abs( this.dimension - 1 ), length ); Surface surface = new Surface( Math.abs( this.dimension - 1 ), length );
Class< ? > theClass; Class< ? > theClass;
...@@ -231,15 +231,15 @@ public class Surface ...@@ -231,15 +231,15 @@ public class Surface
{ {
ReferenceSurfaceExtraction.displaySurface( this ); ReferenceSurfaceExtraction.displaySurface( this );
int count = 0; int count = 0;
Dimensions dim = FinalDimensions.wrap( new long[]{surfaceLines.length,surfaceLines[0].getLength() }); Dimensions dim = FinalDimensions.wrap( new long[]{ getHeight(), getWidth() } );
ImgFactory< UnsignedShortType > factory = Util.getArrayOrCellImgFactory(dim, new UnsignedShortType()); ImgFactory< UnsignedShortType > factory = Util.getArrayOrCellImgFactory( dim, new UnsignedShortType() );
Img< UnsignedShortType > zMap = factory.create(dim); Img< UnsignedShortType > zMap = factory.create( dim );
RandomAccess< UnsignedShortType > randomAccess = zMap.randomAccess(); RandomAccess< UnsignedShortType > randomAccess = zMap.randomAccess();
for ( SurfaceLine surfaceLine : this.get() ) for ( SurfaceLine surfaceLine : this.get() )
{ {
if ( surfaceLine != null ) if ( surfaceLine != null )
{ {
randomAccess.setPosition(surfaceLine.getLine(), 0); randomAccess.setPosition( surfaceLine.getLine(), 0 );
for ( int i = 0; i <= surfaceLine.getDimension().length - 1; i++ ) for ( int i = 0; i <= surfaceLine.getDimension().length - 1; i++ )
{ {
Pixels pixel = surfaceLine.get( i ); Pixels pixel = surfaceLine.get( i );
...@@ -248,25 +248,25 @@ public class Surface ...@@ -248,25 +248,25 @@ public class Surface
if ( pixel.size() > 1 ) if ( pixel.size() > 1 )
{ {
count++; count++;
int z = averageIntZ( pixel ) ; int z = averageIntZ( pixel );
if ( z != -1 ) if ( z != - 1 )
{ {
randomAccess.setPosition(i, 1); randomAccess.setPosition( i, 1 );
randomAccess.get().set(new UnsignedShortType(z + 1)); randomAccess.get().set( new UnsignedShortType( z + 1 ) );
} }
} }
else else
{ {
int z = pixel.get( 0 ).getZ(); int z = pixel.get( 0 ).getZ();
randomAccess.setPosition(i, 1); randomAccess.setPosition( i, 1 );
randomAccess.get().set(new UnsignedShortType(z + 1)); randomAccess.get().set( new UnsignedShortType( z + 1 ) );
} }
} }
} }
} }
} }
ImageJFunctions.show( zMap, "after getzmap" ); ImageJFunctions.show( zMap, "after getzmap" );
System.out.println(" Thre count = " + count); System.out.println( " Thre count = " + count );
return zMap; return zMap;
} }
...@@ -284,7 +284,7 @@ public class Surface ...@@ -284,7 +284,7 @@ public class Surface
{ {
return ( z1 + z2 ) / 2; return ( z1 + z2 ) / 2;
} }
return -1; return - 1;
} }
/** /**
...@@ -308,16 +308,17 @@ public class Surface ...@@ -308,16 +308,17 @@ public class Surface
public int getWidth() public int getWidth()
{ {
for ( SurfaceLine surfaceLine: surfaceLines for ( SurfaceLine surfaceLine : surfaceLines
) )
{ {
if (surfaceLine != null) if ( surfaceLine != null )
{ {
return surfaceLine.getLength(); return surfaceLine.getLength();
} }
} }
return 0; return 0;
} }
public int getHeight() public int getHeight()
{ {
return this.surfaceLines.length; return this.surfaceLines.length;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment