envoi de la forme par Ivy
seuil reconnaissance de la forme
This commit is contained in:
		| @@ -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(";")), | ||||
|                     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); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -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"); | ||||
|     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)) { | ||||
|             System.out.println("c'est un rond"); | ||||
|             result="ROND"; | ||||
|         } else if ((trait < carre) && (trait < rond) && (trait < z)) { | ||||
|             System.out.println("c'est un trait"); | ||||
|             result="TRAIT"; | ||||
|         } else if ((z < carre) && (z < rond) && (z < trait)) { | ||||
|             System.out.println("c'est un z"); | ||||
|             result="Z"; | ||||
|         } | ||||
|         else{ | ||||
|             result="ERROR"; | ||||
|         } | ||||
|     return result; | ||||
|     } | ||||
|  | ||||
|     public static boolean isCorrect(int forme){ | ||||
|         boolean result = true; | ||||
|         if(forme > 1000){ | ||||
|             result = false; | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user