From 8d750e51bc5fa6b54ed568859dd8a6a25ad9e4c4 Mon Sep 17 00:00:00 2001 From: yeom Date: Thu, 1 Nov 2012 06:27:46 +0000 Subject: [PATCH 1/1] changes: generated annotated code but it still causes type errors + re-formatting of the benchmark for generating annotated version. --- Robust/src/Analysis/SSJava/FlowDownCheck.java | 7 +- Robust/src/Analysis/SSJava/FlowGraph.java | 46 +++++- Robust/src/Analysis/SSJava/FlowNode.java | 3 +- .../Analysis/SSJava/LocationInference.java | 145 +++++++++++++++--- Robust/src/Analysis/SSJava/NodeTupleSet.java | 14 +- .../SSJava/EyeTrackingInfer/Classifier.java | 44 +++--- .../EyeTrackingInfer/ClassifierTree.java | 88 +++++------ .../EyeTrackingInfer/DeviationScanner.java | 37 ++--- .../EyeTrackingInfer/DummyCaptureDevice.java | 68 ++++---- .../SSJava/EyeTrackingInfer/EyeDetector.java | 32 ++-- .../SSJava/EyeTrackingInfer/EyePosition.java | 7 +- .../EyeTrackingInfer/FaceAndEyePosition.java | 4 +- .../EyeTrackingInfer/ICaptureDevice.java | 44 +++--- .../SSJava/EyeTrackingInfer/Image.java | 6 +- .../EyeTrackingInfer/IntegralImageData.java | 12 +- .../SSJava/EyeTrackingInfer/LEA.java | 60 +++----- .../EyeTrackingInfer/LEAImplementation.java | 24 +-- .../SSJava/EyeTrackingInfer/Point.java | 12 +- .../SSJava/EyeTrackingInfer/Rectangle2D.java | 10 +- .../SSJava/EyeTrackingInfer/ScanArea.java | 23 ++- 20 files changed, 392 insertions(+), 294 deletions(-) diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index 25f6a8e3..3d245966 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -1426,12 +1426,9 @@ public class FlowDownCheck { // addTypeLocation(on.getRight().getType(), rightLoc); } - System.out.println("\n# OP NODE=" + on.printNode(0)); - // System.out.println("# left loc=" + leftLoc + " from " + - // on.getLeft().getClass()); + // System.out.println("# left loc=" + leftLoc + " from " + on.getLeft().getClass()); // if (on.getRight() != null) { - // System.out.println("# right loc=" + rightLoc + " from " + - // on.getRight().getClass()); + // System.out.println("# right loc=" + rightLoc + " from " + on.getRight().getClass()); // } Operation op = on.getOp(); diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index f71b82d0..c2a8f8ec 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -41,6 +41,8 @@ public class FlowGraph { Map mapMethodInvokeNodeToFlowReturnNode; + Map mapIntersectionDescToEnclosingDescriptor; + public static int interseed = 0; boolean debug = true; @@ -57,6 +59,7 @@ public class FlowGraph { this.mapFlowNodeToOutEdgeSet = new HashMap>(); this.mapFlowNodeToInEdgeSet = new HashMap>(); this.mapMethodInvokeNodeToFlowReturnNode = new HashMap(); + this.mapIntersectionDescToEnclosingDescriptor = new HashMap(); if (!md.isStatic()) { // create a node for 'this' varialbe @@ -74,6 +77,15 @@ public class FlowGraph { } + public void addMapInterLocNodeToEnclosingDescriptor(Descriptor interDesc, ClassDescriptor desc) { + System.out.println("##### INTERLOC=" + interDesc + " enclosing desc=" + desc); + mapIntersectionDescToEnclosingDescriptor.put(interDesc, desc); + } + + public ClassDescriptor getEnclosingDescriptor(Descriptor interDesc) { + return mapIntersectionDescToEnclosingDescriptor.get(interDesc); + } + public Map, FlowNode> getMapDescTupleToInferNode() { return mapDescTupleToInferNode; } @@ -306,7 +318,7 @@ public class FlowGraph { 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) { @@ -338,6 +350,7 @@ public class FlowGraph { public FlowNode createNewFlowNode(NTuple tuple) { + // System.out.println("createNewFlowNode=" + tuple); if (!mapDescTupleToInferNode.containsKey(tuple)) { FlowNode node = new FlowNode(tuple); mapDescTupleToInferNode.put(tuple, node); @@ -388,7 +401,8 @@ public class FlowGraph { Set dstNodeSet = new HashSet(); if (originalDstNode instanceof FlowReturnNode) { FlowReturnNode rnode = (FlowReturnNode) originalDstNode; - Set> rtupleSet = rnode.getReturnTupleSet(); + Set> rtupleSetFromRNode = rnode.getReturnTupleSet(); + Set> rtupleSet = getReturnTupleSet(rtupleSetFromRNode); for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) { NTuple rtuple = (NTuple) iterator2.next(); dstNodeSet.add(getFlowNode(rtuple)); @@ -442,11 +456,13 @@ public class FlowGraph { Set srcNodeSet = new HashSet(); if (originalSrcNode instanceof FlowReturnNode) { FlowReturnNode rnode = (FlowReturnNode) originalSrcNode; - Set> rtupleSet = rnode.getReturnTupleSet(); + Set> rtupleSetFromRNode = rnode.getReturnTupleSet(); + Set> rtupleSet = getReturnTupleSet(rtupleSetFromRNode); + System.out.println("#rnode=" + rnode + " rtupleSet=" + rtupleSet); for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) { NTuple rtuple = (NTuple) iterator2.next(); if (rtuple.startsWith(prefix)) { - System.out.println("rtuple=" + rtuple + " give it to recur=" + originalSrcNode); + // System.out.println("rtuple=" + rtuple + " give it to recur=" + originalSrcNode); recurReachableSetFrom(originalSrcNode, reachableSet); } } @@ -461,6 +477,21 @@ public class FlowGraph { return reachableSet; } + public Set> getReturnTupleSet(Set> in) { + + Set> normalTupleSet = new HashSet>(); + for (Iterator iterator2 = in.iterator(); iterator2.hasNext();) { + NTuple tuple = (NTuple) iterator2.next(); + FlowNode tupleNode = getFlowNode(tuple); + if (tupleNode instanceof FlowReturnNode) { + normalTupleSet.addAll(getReturnTupleSet(((FlowReturnNode) tupleNode).getReturnTupleSet())); + } else { + normalTupleSet.add(tuple); + } + } + return normalTupleSet; + } + // private void getReachFlowNodeSetFrom(FlowNode fn, Set visited) { // // for (Iterator iterator = fn.getOutEdgeSet().iterator(); @@ -528,7 +559,7 @@ public class FlowGraph { Descriptor localDesc = fn.getDescTuple().get(0); - if (fn.isIntermediate()) { + if (fn.isIntermediate() && fn.getDescTuple().size() == 1) { Location interLoc = new Location(md, localDesc.getSymbol()); interLoc.setLocDescriptor(localDesc); locTuple.add(interLoc); @@ -550,6 +581,8 @@ public class FlowGraph { loc.setLocDescriptor(curDesc); if (curDesc instanceof VarDescriptor) { cd = ((VarDescriptor) curDesc).getType().getClassDesc(); + } else if (curDesc instanceof InterDescriptor) { + cd = mapIntersectionDescToEnclosingDescriptor.get(curDesc); } else { // otherwise it should be the last element cd = null; @@ -598,7 +631,8 @@ public class FlowGraph { if (incomingNode instanceof FlowReturnNode) { FlowReturnNode rnode = (FlowReturnNode) incomingNode; Set> nodeTupleSet = rnode.getReturnTupleSet(); - for (Iterator iterator3 = nodeTupleSet.iterator(); iterator3.hasNext();) { + Set> rtupleSet = getReturnTupleSet(nodeTupleSet); + for (Iterator iterator3 = rtupleSet.iterator(); iterator3.hasNext();) { NTuple nodeTuple = (NTuple) iterator3.next(); FlowNode fn = getFlowNode(nodeTuple); if (!visited.contains(fn)) { diff --git a/Robust/src/Analysis/SSJava/FlowNode.java b/Robust/src/Analysis/SSJava/FlowNode.java index c6a6b79e..31a9ded3 100644 --- a/Robust/src/Analysis/SSJava/FlowNode.java +++ b/Robust/src/Analysis/SSJava/FlowNode.java @@ -1,9 +1,9 @@ package Analysis.SSJava; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; +import IR.ClassDescriptor; import IR.Descriptor; import IR.FieldDescriptor; import IR.VarDescriptor; @@ -65,6 +65,7 @@ public class FlowNode { } public void setCompositeLocation(CompositeLocation in) { + System.out.println("$$$set compLoc=" + in); compLoc = in; } diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 6575d4ba..e2adb19e 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -708,6 +708,8 @@ public class LocationInference { System.out.println("generateCompositeLocation=" + nodeDescTuple + " with inferCompLoc=" + inferCompLoc); + MethodDescriptor md = (MethodDescriptor) inferCompLoc.get(0).getDescriptor(); + CompositeLocation newCompLoc = new CompositeLocation(); for (int i = 0; i < inferCompLoc.getSize(); i++) { newCompLoc.addLocation(inferCompLoc.get(i)); @@ -716,7 +718,7 @@ public class LocationInference { Descriptor lastDescOfPrefix = nodeDescTuple.get(0); Descriptor enclosingDescriptor; if (lastDescOfPrefix instanceof InterDescriptor) { - enclosingDescriptor = null; + enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(lastDescOfPrefix); } else { enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc(); } @@ -1602,7 +1604,7 @@ public class LocationInference { NTuple locTuple = new NTuple(); Descriptor enclosingDesc = md; - // System.out.println("md=" + md + " descTuple=" + descTuple); + System.out.println("md=" + md + " descTuple=" + descTuple); for (int i = 0; i < descTuple.size(); i++) { Descriptor desc = descTuple.get(i); @@ -1746,8 +1748,9 @@ public class LocationInference { // this method will return the same nodeLocTuple if the corresponding argument is literal // value. - FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); + // System.out.println("translateToCallerLocTuple=" + nodeLocTuple); + FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); NTuple nodeDescTuple = translateToDescTuple(nodeLocTuple); if (calleeFlowGraph.isParameter(nodeDescTuple)) { int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple); @@ -1757,7 +1760,8 @@ public class LocationInference { // // the type of argument is primitive. // return nodeLocTuple.clone(); // } - // System.out.println("paramIdx=" + paramIdx + " argDescTuple=" + argDescTuple); + // System.out.println("paramIdx=" + paramIdx + " argDescTuple=" + argDescTuple + " from min=" + // + min.printNode(0)); NTuple argLocTuple = translateToLocTuple(mdCaller, argDescTuple); NTuple callerLocTuple = new NTuple(); @@ -2591,20 +2595,31 @@ public class LocationInference { } } - rtr += "\")"; - if (desc instanceof MethodDescriptor) { System.out.println("#EXTRA LOC DECLARATION GEN=" + desc); MethodDescriptor md = (MethodDescriptor) desc; MethodSummary methodSummary = getMethodSummary(md); + TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType(); + if (!ssjava.getMethodContainingSSJavaLoop().equals(desc) && returnType != null + && (!returnType.isVoid())) { + CompositeLocation returnLoc = methodSummary.getRETURNLoc(); + if (returnLoc.getSize() == 1) { + String returnLocStr = generateLocationAnnoatation(methodSummary.getRETURNLoc()); + if (rtr.indexOf(returnLocStr) == -1) { + rtr += "," + returnLocStr; + } + } + } + rtr += "\")"; + if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) { - TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType(); if (returnType != null && (!returnType.isVoid())) { rtr += "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")"; } + CompositeLocation pcLoc = methodSummary.getPCLoc(); if ((pcLoc != null) && (!pcLoc.get(0).isTop())) { rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")"; @@ -2616,6 +2631,8 @@ public class LocationInference { } rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")"; + } else { + rtr += "\")"; } return rtr; @@ -2714,6 +2731,7 @@ public class LocationInference { if (mapDescToDefinitionLine.containsKey(localVarDesc)) { int varLineNum = mapDescToDefinitionLine.get(localVarDesc); String orgSourceLine = sourceVec.get(varLineNum); + System.out.println("varLineNum=" + varLineNum + " org src=" + orgSourceLine); int idx = orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc)); System.out.println("idx=" + idx @@ -3742,6 +3760,8 @@ public class LocationInference { } else if (curDescriptor instanceof NameDescriptor) { // it is "GLOBAL LOC" case! enclosingDescriptor = GLOBALDESC; + } else if (curDescriptor instanceof InterDescriptor) { + enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(curDescriptor); } else { enclosingDescriptor = null; } @@ -4025,6 +4045,21 @@ public class LocationInference { System.out.println(""); toanalyze_methodDescList = computeMethodList(); + // hack... it seems that there is a problem with topological sorting. + // so String.toString(Object o) is appeared too higher in the call chain. + MethodDescriptor mdToString = null; + for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) { + MethodDescriptor md = (MethodDescriptor) iterator.next(); + if (md.toString().equals("public static String String.valueOf(Object o)")) { + mdToString = md; + break; + } + } + if (mdToString != null) { + toanalyze_methodDescList.remove(mdToString); + toanalyze_methodDescList.addLast(mdToString); + } + LinkedList methodDescList = (LinkedList) toanalyze_methodDescList.clone(); @@ -4367,6 +4402,7 @@ public class LocationInference { newImplicitTupleSet.addTupleSet(implicitFlowTupleSet); newImplicitTupleSet.addTupleSet(condTupleNode); + System.out.println("A5"); newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet()); newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet()); @@ -4481,7 +4517,7 @@ public class LocationInference { private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable, IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) { - // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0)); + System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0)); NodeTupleSet condTupleNode = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null, @@ -4520,6 +4556,7 @@ public class LocationInference { // translateToLocTuple(md, callerImplicitTuple)); // } // } + System.out.println("A4"); newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet()); analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet); @@ -4591,12 +4628,13 @@ public class LocationInference { ExpressionNode en, NodeTupleSet nodeSet, NTuple base, NodeTupleSet implicitFlowTupleSet, boolean isLHS) { + // System.out.println("en=" + en.printNode(0) + " class=" + en.getClass()); + // note that expression node can create more than one flow node // nodeSet contains of flow nodes // base is always assigned to null except the case of a name node! NTuple flowTuple; switch (en.kind()) { - case Kind.AssignmentNode: analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base, implicitFlowTupleSet); @@ -4709,6 +4747,7 @@ public class LocationInference { newImplicitTupleSet.addTuple(interTuple); } + System.out.println("A7"); newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet); @@ -4720,6 +4759,7 @@ public class LocationInference { analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null, newImplicitTupleSet, false); + System.out.println("A8"); nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); nodeSet.addTupleSet(tertiaryTupleNode); @@ -4800,7 +4840,7 @@ public class LocationInference { addMapCallerMethodDescToMethodInvokeNodeSet(mdCaller, min); FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); - System.out.println("mdCallee=" + mdCallee); + System.out.println("mdCallee=" + mdCallee + " calleeFlowGraph=" + calleeFlowGraph); Set calleeReturnSet = calleeFlowGraph.getReturnNodeSet(); System.out.println("---calleeReturnSet=" + calleeReturnSet); @@ -4812,6 +4852,7 @@ public class LocationInference { NodeTupleSet baseNodeSet = new NodeTupleSet(); analyzeFlowExpressionNode(mdCaller, nametable, min.getExpression(), baseNodeSet, null, implicitFlowTupleSet, false); + System.out.println("baseNodeSet=" + baseNodeSet); assert (baseNodeSet.size() == 1); NTuple baseTuple = baseNodeSet.iterator().next(); @@ -4827,19 +4868,30 @@ public class LocationInference { // the location type of the return value is started with 'this' // reference NTuple inFlowTuple = new NTuple(baseTuple.getList()); + + if (inFlowTuple.get(0) instanceof InterDescriptor) { + // min.getExpression() + } else { + + } + inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size())); // nodeSet.addTuple(inFlowTuple); + System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from=" + + mdCallee.getThis()); tupleSet.addTuple(inFlowTuple); } else { // TODO + System.out.println("returnNode=" + returnNode); Set inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode); // System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode); for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) { FlowNode inFlowNode = (FlowNode) iterator2.next(); if (inFlowNode.getDescTuple().startsWith(mdCallee.getThis())) { // nodeSet.addTupleSet(baseNodeSet); + System.out.println("2CREATE A NEW TUPLE=" + baseNodeSet + " from=" + + mdCallee.getThis()); tupleSet.addTupleSet(baseNodeSet); - } } } @@ -4864,7 +4916,7 @@ public class LocationInference { NodeTupleSet argTupleSet = new NodeTupleSet(); analyzeFlowExpressionNode(mdCaller, nametable, en, argTupleSet, false); // if argument is liternal node, argTuple is set to NULL - System.out.println("argTupleSet=" + argTupleSet); + System.out.println("---arg idx=" + idx + " argTupleSet=" + argTupleSet); NTuple argTuple = generateArgTuple(mdCaller, argTupleSet); // if an argument is literal value, @@ -4905,6 +4957,7 @@ public class LocationInference { || mdCallee.getModifiers().isNative()) { addParamNodeFlowingToReturnValue(mdCallee, paramNode); // nodeSet.addTupleSet(argTupleSet); + System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode); tupleSet.addTupleSet(argTupleSet); } } @@ -4914,8 +4967,35 @@ public class LocationInference { if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) { FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min); System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode); - setNode.addTupleSet(tupleSet); + + if (needToGenerateInterLoc(tupleSet)) { + System.out.println("20"); + FlowGraph fg = getFlowGraph(mdCaller); + NTuple interTuple = fg.createIntermediateNode().getDescTuple(); + + for (Iterator iterator = tupleSet.iterator(); iterator.hasNext();) { + NTuple tuple = (NTuple) iterator.next(); + + Set> addSet = new HashSet>(); + FlowNode node = fg.getFlowNode(tuple); + if (node instanceof FlowReturnNode) { + addSet.addAll(fg.getReturnTupleSet(((FlowReturnNode) node).getReturnTupleSet())); + } else { + addSet.add(tuple); + } + for (Iterator iterator2 = addSet.iterator(); iterator2.hasNext();) { + NTuple higher = (NTuple) iterator2.next(); + addFlowGraphEdge(mdCaller, higher, interTuple); + } + } + + setNode.addTuple(interTuple); + } else { + setNode.addTupleSet(tupleSet); + } + nodeSet.addTuple(setNode.getDescTuple()); + } // propagateFlowsFromCallee(min, md, min.getMethod()); @@ -4928,8 +5008,14 @@ public class LocationInference { NTuple calleeReturnLocTuple = translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple()); System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple); - nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller, - calleeReturnLocTuple)); + NTuple transaltedToCaller = + translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple); + // System.out.println("translateToCallerLocTuple=" + // + translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple)); + if (transaltedToCaller.size() > 0) { + nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller, + calleeReturnLocTuple)); + } } System.out.println("min nodeSet=" + nodeSet); @@ -5022,14 +5108,16 @@ public class LocationInference { private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable, ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) { - // System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0)); + System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0)); String currentArrayAccessNodeExpStr = aan.printNode(0); arrayAccessNodeStack.push(aan.printNode(0)); NodeTupleSet expNodeTupleSet = new NodeTupleSet(); NTuple base = analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS); + System.out.println("-base=" + base); + nodeSet.setMethodInvokeBaseDescTuple(base); NodeTupleSet idxNodeTupleSet = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS); @@ -5076,9 +5164,17 @@ public class LocationInference { } nodeSetArrayAccessExp.clear(); nodeSetArrayAccessExp.addTuple(interTuple); + FlowGraph fg = getFlowGraph(md); + + System.out.println("base=" + base); + if (base != null) { + fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0), + getClassTypeDescriptor(base.get(base.size() - 1))); + } } } + System.out.println("A1"); nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet()); nodeSet.addTupleSet(nodeSetArrayAccessExp); @@ -5098,15 +5194,19 @@ public class LocationInference { NodeTupleSet leftOpSet = new NodeTupleSet(); NodeTupleSet rightOpSet = new NodeTupleSet(); + System.out.println("analyzeFlowOpNode=" + on.printNode(0)); + // left operand analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet, false); + System.out.println("--leftOpSet=" + leftOpSet); if (on.getRight() != null) { // right operand analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null, implicitFlowTupleSet, false); } + System.out.println("--rightOpSet=" + rightOpSet); Operation op = on.getOp(); @@ -5145,6 +5245,7 @@ public class LocationInference { nodeSet.addTupleSet(leftOpSet); nodeSet.addTupleSet(rightOpSet); + System.out.println("A6"); nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet()); nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet()); @@ -5338,10 +5439,15 @@ public class LocationInference { NTuple higherTuple = iter.next(); addFlowGraphEdge(md, higherTuple, interTuple); } + + FlowGraph fg = getFlowGraph(md); + fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0), + getClassTypeDescriptor(base.get(base.size() - 1))); + nodeSet.clear(); flowFieldTuple = interTuple; } - + System.out.println("A3"); nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet()); } @@ -5430,10 +5536,10 @@ public class LocationInference { NTuple calleeReturnLocTuple = iterator.next(); for (Iterator> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) { NTuple callerLHSTuple = iter2.next(); - globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, - translateToLocTuple(md, callerLHSTuple)); System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> " + translateToLocTuple(md, callerLHSTuple)); + globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, + translateToLocTuple(md, callerLHSTuple)); } } @@ -5483,6 +5589,7 @@ public class LocationInference { if (nodeSet != null) { nodeSet.addTupleSet(nodeSetLHS); + System.out.println("A2"); nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet()); } } diff --git a/Robust/src/Analysis/SSJava/NodeTupleSet.java b/Robust/src/Analysis/SSJava/NodeTupleSet.java index f614080d..52384828 100644 --- a/Robust/src/Analysis/SSJava/NodeTupleSet.java +++ b/Robust/src/Analysis/SSJava/NodeTupleSet.java @@ -14,6 +14,8 @@ public class NodeTupleSet { private ArrayList> globalLocTupleList; + private NTuple baseDescTuple; + public NodeTupleSet() { list = new ArrayList>(); globalLocTupleList = new ArrayList>(); @@ -31,11 +33,21 @@ public class NodeTupleSet { list.add(tuple); } + public void setMethodInvokeBaseDescTuple(NTuple in) { + baseDescTuple = in; + } + + public NTuple getBaseDesc() { + return baseDescTuple; + } + public void addGlobalFlowTuple(NTuple tuple) { + System.out.println("-----add global value flow tuple=" + tuple); globalLocTupleList.add(tuple); } public void addGlobalFlowTupleSet(ArrayList> in) { + System.out.println("-----add global value flow in=" + in); globalLocTupleList.addAll(in); } @@ -91,7 +103,7 @@ public class NodeTupleSet { private void setGlobalLocTupleList(ArrayList> in) { globalLocTupleList = in; } - + public ArrayList> getGlobalLocTupleSet() { return globalLocTupleList; } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Classifier.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Classifier.java index f73ef95b..9fa81d47 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Classifier.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Classifier.java @@ -22,19 +22,16 @@ * @author Florian */ - public class Classifier { - private ScanArea[] scanAreas; - private float[] possibilities_FaceYes; - + private float[] possibilities_FaceNo; - + private int possibilityFaceYes = 0; - + private int possibilityFaceNo = 0; public Classifier(int numScanAreas) { @@ -68,23 +65,20 @@ public class Classifier { * * @param image * @param scaleFactor - * please be aware of the fact that the scanareas are scaled for use - * with 100x100 px images + * please be aware of the fact that the scanareas are scaled for use with 100x100 px + * images * @param translationX * @param translationY * @return true if this region was classified as face, else false */ - - - public boolean classifyFace( IntegralImageData image, - float scaleFactor, int translationX, - int translationY, float borderline) { - long values[] = new long[scanAreas.length]; + public boolean classifyFace(IntegralImageData image, float scaleFactor, int translationX, int translationY, float borderline) { + + long[] values = new long[scanAreas.length]; - float avg = 0f; - int avgItems = 0; - for ( int i = 0; i < scanAreas.length; ++i) { + float avg = 0f; + int avgItems = 0; + for (int i = 0; i < scanAreas.length; ++i) { values[i] = 0l; values[i] += @@ -114,13 +108,13 @@ public class Classifier { // as we just maximize the args we don't actually calculate the accurate // possibility - float isFaceYes = 1.0f;// this.possibilityFaceYes / - // (float)amountYesNo; - float isFaceNo = 1.0f;// this.possibilityFaceNo / - // (float)amountYesNo; + float isFaceYes = 1.0f;// this.possibilityFaceYes / + // (float)amountYesNo; + float isFaceNo = 1.0f;// this.possibilityFaceNo / + // (float)amountYesNo; - for ( int i = 0; i < this.scanAreas.length; ++i) { - boolean bright = (values[i] >= avg); + for (int i = 0; i < this.scanAreas.length; ++i) { + boolean bright = (values[i] >= avg); isFaceYes *= (bright ? this.possibilities_FaceYes[i] : 1 - this.possibilities_FaceYes[i]); isFaceNo *= (bright ? this.possibilities_FaceNo[i] : 1 - this.possibilities_FaceNo[i]); } @@ -163,8 +157,8 @@ public class Classifier { public String toString() { - String str = ""; - for ( int i = 0; i < scanAreas.length; i++) { + String str = ""; + for (int i = 0; i < scanAreas.length; i++) { str += scanAreas[i].toString() + "\n"; } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ClassifierTree.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ClassifierTree.java index 14549029..01c2fe17 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ClassifierTree.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ClassifierTree.java @@ -24,46 +24,40 @@ import SSJava.PCLOC; * @author Florian */ - public class ClassifierTree { - private Classifier classifiers[]; public ClassifierTree(int size) { classifiers = new Classifier[size]; } - public void addClassifier( int idx, Classifier c) { + public void addClassifier(int idx, Classifier c) { classifiers[idx] = c; } /** - * Locates a face by searching radial starting at the last known position. If - * lastCoordinates are null we simply start in the center of the image. + * Locates a face by searching radial starting at the last known position. If lastCoordinates are + * null we simply start in the center of the image. *

- * TODO: This method could quite possible be tweaked so that face recognition - * would be much faster + * TODO: This method could quite possible be tweaked so that face recognition would be much faster * * @param image * the image to process * @param lastCoordinates * the last known coordinates or null if unknown - * @return an rectangle representing the actual face position on success or - * null if no face could be detected + * @return an rectangle representing the actual face position on success or null if no face could + * be detected */ - - - public Rectangle2D locateFaceRadial( Image smallImage, - Rectangle2D lastCoordinates) { - IntegralImageData imageData = new IntegralImageData(smallImage); - float originalImageFactor = 1; + public Rectangle2D locateFaceRadial(Image smallImage, Rectangle2D lastCoordinates) { + + IntegralImageData imageData = new IntegralImageData(smallImage); + float originalImageFactor = 1; if (lastCoordinates == null) { // if we don't have a last coordinate we just begin in the center - int smallImageMaxDimension = - Math.min(smallImage.getWidth(), smallImage.getHeight()); + int smallImageMaxDimension = Math.min(smallImage.getWidth(), smallImage.getHeight()); lastCoordinates = new Rectangle2D((smallImage.getWidth() - smallImageMaxDimension) / 2.0, (smallImage.getHeight() - smallImageMaxDimension) / 2.0, smallImageMaxDimension, @@ -79,27 +73,25 @@ public class ClassifierTree { (lastCoordinates.getHeight() * (1 / originalImageFactor))); } - float startFactor = (float) (lastCoordinates.getWidth() / 100.0f); + float startFactor = (float) (lastCoordinates.getWidth() / 100.0f); // first we calculate the maximum scale factor for our 200x200 image - float maxScaleFactor = - Math.min(imageData.getWidth() / 100f, imageData.getHeight() / 100f); + float maxScaleFactor = Math.min(imageData.getWidth() / 100f, imageData.getHeight() / 100f); // maxScaleFactor = 1.0f; // we simply won't recognize faces that are smaller than 40x40 px - float minScaleFactor = 0.5f; + float minScaleFactor = 0.5f; - float maxScaleDifference = - Math.max(Math.abs(maxScaleFactor - startFactor), Math.abs(minScaleFactor - startFactor)); + float maxScaleDifference = Math.max(Math.abs(maxScaleFactor - startFactor), Math.abs(minScaleFactor - startFactor)); // border for faceYes-possibility must be greater that that - float maxBorder = 0.999f; + float maxBorder = 0.999f; - int startPosX = (int) lastCoordinates.getX(); - int startPosY = (int) lastCoordinates.getX(); + int startPosX = (int) lastCoordinates.getX(); + int startPosY = (int) lastCoordinates.getX(); - int loopidx = 0; - TERMINATE: for ( float factorDiff = 0.0f; Math.abs(factorDiff) <= maxScaleDifference; factorDiff = + int loopidx = 0; + TERMINATE: for (float factorDiff = 0.0f; Math.abs(factorDiff) <= maxScaleDifference; factorDiff = (factorDiff + sgn(factorDiff) * 0.1f) * -1 // we alternate between // negative and positiv // factors @@ -109,50 +101,49 @@ public class ClassifierTree { return null; } - float factor = startFactor + factorDiff; + float factor = startFactor + factorDiff; if (factor > maxScaleFactor || factor < minScaleFactor) continue; // now we calculate the actualDimmension - int actualDimmension = (int) (100 * factor); - int maxX = imageData.getWidth() - actualDimmension; - int maxY = imageData.getHeight() - actualDimmension; + int actualDimmension = (int) (100 * factor); + int maxX = imageData.getWidth() - actualDimmension; + int maxY = imageData.getHeight() - actualDimmension; - int maxDiffX = Math.max(Math.abs(startPosX - maxX), startPosX); - int maxDiffY = Math.max(Math.abs(startPosY - maxY), startPosY); + int maxDiffX = Math.max(Math.abs(startPosX - maxX), startPosX); + int maxDiffY = Math.max(Math.abs(startPosY - maxY), startPosY); - int xidx = 0; - TERMINATE: for ( float xDiff = 0.1f; Math.abs(xDiff) <= maxDiffX; xDiff = + int xidx = 0; + TERMINATE: for (float xDiff = 0.1f; Math.abs(xDiff) <= maxDiffX; xDiff = (xDiff + sgn(xDiff) * 0.5f) * -1) { if (++xidx > 1000) { return null; } - int xPos = Math.round((float) (startPosX + xDiff)); + int xPos = Math.round((float) (startPosX + xDiff)); if (xPos < 0 || xPos > maxX) continue; - int yidx = 0; + int yidx = 0; // yLines: - TERMINATE: for ( float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = + TERMINATE: for (float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = (yDiff + sgn(yDiff) * 0.5f) * -1) { if (++yidx > 1000) { return null; } - int yPos = Math.round(startPosY + yDiff); + int yPos = Math.round(startPosY + yDiff); if (yPos < 0 || yPos > maxY) continue; // by now we should have a valid coordinate to process which we should // do now - boolean backToYLines = false; - for ( int idx = 0; idx < classifiers.length; ++idx) { - float borderline = - 0.8f + (idx / (classifiers.length - 1)) * (maxBorder - 0.8f); + boolean backToYLines = false; + for (int idx = 0; idx < classifiers.length; ++idx) { + float borderline = 0.8f + (idx / (classifiers.length - 1)) * (maxBorder - 0.8f); if (!classifiers[idx].classifyFace(imageData, factor, xPos, yPos, borderline)) { backToYLines = true; break; @@ -167,9 +158,8 @@ public class ClassifierTree { if (backToYLines) { continue; } - Rectangle2D faceRect = - new Rectangle2D(xPos * originalImageFactor, yPos * originalImageFactor, - actualDimmension * originalImageFactor, actualDimmension * originalImageFactor); + + Rectangle2D faceRect = new Rectangle2D(xPos * originalImageFactor, yPos * originalImageFactor, actualDimmension * originalImageFactor, actualDimmension * originalImageFactor); return faceRect; @@ -184,9 +174,7 @@ public class ClassifierTree { } - - - private static int sgn( float value) { + private static int sgn(float value) { return (value < 0 ? -1 : (value > 0 ? +1 : 1)); } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java index 4cc353e0..6da3f7e1 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java @@ -23,10 +23,8 @@ * @author Florian Frankenberger */ - public class DeviationScanner { - private EyePosition eyePositions[]; // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0), @@ -47,8 +45,7 @@ public class DeviationScanner { eyePositions = new EyePosition[3]; } - - public void addEyePosition( EyePosition eyePosition) { + public void addEyePosition(EyePosition eyePosition) { // for ( int i = 1; i < 3; i++) { // eyePositions[i - 1] = eyePositions[i]; @@ -60,24 +57,23 @@ public class DeviationScanner { } - // - - - public int scanForDeviation( Rectangle2D faceRect) { + // + + public int scanForDeviation(Rectangle2D faceRect) { - int deviation = NONE; + int deviation = NONE; - for ( int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (eyePositions[i] == null) { return deviation; } } - double deviationX = 0; - double deviationY = 0; + double deviationX = 0; + double deviationY = 0; - int lastIdx = -1; - for ( int i = 0; i < 3; ++i) { + int lastIdx = -1; + for (int i = 0; i < 3; ++i) { if (lastIdx != -1) { deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX()); deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY()); @@ -85,14 +81,14 @@ public class DeviationScanner { lastIdx = i; } - final double deviationPercentX = 0.04; - final double deviationPercentY = 0.04; + final double deviationPercentX = 0.04; + final double deviationPercentY = 0.04; deviationX /= faceRect.getWidth(); deviationY /= faceRect.getWidth(); - int deviationAbsoluteX = 0; - int deviationAbsoluteY = 0; + int deviationAbsoluteX = 0; + int deviationAbsoluteY = 0; if (deviationX > deviationPercentX) deviationAbsoluteX = 1; if (deviationX < -deviationPercentX) @@ -114,8 +110,7 @@ public class DeviationScanner { return deviation; } - - public int getDirectionFor( int directionX, int directionY) { + public int getDirectionFor(int directionX, int directionY) { if (directionX == +1 && directionY == -1) { return LEFT_UP; @@ -145,7 +140,7 @@ public class DeviationScanner { eyePositions = new EyePosition[3]; } - public String toStringDeviation( int dev) { + public String toStringDeviation(int dev) { if (dev == LEFT_UP) { return "LEFT_UP"; } else if (dev == UP) { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java index 699a620d..e035b650 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java @@ -15,38 +15,44 @@ import de.darkblue.lea.ifaces.ICaptureDevice; */ public class DummyCaptureDevice implements ICaptureDevice { - /** + /** * */ - public DummyCaptureDevice() { - // TODO Auto-generated constructor stub - } - - /* (non-Javadoc) - * @see de.darkblue.lea.ifaces.ICaptureDevice#close() - */ - @Override - public void close() { - } - - /* (non-Javadoc) - * @see de.darkblue.lea.ifaces.ICaptureDevice#getFrameRate() - */ - @Override - public int getFrameRate() { - return 15; - } - - /* (non-Javadoc) - * @see de.darkblue.lea.ifaces.ICaptureDevice#getImage() - */ - @Override - public BufferedImage getImage() { - BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB); - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(new Color(255, 255, 255)); - g2d.fillRect(0, 0, 639, 479); - return image; - } + public DummyCaptureDevice() { + // TODO Auto-generated constructor stub + } + + /* + * (non-Javadoc) + * + * @see de.darkblue.lea.ifaces.ICaptureDevice#close() + */ + @Override + public void close() { + } + + /* + * (non-Javadoc) + * + * @see de.darkblue.lea.ifaces.ICaptureDevice#getFrameRate() + */ + @Override + public int getFrameRate() { + return 15; + } + + /* + * (non-Javadoc) + * + * @see de.darkblue.lea.ifaces.ICaptureDevice#getImage() + */ + @Override + public BufferedImage getImage() { + BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = (Graphics2D) image.getGraphics(); + g2d.setColor(new Color(255, 255, 255)); + g2d.fillRect(0, 0, 639, 479); + return image; + } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java index 11443ab5..d162bc0c 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java @@ -23,16 +23,14 @@ * @author Florian Frankenberger */ - class EyeDetector { - private int width; - + private int height; - + private int[] pixelBuffer; - + double percent; public EyeDetector(Image image, Rectangle2D faceRect) { @@ -57,18 +55,15 @@ class EyeDetector { } - public Point detectEye() { - Point eyePosition = null; - float brightness = 255f; - for ( int y = 0; y < height; ++y) { - for ( int x = 0; x < width; ++x) { - final int position = y * width + x; - final int[] color = - new int[] { (pixelBuffer[position] & 0xFF0000) >> 16, - (pixelBuffer[position] & 0x00FF00) >> 8, pixelBuffer[position] & 0x0000FF }; + Point eyePosition = null; + float brightness = 255f; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + int position = y * width + x; + int[] color = new int[] { (pixelBuffer[position] & 0xFF0000) >> 16, (pixelBuffer[position] & 0x00FF00) >> 8, pixelBuffer[position] & 0x0000FF }; // System.out.println("("+x+","+y+")="+color[0]+" "+color[1]+" "+color[2]); - final float acBrightness = getBrightness(color); + float acBrightness = getBrightness(color); if (acBrightness < brightness) { eyePosition = new Point(x + (int) percent, y + (int) percent); @@ -80,10 +75,9 @@ class EyeDetector { return eyePosition; } - - private static float getBrightness( int[] color) { - int min = Math.min(Math.min(color[0], color[1]), color[2]); - int max = Math.max(Math.max(color[0], color[1]), color[2]); + private static float getBrightness(int[] color) { + int min = Math.min(Math.min(color[0], color[1]), color[2]); + int max = Math.max(Math.max(color[0], color[1]), color[2]); return 0.5f * (max + min); } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java index 500b0086..be45cee3 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java @@ -23,13 +23,12 @@ * @author Florian Frankenberger */ - public class EyePosition { - + private int x; - + private int y; - + private Rectangle2D faceRect; public EyePosition(Point p, Rectangle2D faceRect) { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java index cf24488e..e1d94503 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java @@ -23,12 +23,10 @@ * @author Florian Frankenberger */ - public class FaceAndEyePosition { - private Rectangle2D facePosition; - + private EyePosition eyePosition; public FaceAndEyePosition(Rectangle2D facePosition, EyePosition eyePosition) { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java index f050a978..2caa04a9 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java @@ -17,36 +17,34 @@ * along with LEA. If not, see . */ - import java.awt.image.BufferedImage; /** - * Describes a capture device. For now it is only tested - * with images in 640x480 at RGB or YUV color space. + * Describes a capture device. For now it is only tested with images in 640x480 at + * RGB or YUV color space. * * @author Florian Frankenberger */ public interface ICaptureDevice { - /** - * Returns the frame rate of the image source per second - * - * @return the frame rate (e.g. 15 = 15 frames per second) - */ - public int getFrameRate(); + /** + * Returns the frame rate of the image source per second + * + * @return the frame rate (e.g. 15 = 15 frames per second) + */ + public int getFrameRate(); + + /** + * Will be called a maximum of getFrameRate()-times in a second and returns the actual image of + * the capture device + * + * @return the actual image of the capture device + */ + public BufferedImage getImage(); + + /** + * LEA calls this when it cleans up. You should put your own cleanup code in here. + */ + public void close(); - /** - * Will be called a maximum of getFrameRate()-times in a second and returns - * the actual image of the capture device - * - * @return the actual image of the capture device - */ - public BufferedImage getImage(); - - /** - * LEA calls this when it cleans up. You should put your own cleanup code in here. - */ - public void close(); - - } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java index d91a7e4a..52453203 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java @@ -1,12 +1,10 @@ - public class Image { - int width; - + int height; - + int pixel[][]; public Image(int width, int height) { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java index d517a373..80d7782b 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java @@ -23,14 +23,12 @@ * @author Florian Frankenberger */ - public class IntegralImageData { - private long[][] integral; - + private int width; - + private int hegith; // private Dimension dimension; @@ -51,7 +49,7 @@ public class IntegralImageData { } - public long getIntegralAt( int x, int y) { + public long getIntegralAt(int x, int y) { return this.integral[x][y]; } @@ -63,4 +61,8 @@ public class IntegralImageData { return hegith; } + public String toString() { + super.toString(); + } + } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java index 48a15775..b3fda528 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java @@ -20,22 +20,19 @@ /** * This is the main class of LEA. *

- * 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. *

* The notification is designed as observer pattern. You simply call - * addEyeMovementListener(IEyeMovementListener) to add an - * implementation of IEyeMovementListener to LEA. When a face is - * recognized/lost or whenever an eye movement is detected LEA will call the - * appropriate methods of the listener + * addEyeMovementListener(IEyeMovementListener) to add an implementation of + * IEyeMovementListener to LEA. When a face is recognized/lost or whenever an eye + * movement is detected LEA will call the appropriate methods of the listener *

- * LEA also needs an image source implementing the ICaptureDevice. - * One image source proxy to the Java Media Framework is included ( - * JMFCaptureDevice). + * LEA also needs an image source implementing the ICaptureDevice. One image source + * proxy to the Java Media Framework is included ( JMFCaptureDevice). *

* Example (for using LEA with Java Media Framework): *

@@ -43,22 +40,19 @@ * LEA lea = new LEA(new JMFCaptureDevice(), true); * *

- * 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(null, null); - + private DeviationScanner deviationScanner = new DeviationScanner(); public LEA() { @@ -68,18 +62,17 @@ public class 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 - * Java Media Framework just start from here. + * @METHOD To test LEA with the first capture device from the Java Media Framework + * just start from here. * * @param args * @throws Exception @@ -89,13 +82,12 @@ public class LEA { 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; } @@ -105,14 +97,12 @@ public class LEA { System.out.println("Done."); } - - private void processImage( Image image) { - FaceAndEyePosition positions = implementation.getEyePosition(image); + 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()); + int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); if (deviation != DeviationScanner.NONE) { System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation)); // notifyEyeMovementListenerEyeMoved(deviation); diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java index 998cd69b..b9dc7d39 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java @@ -23,34 +23,28 @@ * @author Florian Frankenberger */ - public class LEAImplementation { - private ClassifierTree classifierTree; - private Rectangle2D lastRectangle; public LEAImplementation() { this.loadFaceData(); } - - - public FaceAndEyePosition getEyePosition( Image image) { + public FaceAndEyePosition getEyePosition(Image image) { if (image == null) return null; - Rectangle2D faceRect = - classifierTree.locateFaceRadial(image, lastRectangle); + Rectangle2D faceRect = classifierTree.locateFaceRadial(image, lastRectangle); if (faceRect.getWidth() > image.getWidth() || faceRect.getHeight() > image.getHeight()) { return null; } - EyePosition eyePosition = null; + EyePosition eyePosition = null; if (faceRect != null) { lastRectangle = faceRect; faceRect = null; - Point point = readEyes(image, lastRectangle); + Point point = readEyes(image, lastRectangle); if (point != null) { eyePosition = new EyePosition(point, lastRectangle); } @@ -62,10 +56,8 @@ public class LEAImplementation { return new FaceAndEyePosition(lastRectangle, eyePosition); } - - - private Point readEyes( Image image, Rectangle2D rect) { - EyeDetector ed = new EyeDetector(image, rect); + private Point readEyes(Image image, Rectangle2D rect) { + EyeDetector ed = new EyeDetector(image, rect); return ed.detectEye(); } @@ -74,8 +66,8 @@ public class LEAImplementation { } /** - * This method loads the faceData from a file called facedata.dat which should - * be within the jar-file + * This method loads the faceData from a file called facedata.dat which should be within the + * jar-file */ private void loadFaceData() { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java index beb0545f..a3b6c37c 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java @@ -1,9 +1,7 @@ - - public class Point { - public int x; - public int y; + public int x; + public int y; public Point(int x, int y) { this.x = x; @@ -12,9 +10,9 @@ public class Point { public Point() { } - - public String toString(){ - return "("+x+","+y+")"; + + public String toString() { + return "(" + x + "," + y + ")"; } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java index e765e70c..ae538162 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java @@ -1,11 +1,9 @@ - - public class Rectangle2D { - double x; - double y; - double width; - double height; + double x; + double y; + double width; + double height; public Rectangle2D(double x, double y, double w, double h) { this.x = x; diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java index abb581b0..62e9b4ae 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java @@ -22,20 +22,17 @@ * @author Florian */ - public class ScanArea { - private Point fromPoint; - + private Point toPoint; - + private float size; /** - * Imagine you want to classify an image with 100px x 100px what would be the - * scanarea in this kind of image. That size gets automatically scalled to fit - * bigger images + * Imagine you want to classify an image with 100px x 100px what would be the scanarea in this + * kind of image. That size gets automatically scalled to fit bigger images * * @param fromPoint * @param toPoint @@ -57,23 +54,23 @@ public class ScanArea { this(new Point(fromX, fromY), new Point(fromX + width, fromY + height)); } - public int getFromX( float scaleFactor) { + public int getFromX(float scaleFactor) { return (int) (this.fromPoint.x * scaleFactor); } - public int getFromY( float scaleFactor) { + public int getFromY(float scaleFactor) { return (int) (this.fromPoint.y * scaleFactor); } - public int getToX( float scaleFactor) { + public int getToX(float scaleFactor) { return (int) (this.toPoint.x * scaleFactor); } - public int getToY( float scaleFactor) { + public int getToY(float scaleFactor) { return (int) (this.toPoint.y * scaleFactor); } - public int getSize( float scaleFactor) { + public int getSize(float scaleFactor) { return (int) (this.size * Math.pow(scaleFactor, 2)); } @@ -110,7 +107,7 @@ public class ScanArea { // } public String toString() { - String str = ""; + String str = ""; str += "fromPoint=(" + fromPoint.x + "," + fromPoint.y + ")"; str += "toPoint=(" + toPoint.x + "," + toPoint.y + ")"; str += "size=" + size; -- 2.34.1