changes.
[IRC.git] / Robust / src / Benchmarks / SSJava / EyeTracking / EyePosition.java
1 /*
2  * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
3  * 
4  * This file is part of LEA.
5  * 
6  * LEA is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU Lesser General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option) any
9  * later version.
10  * 
11  * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13  * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  * 
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with LEA. If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * No description given.
22  * 
23  * @author Florian Frankenberger
24  */
25 @LATTICE("POS")
26 @METHODDEFAULT("OUT<THIS,THISLOC=THIS,RETURNLOC=OUT")
27 public class EyePosition {
28   @LOC("POS")
29   private int x;
30   @LOC("POS")
31   private int y;
32   @LOC("POS")
33   private Rectangle2D faceRect;
34
35   public EyePosition(Point p, Rectangle2D faceRect) {
36     this(p.x, p.y, faceRect);
37   }
38
39   public EyePosition(int x, int y, Rectangle2D faceRect) {
40     this.x = x;
41     this.y = y;
42     this.faceRect = faceRect;
43   }
44
45   public int getX() {
46     return this.x;
47   }
48
49   public int getY() {
50     return this.y;
51   }
52
53   public String toString() {
54     return "(" + x + "," + y + ")";
55   }
56
57   // public Deviation getDeviation(EyePosition oldEyePosition) {
58   // if (oldEyePosition == null) return Deviation.NONE;
59   //
60   // //first we check if the faceRects are corresponding
61   // double widthChange = (this.faceRect.getWidth() -
62   // oldEyePosition.faceRect.getWidth()) / this.faceRect.getWidth();
63   // if (widthChange > 0.1) return Deviation.NONE;
64   //
65   // int maxDeviationX = (int)Math.round(this.faceRect.getWidth() / 4f);
66   // int maxDeviationY = (int)Math.round(this.faceRect.getWidth() / 8f);
67   // int minDeviation = (int)Math.round(this.faceRect.getWidth() / 16f);
68   //
69   // int deviationX = Math.abs(x - oldEyePosition.x);
70   // int directionX = sgn(x - oldEyePosition.x);
71   // if (deviationX < minDeviation || deviationX > maxDeviationX) directionX =
72   // 0;
73   //
74   // int deviationY = Math.abs(y - oldEyePosition.y);
75   // int directionY = sgn(y - oldEyePosition.y);
76   // if (deviationY < minDeviation || deviationY > maxDeviationY) directionY =
77   // 0;
78   //
79   // double deviationXPercent = deviationX / this.faceRect.getWidth();
80   // double deviationYPercent = deviationY / this.faceRect.getWidth();
81   //
82   // System.out.println(String.format("devX: %.2f | devY: %.2f",
83   // deviationXPercent*100f, deviationYPercent*100f));
84   // return Deviation.getDirectionFor(directionX, directionY);
85   // }
86
87   private static int sgn(int i) {
88     if (i > 0)
89       return 1;
90     if (i < 0)
91       return -1;
92     return 0;
93   }
94 }