From: yeom Date: Sat, 3 Nov 2012 06:17:21 +0000 (+0000) Subject: changes: 1) fixes problems in the original EyeTracking benchmark 2) fix a bug in... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=9d767c1f5cef3242ff67473368e5ad327c340bfa changes: 1) fixes problems in the original EyeTracking benchmark 2) fix a bug in the definitely written analysis. It didn't keep cleared shared location type set correctly in certain cases, Inference engine generated annotations again for the EyeTracking, but it has location type errors. --- diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 052ec485..c1f48241 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -67,6 +67,8 @@ public class DefinitelyWrittenCheck { // written to but not overwritten by the higher value private Hashtable mapFlatMethodToDeleteSet; + private Hashtable mapFlatMethodToMustClearMap; + // maps a flat method to the S SET that is a set of heap path to shared // locations that are overwritten by the higher value private Hashtable mapFlatMethodToSharedLocMap; @@ -113,6 +115,7 @@ public class DefinitelyWrittenCheck { private Hashtable mapFlatNodeToSharedLocMapping; private Hashtable mapFlatNodeToDeleteSet; + private Hashtable mapFlatNodeToMustClearMap; private LoopFinder ssjavaLoop; private Set loopIncElements; @@ -122,6 +125,7 @@ public class DefinitelyWrittenCheck { private Set> calleeUnionBoundMayWriteSet; private SharedLocMap calleeUnionBoundDeleteSet; private SharedLocMap calleeIntersectBoundSharedSet; + private SharedLocMap calleeIntersectBoundMustClearSet; Set liveInTempSetToEventLoop; @@ -167,6 +171,9 @@ public class DefinitelyWrittenCheck { this.mapFlatNodeToDeleteSet = new Hashtable(); this.liveness = new Liveness(); this.liveInTempSetToEventLoop = new HashSet(); + this.mapFlatNodeToMustClearMap = new Hashtable(); + this.calleeIntersectBoundMustClearSet = new SharedLocMap(); + this.mapFlatMethodToMustClearMap = new Hashtable(); } public void definitelyWrittenCheck() { @@ -211,14 +218,18 @@ public class DefinitelyWrittenCheck { SharedLocMap sharedLocMap = new SharedLocMap(); SharedLocMap deleteSet = new SharedLocMap(); + SharedLocMap mustClearMap = new SharedLocMap(); - sharedLoc_analyzeMethod(fm, sharedLocMap, deleteSet); + sharedLoc_analyzeMethod(fm, sharedLocMap, deleteSet, mustClearMap); SharedLocMap prevSharedLocMap = mapFlatMethodToSharedLocMap.get(fm); SharedLocMap prevDeleteSet = mapFlatMethodToDeleteSet.get(fm); + SharedLocMap prevMustClearMap = mapFlatMethodToMustClearMap.get(fm); - if (!(deleteSet.equals(prevDeleteSet) && sharedLocMap.equals(prevSharedLocMap))) { + if (!(deleteSet.equals(prevDeleteSet) && sharedLocMap.equals(prevSharedLocMap) && mustClearMap + .equals(prevMustClearMap))) { mapFlatMethodToSharedLocMap.put(fm, sharedLocMap); mapFlatMethodToDeleteSet.put(fm, deleteSet); + mapFlatMethodToMustClearMap.put(fm, mustClearMap); // results for callee changed, so enqueue dependents caller for // further @@ -247,23 +258,24 @@ public class DefinitelyWrittenCheck { } SharedLocMap sharedLocMap = new SharedLocMap(); SharedLocMap deleteSet = new SharedLocMap(); + SharedLocMap mustClearMap = new SharedLocMap(); sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop), - ssjava.getSSJavaLoopEntrance(), sharedLocMap, deleteSet, true); + ssjava.getSSJavaLoopEntrance(), sharedLocMap, deleteSet, mustClearMap, true); } private void sharedLoc_analyzeMethod(FlatMethod fm, SharedLocMap sharedLocMap, - SharedLocMap deleteSet) { + SharedLocMap deleteSet, SharedLocMap mustClearMap) { if (state.SSJAVADEBUG) { System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: " + fm); } - sharedLoc_analyzeBody(fm, fm, sharedLocMap, deleteSet, false); + sharedLoc_analyzeBody(fm, fm, sharedLocMap, deleteSet, mustClearMap, false); } private void sharedLoc_analyzeBody(FlatMethod fm, FlatNode startNode, SharedLocMap sharedLocMap, - SharedLocMap deleteSet, boolean isEventLoopBody) { + SharedLocMap deleteSet, SharedLocMap mustClearMap, boolean isEventLoopBody) { // intraprocedural analysis Set flatNodesToVisit = new HashSet(); @@ -275,6 +287,7 @@ public class DefinitelyWrittenCheck { SharedLocMap currSharedSet = new SharedLocMap(); SharedLocMap currDeleteSet = new SharedLocMap(); + SharedLocMap currMustClearMap = new SharedLocMap(); for (int i = 0; i < fn.numPrev(); i++) { FlatNode prevFn = fn.getPrev(i); @@ -287,17 +300,26 @@ public class DefinitelyWrittenCheck { if (inDeleteLoc != null) { mergeDeleteSet(currDeleteSet, inDeleteLoc); } + + SharedLocMap inMustClearMap = mapFlatNodeToMustClearMap.get(prevFn); + if (inMustClearMap != null) { + mergeSharedLocMap(currMustClearMap, inMustClearMap); + } + } - sharedLoc_nodeActions(fm, fn, currSharedSet, currDeleteSet, sharedLocMap, deleteSet, - isEventLoopBody); + sharedLoc_nodeActions(fm, fn, currSharedSet, currDeleteSet, currMustClearMap, sharedLocMap, + deleteSet, mustClearMap, isEventLoopBody); SharedLocMap prevSharedSet = mapFlatNodeToSharedLocMapping.get(fn); SharedLocMap prevDeleteSet = mapFlatNodeToDeleteSet.get(fn); + SharedLocMap prevMustClearMap = mapFlatNodeToMustClearMap.get(fn); - if (!(currSharedSet.equals(prevSharedSet) && currDeleteSet.equals(prevDeleteSet))) { + if (!(currSharedSet.equals(prevSharedSet) && currDeleteSet.equals(prevDeleteSet) && currMustClearMap + .equals(prevMustClearMap))) { mapFlatNodeToSharedLocMapping.put(fn, currSharedSet); mapFlatNodeToDeleteSet.put(fn, currDeleteSet); + mapFlatNodeToMustClearMap.put(fn, currMustClearMap); for (int i = 0; i < fn.numNext(); i++) { FlatNode nn = fn.getNext(i); if ((!isEventLoopBody) || loopIncElements.contains(nn)) { @@ -312,8 +334,8 @@ public class DefinitelyWrittenCheck { } private void sharedLoc_nodeActions(FlatMethod fm, FlatNode fn, SharedLocMap curr, - SharedLocMap currDeleteSet, SharedLocMap sharedLocMap, SharedLocMap deleteSet, - boolean isEventLoopBody) { + SharedLocMap currDeleteSet, SharedLocMap currMustClearMap, SharedLocMap sharedLocMap, + SharedLocMap deleteSet, SharedLocMap mustClearMap, boolean isEventLoopBody) { MethodDescriptor md = fm.getMethod(); @@ -324,6 +346,10 @@ public class DefinitelyWrittenCheck { TempDescriptor rhs; FieldDescriptor fld; + NTuple fieldLocTuple = null; + Location fieldLoc = null; + boolean isHigherWriteCase = false; + switch (fn.kind()) { case FKind.FlatOpNode: { @@ -374,7 +400,6 @@ public class DefinitelyWrittenCheck { case FKind.FlatSetFieldNode: case FKind.FlatSetElementNode: { - Location fieldLoc; if (fn.kind() == FKind.FlatSetFieldNode) { FlatSetFieldNode fsfn = (FlatSetFieldNode) fn; lhs = fsfn.getDst(); @@ -391,7 +416,7 @@ public class DefinitelyWrittenCheck { break; } - NTuple fieldLocTuple = new NTuple(); + fieldLocTuple = new NTuple(); if (fld.isStatic()) { if (fld.isFinal()) { // in this case, fld has TOP location @@ -433,6 +458,9 @@ public class DefinitelyWrittenCheck { if (!ssjava.isSameHeightWrite(fn)) { computeGENSetForHigherWrite(curr, genSet, fieldLocTuple, fldHeapPath); updateDeleteSetForHigherWrite(currDeleteSet, fieldLocTuple, fldHeapPath); + + isHigherWriteCase = true; + } else { computeGENSetForSameHeightWrite(curr, genSet, fieldLocTuple, fldHeapPath); updateDeleteSetForSameHeightWrite(currDeleteSet, fieldLocTuple, fldHeapPath); @@ -452,6 +480,12 @@ public class DefinitelyWrittenCheck { generateKILLSetForFlatCall(curr, killSet); generateGENSetForFlatCall(curr, genSet); + Set> locTupleSet = calleeIntersectBoundMustClearSet.keySet(); + for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) { + NTuple locTupleKey = (NTuple) iterator.next(); + currMustClearMap.addWrite(locTupleKey, calleeIntersectBoundMustClearSet.get(locTupleKey)); + } + } break; @@ -459,13 +493,38 @@ public class DefinitelyWrittenCheck { // merge the current delete/shared loc mapping mergeSharedLocMap(sharedLocMap, curr); mergeDeleteSet(deleteSet, currDeleteSet); - + mergeSharedLocMap(mustClearMap, currMustClearMap); } break; } computeNewMapping(curr, killSet, genSet); + if (isHigherWriteCase) { + // check all locations with the same shared location are cleared out at this point + Set> writtenSet = curr.get(fieldLocTuple); + Set requirementSet = ssjava.getSharedDescSet(fieldLoc); + + if (checkAllSharedLocationsAreOverwritten(requirementSet, writtenSet)) { + currMustClearMap.addWrite(fieldLocTuple, writtenSet); + } + } + } + + private boolean checkAllSharedLocationsAreOverwritten(Set sharedDescSet, + Set> writtenSet) { + + if (sharedDescSet == null || writtenSet == null) { + return false; + } + Set writtenDescSet = new HashSet(); + for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) { + NTuple tuple = (NTuple) iterator.next(); + writtenDescSet.add(tuple.get(tuple.size() - 1)); + } + + return writtenDescSet.containsAll(sharedDescSet); + // return sharedDescSet.containsAll(writtenDescSet); } @@ -527,7 +586,6 @@ public class DefinitelyWrittenCheck { if (currWriteSet != null) { genSet.addWrite(locTuple, currWriteSet); } - genSet.addWrite(locTuple, hp); } @@ -604,7 +662,6 @@ public class DefinitelyWrittenCheck { private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) { - // System.out.println("computeSharedCoverSet_analyzeMethod=" + fm); MethodDescriptor md = fm.getMethod(); Set flatNodesToVisit = new HashSet(); @@ -1296,7 +1353,10 @@ public class DefinitelyWrittenCheck { Set> writtenSet = mapFlatNodeToSharedLocMapping.get(fn).get(varLocTuple); - if (isCovered(varLocTuple, writtenSet)) { + Set> mustClearSet = + mapFlatNodeToMustClearMap.get(fn).get(varLocTuple); + + if (isCovered(varLocTuple, writtenSet, mustClearSet)) { computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet); computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet); } else { @@ -1398,7 +1458,6 @@ public class DefinitelyWrittenCheck { Set> writtenSet = mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple); - if (isCovered(fieldLocTuple, writtenSet)) { computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet); computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet); @@ -1418,10 +1477,10 @@ public class DefinitelyWrittenCheck { case FKind.FlatCall: { FlatCall fc = (FlatCall) fn; - SharedLocMap sharedLocMap = mapFlatNodeToSharedLocMapping.get(fc); - generateKILLSetForFlatCall(fc, curr, sharedLocMap, readWriteKillSet); - generateGENSetForFlatCall(fc, sharedLocMap, readWriteGenSet); + SharedLocMap mustClearMap = mapFlatNodeToMustClearMap.get(fc); + generateKILLSetForFlatCall(fc, curr, sharedLocMap, mustClearMap, readWriteKillSet); + generateGENSetForFlatCall(fc, sharedLocMap, mustClearMap, readWriteGenSet); } break; @@ -1479,22 +1538,37 @@ public class DefinitelyWrittenCheck { } - private boolean isCovered(NTuple locTuple, Set> inSet) { + private boolean isCovered(NTuple locTuple, Set> curWrittenSet) { - if (inSet == null) { + Set> coverSet = + mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple); + + if (curWrittenSet == null) { return false; } + return curWrittenSet.containsAll(coverSet); + } + + private boolean isCovered(NTuple locTuple, Set> curWrittenSet, + Set> mustClearSet) { + Set> coverSet = mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple); - return inSet.containsAll(coverSet); + if (mustClearSet != null && mustClearSet.containsAll(coverSet)) { + return true; + } + + if (curWrittenSet == null) { + return false; + } + + return curWrittenSet.containsAll(coverSet); } private void checkManyRead(FlatCall fc, Hashtable, Set> curr) { - Set> boundReadSet = mapFlatNodeToBoundReadSet.get(fc); - for (Iterator iterator = boundReadSet.iterator(); iterator.hasNext();) { NTuple readHeapPath = (NTuple) iterator.next(); Set writeAgeSet = curr.get(readHeapPath); @@ -1540,7 +1614,7 @@ public class DefinitelyWrittenCheck { } private void generateGENSetForFlatCall(FlatCall fc, SharedLocMap sharedLocMap, - Hashtable, Set> GENSet) { + SharedLocMap mustClearMap, Hashtable, Set> GENSet) { Set> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc); @@ -1556,10 +1630,9 @@ public class DefinitelyWrittenCheck { Set> sharedWriteHeapPathSet = sharedLocMap.get(locTuple); - if (isCovered(locTuple, sharedLocMap.get(locTuple))) { + if (isCovered(locTuple, sharedLocMap.get(locTuple), mustClearMap.get(locTuple))) { // if it is covered, add all of heap paths belong to the same shared // loc with write age 0 - for (Iterator iterator2 = sharedWriteHeapPathSet.iterator(); iterator2.hasNext();) { NTuple sharedHeapPath = (NTuple) iterator2.next(); addWriteAgeToSet(sharedHeapPath, GENSet, new WriteAge(0)); @@ -1591,7 +1664,7 @@ public class DefinitelyWrittenCheck { private void generateKILLSetForFlatCall(FlatCall fc, Hashtable, Set> curr, SharedLocMap sharedLocMap, - Hashtable, Set> KILLSet) { + SharedLocMap mustClearMap, Hashtable, Set> KILLSet) { Set> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc); @@ -1601,7 +1674,8 @@ public class DefinitelyWrittenCheck { if (isSharedLocation(heapPath)) { NTuple locTuple = getLocationTuple(heapPath); - if (isCovered(locTuple, sharedLocMap.get(locTuple)) && curr.containsKey(heapPath)) { + if (isCovered(locTuple, sharedLocMap.get(locTuple), mustClearMap.get(locTuple)) + && curr.containsKey(heapPath)) { // if it is shared loc and corresponding shared loc has been covered KILLSet.put(heapPath, curr.get(heapPath)); } @@ -1909,6 +1983,7 @@ public class DefinitelyWrittenCheck { NTuple calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam); SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod); SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod); + SharedLocMap calleeMustClearMap = mapFlatMethodToMustClearMap.get(calleeFlatMethod); if (calleeDeleteSet != null) { createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath, @@ -1920,6 +1995,11 @@ public class DefinitelyWrittenCheck { calleeLocationPath, calleeSharedLocMap); } + if (calleeMustClearMap != null) { + createNewMappingOfMustClearMap(callerArgLocationPath, callerArgHeapPath, + calleeLocationPath, calleeMustClearMap); + } + } } @@ -1927,6 +2007,28 @@ public class DefinitelyWrittenCheck { } + private void createNewMappingOfMustClearMap(NTuple callerArgLocationPath, + NTuple callerArgHeapPath, NTuple calleeLocationPath, + SharedLocMap calleeMustClearMap) { + + SharedLocMap calleeParamSharedSet = + calleeMustClearMap.getHeapPathStartedWith(calleeLocationPath); + + Set> keySet = calleeParamSharedSet.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + NTuple calleeLocTupleKey = (NTuple) iterator.next(); + Set> heapPathSet = calleeParamSharedSet.get(calleeLocTupleKey); + Set> boundHeapPathSet = new HashSet>(); + for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) { + NTuple calleeHeapPath = (NTuple) iterator2.next(); + boundHeapPathSet.add(bindHeapPath(callerArgHeapPath, calleeHeapPath)); + } + calleeIntersectBoundMustClearSet.intersect( + bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet); + } + + } + private void createNewMappingOfDeleteSet(NTuple callerArgLocationPath, NTuple callerArgHeapPath, NTuple calleeLocationPath, SharedLocMap calleeDeleteSet) { diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index 3d245966..d9bc290e 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -1155,7 +1155,12 @@ public class FlowDownCheck { // System.out.println("base location=" + callerBaseLoc + " constraint=" + // constraint); - for (int i = 0; i < calleeParamList.size(); i++) { + System.out.println("calleeParamList=" + calleeParamList); + int offset = 0; + if (!md.isStatic()) { + offset = 1; + } + for (int i = offset; i < calleeParamList.size(); i++) { CompositeLocation calleeParamLoc = calleeParamList.get(i); if (calleeParamLoc.get(0).equals(calleeThisLoc) && calleeParamLoc.getSize() > 1) { @@ -1182,6 +1187,8 @@ public class FlowDownCheck { continue; } + System.out.println("---idx=" + i + " callerArgLoc=" + callerArgLoc + " paramLocation=" + + paramLocation); // if (!CompositeLattice.isGreaterThan(callerArgLoc, paramLocation, errorMsg)) { if (CompositeLattice.compare(callerArgLoc, paramLocation, true, errorMsg) == ComparisonResult.LESS) { throw new Error("Caller argument '" + min.getArg(i).printNode(0) + " : " + callerArgLoc @@ -1736,9 +1743,12 @@ public class FlowDownCheck { Set 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 { @@ -1985,6 +1995,9 @@ public class FlowDownCheck { addLocationType(fd.getType(), loc); + if (ssjava.isSharedLocation(loc)) { + ssjava.addSharedDesc(loc, fd); + } } } diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index c2a8f8ec..b9a39f7d 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -458,7 +458,7 @@ public class FlowGraph { FlowReturnNode rnode = (FlowReturnNode) originalSrcNode; Set> rtupleSetFromRNode = rnode.getReturnTupleSet(); Set> rtupleSet = getReturnTupleSet(rtupleSetFromRNode); - System.out.println("#rnode=" + rnode + " rtupleSet=" + rtupleSet); + // System.out.println("#rnode=" + rnode + " rtupleSet=" + rtupleSet); for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) { NTuple rtuple = (NTuple) iterator2.next(); if (rtuple.startsWith(prefix)) { diff --git a/Robust/src/Analysis/SSJava/FlowNode.java b/Robust/src/Analysis/SSJava/FlowNode.java index 31a9ded3..0c83d756 100644 --- a/Robust/src/Analysis/SSJava/FlowNode.java +++ b/Robust/src/Analysis/SSJava/FlowNode.java @@ -28,6 +28,8 @@ public class FlowNode { private boolean isSkeleton; + private boolean isFormHolder = false; + public boolean isIntermediate() { return isIntermediate; } @@ -36,6 +38,14 @@ public class FlowNode { this.isIntermediate = isIntermediate; } + public void setFormHolder(boolean in) { + isFormHolder = in; + } + + public boolean isFromHolder() { + return isFormHolder; + } + public Set getFieldNodeSet() { return fieldNodeSet; } diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index e2adb19e..5502eb88 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -370,6 +370,26 @@ public class LocationInference { System.out.println("\nSSJAVA: Add addtional ordering constriants:"); MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop(); addAddtionalOrderingConstraints(methodEventLoopDesc); + // calculateReturnHolderLocation(); + } + + private void calculateReturnHolderLocation() { + LinkedList methodDescList = + (LinkedList) toanalyze_methodDescList.clone(); + + while (!methodDescList.isEmpty()) { + MethodDescriptor md = methodDescList.removeLast(); + + FlowGraph fg = getFlowGraph(md); + Set nodeSet = fg.getNodeSet(); + for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { + FlowNode flowNode = (FlowNode) iterator.next(); + if (flowNode.isFromHolder()) { + calculateCompositeLocationFromFlowGraph(md, flowNode); + } + } + + } } private void updateCompositeLocationAssignments() { @@ -1536,6 +1556,132 @@ public class LocationInference { } + private CompositeLocation calculateCompositeLocationFromFlowGraph(MethodDescriptor md, + FlowNode node) { + + System.out.println("#############################################################"); + System.out.println("calculateCompositeLocationFromFlowGraph=" + node); + + FlowGraph flowGraph = getFlowGraph(md); + // NTuple paramLocTuple = translateToLocTuple(md, paramNode.getDescTuple()); + // GlobalFlowNode paramGlobalNode = subGlobalFlowGraph.getFlowNode(paramLocTuple); + + List> prefixList = calculatePrefixListFlowGraph(flowGraph, node); + + // Set reachableNodeSet = + // subGlobalFlowGraph.getReachableNodeSetByPrefix(paramGlobalNode.getLocTuple().get(0)); + // + Set reachableNodeSet = + flowGraph.getReachableSetFrom(node.getDescTuple().subList(0, 1)); + + // Set reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node); + + // System.out.println("node=" + node + " prefixList=" + prefixList); + + for (int i = 0; i < prefixList.size(); i++) { + NTuple curPrefix = prefixList.get(i); + Set> reachableCommonPrefixSet = new HashSet>(); + + for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) { + FlowNode reachNode = (FlowNode) iterator2.next(); + NTuple reachLocTuple = translateToLocTuple(md, reachNode.getCurrentDescTuple()); + if (reachLocTuple.startsWith(curPrefix)) { + reachableCommonPrefixSet.add(reachLocTuple); + } + } + // System.out.println("reachableCommonPrefixSet=" + reachableCommonPrefixSet); + + if (!reachableCommonPrefixSet.isEmpty()) { + + MethodDescriptor curPrefixFirstElementMethodDesc = + (MethodDescriptor) curPrefix.get(0).getDescriptor(); + + // MethodDescriptor nodePrefixLocFirstElementMethodDesc = + // (MethodDescriptor) prefixLoc.getDescriptor(); + + // System.out.println("curPrefixFirstElementMethodDesc=" + + // curPrefixFirstElementMethodDesc); + // System.out.println("nodePrefixLocFirstElementMethodDesc=" + // + nodePrefixLocFirstElementMethodDesc); + + // TODO + // if (!node.getLocTuple().startsWith(curPrefix.get(0))) { + + Location curPrefixLocalLoc = curPrefix.get(0); + + Location targetLocalLoc = new Location(md, node.getDescTuple().get(0)); + // Location targetLocalLoc = paramGlobalNode.getLocTuple().get(0); + + CompositeLocation newCompLoc = generateCompositeLocation(curPrefix); + System.out.println("NEED2ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix); + System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc); + + // // makes sure that a newly generated location appears in the hierarchy graph + // for (int compIdx = 0; compIdx < newCompLoc.getSize(); compIdx++) { + // Location curLoc = newCompLoc.get(compIdx); + // getHierarchyGraph(curLoc.getDescriptor()).getHNode(curLoc.getLocDescriptor()); + // } + // subGlobalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc); + node.setCompositeLocation(newCompLoc); + + return newCompLoc; + + } + + } + return null; + } + + private List> calculatePrefixListFlowGraph(FlowGraph graph, FlowNode node) { + + System.out.println("\n##### calculatePrefixList node=" + node); + + MethodDescriptor md = graph.getMethodDescriptor(); + Set incomingNodeSetPrefix = + graph.getIncomingNodeSetByPrefix(node.getDescTuple().get(0)); + // System.out.println("---incomingNodeSetPrefix=" + incomingNodeSetPrefix); + + Set reachableNodeSetPrefix = + graph.getReachableSetFrom(node.getDescTuple().subList(0, 1)); + // System.out.println("---reachableNodeSetPrefix=" + reachableNodeSetPrefix); + + List> prefixList = new ArrayList>(); + + for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) { + FlowNode inNode = (FlowNode) iterator.next(); + NTuple inNodeTuple = translateToLocTuple(md, inNode.getCurrentDescTuple()); + + // if (inNodeTuple.get(0).getLocDescriptor() instanceof InterDescriptor + // || inNodeTuple.get(0).getLocDescriptor().equals(GLOBALDESC)) { + // continue; + // } + + for (int i = 1; i < inNodeTuple.size(); i++) { + NTuple prefix = inNodeTuple.subList(0, i); + if (!prefixList.contains(prefix)) { + prefixList.add(prefix); + } + } + } + + Collections.sort(prefixList, new Comparator>() { + public int compare(NTuple arg0, NTuple arg1) { + int s0 = arg0.size(); + int s1 = arg1.size(); + if (s0 > s1) { + return -1; + } else if (s0 == s1) { + return 0; + } else { + return 1; + } + } + }); + + return prefixList; + + } + private boolean containsClassDesc(ClassDescriptor cd, NTuple prefixLocTuple) { for (int i = 0; i < prefixLocTuple.size(); i++) { Location loc = prefixLocTuple.get(i); @@ -1604,7 +1750,6 @@ public class LocationInference { NTuple locTuple = new NTuple(); Descriptor enclosingDesc = md; - System.out.println("md=" + md + " descTuple=" + descTuple); for (int i = 0; i < descTuple.size(); i++) { Descriptor desc = descTuple.get(i); @@ -4966,12 +5111,14 @@ 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); if (needToGenerateInterLoc(tupleSet)) { System.out.println("20"); FlowGraph fg = getFlowGraph(mdCaller); - NTuple interTuple = fg.createIntermediateNode().getDescTuple(); + FlowNode interNode = fg.createIntermediateNode(); + interNode.setFormHolder(true); + + NTuple interTuple = interNode.getDescTuple(); for (Iterator iterator = tupleSet.iterator(); iterator.hasNext();) { NTuple tuple = (NTuple) iterator.next(); @@ -4990,10 +5137,14 @@ public class LocationInference { } setNode.addTuple(interTuple); + System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + setNode); + } else { setNode.addTupleSet(tupleSet); - } + System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode); + } + // setNode.addTupleSet(tupleSet); nodeSet.addTuple(setNode.getDescTuple()); } diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index a39fd014..da84de63 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -96,7 +96,7 @@ public class SSJavaAnalysis { // keep the field ownership from the linear type checking Hashtable> mapMethodToOwnedFieldSet; - + Set sameHeightWriteFlatNodeSet; CallGraph callgraph; @@ -110,6 +110,8 @@ public class SSJavaAnalysis { private LinkedList sortedDescriptors; + private Map> mapSharedLocToDescSet; + public SSJavaAnalysis(State state, TypeUtil tu, BuildFlat bf, CallGraph callgraph) { this.state = state; this.tu = tu; @@ -129,6 +131,7 @@ public class SSJavaAnalysis { this.mapDescriptorToSetDependents = new Hashtable>(); this.sortedDescriptors = new LinkedList(); this.md2pcLoc = new HashMap(); + this.mapSharedLocToDescSet = new HashMap>(); } public void doCheck() { @@ -166,6 +169,17 @@ public class SSJavaAnalysis { return (LinkedList) sortedDescriptors.clone(); } + public void addSharedDesc(Location loc, Descriptor fd) { + if (!mapSharedLocToDescSet.containsKey(loc)) { + mapSharedLocToDescSet.put(loc, new HashSet()); + } + mapSharedLocToDescSet.get(loc).add(fd); + } + + public Set getSharedDescSet(Location loc) { + return mapSharedLocToDescSet.get(loc); + } + private void inference() { LocationInference inferEngine = new LocationInference(this, state); inferEngine.inference(); diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java b/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java index fa69d235..3c7c94e6 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java @@ -14,7 +14,10 @@ import SSJava.PCLOC; * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * private Point readEyes(@LOC("IN") Image image, @LOC("IN") Rectangle2D rect) { + @LOC("OUT") EyeDetector ed = new EyeDetector(image, rect); + return ed.detectEye(); + } * You should have received a copy of the GNU Lesser General Public License * along with LEA. If not, see . */ @@ -23,15 +26,33 @@ import SSJava.PCLOC; * * @author Florian */ -@LATTICE("CS - * 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 */ @LATTICE("OUT 1000) { - return null; + px = -1; + py = -1; + pwidth = -1; + pheight = -1; + return; } - @LOC("THIS,ClassifierTree.C") float factor = startFactor + factorDiff; + @LOC("THIS,ClassifierTree.CUR") float factor = startFactor + factorDiff; if (factor > maxScaleFactor || factor < minScaleFactor) continue; // now we calculate the actualDimmension - @LOC("THIS,ClassifierTree.C") int actualDimmension = (int) (100 * factor); - @LOC("THIS,ClassifierTree.C") int maxX = imageData.getWidth() - actualDimmension; - @LOC("THIS,ClassifierTree.C") int maxY = imageData.getHeight() - actualDimmension; + @LOC("THIS,ClassifierTree.CUR") int actualDimmension = (int) (100 * factor); + @LOC("THIS,ClassifierTree.CUR") int maxX = imageData.getWidth() - actualDimmension; + @LOC("THIS,ClassifierTree.CUR") int maxY = imageData.getHeight() - actualDimmension; - @LOC("THIS,ClassifierTree.C") int maxDiffX = Math.max(Math.abs(startPosX - maxX), startPosX); - @LOC("THIS,ClassifierTree.C") int maxDiffY = Math.max(Math.abs(startPosY - maxY), startPosY); + @LOC("THIS,ClassifierTree.CUR") int maxDiffX = + Math.max(Math.abs(startPosX - maxX), startPosX); + @LOC("THIS,ClassifierTree.CUR") int maxDiffY = + Math.max(Math.abs(startPosY - maxY), startPosY); - @LOC("CXY") int xidx = 0; - TERMINATE: for (@LOC("CXY") float xDiff = 0.1f; Math.abs(xDiff) <= maxDiffX; xDiff = + @LOC("THIS,ClassifierTree.CUR") int xidx = 0; + TERMINATE: for (@LOC("THIS,ClassifierTree.CUR") float xDiff = 0.1f; Math.abs(xDiff) <= maxDiffX; xDiff = (xDiff + sgn(xDiff) * 0.5f) * -1) { if (++xidx > 1000) { - return null; + px = -1; + py = -1; + pwidth = -1; + pheight = -1; + return; } - @LOC("CXY") int xPos = Math.round((float) (startPosX + xDiff)); + @LOC("THIS,ClassifierTree.CUR") int xPos = Math.round((float) (startPosX + xDiff)); if (xPos < 0 || xPos > maxX) continue; - @LOC("CXY") int yidx = 0; + @LOC("THIS,ClassifierTree.CUR") int yidx = 0; // yLines: - TERMINATE: for (@LOC("CXY") float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = + TERMINATE: for (@LOC("THIS,ClassifierTree.CUR") float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = (yDiff + sgn(yDiff) * 0.5f) * -1) { if (++yidx > 1000) { - return null; + px = -1; + py = -1; + pwidth = -1; + pheight = -1; + return; } - @LOC("CXY") int yPos = Math.round(startPosY + yDiff); + @LOC("THIS,ClassifierTree.CUR") 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 - @LOC("CXY") boolean backToYLines = false; - for (@LOC("CXY") int idx = 0; idx < classifiers.length; ++idx) { - @LOC("CXY") float borderline = - 0.8f + (idx / (classifiers.length - 1)) * (maxBorder - 0.8f); + @LOC("THIS,ClassifierTree.C") boolean backToYLines = false; + for (@LOC("THIS,ClassifierTree.CUR") int idx = 0; idx < size; ++idx) { + @LOC("THIS,ClassifierTree.CUR") float borderline = + 0.8f + (idx / (size - 1)) * (maxBorder - 0.8f); if (!classifiers[idx].classifyFace(imageData, factor, xPos, yPos, borderline)) { backToYLines = true; break; @@ -167,11 +209,12 @@ public class ClassifierTree { if (backToYLines) { continue; } - @LOC("OUT") Rectangle2D faceRect = - new Rectangle2D(xPos * originalImageFactor, yPos * originalImageFactor, - actualDimmension * originalImageFactor, actualDimmension * originalImageFactor); - return faceRect; + x = xPos * originalImageFactor; + y = yPos * originalImageFactor; + width = actualDimmension * originalImageFactor; + height = actualDimmension * originalImageFactor; + return; } @@ -180,7 +223,7 @@ public class ClassifierTree { } // System.out.println("Time: "+(System.currentTimeMillis()-timeStart)+"ms"); - return null; + // return null; } @@ -190,4 +233,36 @@ public class ClassifierTree { return (value < 0 ? -1 : (value > 0 ? +1 : 1)); } + @LATTICE("OUT image.getWidth() || height > image.getHeight()) { + return null; + } + + @LOC("OUT") EyePosition eyePosition = null; + + if (x != -1) { + @LOC("ED") EyeDetector ed = new EyeDetector(image, x, y, width, height); + @LOC("P") Point point = ed.detectEye(); + if (point != null) { + eyePosition = new EyePosition(point.getX(), point.getY()); + } + } + + System.out.println("eyePosition=" + eyePosition); + + @LOC("OUT") FaceAndEyePosition fep = new FaceAndEyePosition(x, y, width, height, eyePosition); + + return fep; + } + + } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/EyeDetector.java b/Robust/src/Benchmarks/SSJava/EyeTracking/EyeDetector.java index 88620a48..ffe8cb62 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/EyeDetector.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/EyeDetector.java @@ -35,12 +35,16 @@ class EyeDetector { @LOC("IMG") double percent; - public EyeDetector(Image image, Rectangle2D faceRect) { + // public EyeDetector(Image image, Rectangle2D faceRect) { + public EyeDetector(Image image, double fx, double fy, double fwidth, double fheight) { - percent = 0.15 * faceRect.getWidth(); + percent = 0.15 * fwidth; Rectangle2D adjustedFaceRect = - new Rectangle2D(faceRect.getX() + percent, faceRect.getY() + percent, faceRect.getWidth() - - percent, faceRect.getHeight() - 2 * percent); + new Rectangle2D(fx + percent, fy + percent, fwidth - percent, fheight - 2 * percent); + // percent = 0.15 * faceRect.getWidth(); + // Rectangle2D adjustedFaceRect = + // new Rectangle2D(faceRect.getX() + percent, faceRect.getY() + percent, faceRect.getWidth() + // - percent, faceRect.getHeight() - 2 * percent); width = (int) adjustedFaceRect.getWidth() / 2; height = (int) adjustedFaceRect.getHeight() / 2; diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java b/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java index 5b4ffd5b..8422220a 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java @@ -29,17 +29,27 @@ public class EyePosition { private int x; @LOC("POS") private int y; - @LOC("POS") - private Rectangle2D faceRect; + + @LOC("POS") private double facex; + @LOC("POS") private double facey; + @LOC("POS") private double facewidth; + @LOC("POS") private double faceheight; - public EyePosition(Point p, Rectangle2D faceRect) { - this(p.x, p.y, faceRect); - } + // 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, Rectangle2D faceRect) { + public EyePosition(int x, int y) { this.x = x; this.y = y; - this.faceRect = faceRect; } public int getX() { diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/FaceAndEyePosition.java b/Robust/src/Benchmarks/SSJava/EyeTracking/FaceAndEyePosition.java index 29e0f6ee..f184e5ae 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/FaceAndEyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/FaceAndEyePosition.java @@ -31,8 +31,8 @@ public class FaceAndEyePosition { @LOC("POS") private EyePosition eyePosition; - public FaceAndEyePosition(Rectangle2D facePosition, EyePosition eyePosition) { - this.facePosition = facePosition; + public FaceAndEyePosition(double x, double y, double w, double h, EyePosition eyePosition) { + this.facePosition = new Rectangle2D(x, y, w, h); this.eyePosition = eyePosition; } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java b/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java index c20bc937..3197ac34 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java @@ -57,7 +57,7 @@ public class LEA { @LOC("IMPL") private LEAImplementation implementation; @LOC("LAST") - private FaceAndEyePosition lastPositions = new FaceAndEyePosition(null, null); + private FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null); @LOC("DEV") private DeviationScanner deviationScanner = new DeviationScanner(); diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java b/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java index cf564ff1..bf5c4978 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java @@ -29,9 +29,6 @@ public class LEAImplementation { @LOC("CT") private ClassifierTree classifierTree; - @LOC("R") - private Rectangle2D lastRectangle; - public LEAImplementation() { this.loadFaceData(); } @@ -39,34 +36,7 @@ public class LEAImplementation { @LATTICE("OUT image.getWidth() || faceRect.getHeight() > image.getHeight()) { - return null; - } - @LOC("V") EyePosition eyePosition = null; - if (faceRect != null) { - lastRectangle = faceRect; - faceRect = null; - @LOC("V") Point point = readEyes(image, lastRectangle); - if (point != null) { - eyePosition = new EyePosition(point, lastRectangle); - } - } else { - lastRectangle = null; - } - System.out.println("eyePosition=" + eyePosition); - - return new FaceAndEyePosition(lastRectangle, eyePosition); - } - - @LATTICE("OUT. */ @@ -24,18 +27,38 @@ import SSJava.PCLOC; * @author Florian */ -public class ClassifierTree { - private Classifier classifiers[]; +public class ClassifierTree { - public ClassifierTree(int size) { + + private Classifier[] classifiers; + + double x; + + double y; + + double width; + + double height; + + + int size; + + + public ClassifierTree( int size) { + this.size = size; classifiers = new Classifier[size]; + x = -1; + y = -1; + width = -1; + height = -1; } - 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. @@ -49,101 +72,123 @@ public class ClassifierTree { * @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; - - if (lastCoordinates == null) { + + public void locateFaceRadial( Image smallImage) { + + double px = x; + double py = y; + double pwidth = width; + double pheight = height; + + x = -1; + y = -1; + width = -1; + height = -1; + + IntegralImageData imageData = new IntegralImageData(smallImage); + float originalImageFactor = 1; + if (px == -1) { + // if(true){ // if we don't have a last coordinate we just begin in the center - int smallImageMaxDimension = Math.min(smallImage.getWidth(), smallImage.getHeight()); - lastCoordinates = - new Rectangle2D((smallImage.getWidth() - smallImageMaxDimension) / 2.0, - (smallImage.getHeight() - smallImageMaxDimension) / 2.0, smallImageMaxDimension, - smallImageMaxDimension); - // System.out.println("lastCoordinates=" + lastCoordinates); + int smallImageMaxDimension = Math.min(smallImage.getWidth(), smallImage.getHeight()); + + px = (smallImage.getWidth() - smallImageMaxDimension) / 2.0; + py = (smallImage.getHeight() - smallImageMaxDimension) / 2.0; + pwidth = smallImageMaxDimension; + pheight = smallImageMaxDimension; } else { // first we have to scale the last coodinates back relative to the resized // image - lastCoordinates = - new Rectangle2D((lastCoordinates.getX() * (1 / originalImageFactor)), - (lastCoordinates.getY() * (1 / originalImageFactor)), - (lastCoordinates.getWidth() * (1 / originalImageFactor)), - (lastCoordinates.getHeight() * (1 / originalImageFactor))); + px = px * (1 / originalImageFactor); + py = py * (1 / originalImageFactor); + pwidth = pwidth * (1 / originalImageFactor); + pheight = pheight * (1 / originalImageFactor); } - float startFactor = (float) (lastCoordinates.getWidth() / 100.0f); + + float startFactor = (float) (pwidth / 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) px; + int startPosY = (int) py; - 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 ) { if (++loopidx > 1000) { - return null; + px = -1; + py = -1; + pwidth = -1; + pheight = -1; + return; } - 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; + px = -1; + py = -1; + pwidth = -1; + pheight = -1; + return; } - 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; + px = -1; + py = -1; + pwidth = -1; + pheight = -1; + return; } - 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 < size; ++idx) { + float borderline = 0.8f + (idx / (size - 1)) * (maxBorder - 0.8f); if (!classifiers[idx].classifyFace(imageData, factor, xPos, yPos, borderline)) { backToYLines = true; break; @@ -159,9 +204,11 @@ public class ClassifierTree { continue; } - Rectangle2D faceRect = new Rectangle2D(xPos * originalImageFactor, yPos * originalImageFactor, actualDimmension * originalImageFactor, actualDimmension * originalImageFactor); - - return faceRect; + x = xPos * originalImageFactor; + y = yPos * originalImageFactor; + width = actualDimmension * originalImageFactor; + height = actualDimmension * originalImageFactor; + return; } @@ -169,13 +216,46 @@ public class ClassifierTree { } - // System.out.println("Time: "+(System.currentTimeMillis()-timeStart)+"ms"); - return null; } - private static int sgn(float value) { + + + private static int sgn( float value) { return (value < 0 ? -1 : (value > 0 ? +1 : 1)); } + + public FaceAndEyePosition getEyePosition( Image image) { + if (image == null) { + return null; + } + + float originalImageFactor = 1; + + locateFaceRadial(image); + + if (width > image.getWidth() || height > image.getHeight()) { + return null; + } + + EyePosition eyePosition = null; + + if (x != -1) { + EyeDetector ed = new EyeDetector(image, x, y, width, height); + Point point = ed.detectEye(); + if (point != null) { + eyePosition = new EyePosition(point.getX(), point.getY()); + } + } + + System.out.println("eyePosition=" + eyePosition); + + FaceAndEyePosition fep = new FaceAndEyePosition(x, y, width, height, eyePosition); + + + return fep; + } + + } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java index 6da3f7e1..4cc353e0 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java @@ -23,8 +23,10 @@ * @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), @@ -45,7 +47,8 @@ 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]; @@ -57,23 +60,24 @@ 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()); @@ -81,14 +85,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) @@ -110,7 +114,8 @@ 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; @@ -140,7 +145,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 e035b650..699a620d 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java @@ -15,44 +15,38 @@ 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 d162bc0c..6e21f392 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java @@ -23,22 +23,27 @@ * @author Florian Frankenberger */ + class EyeDetector { + private int width; - + private int height; - + private int[] pixelBuffer; - + double percent; - public EyeDetector(Image image, Rectangle2D faceRect) { + // public EyeDetector(Image image, Rectangle2D faceRect) { + public EyeDetector(Image image, double fx, double fy, double fwidth, double fheight) { - percent = 0.15 * faceRect.getWidth(); - Rectangle2D adjustedFaceRect = - new Rectangle2D(faceRect.getX() + percent, faceRect.getY() + percent, faceRect.getWidth() - - percent, faceRect.getHeight() - 2 * percent); + percent = 0.15 * fwidth; + Rectangle2D adjustedFaceRect = new Rectangle2D(fx + percent, fy + percent, fwidth - percent, fheight - 2 * percent); + // percent = 0.15 * faceRect.getWidth(); + // Rectangle2D adjustedFaceRect = + // new Rectangle2D(faceRect.getX() + percent, faceRect.getY() + percent, faceRect.getWidth() + // - percent, faceRect.getHeight() - 2 * percent); width = (int) adjustedFaceRect.getWidth() / 2; height = (int) adjustedFaceRect.getHeight() / 2; @@ -55,15 +60,16 @@ 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) { - int position = y * width + x; - 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]); - float acBrightness = getBrightness(color); + final float acBrightness = getBrightness(color); if (acBrightness < brightness) { eyePosition = new Point(x + (int) percent, y + (int) percent); @@ -75,9 +81,10 @@ 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 be45cee3..a599a3c1 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java @@ -23,22 +23,33 @@ * @author Florian Frankenberger */ -public class EyePosition { +public class EyePosition { + private int x; - + private int y; + + private double facex; + private double facey; + private double facewidth; + private double faceheight; - private Rectangle2D faceRect; + // private Rectangle2D faceRect; - public EyePosition(Point p, Rectangle2D faceRect) { - this(p.x, p.y, 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, Rectangle2D faceRect) { + public EyePosition(int x, int y) { this.x = x; this.y = y; - this.faceRect = faceRect; } public int getX() { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java index e1d94503..3dce544d 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java @@ -23,14 +23,16 @@ * @author Florian Frankenberger */ + public class FaceAndEyePosition { + private Rectangle2D facePosition; - + private EyePosition eyePosition; - public FaceAndEyePosition(Rectangle2D facePosition, EyePosition eyePosition) { - this.facePosition = facePosition; + public FaceAndEyePosition(double x, double y, double w, double h, EyePosition eyePosition) { + this.facePosition = new Rectangle2D(x, y, w, h); this.eyePosition = eyePosition; } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java index 2caa04a9..f050a978 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java @@ -17,34 +17,36 @@ * 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(); - - /** - * 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(); + /** + * 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(); + + } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java index 52453203..d91a7e4a 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java @@ -1,10 +1,12 @@ + 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 80d7782b..d517a373 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java @@ -23,12 +23,14 @@ * @author Florian Frankenberger */ + public class IntegralImageData { + private long[][] integral; - + private int width; - + private int hegith; // private Dimension dimension; @@ -49,7 +51,7 @@ public class IntegralImageData { } - public long getIntegralAt(int x, int y) { + public long getIntegralAt( int x, int y) { return this.integral[x][y]; } @@ -61,8 +63,4 @@ 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 b3fda528..40479eb1 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java @@ -20,19 +20,22 @@ /** * 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): *

