// arg idx is starting from 'this' arg
if (fc.getThis() != null) {
- NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
+ NTuple<Location> thisLocationPath = deriveLocationTuple(fc.getMethod(), fc.getThis());
if (thisLocationPath != null) {
mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
}
}
private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
-
assert td.getType() != null;
if (mapDescriptorToLocationPath.containsKey(td)) {
Set<FlatNode> flatNodeSet = ssjava.getBuildFlat().getFlatNodeSet(an);
for (Iterator iterator = flatNodeSet.iterator(); iterator.hasNext();) {
FlatNode fn = (FlatNode) iterator.next();
- System.out.println("SAMEHEIGHT!");
ssjava.addSameHeightWriteFlatNode(fn);
}
- } else {
- System.out.println("NOT SAME HEIGHT!");
- }
+ }
} else {
destLocation =
addOutEdge(fromNode, edge);
addInEdge(toNode, edge);
- System.out.println("add a new edge=" + edge);
+ // System.out.println("add a new edge=" + edge);
}
private void addInEdge(FlowNode toNode, FlowEdge edge) {
bw.write("}\n");
}
+ public void removeEdge(NTuple<Descriptor> from, NTuple<Descriptor> to) {
+
+ Set<FlowEdge> toberemoved = new HashSet<FlowEdge>();
+ Set<FlowEdge> edgeSet = getOutEdgeSet(getFlowNode(from));
+
+ for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+ FlowEdge flowEdge = (FlowEdge) iterator.next();
+ if (flowEdge.getInitTuple().equals(from) && flowEdge.getEndTuple().equals(to)) {
+ toberemoved.add(flowEdge);
+ }
+ }
+
+ edgeSet.removeAll(toberemoved);
+
+ }
+
}
\ No newline at end of file
private boolean isFormHolder = false;
+ private NTuple<Descriptor> baseTuple;
+
public boolean isIntermediate() {
return isIntermediate;
}
return isFormHolder;
}
+ public void setBaseTuple(NTuple<Descriptor> in) {
+ baseTuple = in;
+ }
+
+ public NTuple<Descriptor> getBaseTuple() {
+ return baseTuple;
+ }
+
public Set<FlowNode> getFieldNodeSet() {
return fieldNodeSet;
}
System.out.println("###RETURN COMP LOC=" + returnLoc);
NTuple<Location> returnLocTuple = returnLoc.getTuple();
NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
+ System.out.println("###basetuple=" + baseTuple);
NTuple<Descriptor> newReturnTuple = baseTuple.clone();
for (int i = 1; i < returnLocTuple.size(); i++) {
newReturnTuple.add(returnLocTuple.get(i).getLocDescriptor());
}
System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple);
+
+ FlowReturnNode holderNode = callerFlowGraph.getFlowReturnNode(min);
+ NodeTupleSet holderTupleSet =
+ getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), holderNode);
+
callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple);
+
+ // then need to remove old constraints
+ // TODO SAT
+ System.out.println("###REMOVE OLD CONSTRAINTS=" + holderNode);
+ for (Iterator<NTuple<Descriptor>> iter = holderTupleSet.iterator(); iter.hasNext();) {
+ NTuple<Descriptor> tupleFromHolder = iter.next();
+ Set<FlowEdge> holderOutEdge = callerFlowGraph.getOutEdgeSet(holderNode);
+ for (Iterator iterator2 = holderOutEdge.iterator(); iterator2.hasNext();) {
+ FlowEdge outEdge = (FlowEdge) iterator2.next();
+ NTuple<Descriptor> toberemovedTuple = outEdge.getEndTuple();
+ System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple);
+ callerFlowGraph.removeEdge(tupleFromHolder, toberemovedTuple);
+ }
+ }
+
} else {
// if the return loc set was empty and later pcloc was connected to the return loc
// need to make sure that return loc reflects to this changes.
System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple
+ "-> globalParamLocTuple=" + globalParamLocTuple);
hasChanges = true;
+ System.out.println("B1");
globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple);
}
}
+ "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple="
+ globalParamLocTuple);
hasChanges = true;
+ System.out.println("B2");
+
globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple);
}
}
MethodDescriptor md = (MethodDescriptor) targetLocalLoc.getDescriptor();
FlowGraph flowGraph = getFlowGraph(md);
+
FlowNode flowNode = flowGraph.getFlowNode(node.getDescTuple());
Set<FlowNode> reachableSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
// Location loc = new Location(md, dstVarDesc);
// dstLocTuple.add(loc);
// }
+ System.out.println("B11");
globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple);
if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) {
NTuple<Location> pcLocTuple = (NTuple<Location>) iterator2.next();
+ System.out.println("B12");
+
callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
}
}
GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
- // System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode);
+ System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode);
NTuple<Location> callerSrcNodeLocTuple =
translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
- // System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
+ System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple());
// System.out.println("outNode=" + outNode + " callerDstNodeLocTuple="
// + callerDstNodeLocTuple);
- if (callerDstNodeLocTuple != null) {
+ if (callerSrcNodeLocTuple != null && callerDstNodeLocTuple != null
+ && callerSrcNodeLocTuple.size() > 0 && callerDstNodeLocTuple.size() > 0) {
+ System.out.println("B3");
callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
}
}
TypeDescriptor type = ((FieldDescriptor) desc).getType();
if (type.isArray()) {
- return false;
+ return !type.isPrimitive();
} else {
return type.isPtr();
}
} else if (desc instanceof VarDescriptor) {
TypeDescriptor type = ((VarDescriptor) desc).getType();
if (type.isArray()) {
- return false;
+ return !type.isPrimitive();
} else {
return type.isPtr();
}
private void constructHierarchyGraph() {
+ LinkedList<MethodDescriptor> methodDescList =
+ (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
+
+ while (!methodDescList.isEmpty()) {
+ MethodDescriptor md = methodDescList.removeLast();
+ if (state.SSJAVADEBUG) {
+ HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
+ System.out.println();
+ System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
+ constructHierarchyGraph(md, hierarchyGraph);
+ mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
+
+ }
+ }
+
+ setupToAnalyze();
+ while (!toAnalyzeIsEmpty()) {
+ ClassDescriptor cd = toAnalyzeNext();
+ HierarchyGraph graph = getHierarchyGraph(cd);
+ for (Iterator iter = cd.getFields(); iter.hasNext();) {
+ FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
+ if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
+ graph.getHNode(fieldDesc);
+ }
+ }
+ }
+
+ Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ Descriptor key = (Descriptor) iterator.next();
+ HierarchyGraph graph = getHierarchyGraph(key);
+
+ Set<HNode> nodeToBeConnected = new HashSet<HNode>();
+ for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
+ HNode node = (HNode) iterator2.next();
+ if (!node.isSkeleton() && !node.isCombinationNode()) {
+ if (graph.getIncomingNodeSet(node).size() == 0) {
+ nodeToBeConnected.add(node);
+ }
+ }
+ }
+
+ for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
+ HNode node = (HNode) iterator2.next();
+ System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
+ graph.addEdge(graph.getHNode(TOPDESC), node);
+ }
+
+ }
+
+ }
+
+ private void constructHierarchyGraph2() {
+
// do fixed-point analysis
LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple
+ " srcNode=" + srcNode + " dstNode=" + dstNode);
+ // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple);
+ // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple);
+
if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
&& srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
}
+ private NTuple<Descriptor> translateBaseTuple(FlowNode flowNode, NTuple<Descriptor> inTuple) {
+
+ if (flowNode.getBaseTuple() != null) {
+
+ NTuple<Descriptor> translatedTuple = new NTuple<Descriptor>();
+
+ NTuple<Descriptor> baseTuple = flowNode.getBaseTuple();
+
+ for (int i = 0; i < baseTuple.size(); i++) {
+ translatedTuple.add(baseTuple.get(i));
+ }
+
+ for (int i = 1; i < inTuple.size(); i++) {
+ translatedTuple.add(inTuple.get(i));
+ }
+
+ System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple);
+ return translatedTuple;
+
+ } else {
+ return inTuple;
+ }
+
+ }
+
private MethodSummary getMethodSummary(MethodDescriptor md) {
if (!mapDescToLocationSummary.containsKey(md)) {
mapDescToLocationSummary.put(md, new MethodSummary(md));
if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
flowNodeLowerthanPCLocSet.add(node);
fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
+ System.out.println("B10");
+
subGlobalFlowGraph.addValueFlowEdge(pcLocTuple,
translateToLocTuple(md, node.getDescTuple()));
}
System.out.println("#########################################");
for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) {
FlowNode lowerNode = (FlowNode) iterator.next();
- if (lowerNode.getCompositeLocation() == null) {
+ if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) {
NTuple<Location> lowerLocTuple = translateToLocTuple(md, lowerNode.getDescTuple());
CompositeLocation newComp =
calculateCompositeLocationFromSubGlobalGraph(md, lowerNode);
fn.setDeclarationNode();
if (dn.getExpression() != null) {
+ System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0));
NodeTupleSet nodeSetRHS = new NodeTupleSet();
analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
NTuple<Location> calleeReturnLocTuple = iterator.next();
+ System.out.println("B7");
+
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
}
+ for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
+ .hasNext();) {
+ NTuple<Location> implicitGlobalTuple = iterator.next();
+ System.out.println("B8");
+
+ globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS));
+ }
+
+ System.out.println("-nodeSetRHS=" + nodeSetRHS);
+ System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
+
}
}
assert (baseNodeSet.size() == 1);
NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
+ if (baseTuple.get(0) instanceof InterDescriptor) {
+ if (baseTuple.size() > 1) {
+ throw new Error();
+ }
+ FlowNode interNode = getFlowGraph(mdCaller).getFlowNode(baseTuple);
+ baseTuple = translateBaseTuple(interNode, baseTuple);
+ }
mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
if (!min.getMethod().isStatic()) {
// nodeSet.addTuple(inFlowTuple);
System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from="
+ mdCallee.getThis());
- tupleSet.addTuple(inFlowTuple);
+ // tupleSet.addTuple(inFlowTuple);
+ tupleSet.addTuple(baseTuple);
} else {
// TODO
System.out.println("returnNode=" + returnNode);
}
if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
- FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min);
+ FlowReturnNode returnHolderNode = getFlowGraph(mdCaller).createReturnNode(min);
if (needToGenerateInterLoc(tupleSet)) {
System.out.println("20");
}
}
- setNode.addTuple(interTuple);
- System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + setNode);
+ returnHolderNode.addTuple(interTuple);
+ // TODO
+ nodeSet.addTuple(interTuple);
+ System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode);
} else {
- setNode.addTupleSet(tupleSet);
- System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode);
-
+ returnHolderNode.addTupleSet(tupleSet);
+ System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode);
}
// setNode.addTupleSet(tupleSet);
- nodeSet.addTuple(setNode.getDescTuple());
+ // NodeTupleSet setFromReturnNode=new NodeTupleSet();
+ // setFromReturnNode.addTuple(tuple);
+
+ NodeTupleSet holderTupleSet =
+ getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), returnHolderNode);
+ System.out.println("HOLDER TUPLe SET=" + holderTupleSet);
+ nodeSet.addTupleSet(holderTupleSet);
+
+ nodeSet.addTuple(returnHolderNode.getDescTuple());
}
// propagateFlowsFromCallee(min, md, min.getMethod());
}
+ private NodeTupleSet getNodeTupleSetFromReturnNode(FlowGraph fg, FlowReturnNode node) {
+ NodeTupleSet nts = new NodeTupleSet();
+
+ Set<NTuple<Descriptor>> returnSet = node.getReturnTupleSet();
+
+ for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
+ NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+ FlowNode flowNode = fg.getFlowNode(tuple);
+ if (flowNode instanceof FlowReturnNode) {
+ returnSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
+ } else {
+ returnSet.add(tuple);
+ }
+ }
+
+ for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
+ NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator.next();
+ nts.addTuple(nTuple);
+ }
+
+ return nts;
+
+ }
+
+ private Set<NTuple<Descriptor>> recurGetNode(FlowGraph fg, FlowReturnNode rnode) {
+
+ Set<NTuple<Descriptor>> tupleSet = new HashSet<NTuple<Descriptor>>();
+
+ Set<NTuple<Descriptor>> returnSet = rnode.getReturnTupleSet();
+ for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
+ NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+ FlowNode flowNode = fg.getFlowNode(tuple);
+ if (flowNode instanceof FlowReturnNode) {
+ tupleSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
+ }
+ tupleSet.add(tuple);
+ }
+
+ return tupleSet;
+ }
+
private NTuple<Descriptor> generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) {
int size = 0;
}
// Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
- System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
+ // System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
FlowNode fn = (FlowNode) iterator.next();
NTuple<Location> calleeReturnLocTuple = iterator.next();
for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
NTuple<Descriptor> arrTuple = arrIter.next();
+ System.out.println("B4");
+
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
}
}
if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
System.out.println("1");
- NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+ FlowNode interNode = getFlowGraph(md).createIntermediateNode();
+ NTuple<Descriptor> interTuple = interNode.getDescTuple();
for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
NTuple<Descriptor> higherTuple = iter.next();
if (base != null) {
fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
getClassTypeDescriptor(base.get(base.size() - 1)));
+ interNode.setBaseTuple(base);
}
}
}
for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
.hasNext();) {
NTuple<Location> calleeReturnLocTuple = iterator.next();
+ System.out.println("B9");
+
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
translateToLocTuple(md, flowFieldTuple));
}
NTuple<Descriptor> callerLHSTuple = iter2.next();
System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
+ translateToLocTuple(md, callerLHSTuple));
+ System.out.println("B5");
+
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
translateToLocTuple(md, callerLHSTuple));
}
NTuple<Location> calleeReturnLocTuple = iterator.next();
for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
NTuple<Descriptor> callerLHSTuple = iter2.next();
+ System.out.println("B6");
+
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
translateToLocTuple(md, callerLHSTuple));
System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> "
public class DeviationScanner {\r
\r
@LOC("DEV")\r
- private EyePosition eyePositions[];\r
-\r
- // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),\r
- // RIGHT(-1, 0), LEFT_DOWN(\r
- // +1, +1), DOWN(0, +1), RIGHT_DOWN(-1, +1);\r
+ private int x[];\r
+ @LOC("DEV")\r
+ private int y[];\r
\r
public static final int LEFT_UP = 0;\r
public static final int UP = 1;\r
public static final int RIGHT_DOWN = 8;\r
\r
public DeviationScanner() {\r
- eyePositions = new EyePosition[3];\r
+ x = new int[3];\r
+ y = new int[3];\r
+ SSJAVA.arrayinit(x, -1);\r
+ SSJAVA.arrayinit(y, -1);\r
}\r
\r
- @LATTICE("THIS<C,C<IN,THISLOC=THIS")\r
- public void addEyePosition(@LOC("IN") EyePosition eyePosition) {\r
-\r
- // for (@LOC("THIS,DeviationScanner.C") int i = 1; i < 3; i++) {\r
- // eyePositions[i - 1] = eyePositions[i];\r
- // eyePositions[i] = null;\r
- // }\r
- // eyePositions[eyePositions.length - 1] = eyePosition;\r
-\r
- SSJAVA.append(eyePositions, eyePosition);\r
-\r
+ @LATTICE("THIS<IN,THISLOC=THIS")\r
+ public void addEyePosition(@LOC("IN") int inx, @LOC("IN") int iny) {\r
+ SSJAVA.append(x, inx);\r
+ SSJAVA.append(y, iny);\r
}\r
\r
- // @LATTICE("OUT<DEV,DEV<C,C<THIS,THIS<IN,C*,DEV*,OUT*,THISLOC=THIS,RETURNLOC=OUT")\r
@LATTICE("THIS<C,THIS<IN,THISLOC=THIS,C*")\r
@RETURNLOC("THIS,DeviationScanner.DEV")\r
public int scanForDeviation(@LOC("IN") Rectangle2D faceRect) {\r
@LOC("THIS,DeviationScanner.DEV") int deviation = NONE;\r
\r
for (@LOC("C") int i = 0; i < 3; i++) {\r
- if (eyePositions[i] == null) {\r
+ if (x[i] == -1) {\r
return deviation;\r
}\r
}\r
@LOC("THIS,DeviationScanner.DEV") int lastIdx = -1;\r
for (@LOC("THIS,DeviationScanner.DEV") int i = 0; i < 3; ++i) {\r
if (lastIdx != -1) {\r
- deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX());\r
- deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY());\r
+ deviationX += (x[i] - x[lastIdx]);\r
+ deviationY += (y[i] - y[lastIdx]);\r
}\r
lastIdx = i;\r
}\r
deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);\r
\r
if (deviation != NONE) {\r
- eyePositions = new EyePosition[3];\r
+ SSJAVA.arrayinit(x, -1);\r
+ SSJAVA.arrayinit(y, -1);\r
}\r
- // System.out.println(String.format("%.2f%% | %.2f%% => %d and %d >>> %s",\r
- // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY,\r
- // deviation.toString()));\r
\r
return deviation;\r
}\r
return -1;\r
}\r
\r
- public void clear() {\r
- System.out.println("CLEAR");\r
- eyePositions = new EyePosition[3];\r
- }\r
-\r
public String toStringDeviation(@LOC("IN") int dev) {\r
if (dev == LEFT_UP) {\r
return "LEFT_UP";\r
private int x;
@LOC("POS")
private int y;
-
- @LOC("POS") private double facex;
- @LOC("POS") private double facey;
- @LOC("POS") private double facewidth;
- @LOC("POS") private double faceheight;
-
- // private Rectangle2D faceRect;
-
- // public EyePosition(Point p, Rectangle2D faceRect) {
- // this(p.x, p.y, faceRect);
- // }
- //
- // public EyePosition(int x, int y, Rectangle2D faceRect) {
- // this.x = x;
- // this.y = y;
- // this.faceRect = faceRect;
- // }
public EyePosition(int x, int y) {
this.x = x;
return "(" + x + "," + y + ")";
}
- // public Deviation getDeviation(EyePosition oldEyePosition) {
- // if (oldEyePosition == null) return Deviation.NONE;
- //
- // //first we check if the faceRects are corresponding
- // double widthChange = (this.faceRect.getWidth() -
- // oldEyePosition.faceRect.getWidth()) / this.faceRect.getWidth();
- // if (widthChange > 0.1) return Deviation.NONE;
- //
- // int maxDeviationX = (int)Math.round(this.faceRect.getWidth() / 4f);
- // int maxDeviationY = (int)Math.round(this.faceRect.getWidth() / 8f);
- // int minDeviation = (int)Math.round(this.faceRect.getWidth() / 16f);
- //
- // int deviationX = Math.abs(x - oldEyePosition.x);
- // int directionX = sgn(x - oldEyePosition.x);
- // if (deviationX < minDeviation || deviationX > maxDeviationX) directionX =
- // 0;
- //
- // int deviationY = Math.abs(y - oldEyePosition.y);
- // int directionY = sgn(y - oldEyePosition.y);
- // if (deviationY < minDeviation || deviationY > maxDeviationY) directionY =
- // 0;
- //
- // double deviationXPercent = deviationX / this.faceRect.getWidth();
- // double deviationYPercent = deviationY / this.faceRect.getWidth();
- //
- // System.out.println(String.format("devX: %.2f | devY: %.2f",
- // deviationXPercent*100f, deviationYPercent*100f));
- // return Deviation.getDirectionFor(directionX, directionY);
- // }
-
private static int sgn(int i) {
if (i > 0)
return 1;
+import Benchmarks.SSJava.EyeTrackingInfer.EyePosition;
+
/*
* Copyright 2009 (c) Florian Frankenberger (darkblue.de)
*
/**
* This is the main class of LEA.
* <p>
- * It uses a face detection algorithm to find an a face within the provided
- * image(s). Then it searches for the eye in a region where it most likely
- * located and traces its position relative to the face and to the last known
- * position. The movements are estimated by comparing more than one movement. If
- * a movement is distinctly pointing to a direction it is recognized and all
- * listeners get notified.
+ * It uses a face detection algorithm to find an a face within the provided image(s). Then it
+ * searches for the eye in a region where it most likely located and traces its position relative to
+ * the face and to the last known position. The movements are estimated by comparing more than one
+ * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
+ * get notified.
* <p>
* The notification is designed as observer pattern. You simply call
- * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an
- * implementation of <code>IEyeMovementListener</code> to LEA. When a face is
- * recognized/lost or whenever an eye movement is detected LEA will call the
- * appropriate methods of the listener
+ * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
+ * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
+ * movement is detected LEA will call the appropriate methods of the listener
* <p>
- * LEA also needs an image source implementing the <code>ICaptureDevice</code>.
- * One image source proxy to the <code>Java Media Framework</code> is included (
- * <code>JMFCaptureDevice</code>).
+ * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
+ * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
* <p>
* Example (for using LEA with <code>Java Media Framework</code>):
* <p>
* LEA lea = new LEA(new JMFCaptureDevice(), true);
* </code>
* <p>
- * This will start LEA with the first available JMF datasource with an extra
- * status window showing if face/eye has been detected successfully. Please note
- * that face detection needs about 2 seconds to find a face. After detection the
- * following face detection is much faster.
+ * This will start LEA with the first available JMF datasource with an extra status window showing
+ * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
+ * to find a face. After detection the following face detection is much faster.
*
* @author Florian Frankenberger
*/
-@LATTICE("LAST<DEV,DEV<POS,POS<IMPL")
+@LATTICE("LAST<DEV,DEV<E,E<POS,POS<IMPL")
@METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
public class LEA {
@LOC("IMPL")
private LEAImplementation implementation;
- @LOC("LAST")
- private FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null);
@LOC("DEV")
private DeviationScanner deviationScanner = new DeviationScanner();
}
/**
- * Clears the internal movement buffer. If you just capture some of the eye
- * movements you should call this every time you start recording the
- * movements. Otherwise you may get notified for movements that took place
- * BEFORE you started recording.
+ * Clears the internal movement buffer. If you just capture some of the eye movements you should
+ * call this every time you start recording the movements. Otherwise you may get notified for
+ * movements that took place BEFORE you started recording.
*/
public void clear() {
// this.imageProcessor.clearDeviationScanner();
}
/**
- * @METHOD To test LEA with the first capture device from the
- * <code>Java Media Framework</code> just start from here.
+ * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
+ * just start from here.
*
* @param args
* @throws Exception
@LOC("C") int i = 0;
SSJAVA: while (true) {
- @LOC("IMG") Image image = ImageReader.getImage();
+ @LOC("IMG") Image image = ImageReader.getImage();
if (image == null) {
break;
}
System.out.println("Done.");
}
-
private void processImage(@LOC("IN") Image image) {
@LOC("THIS,LEA.POS") FaceAndEyePosition positions = implementation.getEyePosition(image);
- // if (positions.getEyePosition() != null) {
- deviationScanner.addEyePosition(positions.getEyePosition());
+ deviationScanner.addEyePosition(positions.getEyePosition().getX(), positions.getEyePosition()
+ .getY());
@LOC("THIS,LEA.DEV,DeviationScanner.DEV") int deviation =
deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
if (deviation != DeviationScanner.NONE) {
// notifyEyeMovementListenerEyeMoved(deviation);
}
// }
- lastPositions = positions;
}
}
* @author Florian Frankenberger\r
*/\r
\r
-\r
public class DeviationScanner {\r
\r
- \r
- private EyePosition eyePositions[];\r
+ private int x[];\r
+ private int y[];\r
\r
// LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),\r
// RIGHT(-1, 0), LEFT_DOWN(\r
public static final int RIGHT_DOWN = 8;\r
\r
public DeviationScanner() {\r
- eyePositions = new EyePosition[3];\r
+ x = new int[3];\r
+ y = new int[3];\r
+ SSJAVA.arrayinit(x, -1);\r
+ SSJAVA.arrayinit(y, -1);\r
}\r
\r
- \r
- public void addEyePosition( EyePosition eyePosition) {\r
-\r
- // for ( int i = 1; i < 3; i++) {\r
- // eyePositions[i - 1] = eyePositions[i];\r
- // eyePositions[i] = null;\r
- // }\r
- // eyePositions[eyePositions.length - 1] = eyePosition;\r
-\r
- SSJAVA.append(eyePositions, eyePosition);\r
-\r
+ public void addEyePosition(int inx, int iny) {\r
+ SSJAVA.append(x, inx);\r
+ SSJAVA.append(y, iny);\r
}\r
\r
- // \r
- \r
- \r
- public int scanForDeviation( Rectangle2D faceRect) {\r
+ public int scanForDeviation(Rectangle2D faceRect) {\r
\r
- int deviation = NONE;\r
+ int deviation = NONE;\r
\r
- for ( int i = 0; i < 3; i++) {\r
- if (eyePositions[i] == null) {\r
+ for (int i = 0; i < 3; i++) {\r
+ if (x[i] == -1) {\r
return deviation;\r
}\r
}\r
\r
- double deviationX = 0;\r
- double deviationY = 0;\r
+ double deviationX = 0;\r
+ double deviationY = 0;\r
\r
- int lastIdx = -1;\r
- for ( int i = 0; i < 3; ++i) {\r
+ int lastIdx = -1;\r
+ for (int i = 0; i < 3; ++i) {\r
if (lastIdx != -1) {\r
- deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX());\r
- deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY());\r
+ deviationX += (x[i] - x[lastIdx]);\r
+ deviationY += (y[i] - y[lastIdx]);\r
}\r
lastIdx = i;\r
}\r
\r
- final double deviationPercentX = 0.04;\r
- final double deviationPercentY = 0.04;\r
+ final double deviationPercentX = 0.04;\r
+ final double deviationPercentY = 0.04;\r
\r
deviationX /= faceRect.getWidth();\r
deviationY /= faceRect.getWidth();\r
\r
- int deviationAbsoluteX = 0;\r
- int deviationAbsoluteY = 0;\r
+ int deviationAbsoluteX = 0;\r
+ int deviationAbsoluteY = 0;\r
if (deviationX > deviationPercentX)\r
deviationAbsoluteX = 1;\r
if (deviationX < -deviationPercentX)\r
deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);\r
\r
if (deviation != NONE) {\r
- eyePositions = new EyePosition[3];\r
+ SSJAVA.arrayinit(x, -1);\r
+ SSJAVA.arrayinit(y, -1);\r
}\r
- // System.out.println(String.format("%.2f%% | %.2f%% => %d and %d >>> %s",\r
- // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY,\r
- // deviation.toString()));\r
\r
return deviation;\r
}\r
\r
- \r
- public int getDirectionFor( int directionX, int directionY) {\r
+ public int getDirectionFor(int directionX, int directionY) {\r
\r
if (directionX == +1 && directionY == -1) {\r
return LEFT_UP;\r
return -1;\r
}\r
\r
- public void clear() {\r
- System.out.println("CLEAR");\r
- eyePositions = new EyePosition[3];\r
- }\r
-\r
- public String toStringDeviation( int dev) {\r
+ public String toStringDeviation(int dev) {\r
if (dev == LEFT_UP) {\r
return "LEFT_UP";\r
} else if (dev == UP) {\r
/**
* This is the main class of LEA.
* <p>
- * It uses a face detection algorithm to find an a face within the provided
- * image(s). Then it searches for the eye in a region where it most likely
- * located and traces its position relative to the face and to the last known
- * position. The movements are estimated by comparing more than one movement. If
- * a movement is distinctly pointing to a direction it is recognized and all
- * listeners get notified.
+ * It uses a face detection algorithm to find an a face within the provided image(s). Then it
+ * searches for the eye in a region where it most likely located and traces its position relative to
+ * the face and to the last known position. The movements are estimated by comparing more than one
+ * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
+ * get notified.
* <p>
* The notification is designed as observer pattern. You simply call
- * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an
- * implementation of <code>IEyeMovementListener</code> to LEA. When a face is
- * recognized/lost or whenever an eye movement is detected LEA will call the
- * appropriate methods of the listener
+ * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
+ * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
+ * movement is detected LEA will call the appropriate methods of the listener
* <p>
- * LEA also needs an image source implementing the <code>ICaptureDevice</code>.
- * One image source proxy to the <code>Java Media Framework</code> is included (
- * <code>JMFCaptureDevice</code>).
+ * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
+ * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
* <p>
* Example (for using LEA with <code>Java Media Framework</code>):
* <p>
* LEA lea = new LEA(new JMFCaptureDevice(), true);
* </code>
* <p>
- * This will start LEA with the first available JMF datasource with an extra
- * status window showing if face/eye has been detected successfully. Please note
- * that face detection needs about 2 seconds to find a face. After detection the
- * following face detection is much faster.
+ * This will start LEA with the first available JMF datasource with an extra status window showing
+ * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
+ * to find a face. After detection the following face detection is much faster.
*
* @author Florian Frankenberger
*/
-
public class LEA {
-
private LEAImplementation implementation;
-
- private FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null);
-
+
private DeviationScanner deviationScanner = new DeviationScanner();
public LEA() {
}
/**
- * Clears the internal movement buffer. If you just capture some of the eye
- * movements you should call this every time you start recording the
- * movements. Otherwise you may get notified for movements that took place
- * BEFORE you started recording.
+ * Clears the internal movement buffer. If you just capture some of the eye movements you should
+ * call this every time you start recording the movements. Otherwise you may get notified for
+ * movements that took place BEFORE you started recording.
*/
public void clear() {
// this.imageProcessor.clearDeviationScanner();
}
/**
- * @METHOD To test LEA with the first capture device from the
- * <code>Java Media Framework</code> just start from here.
+ * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
+ * just start from here.
*
* @param args
* @throws Exception
lea.doRun();
}
-
public void doRun() {
- int i = 0;
+ int i = 0;
SSJAVA: while (true) {
- Image image = ImageReader.getImage();
+ Image image = ImageReader.getImage();
if (image == null) {
break;
}
System.out.println("Done.");
}
-
- private void processImage( Image image) {
- FaceAndEyePosition positions = implementation.getEyePosition(image);
- // if (positions.getEyePosition() != null) {
- deviationScanner.addEyePosition(positions.getEyePosition());
- int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
+ private void processImage(Image image) {
+ FaceAndEyePosition positions = implementation.getEyePosition(image);
+ EyePosition eye = positions.getEyePosition();
+ deviationScanner.addEyePosition(eye.getX(),eye.getY());
+ Rectangle2D face = positions.getFacePosition();
+ int deviation = deviationScanner.scanForDeviation(face);// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
if (deviation != DeviationScanner.NONE) {
System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation));
- // notifyEyeMovementListenerEyeMoved(deviation);
}
- // }
- lastPositions = positions;
}
}
static void append(Object array[], Object item) {
for (int i = 1; i < array.length; i++) {
array[i - 1] = array[i];
- array[i]=null;
+ array[i] = null;
}
array[array.length - 1] = item;
}
+
+ static void append(int array[], int item) {
+ for (int i = 1; i < array.length; i++) {
+ array[i - 1] = array[i];
+ array[i] = 0;
+ }
+ array[array.length - 1] = item;
+ }
+
+
+ static void arrayinit(Object array[]) {
+ for (int i = 1; i < array.length; i++) {
+ array[i] = null;
+ }
+ }
}
array[array.length - 1] = item;
}
+ static void append(int array[], int item) {
+ for (int i = 1; i < array.length; i++) {
+ array[i - 1] = array[i];
+ array[i] = 0;
+ }
+ array[array.length - 1] = item;
+ }
+
+ static void arrayinit(Object array[]) {
+ for (int i = 1; i < array.length; i++) {
+ array[i] = null;
+ }
+ }
+
}
length = length + 1;
} while (tmp != 0);
- char chararray[];
+ char[] chararray;
if (x < 0)
chararray = new char[length + 1];
else