envoi de la forme par Ivy

seuil reconnaissance de la forme
This commit is contained in:
DonRenando 2017-01-18 15:18:37 +01:00
parent f8cc3d5cfe
commit 26e681792e
3 changed files with 38 additions and 45 deletions

View File

@ -41,15 +41,18 @@ class Fenetre extends JFrame {
@Override @Override
public void mouseReleased(MouseEvent mouseEvent) { public void mouseReleased(MouseEvent mouseEvent) {
if (!panel.getStroke().isEmpty()) if (!panel.getStroke().isEmpty()) {
monIvy.sendMsg("coord=" + panel.getStroke().toString());
panel.getStroke().normalize(); panel.getStroke().normalize();
System.out.println(panel.getStroke()); String result = Reconnaissance.comparaison(Reconnaissance.reconnaissance(panel.getStroke(), Forme.ROND.split(";")),
Reconnaissance.comparaison(Reconnaissance.reconnaissance(panel.getStroke(), Forme.ROND.split(";")), Reconnaissance.reconnaissance(panel.getStroke(), Forme.CARRE.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.CARRE.split(";")), Reconnaissance.reconnaissance(panel.getStroke(), Forme.TRAIT.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.TRAIT.split(";")), Reconnaissance.reconnaissance(panel.getStroke(), Forme.Z.split(";")));
Reconnaissance.reconnaissance(panel.getStroke(), Forme.Z.split(";"))); System.out.println(result);
monIvy.sendMsg("Geste forme=" + result);
}
} }

View File

@ -31,20 +31,37 @@ public class Reconnaissance {
result += (int) Math.sqrt((Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2))); result += (int) Math.sqrt((Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2)));
cpt++; cpt++;
} }
System.out.println(result);
return result; return result;
} }
public static void comparaison(int rond, int carre, int trait, int z) { public static String comparaison(int rond, int carre, int trait, int z) {
if ((carre < rond) && (carre < trait) && (carre < z)) { String result = null;
System.out.println("C'est un carre"); if(!isCorrect(rond) && !isCorrect(carre) &&!isCorrect(trait) &&!isCorrect(z) )
} else if ((rond < carre) && (rond < trait) && (rond < z)) { {
System.out.println("c'est un rond"); result="ERROR";
} else if ((trait < carre) && (trait < rond) && (trait < z)) {
System.out.println("c'est un trait");
} else if ((z < carre) && (z < rond) && (z < trait)) {
System.out.println("c'est un z");
} }
else if ((carre < rond) && (carre < trait) && (carre < z)) {
result="RECTANGLE";
} else if ((rond < carre) && (rond < trait) && (rond < z)) {
result="ROND";
} else if ((trait < carre) && (trait < rond) && (trait < z)) {
result="TRAIT";
} else if ((z < carre) && (z < rond) && (z < trait)) {
result="Z";
}
else{
result="ERROR";
}
return result;
}
public static boolean isCorrect(int forme){
boolean result = true;
if(forme > 1000){
result = false;
}
return result;
} }
} }

View File

@ -11,36 +11,9 @@ class ivyTranslater implements IvyMessageListener {
ivyTranslater() throws IvyException { ivyTranslater() throws IvyException {
// initialization, name and ready message // initialization, name and ready message
bus = new Ivy("IvyTranslater", "Geste", null); bus = new Ivy("IvyTranslater", "Geste", null);
// classical subscription bus.start("172.31.190.255:2010"); // starts the bus on the default domain
bus.bindMsg("sra5 Parsed=(.*) Confidence", this);
// inner class subscription ( think awt )
bus.bindMsg("^Bye$", (client, args) -> {
// leaves the bus, and as it is the only thread, quits
bus.stop();
});
bus.start("127.255.255.255:2010"); // starts the bus on the default domain
} }
// callback associated to the "Hello" messages"
void recevoire(Panel panel) throws IvyException {
panel.stroke = new Stroke();
bus.bindMsg("^coord=(.*)", (client, args) -> {
if (args[0] != null) {
panel.stroke = new Stroke();
String[] listeCoor = args[0].split(";");
String x;
String y;
for (String coor : listeCoor) {
x = coor.split(",")[0].replace(".0", "");
y = coor.split(",")[1].replace(".0", "");
panel.getStroke().addPoint(Integer.parseInt(x), Integer.parseInt(y));
}
panel.repaint();
}
});
}
void sendMsg(String msg) { void sendMsg(String msg) {
try { try {