package pl.wroc.pwr.roi.model; import java.util.ArrayList; import java.util.List; import pl.wroc.pwr.roi.IROI; public class ROIPixels implements IROI { /** * */ private static final long serialVersionUID = -2687608818148098821L; private int sizeX; private int sizeY; private List< int [ ] > coordinates; public ROIPixels( int sizeX, int sizeY ) { this.sizeX = sizeX; this.sizeY = sizeY; this.coordinates = new ArrayList< int [ ] >( ); } public ROIPixels(int sizeX, int sizeY, List coords) { this.sizeX = sizeX; this.sizeY = sizeY; this.coordinates = coords; } private int search( int x, int y ) { int [ ] coord; for ( int i = 0; i < this.coordinates.size( ); i++ ) { coord = this.coordinates.get( i ); if ( ( coord[ 0 ] == x )&&( coord[ 1 ] == y ) ) { return i; } } return -1; } public void quickAdd(int x, int y) { this.coordinates.add(new int[]{x, y}); } public void quickAdd(int x, int y, int weight) { this.coordinates.add(new int[]{x, y, weight}); } public boolean add( int x, int y ) { int i = this.search( x, y ); if ( i >= 0 ) { return false; } this.coordinates.add( new int[ ]{ x, y } ); return true; } public boolean remove( int x, int y ) { int i = this.search( x, y ); if ( i == -1 ) { return false; } this.coordinates.remove( i ); return true; } public boolean contains( int x, int y ) { return ( this.search( x, y ) >= 0 ); } public List< int[ ] > getROICoordinates( ) { return this.coordinates; } public int getSizeX( ) { return this.sizeX; } public int getSizeY( ) { return this.sizeY; } @Override public String toString() { return "ROIPixels[" + this.getSizeX() + ", " + this.getSizeY() + ", " + this.coordinates.size() + "]"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } }