Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
#define _STLP_DEBUG 1
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include "ext/CornerDeformation.h"
Toshihiro Shimizu 890ddd
#include "ext/StrokeDeformation.h"
Toshihiro Shimizu 890ddd
#include "ext/SquarePotential.h"
Toshihiro Shimizu 890ddd
//#include "ext/StrokeParametricDeformer.h"
Toshihiro Shimizu 890ddd
//#include "ext/NotSimmetricBezierPotential.h"
Toshihiro Shimizu 890ddd
#include "ext/ContextStatus.h"
Toshihiro Shimizu 890ddd
#include "ext/Designer.h"
Toshihiro Shimizu 890ddd
//#include "ext/TriParam.h"
Toshihiro Shimizu 890ddd
#include "ext/ExtUtil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "DeformationSelector.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include <tcurves.h></tcurves.h>
Toshihiro Shimizu 890ddd
//#include <tstrokeutil.h></tstrokeutil.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <algorithm></algorithm>
Toshihiro Shimizu 890ddd
#include <iterator></iterator>
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tmathutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToonzExt;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
REGISTER(CornerDeformation, 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
CornerDeformation::CornerDeformation() {
Shinya Kitaoka 120a6e
  this->setPotential(new SquarePotential);
Shinya Kitaoka 120a6e
  shortcutKey_ = ContextStatus::SHIFT;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
CornerDeformation::~CornerDeformation() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CornerDeformation::draw(Designer *designer) {
Shinya Kitaoka 120a6e
  StrokeDeformationImpl::draw(0);
Shinya Kitaoka 120a6e
  designer->draw(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool CornerDeformation::findExtremes_(const ContextStatus *status,
Shinya Kitaoka 120a6e
                                      Interval &ret) {
Shinya Kitaoka 120a6e
  return ToonzExt::findNearestSpireCorners(status->stroke2change_, status->w_,
Shinya Kitaoka 120a6e
                                           ret, status->cornerSize_,
Shinya Kitaoka 120a6e
                                           &this->getSpiresList());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool CornerDeformation::check_(const ContextStatus *status) {
Shinya Kitaoka 120a6e
  assert(status && "Not status available");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TStroke *s = status->stroke2change_;
Shinya Kitaoka 120a6e
  double w   = status->w_;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isASpireCorner(s, w, status->cornerSize_, &this->getSpiresList()))
Shinya Kitaoka 120a6e
    return true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef USE_TOLERANCE_IN_SELECTION
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // analyse if the selected distance is close to an extreme if an
Shinya Kitaoka 120a6e
  //  extreme is almost an extreme prefer to select extreme
Shinya Kitaoka 120a6e
  const TPointD pressed = status->stroke2change_->getPoint(status->w_);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double pixelTolerance2 = sq(5 * status->pixelSize_);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // array of corners
Shinya Kitaoka 120a6e
  std::vector<double> corners;</double>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // also if an straight extreme was not found prefer smooth
Shinya Kitaoka 120a6e
  if (cornersDetector(status->stroke2change_, status->cornerSize_, corners)) {
Shinya Kitaoka 120a6e
    while (!corners.empty()) {
Shinya Kitaoka 120a6e
      TPointD actual = status->stroke2change_->getPoint(corners.back());
Shinya Kitaoka 120a6e
      if (tdistance2(actual, pressed) < pixelTolerance2) {
Shinya Kitaoka 120a6e
        // status->w_ = corners.back();
Shinya Kitaoka 120a6e
        // out = CornerDeformation::instance();
Shinya Kitaoka 120a6e
        // break;
Shinya Kitaoka 120a6e
        this->w_ = corners.back();
Shinya Kitaoka 120a6e
        return true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      corners.pop_back();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double CornerDeformation::findActionLength() {
Shinya Kitaoka 120a6e
  // just to limit action until parameters are not computed
Shinya Kitaoka 120a6e
  //  return  lengthOfAction_ < stroke2transform_->getLength() ?
Shinya Kitaoka 120a6e
  //          lengthOfAction_ : stroke2transform_->getLength();
Shinya Kitaoka 120a6e
  // return -1;//
Shinya Kitaoka 120a6e
  return stroke2manipulate_->getLength();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
CornerDeformation *CornerDeformation::instance() {
Shinya Kitaoka 120a6e
  static CornerDeformation singleton;
Shinya Kitaoka 120a6e
  return &singleton;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------