From 9c9d79c54d2e296e1d51c8eb5279d1ede194f6f6 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Thu, 29 Dec 2016 18:51:41 +0100 Subject: [PATCH] Enhanced ShapeRule type to carry more information and to be easier to use --- CMakeLists.txt | 4 +-- .../{shapeRule.cpp => ShapeRule.cpp} | 31 +++++++++++++++++-- src/animation/ShapeRule.h | 23 ++++++++++++++ src/animation/mouthAnimation.cpp | 2 +- src/animation/roughAnimation.cpp | 8 ++--- src/animation/roughAnimation.h | 2 +- src/animation/shapeRule.h | 12 ------- src/animation/targetShapeSet.cpp | 2 +- src/animation/targetShapeSet.h | 2 +- src/animation/timingOptimization.cpp | 2 +- 10 files changed, 61 insertions(+), 27 deletions(-) rename src/animation/{shapeRule.cpp => ShapeRule.cpp} (62%) create mode 100644 src/animation/ShapeRule.h delete mode 100644 src/animation/shapeRule.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 681b698..64bd0c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,8 +226,8 @@ add_library(rhubarb-animation src/animation/pauseAnimation.h src/animation/roughAnimation.cpp src/animation/roughAnimation.h - src/animation/shapeRule.cpp - src/animation/shapeRule.h + src/animation/ShapeRule.cpp + src/animation/ShapeRule.h src/animation/shapeShorthands.h src/animation/targetShapeSet.cpp src/animation/targetShapeSet.h diff --git a/src/animation/shapeRule.cpp b/src/animation/ShapeRule.cpp similarity index 62% rename from src/animation/shapeRule.cpp rename to src/animation/ShapeRule.cpp index 52b48f8..eec8cf3 100644 --- a/src/animation/shapeRule.cpp +++ b/src/animation/ShapeRule.cpp @@ -1,4 +1,4 @@ -#include "shapeRule.h" +#include "ShapeRule.h" #include #include "ContinuousTimeline.h" @@ -13,12 +13,37 @@ ContinuousTimeline, AutoJoin> boundedTimelinetoContinuousOptional(co }; } +ShapeRule::ShapeRule(const ShapeSet& shapeSet, const optional& phone, TimeRange phoneTiming) : + shapeSet(shapeSet), + phone(phone), + phoneTiming(phoneTiming) +{} + +ShapeRule ShapeRule::getInvalid() { + return {{}, boost::none,{0_cs, 0_cs}}; +} + +bool ShapeRule::operator==(const ShapeRule& rhs) const { + return shapeSet == rhs.shapeSet && phone == rhs.phone && phoneTiming == rhs.phoneTiming; +} + +bool ShapeRule::operator!=(const ShapeRule& rhs) const { + return !operator==(rhs); +} + +bool ShapeRule::operator<(const ShapeRule& rhs) const { + return shapeSet < rhs.shapeSet + || phone < rhs.phone + || phoneTiming.getStart() < rhs.phoneTiming.getStart() + || phoneTiming.getEnd() < rhs.phoneTiming.getEnd(); +} + ContinuousTimeline getShapeRules(const BoundedTimeline& phones) { // Convert to continuous timeline so that silences aren't skipped when iterating auto continuousPhones = boundedTimelinetoContinuousOptional(phones); // Create timeline of shape rules - ContinuousTimeline shapeRules(phones.getRange(), ShapeRule({Shape::X}, boost::none)); + ContinuousTimeline shapeRules(phones.getRange(), {{Shape::X}, boost::none, {0_cs, 0_cs}}); centiseconds previousDuration = 0_cs; for (const auto& timedPhone : continuousPhones) { optional phone = timedPhone.getValue(); @@ -34,7 +59,7 @@ ContinuousTimeline getShapeRules(const BoundedTimeline& phones // Copy to timeline. // Later shape sets may overwrite earlier ones if overlapping. for (const auto& timedShapeSet : phoneShapeSets) { - shapeRules.set(timedShapeSet.getTimeRange(), ShapeRule(timedShapeSet.getValue(), phone)); + shapeRules.set(timedShapeSet.getTimeRange(), ShapeRule(timedShapeSet.getValue(), phone, timedPhone.getTimeRange())); } } diff --git a/src/animation/ShapeRule.h b/src/animation/ShapeRule.h new file mode 100644 index 0000000..dc42fd3 --- /dev/null +++ b/src/animation/ShapeRule.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Phone.h" +#include "animationRules.h" +#include "BoundedTimeline.h" +#include "ContinuousTimeline.h" + +struct ShapeRule { + ShapeSet shapeSet; + boost::optional phone; + TimeRange phoneTiming; + + ShapeRule(const ShapeSet& shapeSet, const boost::optional& phone, TimeRange phoneTiming); + + static ShapeRule getInvalid(); + + bool operator==(const ShapeRule&) const; + bool operator!=(const ShapeRule&) const; + bool operator<(const ShapeRule&) const; +}; + +// Returns shape rules for an entire timeline of phones. +ContinuousTimeline getShapeRules(const BoundedTimeline& phones); diff --git a/src/animation/mouthAnimation.cpp b/src/animation/mouthAnimation.cpp index f0387cf..e6c62ae 100644 --- a/src/animation/mouthAnimation.cpp +++ b/src/animation/mouthAnimation.cpp @@ -1,6 +1,6 @@ #include "mouthAnimation.h" #include "timedLogging.h" -#include "shapeRule.h" +#include "ShapeRule.h" #include "roughAnimation.h" #include "pauseAnimation.h" #include "tweening.h" diff --git a/src/animation/roughAnimation.cpp b/src/animation/roughAnimation.cpp index 0bb540c..1d1d672 100644 --- a/src/animation/roughAnimation.cpp +++ b/src/animation/roughAnimation.cpp @@ -19,11 +19,9 @@ JoiningContinuousTimeline animateRough(const ContinuousTimelinegetValue(); - const ShapeSet shapeSet = std::get(shapeRule); - const Shape shape = getClosestShape(referenceShape, shapeSet); + const Shape shape = getClosestShape(referenceShape, shapeRule.shapeSet); animation.set(it->getTimeRange(), shape); - const auto phone = std::get>(shapeRule); - const bool anticipateShape = phone && isVowel(*phone) && shapeSet.size() == 1; + const bool anticipateShape = shapeRule.phone && isVowel(*shapeRule.phone) && shapeRule.shapeSet.size() == 1; if (anticipateShape) { // Animate backwards a little const Shape anticipatedShape = shape; @@ -40,7 +38,7 @@ JoiningContinuousTimeline animateRough(const ContinuousTimeline maxAnticipationDuration) break; // Overwrite forward-animated shape with backwards-animated, anticipating shape - const Shape anticipatingShape = getClosestShape(referenceShape, std::get(reverseIt->getValue())); + const Shape anticipatingShape = getClosestShape(referenceShape, reverseIt->getValue().shapeSet); animation.set(reverseIt->getTimeRange(), anticipatingShape); // Make sure the new, backwards-animated shape still resembles the anticipated shape diff --git a/src/animation/roughAnimation.h b/src/animation/roughAnimation.h index 86781ee..83e8567 100644 --- a/src/animation/roughAnimation.h +++ b/src/animation/roughAnimation.h @@ -1,6 +1,6 @@ #pragma once -#include "shapeRule.h" +#include "ShapeRule.h" // Does a rough animation (no tweening, special pause animation, etc.) using a bidirectional algorithm. JoiningContinuousTimeline animateRough(const ContinuousTimeline& shapeRules); diff --git a/src/animation/shapeRule.h b/src/animation/shapeRule.h deleted file mode 100644 index d16abda..0000000 --- a/src/animation/shapeRule.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "Phone.h" -#include "animationRules.h" -#include "BoundedTimeline.h" -#include "ContinuousTimeline.h" - -// A shape set with its original phone -using ShapeRule = std::tuple>; - -// Returns shape rules for an entire timeline of phones. -ContinuousTimeline getShapeRules(const BoundedTimeline& phones); diff --git a/src/animation/targetShapeSet.cpp b/src/animation/targetShapeSet.cpp index b4f18ed..dc9807b 100644 --- a/src/animation/targetShapeSet.cpp +++ b/src/animation/targetShapeSet.cpp @@ -23,7 +23,7 @@ ContinuousTimeline convertToTargetShapeSet(const ContinuousTimeline result(shapeRules); for (const auto& timedShapeRule : shapeRules) { ShapeRule rule = timedShapeRule.getValue(); - std::get(rule) = convertToTargetShapeSet(std::get(rule), targetShapeSet); + rule.shapeSet = convertToTargetShapeSet(rule.shapeSet, targetShapeSet); result.set(timedShapeRule.getTimeRange(), rule); } return result; diff --git a/src/animation/targetShapeSet.h b/src/animation/targetShapeSet.h index 476353a..67bc65d 100644 --- a/src/animation/targetShapeSet.h +++ b/src/animation/targetShapeSet.h @@ -1,7 +1,7 @@ #pragma once #include "Shape.h" -#include "shapeRule.h" +#include "ShapeRule.h" // Returns the closest shape to the specified one that occurs in the target shape set. Shape convertToTargetShapeSet(Shape shape, const ShapeSet& targetShapeSet); diff --git a/src/animation/timingOptimization.cpp b/src/animation/timingOptimization.cpp index 2e5456a..b912b84 100644 --- a/src/animation/timingOptimization.cpp +++ b/src/animation/timingOptimization.cpp @@ -3,7 +3,7 @@ #include #include #include -#include "shapeRule.h" +#include "ShapeRule.h" using std::string; using std::map;