1
22package ee.ut.mrz.volumest;
23
24import ij.measure.Calibration;
25import ij.process.ImageProcessor;
26import java.util.Iterator;
27
28
33public class GraphicsHandler {
34
35 private Calibration calibration;
36
37
40 public GraphicsHandler(Calibration calibration) {
41 this.calibration = calibration;
42 }
43
44
49 public void drawGrid(Grid grid, ImageProcessor ip) {
50 Iterator iter = grid.getGridPoints().iterator();
51 while (iter.hasNext()) {
52 GridPoint point = (GridPoint) iter.next();
53 if (point.isIntersection()) {
54 ip.setColor(Settings.getInstance().getIntersectionColor());
56 } else {
57 if (point.isActive()) {
58 ip.setColor(Settings.getInstance().getSelectionColor());
60 } else {
61 ip.setColor(Settings.getInstance().getGridColor());
63 }
64 }
65 double gwip = Math.round(Settings.getInstance().getGridWidth() / calibration.pixelWidth);
67
68 double vertexLen = Settings.getInstance().getVertexLength() / 100d;
69
70 Reper reper = grid.getReper();
71
72 if (point.isIntersection()) {
73
75 int x = (int) Math.round(point.getXInAfineReper());
76 int y = (int) Math.round(point.getYInAfineReper());
77 int yUp = (int) Math.round(point.getYInAfineReper() + gwip / 4);
79 int yDown = (int) Math.round(point.getYInAfineReper() - gwip / 4);
80
81 int xLeft = (int) Math.round(point.getXInAfineReper() - gwip / 4);
82 int xRight = (int) Math.round(point.getXInAfineReper() + gwip / 4);
83
84
86 ip.setLineWidth(Settings.getInstance().getGridLineThickness());
87
88 ip.moveTo(x, yUp);
89 ip.lineTo(x, yDown);
90
91 ip.moveTo(xRight, y);
92 ip.lineTo(xLeft, y);
93
94 } else {
95
96 if ( point.isActive() || !Settings.getInstance().isDontDisplayGrid() ) {
97 if (Settings.getInstance().getGridType() == Settings.GRID_RIGHT_ANGLES) {
98
99 GridPoint pointUp = new GridPoint(point.getXInCrossReper(), point.getYInCrossReper() - gwip / 2 * vertexLen, reper);
00 GridPoint pointRight = new GridPoint(point.getXInCrossReper() + gwip / 2 * vertexLen, point.getYInCrossReper(), reper);
01
02 int x = (int) Math.round(point.getXInAfineReper());
03 int y = (int) Math.round(point.getYInAfineReper());
04
05 int xUp = (int) Math.round(pointUp.getXInAfineReper());
06 int yUp = (int) Math.round(pointUp.getYInAfineReper());
07
08 int xRight = (int) Math.round(pointRight.getXInAfineReper());
09 int yRight = (int) Math.round(pointRight.getYInAfineReper());
10
11
13 ip.setLineWidth(Settings.getInstance().getGridLineThickness());
14
15 ip.moveTo(x, y);
16 ip.lineTo(xUp, yUp);
17
18 ip.moveTo(x, y);
19 ip.lineTo(xRight, yRight);
20
21
22 }
23
24 if (Settings.getInstance().getGridType() == Settings.GRID_LINES) {
25
26 GridPoint pointUp = new GridPoint(point.getXInCrossReper(), point.getYInCrossReper() - gwip / 2, reper);
27 GridPoint pointRight = new GridPoint(point.getXInCrossReper() + gwip / 2, point.getYInCrossReper(), reper);
28 GridPoint pointDown = new GridPoint(point.getXInCrossReper(), point.getYInCrossReper() + gwip / 2, reper);
29 GridPoint pointLeft = new GridPoint(point.getXInCrossReper() - gwip / 2, point.getYInCrossReper(), reper);
30
31 int x = (int) Math.round(point.getXInAfineReper());
32 int y = (int) Math.round(point.getYInAfineReper());
33
34 int xUp = (int) Math.round(pointUp.getXInAfineReper());
35 int yUp = (int) Math.round(pointUp.getYInAfineReper());
36
37 int xDown = (int) Math.round(pointDown.getXInAfineReper());
38 int yDown = (int) Math.round(pointDown.getYInAfineReper());
39
40 int xLeft = (int) Math.round(pointLeft.getXInAfineReper());
41 int yLeft = (int) Math.round(pointLeft.getYInAfineReper());
42
43 int xRight = (int) Math.round(pointRight.getXInAfineReper());
44 int yRight = (int) Math.round(pointRight.getYInAfineReper());
45
46
47
49 ip.setLineWidth(Settings.getInstance().getGridLineThickness());
50
51 ip.moveTo(x, y);
52 ip.lineTo(xUp, yUp);
53
54 ip.moveTo(x, y);
55 ip.lineTo(xRight, yRight);
56
57 ip.moveTo(x, y);
58 ip.lineTo(xDown, yDown);
59
60 ip.moveTo(x, y);
61 ip.lineTo(xLeft, yLeft);
62
63 }
64 }
65 }
66 }
67 }
68
69
74 public Object copyImage(Object localPixels) {
75 Object pixelsCopy = null;
76
77 if (localPixels instanceof int[]) {
78
79 int[] localPixelsCasted = (int[]) localPixels;
80 int[] pixels = new int[localPixelsCasted.length];
81
82 for (int i = 0; i < pixels.length; i++) {
83 pixels[i] = localPixelsCasted[i];
84 }
85
86 pixelsCopy = pixels;
87
88 } else if (localPixels instanceof byte[]) {
89 byte[] localPixelsCasted = (byte[]) localPixels;
90 byte[] pixels = new byte[localPixelsCasted.length];
91
92 for (int i = 0; i < pixels.length; i++) {
93 pixels[i] = localPixelsCasted[i];
94 }
95
96 pixelsCopy = pixels;
97
98 } else if (localPixels instanceof short[]) {
99 short[] localPixelsCasted = (short[]) localPixels;
00 short[] pixels = new short[localPixelsCasted.length];
01
02 for (int i = 0; i < pixels.length; i++) {
03 pixels[i] = localPixelsCasted[i];
04 }
05
06 pixelsCopy = pixels;
07
08 } else if (localPixels instanceof float[]) {
09 float[] localPixelsCasted = (float[]) localPixels;
10 float[] pixels = new float[localPixelsCasted.length];
11
12 for (int i = 0; i < pixels.length; i++) {
13 pixels[i] = localPixelsCasted[i];
14 }
15
16 pixelsCopy = pixels;
17
18 }
19
20 return pixelsCopy;
21 }
22}
23