| |
| |
| #include "ext/SquarePotential.h" |
| #include <tmathutil.h> |
| #include <algorithm> |
| |
| using namespace std; |
| |
| |
| |
| void ToonzExt::SquarePotential::setParameters_(const TStroke *ref, |
| double par, |
| double al) |
| { |
| ref_ = ref; |
| par_ = par; |
| actionLength_ = al; |
| assert(ref_); |
| |
| strokeLength_ = ref->getLength(); |
| lenghtAtParam_ = ref->getLength(par); |
| |
| |
| leftFactor_ = min(lenghtAtParam_, |
| actionLength_ * 0.5); |
| |
| |
| rightFactor_ = min(strokeLength_ - lenghtAtParam_, |
| actionLength_ * 0.5); |
| |
| |
| |
| |
| range_ = 2.8; |
| } |
| |
| |
| |
| ToonzExt::SquarePotential::~SquarePotential() |
| { |
| } |
| |
| |
| |
| double |
| ToonzExt::SquarePotential::value_(double value2test) const |
| { |
| return this->compute_value(value2test); |
| } |
| |
| |
| |
| |
| double ToonzExt::SquarePotential::compute_shape(double value2test) const |
| { |
| double x = ref_->getLength(value2test); |
| double shape = this->actionLength_ * 0.5; |
| if (isAlmostZero(shape)) |
| shape = 1.0; |
| x = ((x - lenghtAtParam_) * range_) / shape; |
| return x; |
| } |
| |
| |
| |
| double |
| ToonzExt::SquarePotential::compute_value(double value2test) const |
| { |
| |
| |
| |
| |
| |
| double x = 0.0; |
| double res = 0.0; |
| |
| |
| x = ref_->getLength(value2test); |
| |
| double tmp_al = actionLength_ * 0.5; |
| |
| |
| |
| |
| |
| |
| |
| if (leftFactor_ == 0.0) |
| x = 1.0 - x / tmp_al; |
| else if (rightFactor_ == 0.0) |
| x = (x - (strokeLength_ - tmp_al)) / tmp_al; |
| else { |
| if (x <= lenghtAtParam_ && |
| ((lenghtAtParam_ - x) <= leftFactor_)) |
| x = (x - (lenghtAtParam_ - leftFactor_)) / leftFactor_; |
| else if (x > lenghtAtParam_ && |
| ((x - lenghtAtParam_) < rightFactor_)) |
| x = (rightFactor_ - (x - lenghtAtParam_)) / rightFactor_; |
| else |
| x = -1; |
| } |
| |
| if (x < 0.0) |
| return 0.0; |
| |
| |
| res = sq(x); |
| |
| return res; |
| } |
| |
| |
| |
| ToonzExt::Potential * |
| ToonzExt::SquarePotential::clone() |
| { |
| return new SquarePotential; |
| } |
| |
| |
| |
| |
| |