Skip to content

Commit 6573645

Browse files
committed
rebase surface
1 parent 9285bc0 commit 6573645

File tree

6 files changed

+80
-64
lines changed

6 files changed

+80
-64
lines changed

src/compas_occ/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@
3939

4040
__all_plugins__ = [
4141
'compas_occ.geometry.curves',
42+
'compas_occ.geometry.surfaces',
4243
]

src/compas_occ/geometry/__init__.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,16 @@
55
66
.. currentmodule:: compas_occ.geometry
77
8-
Curves
9-
======
8+
Classes
9+
=======
1010
1111
.. autosummary::
1212
:toctree: generated/
1313
:nosignatures:
1414
15-
Curve
16-
NurbsCurve
17-
18-
Surfaces
19-
========
20-
21-
.. autosummary::
22-
:toctree: generated/
23-
:nosignatures:
24-
25-
Surface
26-
NurbsSurface
15+
OCCNurbsCurve
16+
OCCNurbsSurface
2717
2818
"""
2919
from .curves import OCCNurbsCurve # noqa: F401
30-
from .surfaces import Surface # noqa: F401
31-
from .surfaces import NurbsSurface # noqa: F401
20+
from .surfaces import OCCNurbsSurface # noqa: F401

src/compas_occ/geometry/curves/nurbs.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ def __init__(self, name=None) -> None:
113113
super().__init__(name=name)
114114
self.occ_curve = None
115115

116-
def __eq__(self, other: 'NurbsCurve') -> bool:
116+
def __eq__(self, other: 'OCCNurbsCurve') -> bool:
117117
return self.occ_curve.IsEqual(other.occ_curve)
118118

119119
def __str__(self):
120120
lines = [
121-
'NurbsCurve',
121+
'OCCNurbsCurve',
122122
'------------',
123123
f'Points: {self.points}',
124124
f'Weights: {self.weights}',
@@ -166,7 +166,7 @@ def data(self, data: Dict):
166166
)
167167

168168
@classmethod
169-
def from_data(cls, data: Dict) -> 'NurbsCurve':
169+
def from_data(cls, data: Dict) -> 'OCCNurbsCurve':
170170
"""Construct a NURBS curve from its data representation.
171171
172172
Parameters
@@ -176,7 +176,7 @@ def from_data(cls, data: Dict) -> 'NurbsCurve':
176176
177177
Returns
178178
-------
179-
:class:`compas_occ.geometry.NurbsCurve`
179+
:class:`compas_occ.geometry.OCCNurbsCurve`
180180
The constructed curve.
181181
182182
"""
@@ -193,7 +193,7 @@ def from_data(cls, data: Dict) -> 'NurbsCurve':
193193
# ==============================================================================
194194

195195
@classmethod
196-
def from_occ(cls, occ_curve: Geom_BSplineCurve) -> 'NurbsCurve':
196+
def from_occ(cls, occ_curve: Geom_BSplineCurve) -> 'OCCNurbsCurve':
197197
"""Construct a NURBS curve from an existing OCC BSplineCurve."""
198198
curve = cls()
199199
curve.occ_curve = occ_curve
@@ -206,7 +206,7 @@ def from_parameters(cls,
206206
knots: List[float],
207207
multiplicities: List[int],
208208
degree: int,
209-
is_periodic: bool = False) -> 'NurbsCurve':
209+
is_periodic: bool = False) -> 'OCCNurbsCurve':
210210
"""Construct a NURBS curve from explicit curve parameters."""
211211
curve = cls()
212212
curve.occ_curve = Geom_BSplineCurve(
@@ -220,7 +220,7 @@ def from_parameters(cls,
220220
return curve
221221

222222
@classmethod
223-
def from_points(cls, points: List[Point], degree: int = 3) -> 'NurbsCurve':
223+
def from_points(cls, points: List[Point], degree: int = 3) -> 'OCCNurbsCurve':
224224
"""Construct a NURBS curve from control points.
225225
226226
This construction method is similar to the method ``Create`` of the Rhino API for NURBS curves [1]_.
@@ -253,7 +253,7 @@ def from_points(cls, points: List[Point], degree: int = 3) -> 'NurbsCurve':
253253
return curve
254254

