| |
| |
|
|
| |
| |
| |
| #include "ext/StrokeParametricDeformer.h" |
| #include "ext/NotSimmetricExpPotential.h" |
| |
| |
| |
| #include <sstream> |
| |
| #include <tstroke.h> |
| |
| using namespace std; |
| |
| |
| |
| ToonzExt::StrokeParametricDeformer::StrokeParametricDeformer(double actionLenght, |
| double startParameter, |
| TStroke *s, |
| Potential *pot) |
| : startParameter_(startParameter), actionLenght_(actionLenght), vx_(1.0), vy_(1.0), pot_(0) |
| { |
| diff_ = 0.001; |
| |
| try { |
| ref_copy_ = new TStroke(*s); |
| } catch (std::bad_alloc &) { |
| throw std::invalid_argument("Not possible to have a copy of stroke!!!"); |
| } |
| |
| assert(0.0 <= startParameter_ && |
| startParameter_ <= 1.0); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| assert(0.0 <= actionLenght_); |
| |
| |
| if (0.0 > actionLenght_) |
| actionLenght_ = 0.0; |
| |
| |
| |
| |
| pot_ = pot; |
| if (!pot_) |
| throw std::invalid_argument("Not Possible to have a ref of Potential!!!"); |
| |
| pot_->setParameters(ref_copy_, |
| startParameter_, |
| actionLenght_); |
| assert(pot_); |
| startLenght_ = startParameter_; |
| } |
| |
| |
| |
| void ToonzExt::StrokeParametricDeformer::setMouseMove(double vx, |
| double vy) |
| { |
| vx_ = vx; |
| vy_ = vy; |
| } |
| |
| |
| |
| ToonzExt::StrokeParametricDeformer::~StrokeParametricDeformer() |
| { |
| delete pot_; |
| delete ref_copy_; |
| } |
| |
| |
| |
| TThickPoint |
| ToonzExt::StrokeParametricDeformer::getDisplacement(const TStroke &stroke, |
| double w) const |
| { |
| |
| double val = pot_->value(w); |
| |
| assert(val >= 0); |
| |
| |
| return TThickPoint(vx_ * val, vy_ * val, 0.0); |
| } |
| |
| |
| |
| TThickPoint |
| ToonzExt::StrokeParametricDeformer::getDisplacementForControlPoint( |
| const TStroke &stroke, |
| UINT n) const |
| { |
| double w = stroke.getParameterAtControlPoint(n); |
| return this->getDisplacement(stroke, w); |
| } |
| |
| |
| |
| TThickPoint |
| ToonzExt::StrokeParametricDeformer::getDisplacementForControlPointLen( |
| const TStroke &stroke, |
| double cpLen) const |
| { |
| return this->getDisplacement(stroke, cpLen); |
| } |
| |
| |
| |
| double |
| ToonzExt::StrokeParametricDeformer::getDelta(const TStroke &stroke, |
| double w) const |
| { |
| #if 0 |
| double w0 = w; |
| if(w0 == 1.0) |
| return norm( stroke.getSpeed(1.0)); |
| double tmp = stroke.getLength(w0); |
| tmp+=1.0; |
| double w1 = stroke.getParameterAtLength(tmp); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| const double dx = 1.0; |
| TThickPoint pnt = this->getDisplacement(stroke,w1) - |
| this->getDisplacement(stroke,w0); |
| |
| double dy = sqrt( sq(pnt.x) + sq(pnt.y) + sq(pnt.thick) ); |
| |
| assert(dx!=0.0); |
| return dy/dx; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #endif |
| return this->getDisplacement(stroke, w).y; |
| } |
| |
| |
| |
| double |
| ToonzExt::StrokeParametricDeformer::getMaxDiff() const |
| { |
| return diff_; |
| } |
| |
| |
| |
| void ToonzExt::StrokeParametricDeformer::getRange(double &from, |
| double &to) |
| { |
| double x = ref_copy_->getLength(startParameter_); |
| double delta = x - actionLenght_ * 0.5; |
| if (delta > 0) |
| from = ref_copy_->getParameterAtLength(delta); |
| else |
| from = 0.0; |
| |
| delta = x + actionLenght_ * 0.5; |
| if (delta < ref_copy_->getLength()) |
| to = ref_copy_->getParameterAtLength(delta); |
| else |
| to = 1.0; |
| } |
| |
| |
| |
| |
| |