4 import java.awt.image.*;
7 import ij.measure.Calibration;
13 public OvalRoi(
int x,
int y,
int width,
int height) {
14 super(x, y, width, height);
26 this(x, y, width, height);
30 protected void moveHandle(
int ox,
int oy) {
34 int x1=x, y1=y, x2=x1+width, y2=y+height;
35 int w2 = (int)(0.14645*width);
36 int h2 = (int)(0.14645*height);
37 switch (activeHandle) {
38 case 0: x=ox-w2; y=oy-h2;
break;
40 case 2: x2=ox+w2; y=oy-h2;
break;
42 case 4: x2=ox+w2; y2=oy+h2;
break;
44 case 6: x=ox-w2; y2=oy+h2;
break;
47 if (x<0) x=0;
if (y<0) y=0;
58 if ((x+width)>xMax) width=xMax-x;
59 if ((y+height)>yMax) height=yMax-y;
61 imp.
draw(clipX, clipY, clipWidth, clipHeight);
63 oldWidth=width; oldHeight=height;
67 public void draw(Graphics g) {
70 mag = ic!=null?ic.getMagnification():1.0;
71 int sw = (int)(width*mag);
72 int sh = (int)(height*mag);
73 int sw2 = (int)(0.14645*width*mag);
74 int sh2 = (int)(0.14645*height*mag);
81 g.drawOval(sx1, sy1, sw, sh);
82 if (state!=CONSTRUCTING && clipboard==null) {
83 int size2 = HANDLE_SIZE/2;
84 drawHandle(g, sx1+sw2-size2, sy1+sh2-size2);
85 drawHandle(g, sx3-sw2-size2, sy1+sh2-size2);
86 drawHandle(g, sx3-sw2-size2, sy3-sh2-size2);
87 drawHandle(g, sx1+sw2-size2, sy3-sh2-size2);
88 drawHandle(g, sx2-size2, sy1-size2);
89 drawHandle(g, sx3-size2, sy2-size2);
90 drawHandle(g, sx2-size2, sy3-size2);
91 drawHandle(g, sx1-size2, sy2-size2);
95 {updateFullWindow =
false; imp.
draw();}
96 if (state!=NORMAL) showStatus();
101 if (imp==null)
return;
105 if (
Line.getWidth()>1)
106 updateFullWindow =
true;
114 for (
int i=0; i<wand.
npoints; i++) {
121 public boolean contains(
int x,
int y) {
123 if (!super.contains(x, y))
126 x = Math.abs(x - (this.x + width/2));
127 y = Math.abs(y - (this.y + height/2));
130 return (x*x/(a*a) + y*y/(b*b)) <= 1;
137 if (clipboard!=null || ic==null)
return -1;
138 double mag = ic.getMagnification();
139 int size = HANDLE_SIZE+3;
140 int halfSize = size/2;
141 int sx1 = ic.
screenX(x) - halfSize;
142 int sy1 = ic.
screenY(y) - halfSize;
143 int sx3 = ic.
screenX(x+width) - halfSize;
144 int sy3 = ic.
screenY(y+height) - halfSize;
145 int sx2 = sx1 + (sx3 - sx1)/2;
146 int sy2 = sy1 + (sy3 - sy1)/2;
148 int sw2 = (int)(0.14645*(sx3-sx1));
149 int sh2 = (int)(0.14645*(sy3-sy1));
151 if (sx>=sx1+sw2&&sx<=sx1+sw2+size&&sy>=sy1+sh2&&sy<=sy1+sh2+size)
return 0;
152 if (sx>=sx2&&sx<=sx2+size&&sy>=sy1&&sy<=sy1+size)
return 1;
153 if (sx>=sx3-sw2&&sx<=sx3-sw2+size&&sy>=sy1+sh2&&sy<=sy1+sh2+size)
return 2;
154 if (sx>=sx3&&sx<=sx3+size&&sy>=sy2&&sy<=sy2+size)
return 3;
155 if (sx>=sx3-sw2&&sx<=sx3-sw2+size&&sy>=sy3-sh2&&sy<=sy3-sh2+size)
return 4;
156 if (sx>=sx2&&sx<=sx2+size&&sy>=sy3&&sy<=sy3+size)
return 5;
157 if (sx>=sx1+sw2&&sx<=sx1+sw2+size&&sy>=sy3-sh2&&sy<=sy3-sh2+size)
return 6;
158 if (sx>=sx1&&sx<=sx1+size&&sy>=sy2&&sy<=sy2+size)
return 7;
163 if (cachedMask!=null)
166 double a=width/2.0, b=height/2.0;
167 double a2=a*a, b2=b*b;
171 byte[] pixels = (byte[])mask.
getPixels();
172 for (
int y=0; y<height; y++) {
174 for (
int x=0; x<width; x++) {
177 if ((xx*xx/a2+yy*yy/b2)<=1.0)
178 pixels[offset+x] = -1;
187 double pw=1.0, ph=1.0;
193 return Math.PI*(width*pw+height*ph)/2.0;
199 double pw=1.0, ph=1.0;
205 return width*pw>=height*ph?width*pw:height*ph;