1 | /* |
---|
2 | * $Id: Sides.java,v 1.5 2001/02/02 20:27:37 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt.contour; |
---|
14 | |
---|
15 | import gov.noaa.pmel.util.Debug; |
---|
16 | |
---|
17 | import java.util.BitSet; |
---|
18 | |
---|
19 | /** |
---|
20 | * Used to keep track of which sides have been used during the contour |
---|
21 | * line generation process. |
---|
22 | * |
---|
23 | * @author D. W. Denbo |
---|
24 | * @version $Revision: 1.5 $, $Date: 2001/02/02 20:27:37 $ |
---|
25 | * @since 2.0 |
---|
26 | */ |
---|
27 | class Sides { |
---|
28 | BitSet sides_; |
---|
29 | int nx_; |
---|
30 | int ny_; |
---|
31 | int ny2_; |
---|
32 | |
---|
33 | public Sides(int nx, int ny) { |
---|
34 | nx_ = nx; |
---|
35 | ny_ = ny; |
---|
36 | ny2_ = ny_*2; |
---|
37 | sides_ = new BitSet(ny2_*nx_); |
---|
38 | } |
---|
39 | |
---|
40 | public boolean isSideUsed(int i, int j, int side) { |
---|
41 | int ind = index(i,j,side); |
---|
42 | if(ind < 0 || ind > ny2_*nx_-1) { |
---|
43 | if(Debug.CONTOUR) { |
---|
44 | System.out.println("Sides.isSideUsed(): (i,j,side) = " + i + ", " + j + ", " + side); |
---|
45 | } |
---|
46 | return false; |
---|
47 | } |
---|
48 | return sides_.get(ind); |
---|
49 | } |
---|
50 | |
---|
51 | public void setSideUsed(int i, int j, int side, boolean set) { |
---|
52 | int ind = index(i,j,side); |
---|
53 | if(Debug.CONTOUR) { |
---|
54 | if(ind < 0 || ind > ny2_*nx_-1) { |
---|
55 | System.out.println("Sides.setSideUsed(): (i,j,side) = " + i + ", " + j + ", " + side); |
---|
56 | } |
---|
57 | } |
---|
58 | if(set) { |
---|
59 | sides_.set(ind); |
---|
60 | } else { |
---|
61 | sides_.clear(ind); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | public int getSide(int i, int j, int side) { |
---|
66 | int ind = index(i,j,side); |
---|
67 | if(ind < 0 || ind > ny2_*nx_-1) { |
---|
68 | if(Debug.CONTOUR) { |
---|
69 | System.out.println("Sides.getSide(): (i,j,side) = " + i + ", " + j + ", " + side); |
---|
70 | } |
---|
71 | return 0; |
---|
72 | } |
---|
73 | return sides_.get(ind)?1:0; |
---|
74 | } |
---|
75 | |
---|
76 | int index(int i, int j, int side) { |
---|
77 | int index = -10; |
---|
78 | if(side == 1) { /* i+1,j right */ |
---|
79 | index = 1 + j*2 + (i+1)*ny2_; |
---|
80 | } else if(side == 2) { /* i,j+1 top */ |
---|
81 | index = (j+1)*2 + i*ny2_; |
---|
82 | } else if(side == 0) { /* i,j bottom */ |
---|
83 | index = j*2 + i*ny2_; |
---|
84 | } else if(side == 3) { /* i,j left */ |
---|
85 | index = 1 + j*2 + i*ny2_; |
---|
86 | } |
---|
87 | return index; |
---|
88 | } |
---|
89 | public void clear() { |
---|
90 | sides_ = new BitSet(ny2_*nx_); |
---|
91 | } |
---|
92 | } |
---|