mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-26 05:58:48 -05:00
Remove approximated method, since online method is efficient enough
This commit is contained in:
@@ -44,28 +44,10 @@ const double PathCurve::length() const {
|
||||
}
|
||||
|
||||
glm::dvec3 PathCurve::positionAt(double relativeLength) {
|
||||
double u = approximatedCurveParameter(relativeLength * _totalLength); // TODO: only use relative length?
|
||||
double u = curveParameter(relativeLength * _totalLength); // TODO: only use relative length?
|
||||
return interpolate(u);
|
||||
}
|
||||
|
||||
double PathCurve::approximatedCurveParameter(double s) {
|
||||
if (s <= Epsilon) return 0.0;
|
||||
if (s >= _totalLength) return 1.0;
|
||||
|
||||
std::map<double, double>::iterator itSample = _parameterPairs.upper_bound(s);
|
||||
std::map<double, double>::iterator itPrevSample = std::prev(itSample, 1);
|
||||
|
||||
double sSample = itSample->first;
|
||||
double sPrevSample = itPrevSample->first;
|
||||
double uSample = itSample->second;
|
||||
double uPrevSample = itPrevSample->second;
|
||||
|
||||
double slope = (uSample - uPrevSample) / (sSample - sPrevSample);
|
||||
|
||||
// linear fit (TODO: investigate higher order fits?)
|
||||
return uPrevSample + slope * (s - sPrevSample);
|
||||
}
|
||||
|
||||
// Compute the curve parameter from an arc length value, using a combination of
|
||||
// Newton's method and bisection. Source:
|
||||
// https://www.geometrictools.com/Documentation/MovingAlongCurveSpecifiedSpeed.pdf
|
||||
@@ -162,33 +144,6 @@ void PathCurve::initParameterIntervals() {
|
||||
for (unsigned int i = 1; i <= _nrSegments; i++) {
|
||||
_parameterIntervals[i] = _lengthSums[i] / _totalLength;
|
||||
}
|
||||
|
||||
// prepare samples for arc length reparameterization
|
||||
_parameterPairs.clear();
|
||||
_parameterPairs[0.0] = 0.0;
|
||||
double s = 0.0;
|
||||
for (int i = 1; i <= _nrSegments; ++i) {
|
||||
double segmentLength = _lengths[i];
|
||||
// TODO: make nr of samples dependent on segment length somehow
|
||||
double deltaLength = _lengths[i] / _nrParameterSamplesPerSegment;
|
||||
double endLength = _lengthSums[i];
|
||||
double startLength = _lengthSums[i-1];
|
||||
s += deltaLength;
|
||||
while (s < endLength) {
|
||||
double sSegment = s - startLength;
|
||||
double sSegmentEased = segmentLength * ghoul::cubicEaseInOut(sSegment / segmentLength);
|
||||
double sEased = sSegmentEased + startLength;
|
||||
double u = curveParameter(sEased);
|
||||
_parameterPairs[sEased] = u;
|
||||
s += deltaLength;
|
||||
}
|
||||
_parameterPairs[_lengthSums[i]] = _parameterIntervals[i];
|
||||
}
|
||||
_parameterPairs[_totalLength] = 1.0;
|
||||
|
||||
// TODO: remove when not needed
|
||||
//LINFO(fmt::format("number samples: {}", _parameterPairs.size()));
|
||||
//LINFO(fmt::format("next to last value: {}", std::prev(_parameterPairs.end(), 2)->second));
|
||||
}
|
||||
|
||||
double PathCurve::approximatedDerivative(double u, double h) {
|
||||
|
||||
@@ -44,8 +44,6 @@ public:
|
||||
const double length() const;
|
||||
glm::dvec3 positionAt(double relativeLength);
|
||||
|
||||
double approximatedCurveParameter(double s);
|
||||
|
||||
// compute curve parameter that matches the input arc length s
|
||||
double curveParameter(double s);
|
||||
|
||||
@@ -68,9 +66,6 @@ protected:
|
||||
std::vector<double> _lengths;
|
||||
std::vector<double> _lengthSums;
|
||||
double _totalLength;
|
||||
|
||||
int _nrParameterSamplesPerSegment = 100;
|
||||
std::map<double, double> _parameterPairs; // s (arc length), u (curve parameter)
|
||||
};
|
||||
|
||||
class Bezier3Curve : public PathCurve {
|
||||
|
||||
Reference in New Issue
Block a user