2 * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
\r
4 * This file is part of LEA.
\r
6 * LEA is free software: you can redistribute it and/or modify it under the
\r
7 * terms of the GNU Lesser General Public License as published by the Free
\r
8 * Software Foundation, either version 3 of the License, or (at your option) any
\r
11 * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
\r
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
\r
13 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
16 * You should have received a copy of the GNU Lesser General Public License
\r
17 * along with LEA. If not, see <http://www.gnu.org/licenses/>.
\r
21 * No description given.
\r
23 * @author Florian Frankenberger
\r
25 @LATTICE("DEV<C,C<SIZE,SIZE*,C*,DEV*")
\r
26 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
\r
27 public class DeviationScanner {
\r
34 public static final int LEFT_UP = 0;
\r
35 public static final int UP = 1;
\r
36 public static final int RIGHT_UP = 2;
\r
37 public static final int LEFT = 3;
\r
38 public static final int NONE = 4;
\r
39 public static final int RIGHT = 5;
\r
40 public static final int LEFT_DOWN = 6;
\r
41 public static final int DOWN = 7;
\r
42 public static final int RIGHT_DOWN = 8;
\r
44 public DeviationScanner() {
\r
47 SSJAVA.arrayinit(x, -1);
\r
48 SSJAVA.arrayinit(y, -1);
\r
51 @LATTICE("THIS<IN,THISLOC=THIS")
\r
52 public void addEyePosition(@LOC("IN") int inx, @LOC("IN") int iny) {
\r
53 SSJAVA.append(x, inx);
\r
54 SSJAVA.append(y, iny);
\r
57 @LATTICE("THIS<C,THIS<IN,THISLOC=THIS,C*")
\r
58 @RETURNLOC("THIS,DeviationScanner.DEV")
\r
59 public int scanForDeviation(@LOC("IN") Rectangle2D faceRect) {
\r
61 @LOC("THIS,DeviationScanner.DEV") int deviation = NONE;
\r
63 for (@LOC("C") int i = 0; i < 3; i++) {
\r
69 @LOC("THIS,DeviationScanner.DEV") double deviationX = 0;
\r
70 @LOC("THIS,DeviationScanner.DEV") double deviationY = 0;
\r
72 @LOC("THIS,DeviationScanner.DEV") int lastIdx = -1;
\r
73 for (@LOC("THIS,DeviationScanner.DEV") int i = 0; i < 3; ++i) {
\r
74 if (lastIdx != -1) {
\r
75 deviationX += (x[i] - x[lastIdx]);
\r
76 deviationY += (y[i] - y[lastIdx]);
\r
81 @LOC("THIS,DeviationScanner.DEV") final double deviationPercentX = 0.04;
\r
82 @LOC("THIS,DeviationScanner.DEV") final double deviationPercentY = 0.04;
\r
84 deviationX /= faceRect.getWidth();
\r
85 deviationY /= faceRect.getWidth();
\r
87 @LOC("THIS,DeviationScanner.DEV") int deviationAbsoluteX = 0;
\r
88 @LOC("THIS,DeviationScanner.DEV") int deviationAbsoluteY = 0;
\r
89 if (deviationX > deviationPercentX)
\r
90 deviationAbsoluteX = 1;
\r
91 if (deviationX < -deviationPercentX)
\r
92 deviationAbsoluteX = -1;
\r
93 if (deviationY > deviationPercentY)
\r
94 deviationAbsoluteY = 1;
\r
95 if (deviationY < -deviationPercentY)
\r
96 deviationAbsoluteY = -1;
\r
98 deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);
\r
100 if (deviation != NONE) {
\r
101 SSJAVA.arrayinit(x, -1);
\r
102 SSJAVA.arrayinit(y, -1);
\r
108 @LATTICE("OUT<IN,OUT<THIS,THISLOC=THIS,RETURNLOC=OUT")
\r
109 public int getDirectionFor(@LOC("IN") int directionX, @LOC("IN") int directionY) {
\r
111 if (directionX == +1 && directionY == -1) {
\r
113 } else if (directionX == 0 && directionY == -1) {
\r
115 } else if (directionX == -1 && directionY == -1) {
\r
117 } else if (directionX == +1 && directionY == 0) {
\r
119 } else if (directionX == 0 && directionY == 0) {
\r
121 } else if (directionX == -1 && directionY == 0) {
\r
123 } else if (directionX == +1 && directionY == +1) {
\r
125 } else if (directionX == 0 && directionY == +1) {
\r
127 } else if (directionX == -1 && directionY == +1) {
\r
134 public String toStringDeviation(@LOC("IN") int dev) {
\r
135 if (dev == LEFT_UP) {
\r
137 } else if (dev == UP) {
\r
139 } else if (dev == RIGHT_UP) {
\r
141 } else if (dev == LEFT) {
\r
143 } else if (dev == NONE) {
\r
145 } else if (dev == RIGHT) {
\r
147 } else if (dev == LEFT_DOWN) {
\r
148 return "LEFT_DOWN";
\r
149 } else if (dev == DOWN) {
\r
151 } else if (dev == RIGHT_DOWN) {
\r
152 return "RIGHT_DOWN";
\r