Normand Briere
2016-02-27 28ab4dad99d24372ea58b09a00eafbce1291c278
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package mocap.gui;
 
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.util.Vector;
 
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.vecmath.Vector3d;
 
import mocap.JMocap;
import mocap.figure.MotionTrailPoint;
 
/**
 * GUI for testing motion trail visualization.
 *
 * @author Quan Nguyen
 */
public class MotionTrailsControllerGUI extends JFrame
{
 
    private JMocap _jmocap;
    private JTextField _jftStartFrame;
    private JTextField _jftEndFrame;
    private JLabel _jlColor;
    private JTextField _jtfJoint;
    private JButton _jbShowPath;
 
    public MotionTrailsControllerGUI(JMocap jmocap)
    {
        super("Path Controller");
        _jmocap = jmocap;
        initComponents();
    }
 
    private void initComponents()
    {
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
 
        this.setLayout(new GridLayout(/* 3 */0, 2, 6, 3));
 
        this.add(new JLabel(" Start time in sec.:"));
        _jftStartFrame = new JTextField("1");
        this.add(_jftStartFrame);
        this.add(new JLabel(" End time:"));
        _jftEndFrame = new JTextField("4");
        this.add(_jftEndFrame);
        this.add(new JLabel(" Color: "));
        _jlColor = new JLabel();
        _jlColor.setBackground(Color.MAGENTA);
        _jlColor.setOpaque(true);
        this.add(_jlColor);
        this.add(new JLabel(" Joint: "));
        _jtfJoint = new JTextField("rhand");
        this.add(_jtfJoint);
 
        this.add(new JLabel());
        Action showPathAction = new AbstractAction("Show path")
        {
 
            public void actionPerformed(ActionEvent evt)
            {
                showPath();
//                moveJoint();
            }
        };
        _jbShowPath = new JButton(showPathAction);
        this.add(_jbShowPath);
 
        this.pack();
        this.setVisible(true);
 
    }
 
    private void showPath()
    {
        if (_jmocap != null) {
            _jmocap.addMotionTrail(showMotionTrails(
                    Double.parseDouble(_jftStartFrame.getText()),
                    Double.parseDouble(_jftEndFrame.getText()),
                    Color.magenta,
                    _jtfJoint.getText()));
        } else {
            System.out.println("No Mocap");
        }
    }
 
    private void moveJoint()
    {
        _jmocap.getFigure().getSkeleton().setBaseRotDeg(new Vector3d(10, 90, 10));
        _jmocap.getFigure().getSkeleton().setBaseTranslation(new Vector3d(1, 1, 1));
    }
 
    private Vector<MotionTrailPoint> showMotionTrails(double start, double end,
            Color color, String bone)
    {
 
        Vector<MotionTrailPoint> vMotionTrailPoints = new Vector<MotionTrailPoint>();
 
        double dDistance = 1 / (float) _jmocap.getFigure().getPlayer().getPlaybackFps();
        if (bone != null) {
            for (double i = start; i < end; i += dDistance) {
                System.out.println("showMotionTrails::time::" + i);
                vMotionTrailPoints.add(new MotionTrailPoint(bone, i, color));
            }
        }
        System.out.println("showMotionTrails::vMotionTrailPoints::" + vMotionTrailPoints.size());
        return vMotionTrailPoints;
    }
}