changes: generated annotated code but it still causes type errors + re-formatting...
authoryeom <yeom>
Thu, 1 Nov 2012 06:27:46 +0000 (06:27 +0000)
committeryeom <yeom>
Thu, 1 Nov 2012 06:27:46 +0000 (06:27 +0000)
20 files changed:
Robust/src/Analysis/SSJava/FlowDownCheck.java
Robust/src/Analysis/SSJava/FlowGraph.java
Robust/src/Analysis/SSJava/FlowNode.java
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Analysis/SSJava/NodeTupleSet.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Classifier.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ClassifierTree.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DummyCaptureDevice.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyeDetector.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/EyePosition.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/FaceAndEyePosition.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ICaptureDevice.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Image.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/IntegralImageData.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEAImplementation.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Point.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/Rectangle2D.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/ScanArea.java

index 25f6a8e3dd3bffb01e8a9c79b4182082a0b30396..3d2459662bfe54f1be6895cd14a97d5fd91035b2 100644 (file)
@@ -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();
index f71b82d07c07e392cb7e4f917ab752854cc776df..c2a8f8ecc98f1b34288a25729b7bc5a739e43966 100644 (file)
@@ -41,6 +41,8 @@ public class FlowGraph {
 
   Map<MethodInvokeNode, FlowReturnNode> mapMethodInvokeNodeToFlowReturnNode;
 
+  Map<Descriptor, ClassDescriptor> mapIntersectionDescToEnclosingDescriptor;
+
   public static int interseed = 0;
 
   boolean debug = true;
@@ -57,6 +59,7 @@ public class FlowGraph {
     this.mapFlowNodeToOutEdgeSet = new HashMap<FlowNode, Set<FlowEdge>>();
     this.mapFlowNodeToInEdgeSet = new HashMap<FlowNode, Set<FlowEdge>>();
     this.mapMethodInvokeNodeToFlowReturnNode = new HashMap<MethodInvokeNode, FlowReturnNode>();
+    this.mapIntersectionDescToEnclosingDescriptor = new HashMap<Descriptor, ClassDescriptor>();
 
     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<NTuple<Descriptor>, 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<Descriptor> 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<FlowNode> dstNodeSet = new HashSet<FlowNode>();
       if (originalDstNode instanceof FlowReturnNode) {
         FlowReturnNode rnode = (FlowReturnNode) originalDstNode;
-        Set<NTuple<Descriptor>> rtupleSet = rnode.getReturnTupleSet();
+        Set<NTuple<Descriptor>> rtupleSetFromRNode = rnode.getReturnTupleSet();
+        Set<NTuple<Descriptor>> rtupleSet = getReturnTupleSet(rtupleSetFromRNode);
         for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) {
           NTuple<Descriptor> rtuple = (NTuple<Descriptor>) iterator2.next();
           dstNodeSet.add(getFlowNode(rtuple));
@@ -442,11 +456,13 @@ public class FlowGraph {
       Set<FlowNode> srcNodeSet = new HashSet<FlowNode>();
       if (originalSrcNode instanceof FlowReturnNode) {
         FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
-        Set<NTuple<Descriptor>> rtupleSet = rnode.getReturnTupleSet();
+        Set<NTuple<Descriptor>> rtupleSetFromRNode = rnode.getReturnTupleSet();
+        Set<NTuple<Descriptor>> rtupleSet = getReturnTupleSet(rtupleSetFromRNode);
+        System.out.println("#rnode=" + rnode + "  rtupleSet=" + rtupleSet);
         for (Iterator iterator2 = rtupleSet.iterator(); iterator2.hasNext();) {
           NTuple<Descriptor> rtuple = (NTuple<Descriptor>) 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<NTuple<Descriptor>> getReturnTupleSet(Set<NTuple<Descriptor>> in) {
+
+    Set<NTuple<Descriptor>> normalTupleSet = new HashSet<NTuple<Descriptor>>();
+    for (Iterator iterator2 = in.iterator(); iterator2.hasNext();) {
+      NTuple<Descriptor> tuple = (NTuple<Descriptor>) 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<FlowNode> 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<NTuple<Descriptor>> nodeTupleSet = rnode.getReturnTupleSet();
-            for (Iterator iterator3 = nodeTupleSet.iterator(); iterator3.hasNext();) {
+            Set<NTuple<Descriptor>> rtupleSet = getReturnTupleSet(nodeTupleSet);
+            for (Iterator iterator3 = rtupleSet.iterator(); iterator3.hasNext();) {
               NTuple<Descriptor> nodeTuple = (NTuple<Descriptor>) iterator3.next();
               FlowNode fn = getFlowNode(nodeTuple);
               if (!visited.contains(fn)) {
index c6a6b79eb28bcdfa894fd06e9e8a39d67bb806ad..31a9ded33afec455c64623cadbdbd9e3b80ed1bf 100644 (file)
@@ -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;
   }
 
index 6575d4bad7708eca4a0669d04875f7e06c32dd4e..e2adb19e2d4058b6f0b38657d26d4bd7431215ff 100644 (file)
@@ -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<Location> locTuple = new NTuple<Location>();
 
     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<Descriptor> 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<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
 
       NTuple<Location> callerLocTuple = new NTuple<Location>();
@@ -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<MethodDescriptor> methodDescList =
         (LinkedList<MethodDescriptor>) 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<Descriptor> 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<Descriptor> 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<FlowNode> 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<Descriptor> baseTuple = baseNodeSet.iterator().next();
@@ -4827,19 +4868,30 @@ public class LocationInference {
               // the location type of the return value is started with 'this'
               // reference
               NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(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<FlowNode> 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<Descriptor> 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<Descriptor> interTuple = fg.createIntermediateNode().getDescTuple();
+
+          for (Iterator iterator = tupleSet.iterator(); iterator.hasNext();) {
+            NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+
+            Set<NTuple<Descriptor>> addSet = new HashSet<NTuple<Descriptor>>();
+            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<Descriptor> higher = (NTuple<Descriptor>) 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<Location> calleeReturnLocTuple =
             translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple());
         System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple);
-        nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller,
-            calleeReturnLocTuple));
+        NTuple<Location> 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<Descriptor> 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<Descriptor> 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<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
           NTuple<Descriptor> 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());
     }
   }
index f614080d71f97ba3a8cb442f1a1aa27cf36d9623..52384828de15df06bbe46a614b647041a1675a73 100644 (file)
@@ -14,6 +14,8 @@ public class NodeTupleSet {
 
   private ArrayList<NTuple<Location>> globalLocTupleList;
 
+  private NTuple<Descriptor> baseDescTuple;
+
   public NodeTupleSet() {
     list = new ArrayList<NTuple<Descriptor>>();
     globalLocTupleList = new ArrayList<NTuple<Location>>();
@@ -31,11 +33,21 @@ public class NodeTupleSet {
     list.add(tuple);
   }
 
+  public void setMethodInvokeBaseDescTuple(NTuple<Descriptor> in) {
+    baseDescTuple = in;
+  }
+
+  public NTuple<Descriptor> getBaseDesc() {
+    return baseDescTuple;
+  }
+
   public void addGlobalFlowTuple(NTuple<Location> tuple) {
+    System.out.println("-----add global value flow tuple=" + tuple);
     globalLocTupleList.add(tuple);
   }
 
   public void addGlobalFlowTupleSet(ArrayList<NTuple<Location>> in) {
+    System.out.println("-----add global value flow in=" + in);
     globalLocTupleList.addAll(in);
   }
 
@@ -91,7 +103,7 @@ public class NodeTupleSet {
   private void setGlobalLocTupleList(ArrayList<NTuple<Location>> in) {
     globalLocTupleList = in;
   }
-  
+
   public ArrayList<NTuple<Location>> getGlobalLocTupleSet() {
     return globalLocTupleList;
   }
index f73ef95b2aae42be59e2344f3e4edbaaaea9aeec..9fa81d47bda3d71990cbe30cda1986b419a33c04 100644 (file)
  * @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";
     }
 
index 1454902918954b2f7b7638a7409325329e0cb63a..01c2fe17d369f4b65e00d349f6e7b6801e31587e 100644 (file)
@@ -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.
    * <p>
-   * 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));
   }
 
index 4cc353e02d7ba3f92b068672561ef7e8d442c553..6da3f7e1d4a121f4309335eb6bcaec8c36c88c94 100644 (file)
  * @author Florian Frankenberger\r
  */\r
 \r
-\r
 public class DeviationScanner {\r
 \r
-  \r
   private EyePosition eyePositions[];\r
 \r
   // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),\r
@@ -47,8 +45,7 @@ public class DeviationScanner {
     eyePositions = new EyePosition[3];\r
   }\r
 \r
-  \r
-  public void addEyePosition( EyePosition eyePosition) {\r
+  public void addEyePosition(EyePosition eyePosition) {\r
 \r
     // for ( int i = 1; i < 3; i++) {\r
     // eyePositions[i - 1] = eyePositions[i];\r
@@ -60,24 +57,23 @@ public class DeviationScanner {
 \r
   }\r
 \r
-  // \r
-  \r
-  \r
-  public int scanForDeviation( Rectangle2D faceRect) {\r
+  //\r
+\r
+  public int scanForDeviation(Rectangle2D faceRect) {\r
 \r
-     int deviation = NONE;\r
+    int deviation = NONE;\r
 \r
-    for ( int i = 0; i < 3; i++) {\r
+    for (int i = 0; i < 3; i++) {\r
       if (eyePositions[i] == null) {\r
         return deviation;\r
       }\r
     }\r
 \r
-     double deviationX = 0;\r
-     double deviationY = 0;\r
+    double deviationX = 0;\r
+    double deviationY = 0;\r
 \r
-     int lastIdx = -1;\r
-    for ( int i = 0; i < 3; ++i) {\r
+    int lastIdx = -1;\r
+    for (int i = 0; i < 3; ++i) {\r
       if (lastIdx != -1) {\r
         deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX());\r
         deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY());\r
@@ -85,14 +81,14 @@ public class DeviationScanner {
       lastIdx = i;\r
     }\r
 \r
-     final double deviationPercentX = 0.04;\r
-     final double deviationPercentY = 0.04;\r
+    final double deviationPercentX = 0.04;\r
+    final double deviationPercentY = 0.04;\r
 \r
     deviationX /= faceRect.getWidth();\r
     deviationY /= faceRect.getWidth();\r
 \r
-     int deviationAbsoluteX = 0;\r
-     int deviationAbsoluteY = 0;\r
+    int deviationAbsoluteX = 0;\r
+    int deviationAbsoluteY = 0;\r
     if (deviationX > deviationPercentX)\r
       deviationAbsoluteX = 1;\r
     if (deviationX < -deviationPercentX)\r
@@ -114,8 +110,7 @@ public class DeviationScanner {
     return deviation;\r
   }\r
 \r
-  \r
-  public int getDirectionFor( int directionX,  int directionY) {\r
+  public int getDirectionFor(int directionX, int directionY) {\r
 \r
     if (directionX == +1 && directionY == -1) {\r
       return LEFT_UP;\r
@@ -145,7 +140,7 @@ public class DeviationScanner {
     eyePositions = new EyePosition[3];\r
   }\r
 \r
-  public String toStringDeviation( int dev) {\r
+  public String toStringDeviation(int dev) {\r
     if (dev == LEFT_UP) {\r
       return "LEFT_UP";\r
     } else if (dev == UP) {\r
index 699a620d8718ec3cae296dbfe109497dcf755810..e035b650c9e0d4bff9ef1ba443ad4e4d9c283c5c 100644 (file)
@@ -15,38 +15,44 @@ import de.darkblue.lea.ifaces.ICaptureDevice;
  */\r
 public class DummyCaptureDevice implements ICaptureDevice {\r
 \r
-       /**\r
+  /**\r
         * \r
         */\r
-       public DummyCaptureDevice() {\r
-               // TODO Auto-generated constructor stub\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see de.darkblue.lea.ifaces.ICaptureDevice#close()\r
-        */\r
-       @Override\r
-       public void close() {\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see de.darkblue.lea.ifaces.ICaptureDevice#getFrameRate()\r
-        */\r
-       @Override\r
-       public int getFrameRate() {\r
-               return 15;\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see de.darkblue.lea.ifaces.ICaptureDevice#getImage()\r
-        */\r
-       @Override\r
-       public BufferedImage getImage() {\r
-               BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);\r
-               Graphics2D g2d = (Graphics2D)image.getGraphics();\r
-               g2d.setColor(new Color(255, 255, 255));\r
-               g2d.fillRect(0, 0, 639, 479);\r
-               return image;\r
-       }\r
+  public DummyCaptureDevice() {\r
+    // TODO Auto-generated constructor stub\r
+  }\r
+\r
+  /*\r
+   * (non-Javadoc)\r
+   * \r
+   * @see de.darkblue.lea.ifaces.ICaptureDevice#close()\r
+   */\r
+  @Override\r
+  public void close() {\r
+  }\r
+\r
+  /*\r
+   * (non-Javadoc)\r
+   * \r
+   * @see de.darkblue.lea.ifaces.ICaptureDevice#getFrameRate()\r
+   */\r
+  @Override\r
+  public int getFrameRate() {\r
+    return 15;\r
+  }\r
+\r
+  /*\r
+   * (non-Javadoc)\r
+   * \r
+   * @see de.darkblue.lea.ifaces.ICaptureDevice#getImage()\r
+   */\r
+  @Override\r
+  public BufferedImage getImage() {\r
+    BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);\r
+    Graphics2D g2d = (Graphics2D) image.getGraphics();\r
+    g2d.setColor(new Color(255, 255, 255));\r
+    g2d.fillRect(0, 0, 639, 479);\r
+    return image;\r
+  }\r
 \r
 }\r
index 11443ab58bc6de16bfe67e642883a3f2c313ba65..d162bc0c446c17931d94ab322e0109ed9f1a6b45 100644 (file)
  * @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);
   }
index 500b00860f3d13415173374040fd81b167da5375..be45cee383b535b0bb9b2134418967f316bb2c65 100644 (file)
  * @author Florian Frankenberger
  */
 
-
 public class EyePosition {
-  
+
   private int x;
-  
+
   private int y;
-  
+
   private Rectangle2D faceRect;
 
   public EyePosition(Point p, Rectangle2D faceRect) {
index cf24488ee9a716d631c0c0ed015590bc77319b51..e1d94503624c7de56116f34a8944b6fa499a464a 100644 (file)
  * @author Florian Frankenberger
  */
 
-
 public class FaceAndEyePosition {
 
-  
   private Rectangle2D facePosition;
-  
+
   private EyePosition eyePosition;
 
   public FaceAndEyePosition(Rectangle2D facePosition, EyePosition eyePosition) {
index f050a978e7abec7918a46ab904e540407813b372..2caa04a9d06fb45fadec794ef994ef02ed6d4c8f 100644 (file)
  * along with LEA. If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 \r
-\r
 import java.awt.image.BufferedImage;\r
 \r
 /**\r
- * Describes a capture device. For now it is only tested\r
- * with images in <code>640x480</code> at <code>RGB</code> or <code>YUV</code> color space.\r
+ * Describes a capture device. For now it is only tested with images in <code>640x480</code> at\r
+ * <code>RGB</code> or <code>YUV</code> color space.\r
  * \r
  * @author Florian Frankenberger\r
  */\r
 public interface ICaptureDevice {\r
 \r
-       /**\r
-        * Returns the frame rate of the image source per second\r
-        * \r
-        * @return the frame rate (e.g. 15 = 15 frames per second)\r
-        */\r
-       public int getFrameRate();\r
+  /**\r
+   * Returns the frame rate of the image source per second\r
+   * \r
+   * @return the frame rate (e.g. 15 = 15 frames per second)\r
+   */\r
+  public int getFrameRate();\r
+\r
+  /**\r
+   * Will be called a maximum of getFrameRate()-times in a second and returns the actual image of\r
+   * the capture device\r
+   * \r
+   * @return the actual image of the capture device\r
+   */\r
+  public BufferedImage getImage();\r
+\r
+  /**\r
+   * LEA calls this when it cleans up. You should put your own cleanup code in here.\r
+   */\r
+  public void close();\r
 \r
-       /**\r
-        * Will be called a maximum of getFrameRate()-times in a second and returns\r
-        * the actual image of the capture device\r
-        *  \r
-        * @return the actual image of the capture device \r
-        */\r
-       public BufferedImage getImage();\r
-       \r
-       /**\r
-        * LEA calls this when it cleans up. You should put your own cleanup code in here.\r
-        */\r
-       public void close();\r
-       \r
-       \r
 }\r
index d91a7e4a2f6d3fd9039a6e8ae6820ec07450ce7d..5245320355a2ed5ccb669897b79be0b2da9aae9e 100644 (file)
@@ -1,12 +1,10 @@
 
-
 public class Image {
 
-  
   int width;
-  
+
   int height;
-  
+
   int pixel[][];
 
   public Image(int width, int height) {
index d517a3734f511a3ad157273e7ffb31000178e1fe..80d7782bb3a916f5f8b800d4dc882e1bc3e25a5e 100644 (file)
  * @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();
+  }
+
 }
index 48a157752b0dc895cf0efd1c59efd1f0fe784277..b3fda528ca22f3fbb7132eed91fb559a90b00939 100644 (file)
 /**
  * This is the main class of LEA.
  * <p>
- * It uses a face detection algorithm to find an a face within the provided
- * image(s). Then it searches for the eye in a region where it most likely
- * located and traces its position relative to the face and to the last known
- * position. The movements are estimated by comparing more than one movement. If
- * a movement is distinctly pointing to a direction it is recognized and all
- * listeners get notified.
+ * It uses a face detection algorithm to find an a face within the provided image(s). Then it
+ * searches for the eye in a region where it most likely located and traces its position relative to
+ * the face and to the last known position. The movements are estimated by comparing more than one
+ * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
+ * get notified.
  * <p>
  * The notification is designed as observer pattern. You simply call
- * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an
- * implementation of <code>IEyeMovementListener</code> to LEA. When a face is
- * recognized/lost or whenever an eye movement is detected LEA will call the
- * appropriate methods of the listener
+ * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
+ * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
+ * movement is detected LEA will call the appropriate methods of the listener
  * <p>
- * LEA also needs an image source implementing the <code>ICaptureDevice</code>.
- * One image source proxy to the <code>Java Media Framework</code> is included (
- * <code>JMFCaptureDevice</code>).
+ * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
+ * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
  * <p>
  * Example (for using LEA with <code>Java Media Framework</code>):
  * <p>
  * LEA lea = new LEA(new JMFCaptureDevice(), true);
  * </code>
  * <p>
- * This will start LEA with the first available JMF datasource with an extra
- * status window showing if face/eye has been detected successfully. Please note
- * that face detection needs about 2 seconds to find a face. After detection the
- * following face detection is much faster.
+ * This will start LEA with the first available JMF datasource with an extra status window showing
+ * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
+ * to find a face. After detection the following face detection is much faster.
  * 
  * @author Florian Frankenberger
  */
 
-
 public class LEA {
 
-  
   private LEAImplementation implementation;
-  
+
   private FaceAndEyePosition lastPositions = new FaceAndEyePosition(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
-   *         <code>Java Media Framework</code> just start from here.
+   * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
+   *         just start from here.
    * 
    * @param args
    * @throws Exception
@@ -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);
index 998cd69b43f9af9e811d41f2533c98a917ba01a9..b9dc7d39c9b3543a4e03fc2d2bfb2bedf8185aeb 100644 (file)
  * @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() {
 
index beb0545ff17821cc6a2d082529012ccc842a5cec..a3b6c37cc3ec5d2f7609fedfa34102e6118baf3d 100644 (file)
@@ -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 + ")";
   }
 
 }
index e765e70c11df70a2d1afcd00101fb01ba595920e..ae538162d49a73b6622debb51cc49ad42965e10a 100644 (file)
@@ -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;
index abb581b04e81c6d9f969bcfff7edf1c3967b54bd..62e9b4aebbd214debc0624ba879e84780646a950 100644 (file)
  * @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;