// 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();
Map<MethodInvokeNode, FlowReturnNode> mapMethodInvokeNodeToFlowReturnNode;
+ Map<Descriptor, ClassDescriptor> mapIntersectionDescToEnclosingDescriptor;
+
public static int interseed = 0;
boolean debug = true;
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
}
+ 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;
}
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) {
public FlowNode createNewFlowNode(NTuple<Descriptor> tuple) {
+ // System.out.println("createNewFlowNode=" + tuple);
if (!mapDescTupleToInferNode.containsKey(tuple)) {
FlowNode node = new FlowNode(tuple);
mapDescTupleToInferNode.put(tuple, node);
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));
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);
}
}
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();
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);
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;
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)) {
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;
}
public void setCompositeLocation(CompositeLocation in) {
+ System.out.println("$$$set compLoc=" + in);
compLoc = in;
}
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));
Descriptor lastDescOfPrefix = nodeDescTuple.get(0);
Descriptor enclosingDescriptor;
if (lastDescOfPrefix instanceof InterDescriptor) {
- enclosingDescriptor = null;
+ enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(lastDescOfPrefix);
} else {
enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
}
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);
// 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);
// // 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>();
}
}
- 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) + "\")";
}
rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
+ } else {
+ rtr += "\")";
}
return rtr;
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
} 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;
}
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();
newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
newImplicitTupleSet.addTupleSet(condTupleNode);
+ System.out.println("A5");
newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet());
newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
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,
// translateToLocTuple(md, callerImplicitTuple));
// }
// }
+ System.out.println("A4");
newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
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);
newImplicitTupleSet.addTuple(interTuple);
}
+ System.out.println("A7");
newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet);
analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
newImplicitTupleSet, false);
+ System.out.println("A8");
nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
nodeSet.addTupleSet(tertiaryTupleNode);
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);
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();
// 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);
-
}
}
}
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,
|| mdCallee.getModifiers().isNative()) {
addParamNodeFlowingToReturnValue(mdCallee, paramNode);
// nodeSet.addTupleSet(argTupleSet);
+ System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode);
tupleSet.addTupleSet(argTupleSet);
}
}
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());
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);
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);
}
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);
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();
nodeSet.addTupleSet(leftOpSet);
nodeSet.addTupleSet(rightOpSet);
+ System.out.println("A6");
nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet());
nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet());
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());
}
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));
}
}
if (nodeSet != null) {
nodeSet.addTupleSet(nodeSetLHS);
+ System.out.println("A2");
nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet());
}
}
private ArrayList<NTuple<Location>> globalLocTupleList;
+ private NTuple<Descriptor> baseDescTuple;
+
public NodeTupleSet() {
list = new ArrayList<NTuple<Descriptor>>();
globalLocTupleList = new ArrayList<NTuple<Location>>();
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);
}
private void setGlobalLocTupleList(ArrayList<NTuple<Location>> in) {
globalLocTupleList = in;
}
-
+
public ArrayList<NTuple<Location>> getGlobalLocTupleSet() {
return globalLocTupleList;
}
* @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) {
*
* @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] +=
// 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]);
}
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";
}
* @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,
(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
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;
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;
}
-
-
- private static int sgn( float value) {
+ private static int sgn(float value) {
return (value < 0 ? -1 : (value > 0 ? +1 : 1));
}
* @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
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
\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
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
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
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
*/\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
* @author Florian Frankenberger
*/
-
class EyeDetector {
-
private int width;
-
+
private int height;
-
+
private int[] pixelBuffer;
-
+
double percent;
public EyeDetector(Image image, Rectangle2D faceRect) {
}
-
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);
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);
}
* @author Florian Frankenberger
*/
-
public class EyePosition {
-
+
private int x;
-
+
private int y;
-
+
private Rectangle2D faceRect;
public EyePosition(Point p, Rectangle2D faceRect) {
* @author Florian Frankenberger
*/
-
public class FaceAndEyePosition {
-
private Rectangle2D facePosition;
-
+
private EyePosition eyePosition;
public FaceAndEyePosition(Rectangle2D facePosition, EyePosition eyePosition) {
* 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
-
public class Image {
-
int width;
-
+
int height;
-
+
int pixel[][];
public Image(int width, int height) {
* @author Florian Frankenberger
*/
-
public class IntegralImageData {
-
private long[][] integral;
-
+
private int width;
-
+
private int hegith;
// private Dimension dimension;
}
- public long getIntegralAt( int x, int y) {
+ public long getIntegralAt(int x, int y) {
return this.integral[x][y];
}
return hegith;
}
+ public String toString() {
+ super.toString();
+ }
+
}
/**
* 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() {
}
/**
- * Clears the internal movement buffer. If you just capture some of the eye
- * movements you should call this every time you start recording the
- * movements. Otherwise you may get notified for movements that took place
- * BEFORE you started recording.
+ * Clears the internal movement buffer. If you just capture some of the eye movements you should
+ * call this every time you start recording the movements. Otherwise you may get notified for
+ * movements that took place BEFORE you started recording.
*/
public void clear() {
// this.imageProcessor.clearDeviationScanner();
}
/**
- * @METHOD To test LEA with the first capture device from the
- * <code>Java Media Framework</code> just start from here.
+ * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
+ * just start from here.
*
* @param args
* @throws Exception
lea.doRun();
}
-
public void doRun() {
- int i = 0;
+ int i = 0;
SSJAVA: while (true) {
- Image image = ImageReader.getImage();
+ Image image = ImageReader.getImage();
if (image == null) {
break;
}
System.out.println("Done.");
}
-
- private void processImage( Image image) {
- FaceAndEyePosition positions = implementation.getEyePosition(image);
+ 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);
* @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);
}
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();
}
}
/**
- * 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() {
-
-
public class Point {
- public int x;
- public int y;
+ public int x;
+ public int y;
public Point(int x, int y) {
this.x = x;
public Point() {
}
-
- public String toString(){
- return "("+x+","+y+")";
+
+ public String toString() {
+ return "(" + x + "," + y + ")";
}
}
-
-
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;
* @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
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));
}
// }
public String toString() {
- String str = "";
+ String str = "";
str += "fromPoint=(" + fromPoint.x + "," + fromPoint.y + ")";
str += "toPoint=(" + toPoint.x + "," + toPoint.y + ")";
str += "size=" + size;