@@ -40,19 +43,22 @@ * 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 FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null); + private DeviationScanner deviationScanner = new DeviationScanner(); public LEA() { @@ -62,17 +68,18 @@ 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 @@ -82,12 +89,13 @@ 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; } @@ -97,12 +105,13 @@ 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 b9dc7d39..3c2449c7 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java @@ -23,42 +23,21 @@ * @author Florian Frankenberger */ + public class LEAImplementation { + private ClassifierTree classifierTree; - private Rectangle2D lastRectangle; public LEAImplementation() { this.loadFaceData(); } - public FaceAndEyePosition getEyePosition(Image image) { - if (image == null) - return null; - Rectangle2D faceRect = classifierTree.locateFaceRadial(image, lastRectangle); - if (faceRect.getWidth() > image.getWidth() || faceRect.getHeight() > image.getHeight()) { - return null; - } - EyePosition eyePosition = null; - if (faceRect != null) { - lastRectangle = faceRect; - faceRect = null; - Point point = readEyes(image, lastRectangle); - if (point != null) { - eyePosition = new EyePosition(point, lastRectangle); - } - } else { - lastRectangle = null; - } - System.out.println("eyePosition=" + eyePosition); - - return new FaceAndEyePosition(lastRectangle, eyePosition); - } - - private Point readEyes(Image image, Rectangle2D rect) { - EyeDetector ed = new EyeDetector(image, rect); - return ed.detectEye(); + + + public FaceAndEyePosition getEyePosition( Image image) { + return classifierTree.getEyePosition(image); } public boolean needsCalibration() { diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java index a3b6c37c..044f37ec 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java @@ -1,7 +1,9 @@ + + public class Point { - public int x; - public int y; + public int x; + public int y; public Point(int x, int y) { this.x = x; @@ -10,9 +12,17 @@ public class Point { public Point() { } - - public String toString() { - return "(" + x + "," + y + ")"; + + public String toString(){ + return "("+x+","+y+")"; + } + + public int getX(){ + return x; + } + + public int getY(){ + return y; } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java index ae538162..e765e70c 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java @@ -1,9 +1,11 @@ + + 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 62e9b4ae..abb581b0 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java +++ b/Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java @@ -22,17 +22,20 @@ * @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 @@ -54,23 +57,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)); } @@ -107,7 +110,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;