|
Shinya Kitaoka |
810553 |
#pragma once
|
|
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 |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// 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)
|
|
Shinya Kitaoka |
120a6e |
viene percorso in senso antiorario
|
|
Toshihiro Shimizu |
890ddd |
DVAPI double getArea(const TQuadratic &curve);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*! Returns true if the min distance between \b point an \b segment is less o
|
|
Shinya Kitaoka |
120a6e |
* equal to \b distance
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
DVAPI bool isCloseToSegment(const TPointD &point, const TSegment &segment,
|
|
Shinya Kitaoka |
120a6e |
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);
|
|
Shinya Kitaoka |
120a6e |
inline double tdistance(const TPointD &point, const TSegment &segment) {
|
|
Shinya Kitaoka |
120a6e |
return tdistance(segment, point);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
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'
|
|
Shinya Kitaoka |
120a6e |
\note
|
|
Toshihiro Shimizu |
890ddd |
if the segment intersections is larger than one point
|
|
Shinya Kitaoka |
120a6e |
(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 |
|
|
Shinya Kitaoka |
120a6e |
DVAPI int intersect(const TPointD &seg1p0, const TPointD &seg1p1,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &seg2p0, const TPointD &seg2p1,
|
|
Shinya Kitaoka |
120a6e |
std::vector<doublepair> &intersections);</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DVAPI int intersect(const TSegment &first, const TSegment &second,
|
|
Shinya Kitaoka |
120a6e |
std::vector<doublepair> &intersections);</doublepair>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
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 |
*/
|
|
Shinya Kitaoka |
120a6e |
DVAPI int intersect(const TQuadratic &q0, const TQuadratic &q1,
|
|
Shinya Kitaoka |
120a6e |
std::vector<doublepair> &intersections,</doublepair>
|
|
Shinya Kitaoka |
120a6e |
bool checksegments = true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
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 |
*/
|
|
Shinya Kitaoka |
120a6e |
DVAPI int intersect(const TQuadratic &q, const TSegment &s,
|
|
Shinya Kitaoka |
120a6e |
std::vector<doublepair> &intersections,</doublepair>
|
|
Shinya Kitaoka |
120a6e |
bool firstQuad = true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
inline int intersect(const TSegment &s, const TQuadratic &q,
|
|
Shinya Kitaoka |
120a6e |
std::vector<doublepair> &intersections) {</doublepair>
|
|
Shinya Kitaoka |
120a6e |
return intersect(q, s, intersections, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
void split(const T &tq, const std::vector<double> &pars, std::vector<t *=""> &v) {</t></double>
|
|
Shinya Kitaoka |
120a6e |
if (pars.empty()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
T *q1, q2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
UINT i;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
q1 = new T();
|
|
Shinya Kitaoka |
120a6e |
tq.split(pars[0], *q1, q2);
|
|
Shinya Kitaoka |
120a6e |
v.push_back(q1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (i = 1; i < pars.size(); ++i) {
|
|
Shinya Kitaoka |
120a6e |
double newPar = (pars[i] - pars[i - 1]) / (1.0 - pars[i - 1]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
q1 = new T();
|
|
Shinya Kitaoka |
120a6e |
q2.split(newPar, *q1, q2);
|
|
Shinya Kitaoka |
120a6e |
v.push_back(q1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
v.push_back(new T(q2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
void split(const T &tq, double w0, double w1, T &qOut) {
|
|
Shinya Kitaoka |
120a6e |
T q2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
assert(w0 <= w1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if ((w1 - w0 == 0.0) && w0 == 1.0) {
|
|
Shinya Kitaoka |
120a6e |
tq.split(w0, q2, qOut);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
tq.split(w0, qOut, q2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double newPar = (w1 - w0) / (1.0 - w0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
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 |
*/
|
|
Shinya Kitaoka |
120a6e |
class TQuadraticLengthEvaluator {
|
|
Shinya Kitaoka |
120a6e |
double m_c, m_e, m_f, m_sqrt_a_div_2, m_tRef, m_primitive_0;
|
|
Shinya Kitaoka |
120a6e |
bool m_constantSpeed, m_noSpeed0, m_squareIntegrand;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TQuadraticLengthEvaluator() {}
|
|
Shinya Kitaoka |
120a6e |
TQuadraticLengthEvaluator(const TQuadratic &quad) { setQuad(quad); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setQuad(const TQuadratic &quad);
|
|
Shinya Kitaoka |
120a6e |
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 |
//-----------------------------------------------------------------------------
|