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