Search in sources :

Example 1 with BezierPolygonPoint

use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.

the class BezierPolygonProvider method doInterpolate.

private BezierPolygon doInterpolate(Entry<TimelinePosition, List<BezierPolygonPoint>> previousEntry, Entry<TimelinePosition, List<BezierPolygonPoint>> nextEntry, TimelinePosition currentPosition) {
    List<BezierPolygonPoint> lastPoints = previousEntry.getValue();
    List<BezierPolygonPoint> nextPoints = nextEntry.getValue();
    if (lastPoints.size() != nextPoints.size()) {
        // we cannot interpolate a polygon with changing sides
        return new BezierPolygon(lastPoints);
    } else {
        List<BezierPolygonPoint> newPoints = new ArrayList<>();
        for (int i = 0; i < lastPoints.size(); ++i) {
            BezierPolygonPoint point1 = lastPoints.get(i);
            BezierPolygonPoint point2 = nextPoints.get(i);
            double xCoordinate = interpolateAxis(previousEntry, nextEntry, currentPosition, new double[] { point1.getX(), point2.getX() });
            double yCoordinate = interpolateAxis(previousEntry, nextEntry, currentPosition, new double[] { point1.getY(), point2.getY() });
            newPoints.add(new BezierPolygonPoint(xCoordinate, yCoordinate, point1.getType()));
        }
        return new BezierPolygon(newPoints);
    }
}
Also used : ArrayList(java.util.ArrayList) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Example 2 with BezierPolygonPoint

use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.

the class BezierPolygonProvider method getValueAt.

