Commit 375dbc87 authored by Lars Krecklau's avatar Lars Krecklau

* Added a simple random function

* Fixed warnings in the NURBSCurve class and added an error message when a curve is defined with a missmatching knot vector
parent bdbfbc49
......@@ -92,6 +92,9 @@ inline float abs(float a) {return(a < 0.0f ? -a : a);}
inline double abs(double a) {return(a < 0.0 ? -a : a);}
inline int_t abs(int_t a) {return(a < 0 ? -a : a);}
inline double randD (double _from = 0.0, double _to = 1.0) { return (_to - _from) * (double(rand()) / double(RAND_MAX)) + _from; }
inline int32_t randI32 (int32_t _from = 0, int32_t _to = 1) { return (rand() % (_to - _from + 1)) + _from; }
template<typename T>
inline T max(T a, T b) {return(a > b ? a : b);}
......
......@@ -51,8 +51,30 @@ public:
: mDegree(_degree),
mOrder(_degree + 1),
mControlPoints(_controlPoints),
mKnots(_knots)
{}
mKnots()
{
if(mControlPoints.size() == _knots.size() + mOrder)
{
mKnots = _knots;
}
else
{
ACGL::Utils::error() << "Trying to create NURBS curve with a wrong number of knots... automatically generating a valid knot vector instead!" << std::endl;
//First knot with #order multiplicity
mKnots.resize(mControlPoints.size() + mOrder, 0.0f);
//Inner knots
float fCurrentKnot = 1.0f;
for(uint_t i = mOrder; i < mKnots.size()-mOrder; ++i)
{
mKnots[i] = fCurrentKnot;
fCurrentKnot += 1.0f;
}
//Last knot with #order multiplicity
for(uint_t i = mKnots.size() - mOrder; i < mKnots.size(); ++i)
mKnots[i] = fCurrentKnot;
normalizeKnotVector();
}
}
virtual ~NURBSCurve(void){}
uint_t getDegree (void) const { return mDegree; }
......@@ -101,18 +123,18 @@ public:
//reverse the order in the span to easier indices
//in the next step.
std::vector< std::vector<NURBSControlPointType> > controlPointsInSpan;
for(int i = 0; i < mOrder; ++i)
for(uint_t i = 0; i < mOrder; ++i)
controlPointsInSpan.push_back(std::vector<NURBSControlPointType>());
for(int i = 0; i < mOrder; ++i)
for(uint_t i = 0; i < mOrder; ++i)
{
NURBSControlPointType controlPoint = mControlPoints[interval - i];
controlPoint.data *= controlPoint.weight;
controlPointsInSpan[mDegree].push_back(controlPoint);
}
for(int l = 0; l < mDegree; ++l)
for(uint_t l = 0; l < mDegree; ++l)
{
for(int i = 0; i < mDegree - l; ++i)
for(uint_t i = 0; i < mDegree - l; ++i)
{
float fRatio = (_t - mKnots[interval - i]) / (mKnots[interval + mDegree - l - i] - mKnots[interval - i]);
//Please note: Due to the reversed order we have:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment