示例#1
0
Array2D_Real BSplineBasis<Real>::Allocate()
{
	int numRows = mDegree + 1;
	int numCols = mNumCtrlPoints + mDegree;

	return Array2D_Real( numRows, Array1D_Real( numCols, 0.0 ) );
}
示例#2
0
Array1D_Vector3 NURBSCurve<Real>::simpleRefine( int k )
{
    if(k <= 0) return this->mCtrlPoint;

    NURBSCurve<Real> curCurve = *this;

    for(int i = 0; i < k ; i++)
    {
        int segment = 0;
        double maxDist = -DBL_MAX;

        // Find longest segment
        for(int j = 0; j < (int)(curCurve.mCtrlPoint.size() - 1); j++)
        {
            double dist = (curCurve.mCtrlPoint[j+1] - curCurve.mCtrlPoint[j]).norm();

            if(dist > maxDist) {
                maxDist = dist;
                segment = j;
            }
        }

        // Insert knot at middle of longest segment
        Array1D_Real U = curCurve.GetKnotVector(true);

        double t = double(segment) / (curCurve.mCtrlPoint.size()-2);

        int idx = t * (U.size()-2);
        double range = U[idx+1] - U[idx];
        double u = (0.5 * range) + U[idx];

        Array1D_Vector3 newPnts;
        Array1D_Real Ubar;
        Array1D_Real insk = Array1D_Real(1,u);
        curCurve.refine(insk, newPnts, Ubar);

        // Update control points
        curCurve = NURBSCurve<Real>::createCurveFromPoints(newPnts);
    }

    return Array1D_Vector3(curCurve.mCtrlPoint.begin(),curCurve.mCtrlPoint.end());
}