From 228d97d1da2ac4974b1051151f15eb29ec0e5fd0 Mon Sep 17 00:00:00 2001 From: ctrebeau <ctrebeau@pasteur.fr> Date: Wed, 18 Nov 2020 00:02:06 +0100 Subject: [PATCH] Island search : new implementation with relative localisation (3D array instead of list) --- .../fr/pasteur/ida/zellige/main/Main.java | 1 + .../construction/SurfacePixelSelection.java | 6 +- .../utils/islandSearch/IslandSearch.java | 42 +-- .../zellige/utils/islandSearch/SeaLevel.java | 97 ------ .../ida/zellige/utils/islandSearch/World.java | 284 +++++++++--------- .../utils/islandSearch/IslandTest.java | 98 +++--- .../utils/islandSearch/SeaLevelTest.java | 144 ++++----- .../zellige/utils/islandSearch/WorldTest.java | 162 +++++----- 8 files changed, 369 insertions(+), 465 deletions(-) delete mode 100644 src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevel.java diff --git a/src/main/java/fr/pasteur/ida/zellige/main/Main.java b/src/main/java/fr/pasteur/ida/zellige/main/Main.java index 3e050dee..1cffcf89 100644 --- a/src/main/java/fr/pasteur/ida/zellige/main/Main.java +++ b/src/main/java/fr/pasteur/ida/zellige/main/Main.java @@ -61,6 +61,7 @@ public class Main // "C:\\Users\\ctrebeau\\Desktop\\MoucheAile\\STK\\STK_Mouche_c01_f0001_p005.tif"; // "C:\\Users\\ctrebeau\\Downloads\\phantom3b_combined.tif"; // "C:\\Users\\ctrebeau\\Desktop\\HighRes\\STK_170706_Vangl2-Lp-wt_E14.5_Phall_cochlea_01bHighRes_c01_f0001_p005.tif"; +// "C:\\Users\\ctrebeau\\Desktop\\HighRes\\STK_170706_Vangl2-Lp-wt_E14.5_Phall_cochlea_01bHighRes_c01_f0001_p002.tif"; System.out.println(imagePath); // Creation of the image : version with unsigned type. */ /* JY version for opening files. */ diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java index 2f1d2d83..5e665e8c 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java @@ -5,6 +5,8 @@ import fr.pasteur.ida.zellige.surfaceConstruction.parameters.UserParameters; import fr.pasteur.ida.zellige.surfaceConstruction.element.Coordinate; import fr.pasteur.ida.zellige.surfaceConstruction.element.Pixels; import fr.pasteur.ida.zellige.utils.*; +import fr.pasteur.ida.zellige.utils.islandSearch.Island; +import fr.pasteur.ida.zellige.utils.islandSearch.IslandSearch; import net.imglib2.RandomAccess; import net.imglib2.RandomAccessibleInterval; import net.imglib2.converter.Converters; @@ -150,8 +152,10 @@ public class SurfacePixelSelection Img<BitType> finalList = Threshold.classification( amplitudeImg, amplitudeImg.factory(), thresholds ); /* Isolated Pixel removal */ + finalList = IslandSearch.run( finalList, 5 ); + ImageJFunctions.show( finalList.copy(), "isolated pixel sel" ); Img< FloatType > converted = Utils.convertBitTypeIntoFloatType( finalList ); -// ImageJFunctions.show( converted.copy(), "isolated pixel sel" ); + /* Dilatation of the resulting image*/ double sigma = userParameters.getSigmas(); diff --git a/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandSearch.java b/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandSearch.java index 79b0e741..f5895815 100644 --- a/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandSearch.java +++ b/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandSearch.java @@ -38,51 +38,55 @@ public class IslandSearch private void process( ) { - World world = convertImgIntoWorld(); + World world = convertImgIntoWorld2(); world.run(); convertWorldIntoImg(world, output); } - private void convertWorldIntoImg(World world, Img<BitType> image) + private void convertWorldIntoImg( World world, Img<BitType> image) { int count = 0; RandomAccess<BitType> access = image.randomAccess(); - for(int z = 0; z<= world.getHeight() - 1; z ++) + for(int z = 0; z < world.getDepth() ; z ++) { - for ( Sand sand : world.getSeaLevel( z ) ) + for (int y = 0; y < world.getHeight(); y ++) { - if ( sand.getIslandStatus() == -1 ) + for( int x = 0; x < world.getWidth(); x ++) { - int x = sand.getX(); - int y = sand.getY(); + Sand sand = world.getSand(x, y, z); + if ( sand != null && sand.getIslandStatus() == -1 ) + { - Utils.setPosition( access, x, y, z ); - access.get().setZero(); - count++; + + Utils.setPosition( access, x, y, z ); + access.get().setZero(); + count++; + } } } } count = count; } - private World convertImgIntoWorld() + private World convertImgIntoWorld2() { + int width = (int ) classifiedImage.dimension( 0 ); + int height = (int ) classifiedImage.dimension( 1 ); + int depth = (int ) classifiedImage.dimension( 2 ); RandomAccess<BitType> access = classifiedImage.randomAccess(); - World world = new World((int) classifiedImage.dimension( 2 ), islandSize ); + World world = new World(width, height, depth, islandSize ); for(int z = 0; z<= classifiedImage.dimension( 2 ) - 1; z ++) { - - SeaLevel seaLevel = world.getSeaLevel( z ); for(int x = 0; x<= classifiedImage.dimension( 0 ) - 1; x ++) { for(int y = 0; y <= classifiedImage.dimension( 1 ) - 1; y ++) { - final boolean value = Utils.setPositionAndGet(access, x, y, z).get(); - if (value) - { - seaLevel.add(new Sand (x, y, z)); - } + final boolean value = Utils.setPositionAndGet(access, x, y, z).get(); + if (value) + { + world.setSand(x, y, z); + } } } } diff --git a/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevel.java b/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevel.java deleted file mode 100644 index 13a2f1ea..00000000 --- a/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevel.java +++ /dev/null @@ -1,97 +0,0 @@ -package fr.pasteur.ida.zellige.utils.islandSearch; - -import java.util.LinkedList; -import java.util.Queue; - -public class SeaLevel extends Island -{ - private final int level; - private final int islandSize; - - public SeaLevel( int level , int islandSize) - { - this.level = level; - this.islandSize = islandSize; - } - -// public void setLevel( int level ) -// { -// this.level = level; -// } - - - public Island getFourConnected( Sand sand ) - { - sand.setNotVisited( false ); - Island neighbours = new Island(); - int x = sand.getX(); - int y = sand.getY(); - Sand n1 = new Sand( x, y - 1, level ); - Sand n2 = new Sand( x, y + 1, level ); - Sand n3 = new Sand( x - 1, y, level ); - Sand n4 = new Sand( x + 1, y, level ); - addSandToIsland( n1, neighbours ); - addSandToIsland( n2, neighbours ); - addSandToIsland( n3, neighbours ); - addSandToIsland( n4, neighbours ); - return neighbours; - } - - private void addSandToIsland( Sand sand, Island island ) - { - if ( this.contains( sand ) ) - { - int i = indexOf( sand ); - Sand s = this.get( i ); - island.add( s ); - } - } - - public Island buildIsland( Sand sand ) - { - Island island = new Island(); - island.add( sand ); - Queue< Sand > queue = new LinkedList<>(); - queue.add( sand ); - while ( ! queue.isEmpty() ) - { - Sand s0 = queue.remove(); - Island temp = getFourConnected( s0 ); - for ( Sand s : temp ) - { - if ( s.isNotVisited() ) - { - queue.add( s ); - } - island.add( s ); - } - if ( island.size() > islandSize + 1 ) - { - island.reset(); - return island; - } - } - island.reset(); - return island; - } - - public Island getIslandImage( Island island ) - { - Island islandImage = new Island(); - for ( Sand sand : island ) - { - islandImage.add( new Sand( sand.getX(), sand.getY(), level ) ); - } - return islandImage; - } - - public Island extendIsland( Island imageIsland ) - { - Island extendIsland = new Island(); - for ( Sand sand : imageIsland ) - { - extendIsland.addAll( getFourConnected( sand ) ); - } - return extendIsland; - } -} diff --git a/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/World.java b/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/World.java index e9d1c031..0340c2a6 100644 --- a/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/World.java +++ b/src/main/java/fr/pasteur/ida/zellige/utils/islandSearch/World.java @@ -1,213 +1,205 @@ package fr.pasteur.ida.zellige.utils.islandSearch; +import java.util.LinkedList; +import java.util.Queue; + public class World { - private final SeaLevel[] seaLevels; + private final Sand[][][] world; private final int islandSize; + private final int depth; + private final int width; + private final int height; - public World( int height, int islandSize ) + public World( int width, int height, int depth, int islandSize ) { - seaLevels = new SeaLevel[ height ]; + this.depth = depth; + this.world = new Sand[ depth ][ height ][ width ]; this.islandSize = islandSize; - init(); + this.width = width; + this.height = height; } - private void init() + public void run() { - for ( int i = 0; i <= seaLevels.length - 1 ; i++ ) + for ( int z = 0; z < world.length; z++ ) { - seaLevels[i] = new SeaLevel( i, islandSize ); + for ( int y = 0; y < world[0].length; y++ ) + { + for( int x = 0; x < world[0][0].length ; x++) + + { + Sand sand = getSand( x, y, z ); + if ( sand != null && sand.getIslandStatus() == 0 ) + { + setIslandStatus( sand ); + } + } + } } } + public Island getFourConnected( Sand sand ) + { + sand.setNotVisited( false ); + Island neighbours = new Island(); + int x = sand.getX(); + int y = sand.getY(); + int z = sand.getZ(); + Sand n1 = getSand( x, y - 1, z ); + Sand n2 = getSand( x, y + 1, z ); + Sand n3 = getSand( x - 1, y, z ); + Sand n4 = getSand( x + 1, y, z ); + addSandToIsland( n1, neighbours ); + addSandToIsland( n2, neighbours ); + addSandToIsland( n3, neighbours ); + addSandToIsland( n4, neighbours ); + return neighbours; + } - public void run() + public Sand getSand( int x, int y, int z ) + { + try + { + return world[ z ][ y ][ x ]; + } + catch ( ArrayIndexOutOfBoundsException out ) + { + return null; + } + } + + public void setSand(int x, int y, int z) + { + Sand sand = new Sand( x, y, z ); + world[z][y][x] = sand; + } + + private void addSandToIsland( Sand sand, Island island ) { - for ( int i = 0; i <= seaLevels.length - 1; i++ ) + if ( sand != null ) { - for ( Sand sand : seaLevels[ i ] ) + island.add( sand ); + } + } + + public Island buildIsland( Sand sand ) + { + Island island = new Island(); + island.add( sand ); + Queue< Sand > queue = new LinkedList<>(); + queue.add( sand ); + while ( ! queue.isEmpty() ) + { + Sand s0 = queue.remove(); + Island temp = getFourConnected( s0 ); + for ( Sand s : temp ) { - if ( sand.getIslandStatus() == 0 ) + if ( s.isNotVisited() ) { - setIslandStatus( sand ); + queue.add( s ); } + island.add( s ); + } + if ( island.size() > islandSize + 1 ) + { + island.reset(); + return island; } } + island.reset(); + return island; } public void setIslandStatus( Sand sand ) { - SeaLevel seaLevel = getSeaLevel( sand.getZ() ); - Island island = seaLevel.buildIsland( sand ); - if ( island.size() > 6 ) + + Island island = buildIsland( sand ); + if ( island.size() > islandSize ) { island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); } - else + else if ( sand.getZ() < depth && sand.getZ() > 0 ) { - SeaLevel up = getSeaLevelUp( sand ); - if ( up == null ) + int sizeUp = getExtendedIslandSize( island, 1 ); + if ( sizeUp == 0 ) { - SeaLevel down = getSeaLevelDown( sand ); - if ( down == null ) - { - island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); - } - else - { - int sizeDown = getExtendedIslandSize( down, island ); - setExtendedIslandSize( sizeDown, island ); - } + int sizeDown = getExtendedIslandSize( island, - 1 ); + setExtendedIslandSize( sizeDown, island ); } else { - int sizeUp = getExtendedIslandSize( up, island ); - if (sizeUp == 0 ) - { - SeaLevel down = getSeaLevelDown( sand ); - if ( down == null ) - { - island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); - } - else - { - int sizeDown = getExtendedIslandSize( down, island ); - setExtendedIslandSize( sizeDown, island ); - } - } - else - { - island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); - } + island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); } } - } - - private int getExtendedIslandSize( SeaLevel level, Island island ) - { - Island upIsland = level.getIslandImage( island ); - Island extendedIsland = level.extendIsland( upIsland ); - return extendedIsland.size(); - } - private void setExtendedIslandSize( int size, Island island ) - { - if (size == 0) + else if ( sand.getZ() == depth ) { - island.forEach( sand1 -> sand1.setIslandStatus( -1 ) ); + int sizeDown = getExtendedIslandSize( island, - 1 ); + setExtendedIslandSize( sizeDown, island ); } else { - island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); + int sizeUp = getExtendedIslandSize( island, 1 ); + setExtendedIslandSize( sizeUp, island ); } } -// -// -// public void checkIslandStatus( Sand sand ) -// { -// int count = 0; -// if ( sand.isNotVisited() ) -// { -// SeaLevel seaLevel = getSeaLevel( sand.getZ() ); -// Island island = seaLevel.buildIsland( sand ); -// if ( island.size() < 7 ) -// { -// SeaLevel up = getSeaLevelUp( sand ); -// if ( up != null ) -// { -// Island upIsland = up.getIslandImage( island ); -// Island extendedIsland = up.extendIsland( upIsland ); -// if ( extendedIsland.size() == 0 ) -// { -// SeaLevel down = getSeaLevelDown( sand ); -// if ( down != null ) -// { -// Island downIsland = down.getIslandImage( island ); -// Island extendedIsland2 = down.extendIsland( downIsland ); -// if ( extendedIsland2.size() == 0 ) -// { -// island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); -// count++; -// } -// else -// { -// island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); -// } -// } -// else -// { -// island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); -// count++; -// } -// } -// else -// { -// island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); -// -// } -// } -// else -// { -// SeaLevel down = getSeaLevelDown( sand ); -// if ( down != null ) -// { -// Island downIsland = down.getIslandImage( island ); -// Island extendedIsland2 = down.extendIsland( downIsland ); -// if ( extendedIsland2.size() == 0 ) -// { -// island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); -// count++; -// } -// } -// else -// { -// island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); -// count++; -// } -// } -// } -// else -// { -// island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); -// } -// } -// } - - - private SeaLevel getSeaLevelUp( Sand sand ) + public Island getIslandImage( Island island, int level ) { - if ( sand.getZ() < getHeight() - 1 ) + Island islandImage = new Island(); + for ( Sand sand : island ) { - return getSeaLevel( sand.getZ() + 1 ); + islandImage.add( new Sand( sand.getX(), sand.getY(), sand.getZ() + level ) ); } - return null; + return islandImage; } - private SeaLevel getSeaLevelDown( Sand sand ) + + public Island extendIsland( Island imageIsland ) { - if ( sand.getZ() > 0 ) + Island extendIsland = new Island(); + for ( Sand sand : imageIsland ) { - return getSeaLevel( sand.getZ() - 1 ); + extendIsland.addAll( getFourConnected( sand ) ); } + return extendIsland; + } - return null; + private int getExtendedIslandSize( Island island, int level ) + { + Island upIsland = getIslandImage( island, level ); + Island extendedIsland = extendIsland( upIsland ); + return extendedIsland.size(); } - public SeaLevel getSeaLevel( int i ) + + private void setExtendedIslandSize( int size, Island island ) { - return seaLevels[ i ]; + if ( size == 0 ) + { + island.forEach( sand1 -> sand1.setIslandStatus( - 1 ) ); + } + else + { + island.forEach( sand1 -> sand1.setIslandStatus( 1 ) ); + } } - public int getHeight() + public int getDepth() { - return seaLevels.length; + return depth; } - public void setLevel( SeaLevel seaLevel, int i ) + public int getWidth() + { + return width; + } + + public int getHeight() { - this.seaLevels[ i ] = seaLevel; + return height; } } diff --git a/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandTest.java b/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandTest.java index 58c81bc1..f164b9cc 100644 --- a/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandTest.java +++ b/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/IslandTest.java @@ -9,53 +9,53 @@ import static org.junit.jupiter.api.Assertions.*; class IslandTest { - @Test - void addAll() - { - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - Island island = level.getFourConnected( level.get( 0 ) ); - ArrayList<Sand> list = new ArrayList<>(); - list.add(new Sand( 0, 1, 0) ); - list.add(new Sand( 2, 1, 0) ); - int size = island.size(); - island.addAll( list ); - assertEquals( size, island.size() ); - } - - @Test - void add() - { - - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - Island island = level.getFourConnected( level.get( 0 ) ); - assertTrue( island.add(level.get( 0 )) ); - assertFalse( island.add(level.get( 0 )) ); - } - - @Test - void reset() - { - Island island = new Island(); - island.add(new Sand( 1, 1, 0) ); - island.add(new Sand( 0, 1, 0) ); - island.add(new Sand( 2, 1, 0) ); - island.add(new Sand( 1, 0, 0) ); - island.add(new Sand( 1, 2, 0) ); - assertTrue( island.get(0).isNotVisited() ); - island.get(0).setNotVisited( false ); - assertFalse( island.get(0).isNotVisited() ); - island.reset(); - assertTrue( island.get(0).isNotVisited() ); - - } +// @Test +// void addAll() +// { +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// Island island = level.getFourConnected( level.get( 0 ) ); +// ArrayList<Sand> list = new ArrayList<>(); +// list.add(new Sand( 0, 1, 0) ); +// list.add(new Sand( 2, 1, 0) ); +// int size = island.size(); +// island.addAll( list ); +// assertEquals( size, island.size() ); +// } +// +// @Test +// void add() +// { +// +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// Island island = level.getFourConnected( level.get( 0 ) ); +// assertTrue( island.add(level.get( 0 )) ); +// assertFalse( island.add(level.get( 0 )) ); +// } +// +// @Test +// void reset() +// { +// Island island = new Island(); +// island.add(new Sand( 1, 1, 0) ); +// island.add(new Sand( 0, 1, 0) ); +// island.add(new Sand( 2, 1, 0) ); +// island.add(new Sand( 1, 0, 0) ); +// island.add(new Sand( 1, 2, 0) ); +// assertTrue( island.get(0).isNotVisited() ); +// island.get(0).setNotVisited( false ); +// assertFalse( island.get(0).isNotVisited() ); +// island.reset(); +// assertTrue( island.get(0).isNotVisited() ); +// +// } } \ No newline at end of file diff --git a/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevelTest.java b/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevelTest.java index c2d1759f..f193330c 100644 --- a/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevelTest.java +++ b/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/SeaLevelTest.java @@ -7,76 +7,76 @@ import static org.junit.jupiter.api.Assertions.*; class SeaLevelTest { - @Test - void getFourConnected() - { - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - Island island = level.getFourConnected( level.get( 0 ) ); - assertEquals( island.size(), 4 ); - } - - @Test - void buildIsland() - { - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - level.add(new Sand( 3, 1, 0) ); - Island island = level.buildIsland( level.get(0) ); - assertEquals( island.size(), 6 ); - SeaLevel level2 = new SeaLevel( 0 , 6); - level2.add(new Sand( 1, 1, 0) ); - level2.add(new Sand( 0, 1, 0) ); - level2.add(new Sand( 2, 1, 0) ); - level2.add(new Sand( 1, 0, 0) ); - level2.add(new Sand( 1, 2, 0) ); - level2.add(new Sand( 3, 1, 0) ); - level2.add(new Sand( 2, 0, 0) ); - Island island2 = level2.buildIsland( level.get( 0 ) ); - assertEquals( island2.size(), 7 ); - } - - @Test - void getIslandImage() - { - SeaLevel level = new SeaLevel( 0 , 6); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - Island island = level.buildIsland( level.get(0) ); - SeaLevel level2 = new SeaLevel( 1 , 6); - Island image = level2.getIslandImage( island ); - assertEquals( 3, image.size() ); - assertEquals( 1, image.get( 0 ).getZ()); - } - - @Test - void extendIsland() - { - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - Island island = level.buildIsland( level.get(0) ); - SeaLevel level2 = new SeaLevel( 1, 6 ); - Island image = level2.getIslandImage( island ); - level2.add(new Sand( 0, 0, 1) ); - level2.add(new Sand( 0, 2, 1) ); - level2.add(new Sand( 2, 0, 1) ); - level2.add(new Sand( 2, 2, 1) ); - level2.add(new Sand( 1, 3, 1) ); - Island extended = level2.extendIsland( image ); - assertEquals( extended.size(), 5 ); - assertEquals( new Sand( 0, 0, 1), extended.get( 0 ) ); - } +// @Test +// void getFourConnected() +// { +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// Island island = level.getFourConnected( level.get( 0 ) ); +// assertEquals( island.size(), 4 ); +// } +// +// @Test +// void buildIsland() +// { +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// level.add(new Sand( 3, 1, 0) ); +// Island island = level.buildIsland( level.get(0) ); +// assertEquals( island.size(), 6 ); +// SeaLevel level2 = new SeaLevel( 0 , 6); +// level2.add(new Sand( 1, 1, 0) ); +// level2.add(new Sand( 0, 1, 0) ); +// level2.add(new Sand( 2, 1, 0) ); +// level2.add(new Sand( 1, 0, 0) ); +// level2.add(new Sand( 1, 2, 0) ); +// level2.add(new Sand( 3, 1, 0) ); +// level2.add(new Sand( 2, 0, 0) ); +// Island island2 = level2.buildIsland( level.get( 0 ) ); +// assertEquals( island2.size(), 7 ); +// } +// +// @Test +// void getIslandImage() +// { +// SeaLevel level = new SeaLevel( 0 , 6); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// Island island = level.buildIsland( level.get(0) ); +// SeaLevel level2 = new SeaLevel( 1 , 6); +// Island image = level2.getIslandImage( island ); +// assertEquals( 3, image.size() ); +// assertEquals( 1, image.get( 0 ).getZ()); +// } +// +// @Test +// void extendIsland() +// { +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// Island island = level.buildIsland( level.get(0) ); +// SeaLevel level2 = new SeaLevel( 1, 6 ); +// Island image = level2.getIslandImage( island ); +// level2.add(new Sand( 0, 0, 1) ); +// level2.add(new Sand( 0, 2, 1) ); +// level2.add(new Sand( 2, 0, 1) ); +// level2.add(new Sand( 2, 2, 1) ); +// level2.add(new Sand( 1, 3, 1) ); +// Island extended = level2.extendIsland( image ); +// assertEquals( extended.size(), 5 ); +// assertEquals( new Sand( 0, 0, 1), extended.get( 0 ) ); +// } } \ No newline at end of file diff --git a/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/WorldTest.java b/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/WorldTest.java index 85414bdc..de52a83f 100644 --- a/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/WorldTest.java +++ b/src/test/java/fr/pasteur/ida/zellige/utils/islandSearch/WorldTest.java @@ -7,87 +7,87 @@ import static org.junit.jupiter.api.Assertions.*; class WorldTest { - @Test - void run() - { - - World world = new World(3, 6 ); - - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - - level.add(new Sand( 8, 0, 0) ); - level.add(new Sand( 6, 1, 0) ); - level.add(new Sand( 7, 1, 0) ); - level.add(new Sand( 8, 1, 0) ); - level.add(new Sand( 9, 0, 0) ); - level.add(new Sand( 8, 2, 0) ); - - SeaLevel level2 = new SeaLevel( 1 , 6); - level2.add(new Sand( 0, 0, 1) ); - level2.add(new Sand( 0, 2, 1) ); - level2.add(new Sand( 2, 0, 1) ); - level2.add(new Sand( 2, 2, 1) ); - - SeaLevel level3 = new SeaLevel( 2, 6 ); - - world.setLevel( level, 0 ); - world.setLevel( level2, 1 ); - world.setLevel( level3, 2 ); - - world.run(); - assertEquals( level.get(1).getIslandStatus(), 1 ); - assertEquals( level.get(6).getIslandStatus(), -1 ); - assertEquals( level2.get(0).getIslandStatus(), 1 ); - } - - @Test - void setIslandStatus() - { - World world = new World(3 , 6); - - SeaLevel level = new SeaLevel( 0, 6 ); - level.add(new Sand( 1, 1, 0) ); - level.add(new Sand( 0, 1, 0) ); - level.add(new Sand( 2, 1, 0) ); - level.add(new Sand( 1, 0, 0) ); - level.add(new Sand( 1, 2, 0) ); - - level.add(new Sand( 8, 0, 0) ); - level.add(new Sand( 6, 1, 0) ); - level.add(new Sand( 7, 1, 0) ); - level.add(new Sand( 8, 1, 0) ); - level.add(new Sand( 9, 0, 0) ); - level.add(new Sand( 8, 2, 0) ); - - SeaLevel level2 = new SeaLevel( 1 , 6); - level2.add(new Sand( 0, 0, 1) ); - level2.add(new Sand( 0, 2, 1) ); - level2.add(new Sand( 2, 0, 1) ); - level2.add(new Sand( 2, 2, 1) ); - - SeaLevel level3 = new SeaLevel( 2, 6 ); - - world.setLevel( level, 0 ); - world.setLevel( level2, 1 ); - world.setLevel( level3, 2 ); - - world.setIslandStatus( level.get( 0 ) ); - - world.setIslandStatus( level.get(5) ); - - assertEquals( level.get(1).getIslandStatus(), 1 ); - assertEquals( level.get(6).getIslandStatus(), -1 ); - assertEquals( level2.get(1).getIslandStatus(), 0 ); - - assertEquals( level2.get(0).getIslandStatus(), 0 ); - world.setIslandStatus( level2.get(0) ); - assertEquals( level2.get(0).getIslandStatus(), 1 ); - } +// @Test +// void run() +// { +// +// World world = new World(3, 6 ); +// +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// +// level.add(new Sand( 8, 0, 0) ); +// level.add(new Sand( 6, 1, 0) ); +// level.add(new Sand( 7, 1, 0) ); +// level.add(new Sand( 8, 1, 0) ); +// level.add(new Sand( 9, 0, 0) ); +// level.add(new Sand( 8, 2, 0) ); +// +// SeaLevel level2 = new SeaLevel( 1 , 6); +// level2.add(new Sand( 0, 0, 1) ); +// level2.add(new Sand( 0, 2, 1) ); +// level2.add(new Sand( 2, 0, 1) ); +// level2.add(new Sand( 2, 2, 1) ); +// +// SeaLevel level3 = new SeaLevel( 2, 6 ); +// +// world.setLevel( level, 0 ); +// world.setLevel( level2, 1 ); +// world.setLevel( level3, 2 ); +// +// world.run(); +// assertEquals( level.get(1).getIslandStatus(), 1 ); +// assertEquals( level.get(6).getIslandStatus(), -1 ); +// assertEquals( level2.get(0).getIslandStatus(), 1 ); +// } +// +// @Test +// void setIslandStatus() +// { +// World world = new World(3 , 6); +// +// SeaLevel level = new SeaLevel( 0, 6 ); +// level.add(new Sand( 1, 1, 0) ); +// level.add(new Sand( 0, 1, 0) ); +// level.add(new Sand( 2, 1, 0) ); +// level.add(new Sand( 1, 0, 0) ); +// level.add(new Sand( 1, 2, 0) ); +// +// level.add(new Sand( 8, 0, 0) ); +// level.add(new Sand( 6, 1, 0) ); +// level.add(new Sand( 7, 1, 0) ); +// level.add(new Sand( 8, 1, 0) ); +// level.add(new Sand( 9, 0, 0) ); +// level.add(new Sand( 8, 2, 0) ); +// +// SeaLevel level2 = new SeaLevel( 1 , 6); +// level2.add(new Sand( 0, 0, 1) ); +// level2.add(new Sand( 0, 2, 1) ); +// level2.add(new Sand( 2, 0, 1) ); +// level2.add(new Sand( 2, 2, 1) ); +// +// SeaLevel level3 = new SeaLevel( 2, 6 ); +// +// world.setLevel( level, 0 ); +// world.setLevel( level2, 1 ); +// world.setLevel( level3, 2 ); +// +// world.setIslandStatus( level.get( 0 ) ); +// +// world.setIslandStatus( level.get(5) ); +// +// assertEquals( level.get(1).getIslandStatus(), 1 ); +// assertEquals( level.get(6).getIslandStatus(), -1 ); +// assertEquals( level2.get(1).getIslandStatus(), 0 ); +// +// assertEquals( level2.get(0).getIslandStatus(), 0 ); +// world.setIslandStatus( level2.get(0) ); +// assertEquals( level2.get(0).getIslandStatus(), 1 ); +// } } \ No newline at end of file -- GitLab