|
|
ebedef |
|
|
|
ebedef |
|
|
|
ebedef |
#include <tools modifiers="" modifiersimplify.h=""></tools>
|
|
|
ebedef |
#include <algorithm></algorithm>
|
|
|
ebedef |
|
|
|
ebedef |
|
|
|
ebedef |
//*****************************************************************************************
|
|
|
ebedef |
// TModifierSimplify implementation
|
|
|
ebedef |
//*****************************************************************************************
|
|
|
ebedef |
|
|
|
ebedef |
|
|
|
ebedef |
TModifierSimplify::TModifierSimplify(double step):
|
|
|
bdb1e2 |
step(step) { }
|
|
|
ebedef |
|
|
|
ebedef |
|
|
|
ebedef |
void
|
|
|
ebedef |
TModifierSimplify::modifyTrack(
|
|
|
ebedef |
const TTrack &track,
|
|
|
ebedef |
TTrackList &outTracks )
|
|
|
ebedef |
{
|
|
|
ebedef |
if (!track.handler) {
|
|
|
bdb1e2 |
Handler *handler = new Handler();
|
|
|
bdb1e2 |
track.handler = handler;
|
|
|
bdb1e2 |
handler->track = new TTrack(track);
|
|
|
bdb1e2 |
new Interpolator(*handler->track);
|
|
|
ebedef |
}
|
|
|
ebedef |
|
|
|
bdb1e2 |
Handler *handler = dynamic_cast<handler*>(track.handler.getPointer());</handler*>
|
|
|
bdb1e2 |
if (!handler)
|
|
|
ebedef |
return;
|
|
|
bdb1e2 |
|
|
|
bdb1e2 |
outTracks.push_back(handler->track);
|
|
|
bdb1e2 |
TTrack &subTrack = *handler->track;
|
|
|
ebedef |
|
|
|
ebedef |
if (!track.changed())
|
|
|
ebedef |
return;
|
|
|
bdb1e2 |
|
|
|
ebedef |
// remove points
|
|
|
ebedef |
int start = track.size() - track.pointsAdded;
|
|
|
ebedef |
if (start < 0) start = 0;
|
|
|
ebedef |
int subStart = subTrack.floorIndex(subTrack.indexByOriginalIndex(start));
|
|
|
ebedef |
if (subStart < 0) subStart = 0;
|
|
|
ebedef |
start = track.floorIndex(subTrack[subStart].originalIndex);
|
|
|
ebedef |
if (start < 0) start = 0;
|
|
|
ebedef |
subTrack.truncate(subStart);
|
|
|
ebedef |
|
|
|
ebedef |
// add points
|
|
|
ebedef |
double step2 = step*step;
|
|
|
ebedef |
TTrackPoint p0 = subTrack.back();
|
|
|
ebedef |
for(int i = start; i < track.size(); ++i) {
|
|
|
bdb1e2 |
const TTrackPoint &p1 = subTrack.pointFromOriginal(i);
|
|
|
ebedef |
if (!subTrack.empty() && tdistance2(p1.position, p0.position) < step2) {
|
|
|
ebedef |
if (p0.pressure < p1.pressure) p0.pressure = p1.pressure;
|
|
|
398cd8 |
if (i == track.size() - 1) p0.position = p1.position;
|
|
|
ebedef |
p0.tilt = p1.tilt;
|
|
|
ebedef |
p0.time = p1.time;
|
|
|
ebedef |
p0.final = p1.final;
|
|
|
ebedef |
subTrack.pop_back();
|
|
|
ebedef |
subTrack.push_back(p0, false);
|
|
|
ebedef |
} else {
|
|
|
ebedef |
p0 = p1;
|
|
|
ebedef |
subTrack.push_back(p0, false);
|
|
|
ebedef |
}
|
|
|
ebedef |
}
|
|
|
ebedef |
|
|
|
ebedef |
// fix points
|
|
|
ebedef |
if (track.fixedFinished())
|
|
|
ebedef |
subTrack.fix_all();
|
|
|
ebedef |
else
|
|
|
398cd8 |
if (track.fixedSize())
|
|
|
ebedef |
subTrack.fix_to(
|
|
|
398cd8 |
subTrack.floorIndex( subTrack.indexByOriginalIndex(track.fixedSize()-1) ));
|
|
|
ebedef |
|
|
|
ebedef |
track.resetChanges();
|
|
|
ebedef |
}
|