-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaneRiesenfeldSplinesEvaluator.cpp
47 lines (40 loc) · 1.48 KB
/
LaneRiesenfeldSplinesEvaluator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <assert.h>
#include <iostream>
#include "LaneRiesenfeldSplinesEvaluator.h"
#include "modelerapp.h"
using namespace std;
int LaneRiesenfeldSplinesEvaluator::degree = 2;
void LaneRiesenfeldSplinesEvaluator::evaluateCurve(const std::vector<Point>& ptvCtrlPts,
std::vector<Point>& ptvEvaluatedCurvePts,
const float& fAniLength,
const bool& bWrap) const
{
LaneRiesenfeldSplinesEvaluator::degree = ModelerApplication::Instance()->GetDegree();
const int degree = LaneRiesenfeldSplinesEvaluator::degree;
ptvEvaluatedCurvePts.clear();
vector<vector<Point>> degreePoints = vector<vector<Point>>();
// Init
vector<Point> degree0 = vector<Point>();
degree0.push_back(Point(0, ptvCtrlPts[0].y));
for(Point p : ptvCtrlPts)
{
degree0.push_back(p);
degree0.push_back(p);
}
degree0.push_back(Point(fAniLength, ptvCtrlPts[ptvCtrlPts.size() - 1].y));
degreePoints.push_back(degree0);
for(int i = 1; i < degree; i++)
{
vector<Point> curDegreePoints = vector<Point>();
vector<Point> prevDegreePoints = degreePoints[i-1];
for(int j = 0; j < prevDegreePoints.size() - 1; j++)
{
Point p = Point(0.5*(prevDegreePoints[j].x + prevDegreePoints[j + 1].x), 0.5*(prevDegreePoints[j].y + prevDegreePoints[j + 1].y));
curDegreePoints.push_back(p);
}
degreePoints.push_back(curDegreePoints);
}
ptvEvaluatedCurvePts = degreePoints[degree - 1];
ptvEvaluatedCurvePts.push_back(Point(0, ptvCtrlPts[0].y));
ptvEvaluatedCurvePts.push_back(Point(fAniLength, ptvCtrlPts[ptvCtrlPts.size() - 1].y));
}