Class NurbsSurface
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
A NURBS surface implementing ISurface.
public class NurbsSurface : ISurfaceImpl, ISurface, IOctTreeInsertable, ISerializable, IDeserializationCallback, IExportStep
- Inheritance
-
NurbsSurface
- Implements
- Inherited Members
- Extension Methods
Constructors
NurbsSurface(Ellipse[], double[])
Creates a NURBS surface which passes through the provided ellipses (or circles), e.g. the cross sections of a pipe along a curved path. The u parameter follows the ellipses (the surface is rational of degree 2 in u), the v parameter runs from the first to the last ellipse (degree 3, interpolated through the poles of the ellipses). All ellipses must have the same shape (full ellipses or the same kind of arc) so that their BSpline representations have the same number of poles.
public NurbsSurface(Ellipse[] throughEllis, double[] knots = null)
Parameters
throughEllisEllipse[]The ellipses the surface passes through, in the order of the v parameter
knotsdouble[]Optional v parameter values for the ellipses; when null they are derived from the distances of the poles
NurbsSurface(GeoPoint[,], double[,], double[], double[], int, int, bool, bool)
Creates a new NURBS surface with the given data.
public NurbsSurface(GeoPoint[,] poles, double[,] weights, double[] uKnots, double[] vKnots, int uDegree, int vDegree, bool uPeriodic, bool vPeriodic)
Parameters
polesGeoPoint[,]the poles
weightsdouble[,]the weight of the poles
uKnotsdouble[]the knots in u direction (multiple knots may have the same value)
vKnotsdouble[]the knots in v direction (multiple knots may have the same value)
uDegreeintthe degree in u direction
vDegreeintthe degree in v direction
uPeriodicboolclosed in u direction
vPeriodicboolclosed in v direction
NurbsSurface(GeoPoint[,], double[,], double[], double[], int[], int[], int, int, bool, bool)
Creates a new NURBS surface with the given data.
public NurbsSurface(GeoPoint[,] poles, double[,] weights, double[] uKnots, double[] vKnots, int[] uMults, int[] vMults, int uDegree, int vDegree, bool uPeriodic, bool vPeriodic)
Parameters
polesGeoPoint[,]the poles
weightsdouble[,]the weight of the poles
uKnotsdouble[]the knots in u direction (no duplicate values)
vKnotsdouble[]the knots in v direction (no duplicate values)
uMultsint[]the multiplicities in u direction
vMultsint[]the multiplicities in v direction
uDegreeintthe degree in u direction
vDegreeintthe degree in v direction
uPeriodicboolclosed in u direction
vPeriodicboolclosed in v direction
NurbsSurface(GeoPoint[,], int, int, bool, bool)
Creates a new NURBS surface which interpolates the provided points. The surface will contain the provided points exactely and smoothly interpolated inbetween. The points are organized in a two dimensional array resembling the u and v direction (first and second index) of the NURBS surface
public NurbsSurface(GeoPoint[,] throughPoints, int maxUDegree, int maxVDegree, bool uPeriodic, bool vPeriodic)
Parameters
throughPointsGeoPoint[,]Points to be interpolated
maxUDegreeintThe maximum degree in respect of the first index
maxVDegreeintThe maximum degree in respect of the second index
uPeriodicboolPeriodicy in respect of the first index
vPeriodicboolPeriodicy in respect of the second index
NurbsSurface(GeoPoint[,], int, int, double[], double[], bool, bool)
Creates a NURBS surface which interpolates the provided points, like the constructor without knots: the surface contains the
points exactly and is smoothly interpolated in between. The parameters uKnots and vKnots
are currently ignored; the parameter values of the points are derived from the chord lengths of the point rows and columns.
public NurbsSurface(GeoPoint[,] throughPoints, int maxUDegree, int maxVDegree, double[] uKnots, double[] vKnots, bool uPeriodic, bool vPeriodic)
Parameters
throughPointsGeoPoint[,]Points to be interpolated; the first index is the u direction, the second the v direction
maxUDegreeintThe maximum degree in u (reduced when there are fewer points)
maxVDegreeintThe maximum degree in v (reduced when there are fewer points)
uKnotsdouble[]Intended as the parameter values of the points in u direction, currently ignored
vKnotsdouble[]Intended as the parameter values of the points in v direction, currently ignored
uPeriodicboolTrue when the surface is closed in u direction (the last row of points connects to the first)
vPeriodicboolTrue when the surface is closed in v direction (the last column of points connects to the first)
NurbsSurface(SerializationInfo, StreamingContext)
Constructor for the legacy binary deserialization (ISerializable).
protected NurbsSurface(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoThe serialized data
contextStreamingContextThe source of the deserialization
Properties
IsRuled
returns wheather the surface is linear in u or v direction
public override RuledSurfaceMode IsRuled { get; }
Property Value
IsUPeriodic
Returns true, if this surface is periodic in the u direction (e.g. a cylinder) false otherwise.
public override bool IsUPeriodic { get; }
Property Value
IsVPeriodic
Returns true, if this surface is periodic in the v direction (e.g. a torus) false otherwise.
public override bool IsVPeriodic { get; }
Property Value
Poles
The control points of the surface; the first index runs in u direction, the second in v direction. This is the internal array: changing its entries does not update the surface.
public GeoPoint[,] Poles { get; }
Property Value
- GeoPoint[,]
UDegree
The polynomial degree of the surface in u direction. A degree of 1 means that the lines of constant v are straight (see IsRuled).
public int UDegree { get; }
Property Value
UKnotSpanCount
Number of knot spans (intervals between distinct knot values) in u direction. See GetPatchExtent(int, int, bool).
public int UKnotSpanCount { get; }
Property Value
UKnots
The knot vector in u direction with each knot repeated according to its multiplicity (the form the constructors which take knots and degrees expect). A new array on each access.
public double[] UKnots { get; }
Property Value
- double[]
UPeriod
Returns the u priod of this surface if it is u periodic 0.0 otherwise
public override double UPeriod { get; }
Property Value
VDegree
The polynomial degree of the surface in v direction. A degree of 1 means that the lines of constant u are straight (see IsRuled).
public int VDegree { get; }
Property Value
VKnotSpanCount
Number of knot spans (intervals between distinct knot values) in v direction. See GetPatchExtent(int, int, bool).
public int VKnotSpanCount { get; }
Property Value
VKnots
The knot vector in v direction with each knot repeated according to its multiplicity (the form the constructors which take knots and degrees expect). A new array on each access.
public double[] VKnots { get; }
Property Value
- double[]
VPeriod
Returns the v priod of this surface if it is v periodic 0.0 otherwise
public override double VPeriod { get; }
Property Value
Weights
The weights of the control points, with the same indices as Poles, or null for a non-rational surface. This is the internal array: changing its entries does not update the surface.
public double[,] Weights { get; }
Property Value
- double[,]
isRational
True when the surface is rational, i.e. it has weights and at least one of them differs from 1 (e.g. a surface built from exact circles). A non-rational surface is evaluated with the faster non-rational algorithm.
public bool isRational { get; }
Property Value
Methods
Clone()
Returns an identical but independant copy of this surface
public override ISurface Clone()
Returns
CopyData(ISurface)
Copies the data of the given surface to this surface. The two surfaces are guaranteed to be of the same type. (Used after Clone() and Modify(ModOp) to restore the original values).
public override void CopyData(ISurface CopyFrom)
Parameters
CopyFromISurfacewhere to copy the data from
Derivation2At(GeoPoint2D, out GeoPoint, out GeoVector, out GeoVector, out GeoVector, out GeoVector, out GeoVector)
Returns the point, the two first derivations and the three second derivations of the surface at the provided parameter position.
public override void Derivation2At(GeoPoint2D uv, out GeoPoint location, out GeoVector du, out GeoVector dv, out GeoVector duu, out GeoVector dvv, out GeoVector duv)
Parameters
uvGeoPoint2DPoint in the parameter space
locationGeoPointResulting 3D point
duGeoVectorResulting derivation in u
dvGeoVectorResulting derivation in v
duuGeoVectordvvGeoVectorduvGeoVector
DerivationAt(GeoPoint2D, out GeoPoint, out GeoVector, out GeoVector)
Returns the point and the two derivations of the suface in a single call. It returns the same result as calling PointAt(GeoPoint2D), VDirection(GeoPoint2D) und VDirection(GeoPoint2D) succesively but is often faster than the three seperate calls.
public override void DerivationAt(GeoPoint2D uv, out GeoPoint location, out GeoVector du, out GeoVector dv)
Parameters
uvGeoPoint2DPoint in the parameter space
locationGeoPointResulting 3D point
duGeoVectorResulting derivation in u
dvGeoVectorResulting derivation in v
FixedU(double, double, double)
Returns a curve where the u parameter of this surface is fixed and the v parameter starts a vmin and ends at vmax
public override ICurve FixedU(double u, double vmin, double vmax)
Parameters
Returns
FixedV(double, double, double)
Returns a curve where the v parameter of this surface is fixed and the u parameter starts a umin and ends at umax
public override ICurve FixedV(double v, double umin, double umax)
Parameters
Returns
GetCanonicalForm(double, BoundingRect?)
Returns a simpler form of this surface: SurfaceOfLinearExtrusion might be a cylinder, NURBS might be a sphere etc. Returns null, if there is no simpler form
public override ISurface GetCanonicalForm(double precision, BoundingRect? bounds)
Parameters
precisiondoublemaximal allowed deviation of the new surface
boundsBoundingRect?the part of the parameter space in which the surfaces must coincide; null: the natural bounds of this surface
Returns
GetCanonicalFormOld(double, BoundingRect?)
Previous implementation of GetCanonicalForm(double, BoundingRect?): tries to find an elementary surface (plane, cylinder, cone, sphere, torus) which coincides with this NURBS surface by checking whether its parameter lines are lines and circles. Kept for reference; not used by CADability.
public ISurface GetCanonicalFormOld(double precision, BoundingRect? bounds)
Parameters
precisiondoubleThe maximum allowed distance between the NURBS surface and the elementary surface
boundsBoundingRect?The part of the parameter space to check, or null for the whole surface
Returns
- ISurface
The elementary surface, or null when none was found
GetExtrema()
Returns an array of points in parametric space where there are extrema in direction of x-, y- or z-axis. The normal vector in a extremum is parallel to one of the axis and the surface has a relative maximum or minimum in this direction.
public override GeoPoint2D[] GetExtrema()
Returns
- GeoPoint2D[]
s.a.
GetKnotSpan(int, int)
The uv rectangle of the knot span with the provided indices. The indices refer to the distinct knot values, i.e. uKnotIndex may range from 0 to UKnotSpanCount-1.
public BoundingRect GetKnotSpan(int uKnotIndex, int vKnotIndex)
Parameters
Returns
GetLineIntersection(GeoPoint, GeoVector)
Returns the intersectionpoints of this surface with the line given by the parameters. Teh returned point are in the parametric (u/v) space of this surface.
public override GeoPoint2D[] GetLineIntersection(GeoPoint startPoint, GeoVector direction)
Parameters
Returns
GetMaximumExtent()
Returns the whole parameter range in which the surface is defined: from the first to the last knot in u and in v. Unlike GetNaturalBounds(out double, out double, out double, out double) it does not depend on the bounds a face has set.
public BoundingRect GetMaximumExtent()
Returns
- BoundingRect
The rectangle of the parameter space covered by the knot vectors
GetModified(ModOp)
Implements GetModified(ModOp).
public override ISurface GetModified(ModOp m)
Parameters
mModOphow to modify
Returns
- ISurface
modified surface
GetNaturalBounds(out double, out double, out double, out double)
Returns the natural bounds of the surface. The returned values may be infinite
public override void GetNaturalBounds(out double umin, out double umax, out double vmin, out double vmax)
Parameters
GetNonPeriodicSurface(ICurve[])
Implements GetNonPeriodicSurface(ICurve[])
public override ISurface GetNonPeriodicSurface(ICurve[] orientedCurves)
Parameters
orientedCurvesICurve[]3d curves describing the outline that will be used on the resulting surface
Returns
GetNormal(GeoPoint2D)
Returns the normal vector (perpendicular to the surface) at the given u/v point
public override GeoVector GetNormal(GeoPoint2D uv)
Parameters
uvGeoPoint2Dposition of normal
Returns
- GeoVector
normal vector
GetOffsetSurface(double)
Returns a surface that is "parallel" to this surface, i.e. each point on this surface corresponds a point on the returned surface that has the same (u,v) coordinates and has the 3d coordinates oft the point plus offset*Normal at this point
public override ISurface GetOffsetSurface(double offset)
Parameters
offsetdoubleOffset to this surface
Returns
- ISurface
The offset surface
GetPatchExtent(BoundingRect, bool)
Implements GetPatchExtent(BoundingRect, bool)
public override BoundingCube GetPatchExtent(BoundingRect uvPatch, bool rough)
Parameters
uvPatchBoundingRectroughbooltrue: a quickly computed extent which may be larger than necessary is sufficient (ignored here)
Returns
GetPatchExtent(int, int, bool)
Returns the extent of the surface patch on the knot span [uKnots[uKnotIndex], uKnots[uKnotIndex+1]] x [vKnots[vKnotIndex], vKnots[vKnotIndex+1]] (indices refer to distinct knot values, see UKnotSpanCount and GetKnotSpan(int, int)). The returned box is guaranteed to contain the patch. With rough==true the convex hull property of the poles influencing the span is used: very fast, but the box may be considerably larger than the patch. With rough==false the box is close to the smallest enclosing box: extrema on the four boundary curves and Newton iterations for inner extrema yield a reference box (a lower bound, since it only contains points on the surface), and the Bézier hull of the span is subdivided until it (almost) matches the reference box. The result of the subdivision is returned, so the guarantee to contain the patch is preserved. Tight boxes are cached, the cache is invalidated when the surface is modified.
public BoundingCube GetPatchExtent(int uKnotIndex, int vKnotIndex, bool rough = false)
Parameters
uKnotIndexintindex of the knot span in u direction (referring to distinct knot values)
vKnotIndexintindex of the knot span in v direction (referring to distinct knot values)
roughbooltrue: fast pole hull, false: tight box
Returns
GetPlaneIntersection(PlaneSurface, double, double, double, double, double)
Returns the intersection curve(s) of this surface with the given plane. An empty array is returned if there is no intersection. umin, umax, vmin, vmax define the Parameterspace of this surface (not of the PlaneSurface) for the intersection. It is also the periodic domain in which the 2d curve for this surface will be returned, if this surface is periodic. the resulting curves may exceed the area provided by umin, umax, vmin, vmax.
public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
Parameters
plPlaneSurfaceplane to intersect with
umindoubleminimum u value of the parameter space of this surface to consider
umaxdoublemaximum u value of the parameter space of this surface to consider
vmindoubleminimum v value of the parameter space of this surface to consider
vmaxdoublemaximum v value of the parameter space of this surface to consider
precisiondoublemaximum allowed deviation of the resulting curves from the exact intersection
Returns
- IDualSurfaceCurve[]
intersection curves
GetProjectedCurve(ICurve, double)
Returns the projection of the given curve in 2D coordinates. Should only be used for curves that are close to the surface.
public override ICurve2D GetProjectedCurve(ICurve curve, double precision)
Parameters
curveICurvethe 3d curve to project onto this surface
precisiondoublemaximum allowed deviation of the resulting 2d curve (mapped onto the surface) from the provided curve
Returns
GetPropertyEntry(IFrame)
Gets the IPropertyEntry to display this surface in the property grid (may be null)
public override IPropertyEntry GetPropertyEntry(IFrame frame)
Parameters
frameIFrame
Returns
GetSafeParameterSteps(double, double, double, double, out double[], out double[])
Gets spans of the parameterspace that are guaranteed to contain only one inflection point. The returned intu should contain umin as first and umax as last value (same with v)
public override void GetSafeParameterSteps(double umin, double umax, double vmin, double vmax, out double[] intu, out double[] intv)
Parameters
GetSaveUSteps()
Returns u values which subdivide the parameter range into intervals that GetExtrema() searches one by one for extrema in direction of the axes. Each interval must contain at most one extremum per axis direction (the periodic surfaces return quarter circles). The base implementation returns an empty array, which makes GetExtrema() find nothing.
protected override double[] GetSaveUSteps()
Returns
- double[]
Ascending u values from the start to the end of the parameter range, or an empty array
GetSaveVSteps()
Returns v values which subdivide the parameter range into intervals that GetExtrema() searches one by one for extrema in direction of the axes, see GetSaveUSteps(). The base implementation returns an empty array.
protected override double[] GetSaveVSteps()
Returns
- double[]
Ascending v values from the start to the end of the parameter range, or an empty array
GetSimpleSurface(double, out ISurface, out ModOp2D)
Returns true if this NurbsSurface can be represented as a simpler surface. Simple surfaces have better performances.
public bool GetSimpleSurface(double precision, out ISurface simpleSurface, out ModOp2D reparametrisation)
Parameters
precisiondoubleThe precision within the simpler surface must approximate this surface (0.0: use global Precision)
simpleSurfaceISurfacethe found surface or null
reparametrisationModOp2Dthe needed reparametrisation of the uv space from this surface to the surface found
Returns
- bool
true, if simpler form exists
GetUSingularities()
returns the values for the u parameter where this surface is singular i.e. changing v with this u parameter fixed doesn't change the 3D point.
public override double[] GetUSingularities()
Returns
- double[]
list of u singularities
GetVSingularities()
returns the values for the v parameter where this surface is singular i.e. changing u with this v parameter fixed doesn't change the 3D point.
public override double[] GetVSingularities()
Returns
- double[]
list of v singularities
GetZMinMax(Projection, double, double, double, double, ref double, ref double)
Gets the minimum and maximumm valus for the z-coordinate of a rectangular patch (in parametric space) of this surface under a certain projection
public override void GetZMinMax(Projection p, double umin, double umax, double vmin, double vmax, ref double zMin, ref double zMax)
Parameters
pProjectionthe projection
umindoubleleft bound of the rectangular patch
umaxdoubleright bound of the rectangular patch
vmindoublebottom bound of the rectangular patch
vmaxdoubletop bound of the rectangular patch
zMindoublereturned minimum
zMaxdoublereturned maximum
HasDiscontinuousDerivative(out ICurve2D[])
Tells whether there are lines in the parameter space across which the first derivative (and thus the normal) of the surface jumps. This is the case for a NurbsSurface of degree 1 with inner knots, which consists of planar or ruled strips with sharp bends between them. Faces on such a surface are split along these lines before they are triangulated or intersected.
public override bool HasDiscontinuousDerivative(out ICurve2D[] discontinuities)
Parameters
discontinuitiesICurve2D[]The 2d curves (in the u/v system) along which the derivative is discontinuous; null when the result is false
Returns
- bool
true when there are discontinuities, false for the usual smooth surfaces
HitTest(BoundingCube, out GeoPoint2D)
Returns true, if this surface interferes with the provided cube. If this is the case uv will contain a point (in the parameter system of the surface) which is inside the cube
public override bool HitTest(BoundingCube cube, out GeoPoint2D uv)
Parameters
cubeBoundingCubeuvGeoPoint2D
Returns
Intersect(BoundingRect, ISurface, BoundingRect)
Returns the intersection curves between this surface and the provided other surface. Both surfaces are bound by rectangles.
public override ICurve[] Intersect(BoundingRect thisBounds, ISurface other, BoundingRect otherBounds)
Parameters
thisBoundsBoundingRectBounds for this surface
otherISurfaceOther surface
otherBoundsBoundingRectBounds of other surface
Returns
- ICurve[]
Array of intersection curves
Intersect(ICurve, BoundingRect, out GeoPoint[], out GeoPoint2D[], out double[])
Returns the intersection of the provided curve with this surface.
The result may be empty.
public override void Intersect(ICurve curve, BoundingRect uvExtent, out GeoPoint[] ips, out GeoPoint2D[] uvOnFaces, out double[] uOnCurve3Ds)
Parameters
curveICurveThe curve to be intersected with
uvExtentBoundingRectThe part of the parameter space of this surface in which intersection points are searched. It is also the periodic domain in which the u/v values of the intersection points are returned
ipsGeoPoint[]Resulting 3d intersection points
uvOnFacesGeoPoint2D[]u/v values of the intersection points on this surface
uOnCurve3Dsdouble[]u parameter of intersection points on the curve
IsVanishingProjection(Projection, double, double, double, double)
Returns true if the given projection makes the surface disappear, i.e. degenerate to an edge.
public override bool IsVanishingProjection(Projection p, double umin, double umax, double vmin, double vmax)
Parameters
pProjectionthe projection
umindoubleumaxdoublevmindoublevmaxdouble
Returns
- bool
true if vanishing, falso otherwise
Make3dCurve(ICurve2D)
Returns a 3-dimensional curve from the given 2-dimensional curve. the 2-dimensional curve is interpreted in the u/v system of the surface.
public override ICurve Make3dCurve(ICurve2D curve2d)
Parameters
curve2dICurve2Dthe base curve
Returns
- ICurve
corresponding 3-d curve
MaxDist(GeoPoint2D, GeoPoint2D, out GeoPoint2D)
Returns the maximum distance between the surface and the straight 3d line connecting the surface points at sp
and ep, i.e. the error made when the segment from sp to ep in the
parameter space is replaced by a straight line in 3d. The triangulation uses it to decide whether an edge of a triangle must be
subdivided. The base implementation only samples the distance at 1/4, 1/2 and 3/4 of the segment; the elementary surfaces
override it with exact computations.
public override double MaxDist(GeoPoint2D sp, GeoPoint2D ep, out GeoPoint2D mp)
Parameters
spGeoPoint2DStart point in the parameter space
epGeoPoint2DEnd point in the parameter space
mpGeoPoint2DThe u/v position where the maximum distance was found
Returns
- double
The maximum distance found
Modify(ModOp)
Modifies this surface with the given operation
public override void Modify(ModOp m)
Parameters
mModOphow to modif
PointAt(GeoPoint2D)
Returns the 3-dimensional point at the given u/v point
public override GeoPoint PointAt(GeoPoint2D uv)
Parameters
uvGeoPoint2Dposition
Returns
- GeoPoint
point
ReverseOrientation()
Reverses the orientation of this surface. The normal vector will point to the other side after this operation. The returned ModOp2D determins how (u,v) coordinates of the parameter space have to be transformed to define the same 3d point.
public override ModOp2D ReverseOrientation()
Returns
- ModOp2D
Transformation of the parameter space
SameGeometry(BoundingRect, ISurface, BoundingRect, double, out ModOp2D)
Returns true if this surface and the other surface are geometrically identical, i.e. describe the same surface
in 3D space. The may have a different u/v system. The returned firstToSecond contains
the ModOp to convert from the u/v system of the first surface to the second surface.
public override bool SameGeometry(BoundingRect thisBounds, ISurface other, BoundingRect otherBounds, double precision, out ModOp2D firstToSecond)
Parameters
thisBoundsBoundingRectBounds for this surface
otherISurfaceOther surface
otherBoundsBoundingRectBounds of other surface
precisiondoubleRequired precision
firstToSecondModOp2DTransformation between different u/v systems
Returns
- bool
True if the surfaces are geometrically equal
TrimmU(double, double)
Returns a new NURBS surface which is the part of this surface between the u parameters u0 and
u1: the knot vector is clamped to this interval, the v direction stays unchanged. This surface is not modified.
public NurbsSurface TrimmU(double u0, double u1)
Parameters
Returns
- NurbsSurface
The trimmed surface, or null when this surface is not initialized
TrimmV(double, double)
Returns a new NURBS surface which is the part of this surface between the v parameters v0 and
v1: the knot vector is clamped to this interval, the u direction stays unchanged. This surface is not modified.
public NurbsSurface TrimmV(double v0, double v1)
Parameters
Returns
- NurbsSurface
The trimmed surface, or null when this surface is not initialized
UDirection(GeoPoint2D)
Returns the direction at the given u/v point in direction of the u-axis
public override GeoVector UDirection(GeoPoint2D uv)
Parameters
uvGeoPoint2Dposition
Returns
- GeoVector
direction
VDirection(GeoPoint2D)
Returns the direction at the given u/v point in direction of the v-axis
public override GeoVector VDirection(GeoPoint2D uv)
Parameters
uvGeoPoint2Dposition
Returns
- GeoVector
direction