|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCURVES_UTIL_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TCURVES_UTIL_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "tutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgeometry.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TGEOMETRY_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//forwards declarations
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSegment;
|
|
Toshihiro Shimizu |
890ddd |
class TQuadratic;
|
|
Toshihiro Shimizu |
890ddd |
class TThickQuadratic;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! area (orientata) del trapeziode limitato dalla curva
|
|
Toshihiro Shimizu |
890ddd |
e dall'asse delle ascisse. L'area e' positiva se p(0),...p(t)...,p(1),p(0)
|
|
Toshihiro Shimizu |
890ddd |
viene percorso in senso antiorario
|
|
Toshihiro Shimizu |
890ddd |
DVAPI double getArea(const TQuadratic &curve);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! Returns true if the min distance between \b point an \b segment is less o equal to \b distance
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI bool isCloseToSegment(const TPointD &point, const TSegment &segment, double distance);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Compute min distance between a segment and a point
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI double tdistance(const TSegment &segment, const TPointD &point);
|
|
Toshihiro Shimizu |
890ddd |
inline double tdistance(const TPointD &point, const TSegment &segment)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return tdistance(segment, point);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Compute intersection between segments;
|
|
Toshihiro Shimizu |
890ddd |
return the number of intersections (0/1/2/-1) and add them
|
|
Toshihiro Shimizu |
890ddd |
(as a param couple) to the vector 'intersections'
|
|
Toshihiro Shimizu |
890ddd |
\note
|
|
Toshihiro Shimizu |
890ddd |
if the segment intersections is larger than one point
|
|
Toshihiro Shimizu |
890ddd |
(i.e. the segments share a sub-segment) return 2 and
|
|
Toshihiro Shimizu |
890ddd |
in vector there are extremes of sub-segment.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI int intersect(const TPointD &seg1p0, const TPointD &seg1p1, const TPointD &seg2p0, const TPointD &seg2p1,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<doublepair> &intersections);</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI int intersect(const TSegment &first,
|
|
Toshihiro Shimizu |
890ddd |
const TSegment &second,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<doublepair> &intersections);</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Compute intersection between quadratics;
|
|
Toshihiro Shimizu |
890ddd |
return the number of intersections (0-4) and add them
|
|
Toshihiro Shimizu |
890ddd |
(as a param couple) to the vector 'intersections'
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI int intersect(const TQuadratic &q0,
|
|
Toshihiro Shimizu |
890ddd |
const TQuadratic &q1,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<doublepair> &intersections, bool checksegments = true);</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Compute intersection between and a segment;
|
|
Toshihiro Shimizu |
890ddd |
return the number of intersections [0,2] and add them
|
|
Toshihiro Shimizu |
890ddd |
(as a param couple) to the vector 'intersections'.
|
|
Toshihiro Shimizu |
890ddd |
Remark:
|
|
Toshihiro Shimizu |
890ddd |
In pair "first" is for the first object and "second"
|
|
Toshihiro Shimizu |
890ddd |
its for the second.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVAPI int intersect(const TQuadratic &q,
|
|
Toshihiro Shimizu |
890ddd |
const TSegment &s,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<doublepair> &intersections,</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
bool firstQuad = true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline int intersect(const TSegment &s,
|
|
Toshihiro Shimizu |
890ddd |
const TQuadratic &q,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<doublepair> &intersections)</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return intersect(q, s, intersections, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void split(const T &tq,
|
|
Shinya Kitaoka |
3bfa54 |
const std::vector<double> &pars,</double>
|
|
Toshihiro Shimizu |
890ddd |
std::vector<t *=""> &v)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (pars.empty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *q1, q2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UINT i;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
q1 = new T();
|
|
Toshihiro Shimizu |
890ddd |
tq.split(pars[0], *q1, q2);
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(q1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 1; i < pars.size(); ++i) {
|
|
Toshihiro Shimizu |
890ddd |
double newPar = (pars[i] - pars[i - 1]) / (1.0 - pars[i - 1]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
q1 = new T();
|
|
Toshihiro Shimizu |
890ddd |
q2.split(newPar, *q1, q2);
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(q1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
v.push_back(new T(q2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void split(const T &tq, double w0, double w1, T &qOut)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
T q2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(w0 <= w1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((w1 - w0 == 0.0) && w0 == 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
tq.split(w0, q2, qOut);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tq.split(w0, qOut, q2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double newPar = (w1 - w0) / (1.0 - w0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
q2.split(newPar, qOut, q2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI double computeStep(const TQuadratic &quad, double pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI double computeStep(const TThickQuadratic &quad, double pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
TQuadraticLengthEvaulator is an explicit length builder that for a specified
|
|
Toshihiro Shimizu |
890ddd |
quadratic.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
The purpose of a dedicated evaluator for the length of a quadratic is that of
|
|
Toshihiro Shimizu |
890ddd |
minimizing its computational cost.
|
|
Toshihiro Shimizu |
890ddd |
Both assigning a quadratic to the evaluator and retrieving its length up
|
|
Toshihiro Shimizu |
890ddd |
to a given parameter cost 1 sqrt and 1 log.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
class TQuadraticLengthEvaluator
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double m_c, m_e, m_f, m_sqrt_a_div_2, m_tRef, m_primitive_0;
|
|
Toshihiro Shimizu |
890ddd |
bool m_constantSpeed, m_noSpeed0, m_squareIntegrand;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TQuadraticLengthEvaluator() {}
|
|
Toshihiro Shimizu |
890ddd |
TQuadraticLengthEvaluator(const TQuadratic &quad) { setQuad(quad); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setQuad(const TQuadratic &quad);
|
|
Toshihiro Shimizu |
890ddd |
double getLengthAt(double t) const;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// End Of File
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|