|
20 | 20 | import OCP.TopAbs as ta # Tolopolgy type enum
|
21 | 21 | import OCP.GeomAbs as ga # Geometry type enum
|
22 | 22 |
|
| 23 | +from OCP.Precision import Precision |
| 24 | + |
23 | 25 | from OCP.gp import (
|
24 | 26 | gp_Vec,
|
25 | 27 | gp_Pnt,
|
|
36 | 38 | )
|
37 | 39 |
|
38 | 40 | # Array of points (used for B-spline construction):
|
39 |
| -from OCP.TColgp import TColgp_HArray1OfPnt |
| 41 | +from OCP.TColgp import TColgp_HArray1OfPnt, TColgp_HArray2OfPnt |
40 | 42 |
|
41 | 43 | # Array of vectors (used for B-spline interpolation):
|
42 | 44 | from OCP.TColgp import TColgp_Array1OfVec
|
|
113 | 115 | GeomAPI_Interpolate,
|
114 | 116 | GeomAPI_ProjectPointOnSurf,
|
115 | 117 | GeomAPI_PointsToBSpline,
|
| 118 | + GeomAPI_PointsToBSplineSurface, |
116 | 119 | )
|
117 | 120 |
|
118 | 121 | from OCP.BRepFill import BRepFill
|
@@ -1554,9 +1557,7 @@ def makeSplineApprox(
|
1554 | 1557 | Approximate a spline through the provided points.
|
1555 | 1558 |
|
1556 | 1559 | :param listOfVector: a list of Vectors that represent the points
|
1557 |
| - :param tol: tolerance of the algorithm (consult OCC documentation). Used to check that the |
1558 |
| - specified points are not too close to each other, and that tangent vectors are not too |
1559 |
| - short. (In either case interpolation may fail.) |
| 1560 | + :param tol: tolerance of the algorithm (consult OCC documentation). |
1560 | 1561 | :param smoothing: optional tuple of 3 weigths use for variational smoothing (default: None)
|
1561 | 1562 | :param minDeg: minimum spline degree. Enforced only when smothing is None (default: 1)
|
1562 | 1563 | :param maxDeg: maximum spline degree (default: 6)
|
@@ -2067,6 +2068,47 @@ def makeFromWires(
|
2067 | 2068 |
|
2068 | 2069 | return cls(face).fix()
|
2069 | 2070 |
|
| 2071 | + @classmethod |
| 2072 | + def makeSplineApprox( |
| 2073 | + cls: Type["Face"], |
| 2074 | + points: List[List[Vector]], |
| 2075 | + tol: float = 1e-2, |
| 2076 | + smoothing: Optional[Tuple[float, float, float]] = None, |
| 2077 | + minDeg: int = 1, |
| 2078 | + maxDeg: int = 3, |
| 2079 | + ) -> "Face": |
| 2080 | + """ |
| 2081 | + Approximate a spline surface through the provided points. |
| 2082 | +
|
| 2083 | + :param points: a 2D list of Vectors that represent the points |
| 2084 | + :param tol: tolerance of the algorithm (consult OCC documentation). |
| 2085 | + :param smoothing: optional tuple of 3 weigths use for variational smoothing (default: None) |
| 2086 | + :param minDeg: minimum spline degree. Enforced only when smothing is None (default: 1) |
| 2087 | + :param maxDeg: maximum spline degree (default: 6) |
| 2088 | + :return: an Face |
| 2089 | + """ |
| 2090 | + points_ = TColgp_HArray2OfPnt(1, len(points), 1, len(points[0])) |
| 2091 | + |
| 2092 | + for i, vi in enumerate(points): |
| 2093 | + for j, v in enumerate(vi): |
| 2094 | + points_.SetValue(i + 1, j + 1, v.toPnt()) |
| 2095 | + |
| 2096 | + if smoothing: |
| 2097 | + spline_builder = GeomAPI_PointsToBSplineSurface( |
| 2098 | + points_, *smoothing, DegMax=maxDeg, Tol3D=tol |
| 2099 | + ) |
| 2100 | + else: |
| 2101 | + spline_builder = GeomAPI_PointsToBSplineSurface( |
| 2102 | + points_, DegMin=minDeg, DegMax=maxDeg, Tol3D=tol |
| 2103 | + ) |
| 2104 | + |
| 2105 | + if not spline_builder.IsDone(): |
| 2106 | + raise ValueError("B-spline approximation failed") |
| 2107 | + |
| 2108 | + spline_geom = spline_builder.Surface() |
| 2109 | + |
| 2110 | + return cls(BRepBuilderAPI_MakeFace(spline_geom, Precision.Confusion_s()).Face()) |
| 2111 | + |
2070 | 2112 | def fillet2D(self, radius: float, vertices: Iterable[Vertex]) -> "Face":
|
2071 | 2113 | """
|
2072 | 2114 | Apply 2D fillet to a face
|
|
0 commit comments