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