17 template <
typename Real>
27 int degree1,
int numControls1,
int numSamples1,
35 inline int GetDegree(
int dimension)
const;
58 template <
typename Real>
60 int numSamples0,
int degree1,
int numControls1,
int numSamples1,
66 LogAssert(1 <= degree0 && degree0 + 1 < numControls0,
"Invalid degree.");
67 LogAssert(numControls0 <= numSamples0,
"Invalid number of controls.");
68 LogAssert(1 <= degree1 && degree1 + 1 < numControls1,
"Invalid degree.");
69 LogAssert(numControls1 <= numSamples1,
"Invalid number of controls.");
70 LogAssert(sampleData,
"Invalid sample data.");
82 for (dim = 0; dim < 2; ++dim)
91 input.
uniqueKnots[0].multiplicity = mDegree[dim] + 1;
93 Real factor = ((Real)1) / (Real)last;
94 for (
int i = 1; i < last; ++i)
100 input.
uniqueKnots[last].multiplicity = mDegree[dim] + 1;
101 mBasis[dim].Create(input);
103 tMultiplier[dim] = ((Real)1) / (Real)(
mNumSamples[dim] - 1);
111 int i0, i1, i2, imin, imax;
120 for (dim = 0; dim < 2; ++dim)
124 for (i1 = 0; i1 < i0; ++i1)
126 ATAMat[dim](i0, i1) = ATAMat[dim](i1, i0);
130 if (i1Max >= mNumControls[dim])
132 i1Max = mNumControls[dim] - 1;
135 for (i1 = i0; i1 <= i1Max; ++i1)
137 Real
value = (Real)0;
140 t = tMultiplier[dim] * (Real)i2;
141 mBasis[dim].Evaluate(t, 0, imin, imax);
142 if (imin <= i0 && i0 <= imax && imin <= i1 && i1 <= imax)
144 Real b0 =
mBasis[dim].GetValue(0, i0);
145 Real b1 =
mBasis[dim].GetValue(0, i1);
149 ATAMat[dim](i0, i1) = value;
157 for (dim = 0; dim < 2; dim++)
160 size_t numBytes =
mNumControls[dim] * mNumSamples[dim] *
sizeof(Real);
161 memset(ATMat[dim][0], 0, numBytes);
164 for (i1 = 0; i1 < mNumSamples[dim]; ++i1)
166 t = tMultiplier[dim] * (Real)i1;
167 mBasis[dim].Evaluate(t, 0, imin, imax);
168 if (imin <= i0 && i0 <= imax)
170 ATMat[dim][i0][i1] =
mBasis[dim].GetValue(0, i0);
178 for (dim = 0; dim < 2; ++dim)
180 bool solved = ATAMat[dim].template SolveSystem<true>(ATMat[dim][0],
182 LogAssert(solved,
"Failed to solve linear system.");
190 for (i0 = 0; i0 < mNumControls[0]; ++i0)
195 Real x1Value = ATMat[1][i1][j1];
196 for (
int j0 = 0; j0 < mNumSamples[0]; ++j0)
198 Real x0Value = ATMat[0][i0][j0];
201 sum += (x0Value * x1Value) * sample;
209 template <
typename Real>
inline 215 template <
typename Real>
inline 221 template <
typename Real>
inline 227 template <
typename Real>
inline 233 template <
typename Real>
inline 239 template <
typename Real>
inline 246 template <
typename Real>
249 int iumin, iumax, ivmin, ivmax;
250 mBasis[0].Evaluate(u, 0, iumin, iumax);
251 mBasis[1].Evaluate(v, 0, ivmin, ivmax);
254 for (
int iv = ivmin; iv <= ivmax; ++iv)
256 Real value1 =
mBasis[1].GetValue(0, iv);
257 for (
int iu = iumin; iu <= iumax; ++iu)
259 Real value0 =
mBasis[0].GetValue(0, iu);
261 position += (value0 * value1) * control;
std::vector< Vector3< Real > > mControlData
Vector3< Real > const * GetControlData() const
BasisFunction< Real > const & GetBasis(int dimension) const
#define LogAssert(condition, message)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLsizei const GLfloat * value
BSplineSurfaceFit(int degree0, int numControls0, int numSamples0, int degree1, int numControls1, int numSamples1, Vector3< Real > const *sampleData)
Vector3< Real > GetPosition(Real u, Real v) const
Vector3< Real > const * GetSampleData() const
int GetNumSamples(int dimension) const
Vector3< Real > const * mSampleData
BasisFunction< Real > mBasis[2]
GLenum GLenum GLenum input
int GetNumControls(int dimension) const
int GetDegree(int dimension) const