Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  tstrokedeformations.cpp
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//  Revision History:
Toshihiro Shimizu 890ddd
//  16/07/2002  m_lengthOfDeformation is almost TConsts::epsilon
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tstrokedeformations.h"
Toshihiro Shimizu 890ddd
#include "tcurveutil.h"
Toshihiro Shimizu 890ddd
#include "tmathutil.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
const double nine_inv = 1.0 / 9.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
           _____|  r
Toshihiro Shimizu 890ddd
          /     |\  inner
Toshihiro Shimizu 890ddd
      __/          \___|
Toshihiro Shimizu 890ddd
                       | r 
Toshihiro Shimizu 890ddd
                          outer
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
                    {  1  if  r <= r
Toshihiro Shimizu 890ddd
                    {              inner
Toshihiro Shimizu 890ddd
                    {
Toshihiro Shimizu 890ddd
 bowl potential(r)= {  cos( (r - r ) / (r  - r ) * pi_2 )  if   r < r  <= r
Toshihiro Shimizu 890ddd
                    {             i      o    i                  i         o
Toshihiro Shimizu 890ddd
                    {
Toshihiro Shimizu 890ddd
                    {  0  if  r > r
Toshihiro Shimizu 890ddd
                                   o
Toshihiro Shimizu 890ddd
    
Toshihiro Shimizu 890ddd
   */
Toshihiro Shimizu 890ddd
struct bowlPotential {
Toshihiro Shimizu 890ddd
	double m_radiusInner;
Toshihiro Shimizu 890ddd
	double m_radiusOuter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bowlPotential(double radiusInner,
Toshihiro Shimizu 890ddd
				  double radiusOuter)
Toshihiro Shimizu 890ddd
		: m_radiusInner(radiusInner), m_radiusOuter(radiusOuter)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(m_radiusInner > 0);
Toshihiro Shimizu 890ddd
		assert(m_radiusOuter >= m_radiusInner);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual double value(double radiusToTest)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(radiusToTest >= 0);
Toshihiro Shimizu 890ddd
		if (radiusToTest <= m_radiusInner)
Toshihiro Shimizu 890ddd
			return 1.0;
Toshihiro Shimizu 890ddd
		if (radiusToTest > m_radiusOuter)
Toshihiro Shimizu 890ddd
			return 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return 0.5 * (1.0 + cos((radiusToTest - m_radiusInner) / (m_radiusOuter - m_radiusInner) * TConsts::pi));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual double gradient(double radiusToTest)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(radiusToTest >= 0);
Toshihiro Shimizu 890ddd
		if (radiusToTest <= m_radiusInner || radiusToTest > m_radiusOuter)
Toshihiro Shimizu 890ddd
			return 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		double den = TConsts::pi / (m_radiusOuter - m_radiusInner);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return -0.5 * den * sin(den * (radiusToTest - m_radiusInner));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual ~bowlPotential() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double wyvillPotential(double r, double R)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (0.0 == R)
Toshihiro Shimizu 890ddd
		return 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (0 > r || r >= R)
Toshihiro Shimizu 890ddd
		return 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double ratio2 = sq(r / R);
Toshihiro Shimizu 890ddd
	double ratio4 = sq(ratio2);
Toshihiro Shimizu 890ddd
	double ratio6 = ratio2 * ratio4;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 1.0 + (17.0 * ratio4 - (4.0 * ratio6 + 22.0 * ratio2)) * nine_inv;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
double derivateOfWyvillPotential(double r, double R)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (0.0 == R)
Toshihiro Shimizu 890ddd
		return 0.0;
Toshihiro Shimizu 890ddd
	if (0 > r || r > R)
Toshihiro Shimizu 890ddd
		return 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double inv_of_R = 1.0 / R;
Toshihiro Shimizu 890ddd
	double ratio = r / R;
Toshihiro Shimizu 890ddd
	double ratio2 = sq(ratio);
Toshihiro Shimizu 890ddd
	double ratio3 = ratio * ratio2;
Toshihiro Shimizu 890ddd
	double ratio5 = ratio3 * ratio2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return inv_of_R * nine_inv * (68.0 * ratio3 - (24.0 * ratio5 + 66.0 * ratio));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const double c_maxLenghtOfGaussian = 3.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
double gaussianPotential(double x)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return exp(-sq(x));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
double derivateOfGaussianPotential(double x)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return -2 * x * exp(-sq(x));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* 
Toshihiro Shimizu 890ddd
  Check if vector distance is in segment.
Toshihiro Shimizu 890ddd
  bool  pointProjectionIsInSegment( const TPointD& p, const TSegment& seg )
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    TPointD 
Toshihiro Shimizu 890ddd
      a ( p - seg.getP0()),
Toshihiro Shimizu 890ddd
      b ( seg.getP1() - seg.getP0());
Toshihiro Shimizu 890ddd
    
Toshihiro Shimizu 890ddd
    double  b2 = b*b;
Toshihiro Shimizu 890ddd
    
Toshihiro Shimizu 890ddd
    if( ! isAlmostZero(b2) )
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      b2 = a * b / b2;
Toshihiro Shimizu 890ddd
      if (  0 <= b2 && b2 <= 1.0 ) return true; 
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
    
Toshihiro Shimizu 890ddd
    return false;
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double normOfGradientOfWyvillPotential(double r, double R)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD grad;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	grad.x = 1.0;
Toshihiro Shimizu 890ddd
	grad.y = derivateOfWyvillPotential(r, R);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return norm(grad);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // end of unnamed namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct TStrokePointDeformation::Imp {
Toshihiro Shimizu 890ddd
	TPointD m_circleCenter;
Toshihiro Shimizu 890ddd
	double m_circleRadius;
Toshihiro Shimizu 890ddd
	TPointD *m_vect;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bowlPotential *m_potential;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Imp(const TPointD ¢er,
Toshihiro Shimizu 890ddd
		double radius)
Toshihiro Shimizu 890ddd
		: m_circleCenter(center), m_circleRadius(radius), m_vect(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_potential = new bowlPotential(0.3 * m_circleRadius, m_circleRadius);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Imp(const TPointD &vect,
Toshihiro Shimizu 890ddd
		const TPointD ¢er,
Toshihiro Shimizu 890ddd
		double radius)
Toshihiro Shimizu 890ddd
		: m_circleCenter(center), m_circleRadius(radius), m_vect(new TPointD(vect))
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_potential = new bowlPotential(0.3 * m_circleRadius, m_circleRadius);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~Imp()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		delete m_vect;
Toshihiro Shimizu 890ddd
		delete m_potential;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokePointDeformation::TStrokePointDeformation(const TPointD ¢er,
Toshihiro Shimizu 890ddd
												 double radius)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp = new Imp(center, radius);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokePointDeformation::TStrokePointDeformation(const TPointD &vect,
Toshihiro Shimizu 890ddd
												 const TPointD ¢er,
Toshihiro Shimizu 890ddd
												 double radius)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp = new Imp(vect, center, radius);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokePointDeformation::~TStrokePointDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_imp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokePointDeformation::getDisplacementForControlPoint(const TStroke &stroke, UINT n) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// riferimento ad un punto ciccione della stroke
Toshihiro Shimizu 890ddd
	TPointD pntOfStroke(convert(stroke.getControlPoint(n)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double d = tdistance(pntOfStroke, m_imp->m_circleCenter);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_imp->m_vect)
Toshihiro Shimizu 890ddd
		return m_imp->m_potential->value(d) * TThickPoint(*m_imp->m_vect, 0);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		double outVal = m_imp->m_potential->value(d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return TThickPoint(outVal, outVal, 0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokePointDeformation::getDisplacementForControlPointLen(const TStroke &stroke, double cpLen) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(0);
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokePointDeformation::getDisplacement(const TStroke &stroke, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// riferimento ad un punto ciccione della stroke
Toshihiro Shimizu 890ddd
	TThickPoint
Toshihiro Shimizu 890ddd
		thickPnt = m_imp->m_vect ? stroke.getControlPointAtParameter(w) : stroke.getThickPoint(w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(thickPnt != TConsts::natp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD pntOfStroke(convert(thickPnt));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double d = tdistance(pntOfStroke, m_imp->m_circleCenter);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_imp->m_vect)
Toshihiro Shimizu 890ddd
		return m_imp->m_potential->value(d) * TThickPoint(*m_imp->m_vect, 0);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		double outVal = m_imp->m_potential->value(d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return TThickPoint(outVal, outVal, 0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokePointDeformation::getDelta(const TStroke &stroke, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// reference to a thickpoint
Toshihiro Shimizu 890ddd
	TThickPoint
Toshihiro Shimizu 890ddd
		thickPnt = m_imp->m_vect ? stroke.getControlPointAtParameter(w) : stroke.getThickPoint(w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(thickPnt != TConsts::natp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD
Toshihiro Shimizu 890ddd
		pntOfStroke = convert(thickPnt);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double d = tdistance(pntOfStroke, m_imp->m_circleCenter);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return m_imp->m_potential->gradient(d);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokePointDeformation::getMaxDiff() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return 0.005;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeParamDeformation::TStrokeParamDeformation(const TStroke *ref,
Toshihiro Shimizu 890ddd
												 const TPointD &vect,
Toshihiro Shimizu 890ddd
												 double s,
Toshihiro Shimizu 890ddd
												 double l)
Toshihiro Shimizu 890ddd
	: m_pRef(ref), m_startParameter(s), m_lengthOfDeformation(l), m_vect(new TPointD(vect))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_lengthOfDeformation >= 0);
Toshihiro Shimizu 890ddd
	if (isAlmostZero(m_lengthOfDeformation))
Toshihiro Shimizu 890ddd
		m_lengthOfDeformation = TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeParamDeformation::TStrokeParamDeformation(const TStroke *ref,
Toshihiro Shimizu 890ddd
												 double s,
Toshihiro Shimizu 890ddd
												 double l)
Toshihiro Shimizu 890ddd
	: m_pRef(ref), m_startParameter(s), m_lengthOfDeformation(l), m_vect(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_lengthOfDeformation >= 0);
Toshihiro Shimizu 890ddd
	if (isAlmostZero(m_lengthOfDeformation))
Toshihiro Shimizu 890ddd
		m_lengthOfDeformation = TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
TThickPoint TStrokeParamDeformation::getDisplacementForControlPoint(const TStroke &stroke, UINT n) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double diff = stroke.getLengthAtControlPoint(n);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	diff = diff - m_startParameter;
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_vect)
Toshihiro Shimizu 890ddd
			return gaussianPotential(diff) * TThickPoint(*m_vect, 0);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			double outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			return TThickPoint(outVal, outVal, 0);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeParamDeformation::getDisplacementForControlPointLen(const TStroke &stroke, double cpLenDiff) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	//double  diff =  stroke.getLengthAtControlPoint(n);
Toshihiro Shimizu 890ddd
	//double  diff =  cpLen;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double diff = cpLenDiff;
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_vect)
Toshihiro Shimizu 890ddd
			return gaussianPotential(diff) * TThickPoint(*m_vect, 0);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			double outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			return TThickPoint(outVal, outVal, 0);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeParamDeformation::getDisplacement(const TStroke &stroke, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double diff = stroke.getLength(w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	diff = diff - m_startParameter;
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_vect)
Toshihiro Shimizu 890ddd
			return gaussianPotential(diff) * TThickPoint(*m_vect, 0);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			double outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			return TThickPoint(outVal, outVal, 0);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeParamDeformation::getDelta(const TStroke &stroke, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double diff = stroke.getLength(w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	diff = diff - m_startParameter;
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return derivateOfGaussianPotential(diff);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeParamDeformation::getMaxDiff() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return 0.09;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeParamDeformation::~TStrokeParamDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_vect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
TStrokeBenderDeformation::TStrokeBenderDeformation(const TStroke *ref,
Toshihiro Shimizu 890ddd
												   double s,
Toshihiro Shimizu 890ddd
												   double l)
Toshihiro Shimizu 890ddd
	: m_pRef(ref), m_startLength(s), m_lengthOfDeformation(l), m_vect(0), m_versus(INNER)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_lengthOfDeformation >= 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isAlmostZero(m_lengthOfDeformation))
Toshihiro Shimizu 890ddd
		m_lengthOfDeformation = TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeBenderDeformation::TStrokeBenderDeformation(const TStroke *ref,
Toshihiro Shimizu 890ddd
												   const TPointD &vect,
Toshihiro Shimizu 890ddd
												   double angle,
Toshihiro Shimizu 890ddd
												   double s,
Toshihiro Shimizu 890ddd
												   int innerOrOuter,
Toshihiro Shimizu 890ddd
												   double l)
Toshihiro Shimizu 890ddd
	: m_pRef(ref), m_startLength(s), m_lengthOfDeformation(l), m_vect(new TPointD(vect)), m_versus(innerOrOuter), m_angle(angle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_lengthOfDeformation >= 0);
Toshihiro Shimizu 890ddd
	if (isAlmostZero(m_lengthOfDeformation))
Toshihiro Shimizu 890ddd
		m_lengthOfDeformation = TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeBenderDeformation::~TStrokeBenderDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_vect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeBenderDeformation::getMaxDiff() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//  return  0.09; OK per gaussiana
Toshihiro Shimizu 890ddd
	return 0.4;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeBenderDeformation::getDisplacementForControlPoint(const TStroke &s, UINT n) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double strokeLengthAtParameter = s.getLengthAtControlPoint(n);
Toshihiro Shimizu 890ddd
	double diff = strokeLengthAtParameter - m_startLength;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_vect) {
Toshihiro Shimizu 890ddd
		double outVal = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (fabs(diff) <= m_lengthOfDeformation && m_versus == INNER) {
Toshihiro Shimizu 890ddd
			diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
			outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
		} else if (m_versus == OUTER) {
Toshihiro Shimizu 890ddd
			double valForGaussian =
Toshihiro Shimizu 890ddd
				-c_maxLenghtOfGaussian + 2 * c_maxLenghtOfGaussian / m_lengthOfDeformation * strokeLengthAtParameter;
Toshihiro Shimizu 890ddd
			outVal = 1.0 - gaussianPotential(valForGaussian);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPointD cp = convert(s.getControlPoint(n));
Toshihiro Shimizu 890ddd
		TPointD p = cp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRotation rot(*m_vect, outVal * rad2degree(m_angle));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		p = rot * p;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return TThickPoint(p - cp, 0.0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeBenderDeformation::getDisplacementForControlPointLen(const TStroke &stroke, double cpLen) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(0);
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeBenderDeformation::getDisplacement(const TStroke &s, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double strokeLengthAtParameter = s.getLength(w);
Toshihiro Shimizu 890ddd
	double diff = strokeLengthAtParameter - m_startLength;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_vect) {
Toshihiro Shimizu 890ddd
		double outVal = 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (fabs(diff) <= m_lengthOfDeformation)
Toshihiro Shimizu 890ddd
			if (m_versus == INNER) {
Toshihiro Shimizu 890ddd
				diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
				outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			} else if (m_versus == OUTER) {
Toshihiro Shimizu 890ddd
				double valForGaussian =
Toshihiro Shimizu 890ddd
					-c_maxLenghtOfGaussian + 2 * c_maxLenghtOfGaussian / m_lengthOfDeformation * strokeLengthAtParameter;
Toshihiro Shimizu 890ddd
				outVal = 1.0 - gaussianPotential(valForGaussian);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPointD cp = convert(s.getControlPointAtParameter(w));
Toshihiro Shimizu 890ddd
		TPointD p = cp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRotation rot(*m_vect, outVal * rad2degree(m_angle));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		p = rot * p;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return TThickPoint(p - cp, 0.0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeBenderDeformation::getDelta(const TStroke &s, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double totalLenght = s.getLength();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (totalLenght != 0) {
Toshihiro Shimizu 890ddd
		double val = s.getLength(w) / totalLenght * TConsts::pi * 10.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return sin(val);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeTwirlDeformation::TStrokeTwirlDeformation(const TPointD ¢er, double radius)
Toshihiro Shimizu 890ddd
	: m_center(center), m_innerRadius2(sq(radius)), m_vectorOfMovement(TPointD())
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_outerRadius = 1.25 * radius;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeTwirlDeformation::TStrokeTwirlDeformation(const TPointD ¢er, double radius, const TPointD &v)
Toshihiro Shimizu 890ddd
	: m_center(center), m_innerRadius2(sq(radius)), m_vectorOfMovement(v)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_outerRadius = 1.25 * radius;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeTwirlDeformation::~TStrokeTwirlDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeTwirlDeformation::getDisplacement(const TStroke &stroke, double s) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double outVal = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double distance2 = tdistance2(convert(stroke.getControlPointAtParameter(s)), m_center);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (distance2 <= m_innerRadius2)
Toshihiro Shimizu 890ddd
		outVal = wyvillPotential(distance2, m_innerRadius2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint(m_vectorOfMovement * outVal, 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeTwirlDeformation::getDelta(const TStroke &stroke, double s) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  vector<doublepair>  vres;</doublepair>
Toshihiro Shimizu 890ddd
  
Toshihiro Shimizu 890ddd
  if(intersect( stroke, m_center, m_outerRadius, vres))
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
    double totalLenght = stroke.getLength();
Toshihiro Shimizu 890ddd
    
Toshihiro Shimizu 890ddd
    if(totalLenght != 0)
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      double val =  stroke.getLength(s)/totalLenght * TConsts::pi *11.0;
Toshihiro Shimizu 890ddd
      
Toshihiro Shimizu 890ddd
      return sin(val);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeTwirlDeformation::getMaxDiff() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return 0.4;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeThicknessDeformation::TStrokeThicknessDeformation(const TStroke *ref,
Toshihiro Shimizu 890ddd
														 const TPointD &vect,
Toshihiro Shimizu 890ddd
														 double s,
Toshihiro Shimizu 890ddd
														 double l,
Toshihiro Shimizu 890ddd
														 double versus)
Toshihiro Shimizu 890ddd
	: m_lengthOfDeformation(l), m_startParameter(s), m_versus(versus), m_vect(new TPointD(vect)), m_pRef(ref)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_lengthOfDeformation >= 0);
Toshihiro Shimizu 890ddd
	if (isAlmostZero(m_lengthOfDeformation))
Toshihiro Shimizu 890ddd
		m_lengthOfDeformation = TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeThicknessDeformation::TStrokeThicknessDeformation(const TStroke *ref,
Toshihiro Shimizu 890ddd
														 double s,
Toshihiro Shimizu 890ddd
														 double l)
Toshihiro Shimizu 890ddd
	: m_lengthOfDeformation(l), m_startParameter(s), m_vect(0), m_pRef(ref)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_lengthOfDeformation >= 0);
Toshihiro Shimizu 890ddd
	if (isAlmostZero(m_lengthOfDeformation))
Toshihiro Shimizu 890ddd
		m_lengthOfDeformation = TConsts::epsilon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
TThickPoint TStrokeThicknessDeformation::getDisplacementForControlPoint(const TStroke &stroke, UINT n) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double diff = stroke.getLengthAtControlPoint(n);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	diff = diff - m_startParameter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TThickPoint delta;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_vect) {
Toshihiro Shimizu 890ddd
			//tsign(m_vect->y) * 0.1
Toshihiro Shimizu 890ddd
			delta = TThickPoint(0, 0, m_versus * norm(*m_vect) * gaussianPotential(diff));
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			double outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			delta = TThickPoint(0, 0, outVal);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//TThickPoint cp = stroke.getControlPoint(n);
Toshihiro Shimizu 890ddd
		//if(cp.thick + delta.thick<0.001) delta.thick = 0.001-cp.thick;
Toshihiro Shimizu 890ddd
		return delta;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeThicknessDeformation::getDisplacementForControlPointLen(const TStroke &stroke, double diff) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TThickPoint delta;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_vect) {
Toshihiro Shimizu 890ddd
			//tsign(m_vect->y) * 0.1
Toshihiro Shimizu 890ddd
			delta = TThickPoint(0, 0, m_versus * norm(*m_vect) * gaussianPotential(diff));
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			double outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			delta = TThickPoint(0, 0, outVal);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//TThickPoint cp = stroke.getControlPoint(n);
Toshihiro Shimizu 890ddd
		//if(cp.thick + delta.thick<0.001) delta.thick = 0.001-cp.thick;
Toshihiro Shimizu 890ddd
		return delta;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TStrokeThicknessDeformation::getDisplacement(const TStroke &stroke, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double diff = stroke.getLength(w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	diff = diff - m_startParameter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_vect)
Toshihiro Shimizu 890ddd
			return gaussianPotential(diff) * TThickPoint(*m_vect, 0);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			double outVal = gaussianPotential(diff);
Toshihiro Shimizu 890ddd
			return TThickPoint(0, 0, outVal);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeThicknessDeformation::getDelta(const TStroke &stroke, double w) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// potenziale exp^(-x^2) limitato tra [-c_maxLenghtOfGaussian,c_maxLenghtOfGaussian]
Toshihiro Shimizu 890ddd
	double diff = stroke.getLength(w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	diff = diff - m_startParameter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (fabs(diff) <= m_lengthOfDeformation) {
Toshihiro Shimizu 890ddd
		// modulo il vettore spostamento in funzione  del potenziale
Toshihiro Shimizu 890ddd
		//  il termine (1.0/m_lengthOfDeformation) * 3 scala
Toshihiro Shimizu 890ddd
		//  il punto in diff su un sistema di coordinate
Toshihiro Shimizu 890ddd
		//  normalizzato, associato con la curva exp^(-x^2)
Toshihiro Shimizu 890ddd
		diff *= (1.0 / m_lengthOfDeformation) * c_maxLenghtOfGaussian;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return derivateOfGaussianPotential(diff);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TStrokeThicknessDeformation::getMaxDiff() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return 0.09;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStrokeThicknessDeformation::~TStrokeThicknessDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_vect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointDeformation::TPointDeformation(const TStroke *stroke,
Toshihiro Shimizu 890ddd
									 const TPointD ¢er,
Toshihiro Shimizu 890ddd
									 double radius)
Toshihiro Shimizu 890ddd
	: m_strokeRef(stroke), m_center(center), m_radius(radius)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_strokeRef);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointDeformation::TPointDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointDeformation::~TPointDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TThickPoint TPointDeformation::getDisplacement(double s) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// riferimento ad un punto ciccione della stroke
Toshihiro Shimizu 890ddd
	TThickPoint
Toshihiro Shimizu 890ddd
		thickPnt = m_strokeRef->getPointAtLength(s);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(thickPnt != TConsts::natp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD pntOfStroke(convert(thickPnt));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double d = tdistance(pntOfStroke, m_center);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double outVal = wyvillPotential(d, m_radius);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TThickPoint(outVal, outVal, 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// return ratio: (number of Control Point)/length
Toshihiro Shimizu 890ddd
double TPointDeformation::getCPDensity(double s) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// reference to a thickpoint
Toshihiro Shimizu 890ddd
	TThickPoint
Toshihiro Shimizu 890ddd
		thickPnt = m_strokeRef->getThickPointAtLength(s);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(thickPnt != TConsts::natp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD
Toshihiro Shimizu 890ddd
		pntOfStroke = convert(thickPnt);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double d = tdistance(pntOfStroke, m_center);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return normOfGradientOfWyvillPotential(d, m_radius);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TPointDeformation::getCPCountInRange(double s0, double s1) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (s1 < s0)
Toshihiro Shimizu 890ddd
		swap(s1, s0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double step = (s1 - s0) * 0.1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double cpCount = 0.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (double s = s0; s < s1; s += step)
Toshihiro Shimizu 890ddd
		cpCount += getCPDensity(s);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	cpCount += getCPDensity(s1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return cpCount;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TPointDeformation::getMinCPDensity() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return 0.3;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------