import java.util.Vector ; import java.lang.Integer ; public class Image { protected int l, c, l1, c1, d1, nbLig, nbCol ; protected boolean[][] image ; // Constructor public Image(boolean[][] tableau, int nbL, int nbC) { image = tableau ; nbLig = nbL ; nbCol = nbC ; } // LOOKING FOR THE FIRST POINT TO THE TOP-LEFT public Vector contour() { l = 1 ; c = 1 ; boolean trouve = false ; while (!trouve) { trouve = image[l][c] ; if (!trouve) { // On passe a la case suivante, ligne par ligne if (c < nbCol) c = c + 1 ; else {c = 1 ; l = l + 1 ;} } // if } // while l1 = l ; c1 = c ; // LOOKING FOR THE RIGHT DIRECTION // Looking for the first direction int d = 0 ; if (image[l][c+1]) d = 0 ; else d = 1 ; d1 = d ; // Looking for the next points and directions boolean fin = false ; Vector contour = new Vector() ; contour.add(new Integer(l)) ; contour.add(new Integer(c)) ; contour.add(new Integer(d)) ; while (!fin) { // We follow direction d to find the next point if (d == 0) c++ ; else if (d == 1) l++ ; else if (d == 2) c-- ; else if (d == 3) l-- ; // We look for the next direction d = (d + 3) % 4 ; while (!image[l][c]) { if (d == 0) c++ ; else if (d == 1) l++ ; else if (d == 2) c-- ; else if (d == 3) l-- ; d = (d + 3) % 4 ; } // while // We record the point of the contour contour.add(new Integer(l)) ; contour.add(new Integer(c)) ; contour.add(new Integer(d)) ; // We have finished when we come back to the first point and in the first direction fin = (l1==l) & (c1==c) & (d1==d) ; } // while return contour ; } // contour } // class