255255
@classmethod
256-
def from_interpolation(cls, points: List[Point], precision: float = 1e-3) -> 'NurbsCurve':
256+
def from_interpolation(cls, points: List[Point], precision: float = 1e-3) -> 'OCCNurbsCurve':
257257
"""Construct a NURBS curve by interpolating a set of points.
258258
259259
This construction method is similar to the method ``CreateHSpline`` of the Rhino API for NURBS curves [1]_.
@@ -271,12 +271,12 @@ def from_interpolation(cls, points: List[Point], precision: float = 1e-3) -> 'Nu
271271
return curve
272272

273273
@classmethod
274-
def from_step(cls, filepath: str) -> 'NurbsCurve':
274+
def from_step(cls, filepath: str) -> 'OCCNurbsCurve':
275275
"""Load a NURBS curve from an STP file."""
276276
pass
277277

278278
@classmethod
279-
def from_edge(cls, edge: TopoDS_Edge) -> 'NurbsCurve':
279+
def from_edge(cls, edge: TopoDS_Edge) -> 'OCCNurbsCurve':
280280
"""Construct a NURBS curve from an existing OCC TopoDS_Edge."""
281281
res = BRep_Tool_Curve(edge)
282282
if len(res) != 3:
@@ -288,7 +288,7 @@ def from_arc(cls, arc, degree, pointcount=None):
288288
pass
289289

290290
@classmethod
291-
def from_circle(cls, circle: Circle) -> 'NurbsCurve':
291+
def from_circle(cls, circle: Circle) -> 'OCCNurbsCurve':
292292
"""Construct a NURBS curve from a circle.
293293
294294
This construction method is similar to the method ``CreateFromCircle`` of the Rhino API for NURBS curves [1]_.
@@ -490,7 +490,7 @@ def is_rational(self) -> bool:
490490
# Methods
491491
# ==============================================================================
492492

493-
def copy(self) -> 'NurbsCurve':
493+
def copy(self) -> 'OCCNurbsCurve':
494494
"""Make an independent copy of the current curve."""
495495
return NurbsCurve.from_parameters(
496496
self.points,
@@ -507,7 +507,7 @@ def transform(self, T: Transformation) -> None:
507507
occ_T.SetValues(* T.list)
508508
self.occ_curve.Transform(occ_T)
509509

510-
def transformed(self, T: Transformation) -> 'NurbsCurve':
510+
def transformed(self, T: Transformation) -> 'OCCNurbsCurve':
511511
"""Transform a copy of the curve."""
512512
copy = self.copy()
513513
copy.transform(T)
@@ -591,7 +591,11 @@ def curvature_at(self, t):
591591
The corresponding curvature vector.
592592
593593
"""
594-
pass
594+
point = gp_Pnt()
595+
uvec = gp_Vec()
596+
vvec = gp_Vec()
597+
self.occ_curve.D2(t, point, uvec, vvec)
598+
return Vector.from_occ(vvec)
595599

596600
def frame_at(self, t):
597601
"""Compute the local frame at a point on the curve.
@@ -643,20 +647,17 @@ def divide_by_length(self, length):
643647
"""Divide the curve into segments of specified length."""
644648
pass
645649

646-
def fair(self):
647-
pass
648-
649650
def aabb(self, precision: float = 0.0) -> Box:
650651
"""Compute the axis aligned bounding box of the curve."""
651652
box = Bnd_Box()
652653
BndLib_Add3dCurve_Add(GeomAdaptor_Curve(self.occ_curve), precision, box)
653654
return Box.from_diagonal((
654655
Point.from_occ(box.CornerMin()),
655-
Point.from_occ(box.CornerMax())
656-
))
656+
Point.from_occ(box.CornerMax())))
657657

658658
def obb(self, precision: float = 0.0) -> Box:
659659
"""Compute the oriented bounding box of the curve."""
660+
pass
660661

661662
def length(self, precision: float = 1e-3) -> float:
662663
"""Compute the length of the curve."""
@@ -686,7 +687,7 @@ def segment(self, u: float, v: float, precision: float = 1e-3) -> None:
686687
raise ValueError('The given domain is zero length.')
687688
self.occ_curve.Segment(u, v, precision)
688689

