BallDetector(boolean _display) { ctx = Freenect.createContext(); if (ctx.numDevices() > 0) { kinect = ctx.openDevice(0); } else { System.err.println("WARNING: No kinects detected"); return; } display = _display; controlFrame = new JFrame("Controls"); controlFrame.setLayout(new GridLayout(5, 1)); controlFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pg = new ParameterGUI(); pg.addIntSlider("maxDepth", "max depth", 800, 2047, 1050); pg.addIntSlider("blobThresh", "blob thresh", 1, 500, 125); pg.addIntSlider("thresh", "thresh", 1, 100, 10); pg.addIntSlider("frames", "frames", 1, 1000, 1); pg.addListener( new ParameterListener() { public void parameterChanged(ParameterGUI _pg, String name) { if (name.equals("thresh")) { KinectDepthVideo.THRESH = _pg.gi(name); } else if (name.equals("frames")) { KinectDepthVideo.MAX_FRAMES = _pg.gi(name); } else if (name.equals("maxDepth")) { KinectDepthVideo.MAX_DEPTH = _pg.gi(name); } } }); controlFrame.add(pg, 0, 0); startTracking = new JButton("Start Tracking Balls"); startTracking.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!tracking) { tracking = true; colorStream.pause(); depthStream.pause(); startTracking.setText("Stop Tracking"); } else { tracking = false; colorStream.resume(); depthStream.resume(); startTracking.setText("Start Tracking Balls"); } } }); controlFrame.add(startTracking, 1, 0); resetProjectile = new JButton("Reset Projectile"); resetProjectile.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { lcm.publish("6_RESET", "reset"); } catch (IOException ex) { System.out.println("can't publish reset"); } } }); controlFrame.add(resetProjectile, 2, 0); resetDepth = new JButton("Reset Depth Avgs"); resetDepth.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { DepthClearer ic = new DepthClearer(pg); ic.start(); } }); controlFrame.add(resetDepth, 3, 0); JPanel scoreButtons = new JPanel(new GridLayout(1, 3)); JButton addHuman = new JButton("human++"); addHuman.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { lcm.publish("6_SCORE_HUMAN", "bish"); } catch (IOException ex) { System.out.println("can't publish score"); } } }); JButton addRobot = new JButton("robot++"); addRobot.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { lcm.publish("6_SCORE_ROBOT", "bish"); } catch (IOException ex) { System.out.println("can't publish score"); } } }); JButton resetScores = new JButton("reset scores"); resetScores.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { lcm.publish("6_SCORE_RESET", "bish"); } catch (IOException ex) { System.out.println("can't publish score"); } } }); scoreButtons.add(addHuman, 0, 0); scoreButtons.add(addRobot, 0, 1); scoreButtons.add(resetScores, 0, 2); controlFrame.add(scoreButtons, 4, 0); controlFrame.setSize(800, 600); controlFrame.setVisible(true); colorFrame = new JFrame("color feed"); colorMonitor = new Object(); colorStream = new KinectRGBVideo(kinect, colorMonitor, display); colorFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); colorFrame.addWindowListener(new RGBClose()); colorFrame.setSize(KinectVideo.WIDTH, KinectVideo.HEIGHT); colorFrame.setContentPane(colorStream); colorFrame.setVisible(true); depthFrame = new JFrame("depth feed"); depthMonitor = new Object(); depthStream = new KinectDepthVideo(kinect, depthMonitor, display); depthFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); depthFrame.setSize(KinectVideo.WIDTH, KinectVideo.HEIGHT); depthFrame.setContentPane(depthStream); depthFrame.setVisible(true); rgbImg = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB); depthImg = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB); validImageValue = new boolean[KinectVideo.WIDTH * KinectVideo.HEIGHT]; try { lcm = new LCM("udpm://239.255.76.67:7667?ttl=1"); } catch (IOException e) { lcm = LCM.getSingleton(); } BALL = new Statistics(); finder = new BallTracker(KinectVideo.WIDTH, KinectVideo.HEIGHT, false); if (display) { depthImg = depthStream.getFrame(); rgbImg = colorStream.getFrame(); } // get robot position from click depthStream.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { Point botPix = e.getPoint(); botStart = depthStream.getWorldCoords(botPix); botStart.z += 0.08; System.out.println("botStart: " + botStart.toString()); depthStream.showSubtraction(); depthStream.botLoc = botPix; } }); DepthClearer ic = new DepthClearer(pg); ic.start(); }
public LJ3MDApp() { tNum.setHorizontalAlignment(JTextField.CENTER); tTemp.setHorizontalAlignment(JTextField.CENTER); tRho.setHorizontalAlignment(JTextField.CENTER); tSpeed.setHorizontalAlignment(JTextField.CENTER); tAvK.setHorizontalAlignment(JTextField.RIGHT); tAvU.setHorizontalAlignment(JTextField.RIGHT); tAvp.setHorizontalAlignment(JTextField.RIGHT); float[] aveKing = new float[501]; float[] avePot = new float[501]; float[] aveEn = new float[501]; JFrame box = new JFrame(); box.setLayout(new BorderLayout()); box.setSize(1000, 1000); box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cpnl = new JPanel(); // create a panel for controls cpnl.setLayout(new GridLayout(18, 2)); box.add(cpnl, BorderLayout.EAST); // add controls cpnl.add(bStart); bStart.addActionListener(this); cpnl.add(bReset); bReset.addActionListener(this); cpnl.add(new JLabel(" N:")); tNum.addActionListener(this); cpnl.add(tNum); cpnl.add(new JLabel(" Density (\u03c1):")); tRho.addActionListener(this); cpnl.add(tRho); cpnl.add(new JLabel(" Steps/frame:")); tSpeed.addActionListener(this); cpnl.add(tSpeed); cpnl.add(bTstat); bTstat.addActionListener(this); cpnl.add(bPot); bPot.addActionListener(this); cpnl.add(new JLabel(" < K/N > :")); tAvK.setEditable(false); cpnl.add(tAvK); cpnl.add(new JLabel(" Temperature:")); tTemp.setEditable(false); cpnl.add(tTemp); cpnl.add(new JLabel(" < U/N > :")); tAvU.setEditable(false); cpnl.add(tAvU); cpnl.add(new JLabel(" < pressure > :")); tAvp.setEditable(false); cpnl.add(tAvp); cpnl.add(bRetime); bRetime.addActionListener(this); spnl = new JPanel(); // create a panel for status box.add(spnl, BorderLayout.SOUTH); lStatus.setFont(new Font("Courier", 0, 12)); spnl.add(lStatus); canvas = new XYZCanvas(); box.add(canvas, BorderLayout.CENTER); timer = new Timer(delay, this); timer.start(); // timer.stop(); box.setVisible(true); }