@Override
public BezierPolygon getValueAt(TimelinePosition position) {
    Entry<TimelinePosition, List<BezierPolygonPoint>> lastEntry = values.lastEntry();
    Entry<TimelinePosition, List<BezierPolygonPoint>> firstEntry = values.firstEntry();
    if (values.isEmpty() || !useKeyframes) {
        return new BezierPolygon(defaultValues);
    } else if (values.size() == 1) {
        return new BezierPolygon(values.firstEntry().getValue());
    } else if (position.isGreaterThan(lastEntry.getKey())) {
        return new BezierPolygon(lastEntry.getValue());
    } else if (position.isLessThan(firstEntry.getKey())) {
        return new BezierPolygon(firstEntry.getValue());
    } else {
        Entry<TimelinePosition, List<BezierPolygonPoint>> previousEntry = values.floorEntry(position);
        Entry<TimelinePosition, List<BezierPolygonPoint>> nextEntry = values.ceilingEntry(position);
        if (previousEntry.getKey().getSeconds().doubleValue() >= nextEntry.getKey().getSeconds().doubleValue()) {
            return new BezierPolygon(previousEntry.getValue());
        }
        return doInterpolate(previousEntry, nextEntry, position);
    }
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Example 3 with BezierPolygonPoint

use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.

the class BezierPolygonProviderDesSerFactory method deserialize.

@Override
public BezierPolygonProvider deserialize(JsonNode data, SavedContentAddable<?> currentFieldValue, LoadMetadata loadMetadata) {
    try {
        List<BezierPolygonPoint> defaultValues = objectMapper.readValue(objectMapper.treeAsTokens(data.get("defaultValue")), objectMapper.getTypeFactory().constructType(new TypeReference<List<BezierPolygonPoint>>() {
        }));
        TreeMap<TimelinePosition, List<BezierPolygonPoint>> values = objectMapper.readValue(objectMapper.treeAsTokens(data.get("values")), objectMapper.getTypeFactory().constructType(new TypeReference<TreeMap<TimelinePosition, List<BezierPolygonPoint>>>() {
        }));
        UnivariateInterpolator interpolator;
        interpolator = (UnivariateInterpolator) Class.forName(data.get("interpolatorImplementation").asText()).newInstance();
        boolean useKeyframes = data.get("useKeyframes").asBoolean();
        return new BezierPolygonProvider(useKeyframes, defaultValues, values, interpolator);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) UnivariateInterpolator(org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Example 4 with BezierPolygonPoint

use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.

the class BezierPolygonInputTypeStrategy method draw.

@Override
public void draw(DrawRequestParameter parameterObject) {
    double translateX = parameterObject.getCanvasTranslateX();
    double translateY = parameterObject.getCanvasTranslateY();
    parameterObject.getCanvas().setFill(Color.BLUE);
    parameterObject.getCanvas().setStroke(Color.BLUE);
    Point previousRealPoint = null;
    for (int i = 0; i < result.size(); ++i) {
        BezierPolygonPoint currentBezier = result.get(i);
        Point current = pointFromBezierPoint(currentBezier).multiply(parameterObject.getWidth(), parameterObject.getHeight());
        int diameter = 10;
        if (isMouseCloseToFirstPoint && i == 0 && !finishOnRightClick) {
            diameter = 20;
        }
        if (mouseCloseTo.isPresent() && mouseCloseTo.get().equals(i)) {
            parameterObject.getCanvas().setFill(Color.RED);
        } else {
            if (currentBezier.type == SplinePolygonType.SPLINE) {
                parameterObject.getCanvas().setFill(Color.GRAY);
            } else {
                parameterObject.getCanvas().setFill(Color.BLUE);
            }
        }
        parameterObject.getCanvas().fillOval(current.x - diameter / 2 + translateX, current.y - diameter / 2 + translateY, diameter, diameter);
        if (currentBezier.type == SplinePolygonType.SPLINE) {
            parameterObject.getCanvas().setStroke(Color.GRAY);
        } else {
            parameterObject.getCanvas().setStroke(Color.BLUE);
        }
        if (previousRealPoint != null) {
            parameterObject.getCanvas().strokeLine(previousRealPoint.x + translateX, previousRealPoint.y + translateY, current.x + translateX, current.y + translateY);
        }
        if (currentBezier.type == SplinePolygonType.POINT) {
            previousRealPoint = current;
        }
    }
}
Also used : Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Example 5 with BezierPolygonPoint

use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.

the class BezierPolygonInputTypeStrategy method onMouseDownEvent.

@Override
public void onMouseDownEvent(StrategyMouseInput input) {
    if (input.mouseEvent.isSecondaryButtonDown()) {
        isFinished = true;
    } else {
        double x = input.x;
        double y = input.y;
        pointIndexToUpdate = findPointNear(new Point(input.x, input.y));
        if (input.mouseEvent.isMiddleButtonDown()) {
            if (pointIndexToUpdate.isPresent()) {
                int indexToRemove = pointIndexToUpdate.get();
                result.remove(indexToRemove);
                if (indexToRemove < result.size() && result.get(indexToRemove).type == SplinePolygonType.SPLINE) {
                    // next point
                    result.remove(indexToRemove);
                }
            }
            return;
        }
        if (isCloseToFirstPoint(new Point(input.x, input.y)) && !finishOnRightClick) {
            if (result.size() > 1) {
                BezierPolygonPoint controlPoint = createControlPoint(result.get(0), result.get(result.size() - 1));
                result.add(controlPoint);
            }
            isFinished = true;
        } else {
            if (pointIndexToUpdate.isPresent()) {
                int index = pointIndexToUpdate.get();
                updatePointAtIndex(input, index);
            } else {
                BezierPolygonPoint currentPoint = new BezierPolygonPoint(x, y, SplinePolygonType.POINT);
                if (result.size() >= 1) {
                    BezierPolygonPoint controlPoint = createControlPoint(currentPoint, result.get(result.size() - 1));
                    result.add(controlPoint);
                }
                result.add(currentPoint);
            }
        }
    }
}
Also used : Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Aggregations

BezierPolygonPoint (com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)5 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)2 Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)2 BezierPolygon (com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Entry (java.util.Map.Entry)1 UnivariateInterpolator (org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator)1