Search in sources :

Example 1 with LeapMotionEditorEventWithFrame

use of org.jwildfire.create.tina.leapmotion.LeapMotionEditorListenerRecorder.LeapMotionEditorEventWithFrame in project JWildfire by thargor6.

the class LeapMotionControllerHolder method compress.

private List<LeapMotionEditorEventWithFrame> compress(List<LeapMotionEditorEventWithFrame> pInput) {
    Map<Integer, List<LeapMotionEditorEventWithFrame>> map = new HashMap<Integer, List<LeapMotionEditorEventWithFrame>>();
    for (LeapMotionEditorEventWithFrame event : pInput) {
        int frame = Tools.FTOI(event.getFrame());
        List<LeapMotionEditorEventWithFrame> lst = map.get(frame);
        if (lst == null) {
            lst = new ArrayList<LeapMotionEditorEventWithFrame>();
            map.put(frame, lst);
        }
        lst.add(event);
    }
    List<Integer> sortedFrames = new ArrayList<Integer>(map.keySet());
    Collections.sort(sortedFrames);
    List<LeapMotionEditorEventWithFrame> res = new ArrayList<LeapMotionEditorEventWithFrame>();
    for (Integer frame : sortedFrames) {
        LeapMotionEditorEventWithFrame compressed = new LeapMotionEditorEventWithFrame();
        compressed.setFrame(frame);
        int cnt = 0;
        for (LeapMotionEditorEventWithFrame src : map.get(frame)) {
            compressed.getLeftHand().setPosX(compressed.getLeftHand().getPosX() + src.getLeftHand().getPosX());
            compressed.getLeftHand().setPosY(compressed.getLeftHand().getPosY() + src.getLeftHand().getPosY());
            compressed.getLeftHand().setPosZ(compressed.getLeftHand().getPosZ() + src.getLeftHand().getPosZ());
            compressed.getLeftHand().setRoll(compressed.getLeftHand().getRoll() + src.getLeftHand().getRoll());
            compressed.getLeftHand().setPitch(compressed.getLeftHand().getPitch() + src.getLeftHand().getPitch());
            compressed.getLeftHand().setYaw(compressed.getLeftHand().getYaw() + src.getLeftHand().getYaw());
            compressed.getRightHand().setPosX(compressed.getRightHand().getPosX() + src.getRightHand().getPosX());
            compressed.getRightHand().setPosY(compressed.getRightHand().getPosY() + src.getRightHand().getPosY());
            compressed.getRightHand().setPosZ(compressed.getRightHand().getPosZ() + src.getRightHand().getPosZ());
            compressed.getRightHand().setRoll(compressed.getRightHand().getRoll() + src.getRightHand().getRoll());
            compressed.getRightHand().setPitch(compressed.getRightHand().getPitch() + src.getRightHand().getPitch());
            compressed.getRightHand().setYaw(compressed.getRightHand().getYaw() + src.getRightHand().getYaw());
            cnt++;
        }
        compressed.getLeftHand().setPosX(compressed.getLeftHand().getPosX() / (double) cnt);
        compressed.getLeftHand().setPosY(compressed.getLeftHand().getPosY() / (double) cnt);
        compressed.getLeftHand().setPosZ(compressed.getLeftHand().getPosZ() / (double) cnt);
        compressed.getLeftHand().setRoll(compressed.getLeftHand().getRoll() / (double) cnt);
        compressed.getLeftHand().setPitch(compressed.getLeftHand().getPitch() / (double) cnt);
        compressed.getLeftHand().setYaw(compressed.getLeftHand().getYaw() / (double) cnt);
        compressed.getRightHand().setPosX(compressed.getRightHand().getPosX() / (double) cnt);
        compressed.getRightHand().setPosY(compressed.getRightHand().getPosY() / (double) cnt);
        compressed.getRightHand().setPosZ(compressed.getRightHand().getPosZ() / (double) cnt);
        compressed.getRightHand().setRoll(compressed.getRightHand().getRoll() / (double) cnt);
        compressed.getRightHand().setPitch(compressed.getRightHand().getPitch() / (double) cnt);
        compressed.getRightHand().setYaw(compressed.getRightHand().getYaw() / (double) cnt);
        res.add(compressed);
    }
    return res;
}
Also used : LeapMotionEditorEventWithFrame(org.jwildfire.create.tina.leapmotion.LeapMotionEditorListenerRecorder.LeapMotionEditorEventWithFrame) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with LeapMotionEditorEventWithFrame

use of org.jwildfire.create.tina.leapmotion.LeapMotionEditorListenerRecorder.LeapMotionEditorEventWithFrame in project JWildfire by thargor6.

the class LeapMotionControllerHolder method applyMotionToFlame.

private void applyMotionToFlame(LeapMotionEditorListenerRecorder pRecorder, Flame pFlame) {
    List<LeapMotionEditorEventWithFrame> dataList = pRecorder.getTransformedData();
    dataList = compress(dataList);
    if (dataList.size() > 1) {
        LeapMotionConnectedProperties config = pRecorder.getConfig();
        for (LeapMotionConnectedProperty property : config.getProperties()) {
            MotionCurve curve = property.getOutputChannel().getMotionCurve(property, pFlame);
            if (curve != null) {
                int[] frames = new int[dataList.size()];
                double[] amp = new double[dataList.size()];
                double ampMin = 0.0, ampMax = 0.0;
                for (int i = 0; i < dataList.size(); i++) {
                    LeapMotionEditorEventWithFrame data = dataList.get(i);
                    double recordedValue = property.getInputChannel().getValue(property.getLeapMotionHand(), data);
                    double transformedValue = property.transformInputValue(recordedValue);
                    frames[i] = Tools.FTOI(data.getFrame());
                    amp[i] = transformedValue;
                    if (amp[i] < ampMin) {
                        ampMin = amp[i];
                    } else if (amp[i] > ampMax) {
                        ampMax = amp[i];
                    }
                }
                curve.setPoints(frames, amp);
                curve.setViewXMin(-10);
                curve.setViewXMax(Tools.FTOI(dataList.get(dataList.size() - 1).getFrame()) + 10);
                curve.setViewYMin(ampMin + (ampMax - ampMin) / 10.0);
                curve.setViewYMax(ampMax + (ampMax - ampMin) / 10.0);
                curve.setEnabled(true);
            }
        }
    }
}
Also used : LeapMotionEditorEventWithFrame(org.jwildfire.create.tina.leapmotion.LeapMotionEditorListenerRecorder.LeapMotionEditorEventWithFrame) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve)

Aggregations

LeapMotionEditorEventWithFrame (org.jwildfire.create.tina.leapmotion.LeapMotionEditorListenerRecorder.LeapMotionEditorEventWithFrame)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MotionCurve (org.jwildfire.create.tina.base.motion.MotionCurve)1