ObjectLabelingCanvas.java
Go to the documentation of this file.
00001 package edu.tum.cs.ias.knowrob;
00002 
00003 import java.awt.event.MouseListener;
00004 import java.awt.event.MouseMotionListener;
00005 import controlP5.ControlP5;
00006 import processing.core.*;
00007 import ros.*;
00008 import ros.pkg.mesh_label_node.srv.LabelMesh;
00009 
00010 
00011 public class ObjectLabelingCanvas extends PApplet implements MouseListener, MouseMotionListener {
00012 
00013         private static final long serialVersionUID = 4575739930038583994L;
00014         public enum Part {KITCHEN_VIS, ACTION_VIS, VIDEO, ALL}; 
00015 
00016           
00017         static Ros ros;
00018         static NodeHandle n;
00022         protected static void initRos() {
00023 
00024         ros = Ros.getInstance();
00025 
00026                 if(!Ros.getInstance().isInitialized()) {
00027                 ros.init("knowrob_comm_vis_applet");
00028                 }
00029                 n = ros.createNodeHandle();
00030 
00031         }       
00032         
00033         // components
00034         protected MeshLabelApplet label_applet;
00035         protected MeshVisApplet mesh_applet;
00036         
00037         public ControlP5 controlP5;
00038         
00039         private String label="";
00040         private String label_set="";
00041         
00042         public ObjectLabelingCanvas() {
00043                 
00044                 this.init();
00045 
00046 
00047                 label_applet = new MeshLabelApplet();
00048                 label_applet.setSize(700, 80);
00049                 label_applet.init();
00050                 
00051                 label_applet.setObjectLabelingCanvas(this);
00052                 
00053                 mesh_applet = new MeshVisApplet();
00054                 mesh_applet.setSize(700, 600);
00055                 mesh_applet.init();
00056                 
00057                 this.add(label_applet);
00058                 this.add(mesh_applet);
00059         
00060 
00061                 // start ROS environment
00062                 new LabelMeshCallback();
00063             
00064             Thread startRosServices = new Thread( new RosServiceThread() ); 
00065             startRosServices.start();
00066                 
00067                 
00068                 this.setSize(700, 700);
00069                 this.draw();
00070                 this.setVisible(true);
00071                 
00072         }
00073         
00074         
00075         public void draw() {
00076                 background(20, 20, 20);
00077         }
00078 
00079         
00087           public class RosServiceThread implements Runnable {
00088                 
00089                 @Override public void run() {
00090                         
00091                         try {
00092 
00093                                 initRos();
00094                                 
00095                                 n.advertiseService("/mesh_label_node",  new LabelMesh(),  new LabelMeshCallback());
00096                                 ros.spin();
00097                                 
00098                         } catch(RosException e) {
00099                                 e.printStackTrace();
00100                         }
00101                 }
00102           }
00103         
00111                 class LabelMeshCallback implements ServiceServer.Callback<LabelMesh.Request, LabelMesh.Response> {
00112                         
00113                         @Override
00114                         public LabelMesh.Response call(LabelMesh.Request req) {
00115 
00116                                 LabelMesh.Response res = new LabelMesh.Response();
00117                                 res.label = "";
00118 
00119                                 if (req.mesh != null) {
00120                                         
00121                                         mesh_applet.readTriangleMesh(req.mesh);
00122                                         
00123                                         // wait for the GUI to set the label and notify me
00124                                         synchronized( label_set ) 
00125                                         { 
00126                                           try { 
00127                                             label_set.wait(); 
00128                                             res.label = label;
00129                                             return res;
00130                                             
00131                                           } catch ( InterruptedException e ) { 
00132                                                   e.printStackTrace();
00133                                           } 
00134                                         }
00135                                 }
00136                                 return res;
00137                                 
00138                         }
00139                 }
00140                 
00141         // called from the GUI: label set, notify waiting ROS answer thread
00142         public void setLabel(String l) {
00143                 
00144                 synchronized(label_set) {
00145                         label=l;
00146                         label_set.notify();
00147                 }
00148         }
00149                 
00150                 
00151         public static void main(String args[]) {
00152                 PApplet.main(new String[] { "edu.tum.cs.ias.knowrob.ObjectLabelingCanvas" });
00153         }
00154 }
00155 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


mesh_label_node
Author(s): Moritz Tenorth
autogenerated on Thu May 23 2013 16:34:49