Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
FreehandRoi.java
1 package ij.gui;
2 
3 import java.awt.*;
4 import java.awt.image.*;
5 import ij.*;
6 
8 public class FreehandRoi extends PolygonRoi {
9 
10 
11  public FreehandRoi(int x, int y, ImagePlus imp) {
12  super(x, y, imp);
13  if (Toolbar.getToolId()==Toolbar.FREEROI)
14  type = FREEROI;
15  else
16  type = FREELINE;
17  }
18 
19  protected void grow(int ox, int oy) {
20  if (ox<0) ox = 0;
21  if (oy<0) oy = 0;
22  if (ox>xMax) ox = xMax;
23  if (oy>yMax) oy = yMax;
24  if (ox!=xp[nPoints-1] || oy!=yp[nPoints-1]) {
25  xp[nPoints] = ox-x;
26  yp[nPoints] = oy-y;
27  nPoints++;
28  if (nPoints==xp.length)
29  enlargeArrays();
30  drawLine();
31  }
32  }
33 
34  void drawLine() {
35  int x1 = xp[nPoints-2]+x;
36  int y1 = yp[nPoints-2]+y;
37  int x2 = xp[nPoints-1]+x;
38  int y2 = yp[nPoints-1]+y;
39  int xmin = Math.min(x1, x2);
40  int xmax = Math.max(x1, x2);
41  int ymin = Math.min(y1, y2);
42  int ymax = Math.max(y1, y2);
43  int margin = 4;
44  if (ic!=null) {
45  double mag = ic.getMagnification();
46  if (mag<1.0) margin = (int)(margin/mag);
47  }
48  imp.draw(xmin-margin, ymin-margin, (xmax-xmin)+margin*2, (ymax-ymin)+margin*2);
49  }
50 
51  protected void handleMouseUp(int screenX, int screenY) {
52  if (state==CONSTRUCTING) {
53  addOffset();
54  finishPolygon();
55  }
56  state = NORMAL;
57  }
58 
59 }