Using the Ge library you can create and modify NURBS curves in 2D and 3D space represented by the OdGeNurbCurve2d and OdGeNurbCurve3d classes respectively. This topic describes the most commonly used operations with 3D NURBS curves; the functionality of 2D curves is similar to that of 3D.
In the Ge library, NURBS splines can be defined by control points and fit points.
To create an OdGeNurbCurve3d object, use the appropriate constructor from the constructors list:
For example, the following creates a rational NURBS curve by a given degree, knot vector and control points:
OdGeKnotVector knots;
OdGePoint3dArray cntrlPnts;
knots.append(0.0);
knots.append(0.0);
knots.append(0.0);
knots.append(0.0);
knots.append(1.0);
knots.append(1.0);
knots.append(1.0);
knots.append(1.0);
cntrlPnts.append(OdGePoint3d(0,0,0));
cntrlPnts.append(OdGePoint3d(1,1,0));
cntrlPnts.append(OdGePoint3d(2,1,0));
cntrlPnts.append(OdGePoint3d(3,0,0));
OdGeNurbCurve3d nurb(3, knots, cntrlPnts);
The OdGeNurbCurve3d class provides a set of methods for working with spline definition data.
Using this functionality you are able to add or delete control points, insert or delete knots, get values of specific spline parameters or set parameters to their new values, etc.
The addControlPointAt() method adds a control point at the specified knot value using the weight parameter to set the weight value for rational splines (if the weight isn't specified, a default value of 1.0 will be used). The deleteControlPointAt() deletes a control point with specified index from the control points array. The addKnot() method adds a new knot in the spline knot vector. To increase the degree of the spline by a specific value, use the elevateDegree() method. If the spline is not already rational, you can make it rational (each control point is assigned the specified weight) using the makeRational() method.
To get all data that defines a NURBS curve, use the getDefinitionData() method. It returns the degree of the spline, two boolean values indicating if the spline is rational and periodic, knots of the spline, and two arrays for control points and for corresponding weights.
OdGeKnotVector knots;
OdGePoint3dArray cntrlPnts;
OdGeDoubleArray weights;
int degree;
bool isRational, isPeriodic;
nurb.getDefinitionData(degree, isRational, isPeriodic, knots, cntrlPnts, weights);
To set definition data of a NURBS curve, use the set() method. It sets the degree of the spline, knots, an array of control points, an array for corresponding weights, and a flag that indicates if the spline is periodic:
nurb.set(degree, knots, cntrlPnts, weights, isPeriodic);
You can also join the spline with another one using the joinWith() method. To calculate the resulting spline, both splines must be open and the start point of the input spline must be equal to the endpoint of the initial spline.
If the spline is open, you can make it closed using the makeClosed() method that creates a smooth spline between the first and end points and joins it with the initial spline.
The hardTrimByParams() method trims NURBS curves to the newStartParam
and newEndParam
parameter values.
Use one of the convertFrom() methods to convert the specified curve to a NURBS curve. These methods return a raw pointer to the converted curve, so caller is responsible for clearing allocated memory for the converted curve. For example to convert a 3D line segment:
OdGeLineSeg3d line3d;
OdGeNurbCurve3d* convertedCurve = OdGeNurbCurve3d::convertFrom(&line3d);
...
delete convertedCurve;
The spline object can contain fit data that defines its behavior at fit points.
If the spline contains fit data, use one of the getFitData() methods to obtain all the fit data that is used to construct the spline, including the fit points, fit tolerance, start and end tangent values (if they exist), and knot parameterization:
nurb.getFitData(fitPnts, fitTolerance, isTangentsExist, startTangent, endTangent, knotParam);
In the case of a spline constructed by control points, you can calculate fit data using the buildFitData() method. The method returns the true value if the data is successfully calculated.
Besides all fit data, you can get specific fit parameters for the spline using such methods as: getFitPointAt(), getFitKnotParameterization(), getFitTangents() and getFitTolerance(). For example, to get the fit point at an index of 0, fit knot parameterization, start and end tangent vectors, and fit tolerance of the spline:
nurb.getFitPointAt(0, OdGePoint3d());
OdGeKnotParameterization knotParam;
nurb.getFitKnotParameterization(knotParam);
nurb.getFitKnotParameterization(startTangent, endTangent);
nurb.getFitTolerance(fitTolerance);
To set fit data, use the setFitData() method with the following available signatures:
For example:
nurb.setFitData(fitPnts, OdGeVector3d(0,1,0), OdGeVector3d(1,-1,0), OdGeTol(1.e-6));
To set specific fit data, use such methods as: setFitPointAt(), setFitTangents() and setFitTolerance().
The addFitPointAt() method adds a fit point at the specified specified fit point index. The deleteFitPointAt() deletes a fit point with specified index from the fit points array.
If the spline is open, you can make it closed using the makeClosedFit() method that creates a smooth spline between the first and end interpolated points and joins it with the initial spline.
To purge all fit data that is used to construct the spline, use purgeFitData(). This method cleans the fit points array, start and end tangents without changing knots, control points and their weights, and returns true. If the spline doesn't contain fit data, the method only returns false.
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|