689-
def segmented(self, u: float, v: float, precision: float = 1e-3) -> 'NurbsCurve':
690+
def segmented(self, u: float, v: float, precision: float = 1e-3) -> 'OCCNurbsCurve':
690691
"""Returns a copy of this curve by segmenting it between the parameters u and v.
691692
692693
Parameters
Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
1-
from ._surface import Surface # noqa F401
2-
from .nurbs import NurbsSurface # noqa F401
1+
from compas.plugins import plugin
2+
from compas.geometry import NurbsSurface
3+
4+
from .nurbs import OCCNurbsSurface
5+
6+
7+
@plugin(category='factories', requires=['compas_occ'])
8+
def new_nurbssurface(cls, *args, **kwargs):
9+
return super(NurbsSurface, OCCNurbsSurface).__new__(OCCNurbsSurface)
10+
11+
12+
@plugin(category='factories', requires=['compas_occ'])
13+
def new_nurbssurface_from_parameters(*args, **kwargs):
14+
return OCCNurbsSurface.from_parameters(*args, **kwargs)
15+
16+
17+
@plugin(category='factories', requires=['compas_occ'])
18+
def new_nurbssurface_from_points(*args, **kwargs):
19+
return OCCNurbsSurface.from_points(*args, **kwargs)
20+
21+
22+
@plugin(category='factories', requires=['compas_occ'])
23+
def new_nurbssurface_from_fill(cls, *args, **kwargs):
24+
return OCCNurbsSurface.from_fill(*args, **kwargs)
25+
26+
27+
@plugin(category='factories', requires=['compas_occ'])
28+
def new_nurbssurface_from_step(cls, *args, **kwargs):
29+
return OCCNurbsSurface.from_step(*args, **kwargs)
30+

src/compas_occ/geometry/surfaces/_surface.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/compas_occ/geometry/surfaces/nurbs.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
from compas_occ.conversions import floats2_from_array2
2323
from compas_occ.conversions import points2_from_array2
2424

25-
from ..curves import NurbsCurve
26-
from ._surface import Surface
25+
from ..curves import OCCNurbsCurve
26+
27+
from compas.geometry import NurbsSurface
2728

2829
from OCC.Core.gp import gp_Trsf
2930
from OCC.Core.gp import gp_Pnt
@@ -46,6 +47,7 @@
4647
from OCC.Core.BndLib import BndLib_AddSurface_AddOptimal
4748
from OCC.Core.BRepBndLib import brepbndlib_AddOBB
4849

50+
4951
Point.from_occ = classmethod(compas_point_from_occ_point)
5052
Point.to_occ = compas_point_to_occ_point
5153
Vector.from_occ = classmethod(compas_vector_from_occ_vector)
@@ -83,7 +85,7 @@ def __iter__(self):
8385
return iter(self.points)
8486

8587

86-
class NurbsSurface(Surface):
88+
class OCCNurbsSurface(NurbsSurface):
8789
"""Class representing a NURBS surface based on the BSplineSurface of the OCC geometry kernel.
8890
8991
Attributes
@@ -143,7 +145,7 @@ def __init__(self, name: str = None) -> None:
143145
self.occ_surface = None
144146
self._points = None
145147

146-
def __eq__(self, other: 'NurbsSurface') -> bool:
148+
def __eq__(self, other: 'OCCNurbsSurface') -> bool:
147149
for a, b in zip(flatten(self.points), flatten(other.points)):
148150
if a != b:
149151
return False
@@ -164,7 +166,7 @@ def __eq__(self, other: 'NurbsSurface') -> bool:
164166

165167
def __str__(self):
166168
lines = [
167-
'NurbsSurface',
169+
'OCCNurbsSurface',
168170
'--------------',
169171
f'Points: {self.points}',
170172
f'Weights: {self.weights}',
@@ -226,7 +228,7 @@ def data(self, data: Dict):
226228
)
227229

228230
@classmethod
229-
def from_data(cls, data: Dict) -> 'NurbsSurface':
231+
def from_data(cls, data: Dict) -> 'OCCNurbsSurface':
230232
"""Construct a BSpline surface from its data representation.
231233
232234
Parameters
@@ -236,7 +238,7 @@ def from_data(cls, data: Dict) -> 'NurbsSurface':
236238
237239
Returns
238240
-------
239-
:class:`compas_occ.geometry.NurbsSurface`
241+
:class:`compas_occ.geometry.OCCNurbsSurface`
240242
The constructed surface.
241243
242244
"""
@@ -264,7 +266,7 @@ def from_data(cls, data: Dict) -> 'NurbsSurface':
264266
# ==============================================================================
265267

