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
public void mouseReleased(MouseEvent mouseEvent) {
if (!panel.getStroke().isEmpty())
monIvy.sendMsg("coord=" + panel.getStroke().toString());
if (!panel.getStroke().isEmpty()) {
panel.getStroke().normalize();
System.out.println(panel.getStroke());
Reconnaissance.comparaison(Reconnaissance.reconnaissance(panel.getStroke(), Forme.ROND.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.CARRE.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.TRAIT.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.Z.split(";")));
panel.getStroke().normalize();
String result = Reconnaissance.comparaison(Reconnaissance.reconnaissance(panel.getStroke(), Forme.ROND.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.CARRE.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.TRAIT.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)));
cpt++;
}
System.out.println(result);
return result;
}
public static void comparaison(int rond, int carre, int trait, int z) {
if ((carre < rond) && (carre < trait) && (carre < z)) {
System.out.println("C'est un carre");
} else if ((rond < carre) && (rond < trait) && (rond < z)) {
System.out.println("c'est un rond");
} 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");
public static String comparaison(int rond, int carre, int trait, int z) {
String result = null;
if(!isCorrect(rond) && !isCorrect(carre) &&!isCorrect(trait) &&!isCorrect(z) )
{
result="ERROR";
}
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 {
// initialization, name and ready message
bus = new Ivy("IvyTranslater", "Geste", null);
// classical subscription
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
bus.start("172.31.190.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) {
try {