266268
@classmethod
267-
def from_occ(cls, occ_surface: Geom_BSplineSurface) -> 'NurbsSurface':
269+
def from_occ(cls, occ_surface: Geom_BSplineSurface) -> 'OCCNurbsSurface':
268270
"""Construct a NUBRS surface from an existing OCC BSplineSurface."""
269271
surface = cls()
270272
surface.occ_surface = occ_surface
@@ -281,7 +283,7 @@ def from_parameters(cls,
281283
u_degree: int,
282284
v_degree: int,
283285
is_u_periodic: bool = False,
284-
is_v_periodic: bool = False) -> 'NurbsSurface':
286+
is_v_periodic: bool = False) -> 'OCCNurbsSurface':
285287
"""Construct a NURBS surface from explicit parameters."""
286288
surface = cls()
287289
surface.occ_surface = Geom_BSplineSurface(
@@ -302,7 +304,7 @@ def from_parameters(cls,
302304
def from_points(cls,
303305
points: List[List[Point]],
304306
u_degree: int = 3,
305-
v_degree: int = 3) -> 'NurbsSurface':
307+
v_degree: int = 3) -> 'OCCNurbsSurface':
306308
"""Construct a NURBS surface from control points."""
307309
u = len(points[0])
308310
v = len(points)
@@ -335,7 +337,7 @@ def from_points(cls,
335337
)
336338

337339
@classmethod
338-
def from_meshgrid(cls, nu: int = 10, nv: int = 10) -> 'NurbsSurface':
340+
def from_meshgrid(cls, nu: int = 10, nv: int = 10) -> 'OCCNurbsSurface':
339341
"""Construct a NURBS surface from a mesh grid."""
340342
UU, VV = meshgrid(linspace(0, nu, nu + 1), linspace(0, nv, nv + 1))
341343
points = []
@@ -347,18 +349,18 @@ def from_meshgrid(cls, nu: int = 10, nv: int = 10) -> 'NurbsSurface':
347349
return cls.from_points(points=points)
348350

349351
@classmethod
350-
def from_step(cls, filepath: str) -> 'NurbsSurface':
352+
def from_step(cls, filepath: str) -> 'OCCNurbsSurface':
351353
"""Load a NURBS surface from a STP file."""
352354
raise NotImplementedError
353355

354356
@classmethod
355-
def from_face(cls, face: TopoDS_Face) -> 'NurbsSurface':
357+
def from_face(cls, face: TopoDS_Face) -> 'OCCNurbsSurface':
356358
"""Construct a NURBS surface from an existing OCC TopoDS_Face."""
357359
srf = BRep_Tool_Surface(face)
358360
return cls.from_occ(srf)
359361

360362
@classmethod
361-
def from_fill(cls, curve1: NurbsCurve, curve2: NurbsCurve) -> 'NurbsSurface':
363+
def from_fill(cls, curve1: OCCNurbsCurve, curve2: OCCNurbsCurve) -> 'OCCNurbsSurface':
362364
"""Construct a NURBS surface from the infill between two NURBS curves."""
363365
surface = cls()
364366
occ_fill = GeomFill_BSplineCurves(curve1.occ_curve, curve2.occ_curve, GeomFill_CoonsStyle)
@@ -520,7 +522,7 @@ def is_v_periodic(self) -> bool:
520522
# Methods
521523
# ==============================================================================
522524

523-
def copy(self) -> 'NurbsSurface':
525+
def copy(self) -> 'OCCNurbsSurface':
524526
"""Make an independent copy of the surface."""
525527
return NurbsSurface.from_parameters(
526528
self.points,
@@ -541,7 +543,7 @@ def transform(self, T: Transformation) -> None:
541543
_T.SetValues(* T.list[:12])
542544
self.occ_surface.Transform(_T)
543545

544-
def transformed(self, T: Transformation) -> 'NurbsSurface':
546+
def transformed(self, T: Transformation) -> 'OCCNurbsSurface':
545547
"""Transform an independent copy of this surface."""
546548
copy = self.copy()
547549
copy.transform(T)
@@ -569,17 +571,17 @@ def v_space(self, n: int = 10) -> Generator[float, None, None]:
569571
vmin, vmax = self.v_domain
570572
return np.linspace(vmin, vmax, n)
571573

572-
def u_isocurve(self, u: float) -> NurbsCurve:
574+
def u_isocurve(self, u: float) -> OCCNurbsCurve:
573575
"""Compute the isoparametric curve at parameter u."""
574576
occ_curve = self.occ_surface.UIso(u)
575-
return NurbsCurve.from_occ(occ_curve)
577+
return OCCNurbsCurve.from_occ(occ_curve)
576578

577-
def v_isocurve(self, v: float) -> NurbsCurve:
579+
def v_isocurve(self, v: float) -> OCCNurbsCurve:
578580
"""Compute the isoparametric curve at parameter v."""
579581
occ_curve = self.occ_surface.VIso(v)
580-
return NurbsCurve.from_occ(occ_curve)
582+
return OCCNurbsCurve.from_occ(occ_curve)
581583

582-
def boundary(self) -> List[NurbsCurve]:
584+
def boundary(self) -> List[OCCNurbsCurve]:
583585
"""Compute the boundary curves of the surface."""
584586
umin, umax, vmin, vmax = self.occ_surface.Bounds()
585587
curves = [

0 commit comments

Comments
 (0)