Skip to content

Commit 8828509

Browse files
committed
use new curve
1 parent 56ed1db commit 8828509

File tree

3 files changed

+125
-43
lines changed

3 files changed

+125
-43
lines changed

src/compas_occ/brep/brep.py

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from compas_occ.conversions import triangle_to_face
4949
from compas_occ.conversions import quad_to_face
5050
from compas_occ.conversions import ngon_to_face
51-
from compas_occ.geometry import OCCNurbsSurface as NurbsSurface
51+
from compas_occ.geometry import NurbsSurface
5252

5353
from compas_occ.brep import BRepVertex
5454
from compas_occ.brep import BRepEdge
@@ -61,21 +61,21 @@ class BRep:
6161
6262
Attributes
6363
----------
64-
shape : :class:`TopoDS_Shape`
64+
shape : ``TopoDS_Shape``
6565
The underlying OCC shape of the BRep.
66-
type : :class:`TopAbs_ShapeEnum`, read-only
67-
One of `{TopAbs_COMPOUND, TopAbs_COMPSOLID, TopAbs_SOLID, TopAbs_SHELL, TopAbs_FACE, TopAbs_WIRE, TopAbs_EDGE, TopAbs_VERTEX, TopAbs_SHAPE}`.
68-
vertices : list[:class:`BRepVertex`], read-only
66+
type : ``TopAbs_ShapeEnum``, read-only
67+
The type of BRep shape.
68+
vertices : list[:class:`compas_occ.brep.BRepVertex`], read-only
6969
The vertices of the BRep.
70-
edges : list[:class:`BRepEdge`], read-only
70+
edges : list[:class:`compas_occ.brep.BRepEdge`], read-only
7171
The edges of the BRep.
72-
loops : list[:class:`BRepLoop`], read-only
72+
loops : list[:class:`compas_occ.brep.BRepLoop`], read-only
7373
The loops of the BRep.
74-
faces : list[:class:`BRepFace`], read-only
74+
faces : list[:class:`compas_occ.brep.BRepFace`], read-only
7575
The faces of the BRep.
76-
orientation : :class:`TopAbs_Orientation`, read-only
77-
One of `{TopAbs_FORWARD, TopAbs_REVERSED, TopAbs_INTERNAL, TopAbs_EXTERNAL}`.
78-
frame : :class:`Frame`, read-only
76+
orientation : TopAbs_Orientation, read-only
77+
Orientation of the shape.
78+
frame : :class:`compas.geometry.Frame`, read-only
7979
The local coordinate system of the BRep.
8080
area : float, read-only
8181
The surface area of the BRep.
@@ -195,7 +195,7 @@ def from_corners(cls,
195195
p1 : :class:`compas.geometry.Point`
196196
p2 : :class:`compas.geometry.Point`
197197
p3 : :class:`compas.geometry.Point`
198-
p4 : :class:`compas.geometry.Point`
198+
p4 : :class:`compas.geometry.Point`, optional
199199
200200
Returns
201201
-------
@@ -238,12 +238,12 @@ def from_polygons(cls, polygons: List[compas.geometry.Polygon]) -> 'BRep':
238238
return brep
239239

240240
@classmethod
241-
def from_curves(cls, curves) -> 'BRep':
241+
def from_curves(cls, curves: List[compas.geometry.NurbsCurve]) -> 'BRep':
242242
"""Construct a BRep from a set of curves.
243243
244244
Parameters
245245
----------
246-
curves : list[:class:`compas_occ.geometry.OCCNurbsCurve`]
246+
curves : list[:class:`compas.geometry.NurbsCurve`]
247247
248248
Returns
249249
-------
@@ -449,6 +449,7 @@ def to_json(self, filepath: str):
449449
Parameters
450450
----------
451451
filepath : str
452+
Location of the file.
452453
453454
Returns
454455
-------
@@ -464,8 +465,11 @@ def to_step(self, filepath: str, schema: str = "AP203", unit: str = "MM") -> Non
464465
Parameters
465466
----------
466467
filepath : str
468+
Location of the file.
467469
schema : str, optional
470+
STEP file format schema.
468471
unit : str, optional
472+
Base units for the geometry in the file.
469473
470474
Returns
471475
-------
@@ -499,7 +503,9 @@ def to_meshes(self, u=16, v=16):
499503
Parameters
500504
----------
501505
u : int, optional
506+
The number of mesh faces in the U direction of the underlying surface geometry of every face of the BRep.
502507
v : int, optional
508+
The number of mesh faces in the V direction of the underlying surface geometry of every face of the BRep.
503509
504510
Returns
505511
-------
@@ -511,7 +517,7 @@ def to_meshes(self, u=16, v=16):
511517
brep.shape = converter.Shape()
512518
meshes = []
513519
for face in brep.faces:
514-
srf = NurbsSurface.from_face(face)
520+
srf = NurbsSurface.from_face(face.face)
515521
mesh = srf.to_vizmesh(u, v)
516522
meshes.append(mesh)
517523
return meshes
@@ -574,24 +580,77 @@ def is_convex(self) -> bool:
574580
return self.shape.Convex()
575581

576582
def is_manifold(self) -> bool:
583+
"""Check if the shape is manifold.
584+
585+
Returns
586+
-------
587+
bool
588+
589+
Notes
590+
-----
591+
A BRep is non-manifold if at least one edge is shared by more than two faces.
592+
593+
"""
577594
pass
578595

579596
def is_solid(self) -> bool:
597+
"""Check if the shape is a solid.
598+
599+
Returns
600+
-------
601+
bool
602+
603+
"""
580604
pass
581605

582606
def is_surface(self) -> bool:
607+
"""Check if the shape is a surface.
608+
609+
Returns
610+
-------
611+
bool
612+
613+
"""
583614
pass
584615

585616
def cull_unused_vertices(self) -> None:
617+
"""Remove all unused vertices.
618+
619+
Returns
620+
-------
621+
None
622+
623+
"""
586624
pass
587625

588626
def cull_unused_edges(self) -> None:
627+
"""Remove all unused edges.
628+
629+
Returns
630+
-------
631+
None
632+
633+
"""
589634
pass
590635

591636
def cull_unused_loops(self) -> None:
637+
"""Remove all unused loops.
638+
639+
Returns
640+
-------
641+
None
642+
643+
"""
592644
pass
593645

594646
def cull_unused_faces(self) -> None:
647+
"""Remove all unused faces.
648+
649+
Returns
650+
-------
651+
None
652+
653+
"""
595654
pass
596655

597656
# flip
@@ -611,5 +670,19 @@ def cull_unused_faces(self) -> None:
611670
# translate
612671
# unjoin edges
613672

614-
def contours(self, plane: compas.geometry.Plane, spacing: Optional[float] = None) -> List[List[compas.geometry.Polyline]]:
673+
def contours(self,
674+
planes: List[compas.geometry.Plane]) -> List[List[compas.geometry.Polyline]]:
675+
"""Generate contour lines by slicing the BRep shape with a series of planes.
676+
677+
Parameters
678+
----------
679+
planes : list[:class:`compas.geometry.Plane`]
680+
The slicing planes.
681+
682+
Returns
683+
-------
684+
list[list[:class:`compas.geometry.Polyline`]]
685+
A list of polylines per plane.
686+
687+
"""
615688
pass

src/compas_occ/brep/brepedge.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from typing import List
22
from enum import Enum
33

4-
from OCC.Core.TopoDS import TopoDS_Edge, topods_Edge
4+
from OCC.Core.TopoDS import TopoDS_Edge
5+
from OCC.Core.TopoDS import topods_Edge
56

67
from OCC.Core.TopExp import TopExp_Explorer
78
from OCC.Core.TopAbs import TopAbs_VERTEX
89

910
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
10-
from OCC.Core.GeomAdaptor import GeomAdaptor_Curve
11+
# from OCC.Core.GeomAdaptor import GeomAdaptor_Curve
12+
# from OCC.Core.Geom import Geom_Curve
1113

1214
from OCC.Core.TopExp import topexp_FirstVertex
1315
from OCC.Core.TopExp import topexp_LastVertex
@@ -19,14 +21,20 @@
1921
from compas.geometry import Ellipse
2022

2123
from compas_occ.brep import BRepVertex
24+
from compas_occ.geometry import Curve
2225

2326

2427
class BRepEdge:
2528
"""Class representing an edge in the BRep of a geometric shape.
2629
30+
Parameters
31+
----------
32+
edge : TopoDS_Edge
33+
An OCC BRep edge.
34+
2735
Attributes
2836
----------
29-
edge : :class:`TopoDS_Edge`
37+
edge : ``TopoDS_Edge``
3038
The underlying OCC topological edge data structure.
3139
type : :class:`BRepEdge.CurveType`, read-only
3240
The type of the geometric curve underlying the topological edge.
@@ -46,15 +54,15 @@ class BRepEdge:
4654
True if the underlying curve is a bspline curve.
4755
is_other : bool, read-only
4856
True if the underlying curve is an other type of curve.
49-
vertices : list of :class:`BRepVertex`, read-only
57+
vertices : list[:class:`compas_occ.brep.BRepVertex`], read-only
5058
The topological vertices of the edge.
51-
first_vertex : :class:`BRepVertex`, read-only
59+
first_vertex : :class:`compas_occ.brep.BRepVertex`, read-only
5260
The first vertex with forward orientation.
53-
last_vertex : :class:`BRepVertex`, read-only
61+
last_vertex : :class:`compas_occ.brep.BRepVertex`, read-only
5462
The first vertex with reversed orientation.
55-
adaptor : BRepAdaptor_Curve
63+
adaptor : ``BRepAdaptor_Curve``
5664
Edge adaptor for extracting curve geometry.
57-
curve : GeomAdaptor_Curve
65+
curve : :class:`compas_occ.geometry.OCCCurve`
5866
Curve geometry from the edge adaptor.
5967
6068
"""
@@ -85,7 +93,7 @@ def edge(self, edge: TopoDS_Edge) -> None:
8593

8694
@property
8795
def type(self) -> int:
88-
return BRepEdge.CurveType(self.curve.GetType())
96+
return BRepEdge.CurveType(self.adaptor.Curve().GetType())
8997

9098
@property
9199
def is_line(self) -> bool:
@@ -144,9 +152,10 @@ def adaptor(self) -> BRepAdaptor_Curve:
144152
return self._adaptor
145153

146154
@property
147-
def curve(self) -> GeomAdaptor_Curve:
155+
def curve(self) -> Curve:
148156
if not self._curve:
149-
self._curve = self.adaptor.Curve()
157+
self._curve = Curve()
158+
self._curve.occ_curve = self.adaptor.Curve()
150159
return self._curve
151160

152161
def to_line(self) -> compas.geometry.Line:
@@ -187,7 +196,8 @@ def to_circle(self) -> compas.geometry.Circle:
187196
if not self.is_circle:
188197
raise ValueError(f'The underlying geometry is not a circle: {self.type}')
189198

190-
circle = self.curve.Circle()
199+
curve = self.adaptor.Curve()
200+
circle = curve.Circle()
191201
location = circle.Location()
192202
direction = circle.Axis().Direction()
193203
radius = circle.Radius()
@@ -212,7 +222,8 @@ def to_ellipse(self) -> compas.geometry.Ellipse:
212222
if not self.is_ellipse:
213223
raise ValueError(f'The underlying geometry is not an ellipse: {self.type}')
214224

215-
ellipse = self.curve.Ellipse()
225+
curve = self.adaptor.Curve()
226+
ellipse = curve.Ellipse()
216227
location = ellipse.Location()
217228
direction = ellipse.Axis().Direction()
218229
major = ellipse.MajorRadius()
@@ -232,13 +243,10 @@ def to_hyperbola(self) -> None:
232243
------
233244
ValueError
234245
If the underlying geometry is not a hyperbola.
235-
NotImplementedError
236-
In all other cases
237246
238247
"""
239248
if not self.is_hyperbola:
240249
raise ValueError(f'The underlying geometry is not a hyperbola: {self.type}')
241-
242250
raise NotImplementedError
243251

244252
def to_parabola(self) -> None:
@@ -252,13 +260,10 @@ def to_parabola(self) -> None:
252260
------
253261
ValueError
254262
If the underlying geometry is not a parabola.
255-
NotImplementedError
256-
In all other cases
257263
258264
"""
259265
if not self.is_parabola:
260266
raise ValueError(f'The underlying geometry is not a parabola: {self.type}')
261-
262267
raise NotImplementedError
263268

264269
def to_bezier(self) -> None:
@@ -272,13 +277,10 @@ def to_bezier(self) -> None:
272277
------
273278
ValueError
274279
If the underlying geometry is not a bezier curve.
275-
NotImplementedError
276-
In all other cases
277280
278281
"""
279282
if not self.is_bezier:
280283
raise ValueError(f'The underlying geometry is not a bezier: {self.type}')
281-
282284
raise NotImplementedError
283285

284286
def to_bspline(self) -> None:
@@ -292,11 +294,18 @@ def to_bspline(self) -> None:
292294
------
293295
ValueError
294296
If the underlying geometry is not a bspline.
295-
NotImplementedError
296-
In all other cases
297297
298298
"""
299299
if not self.is_bspline:
300300
raise ValueError(f'The underlying geometry is not a bspline: {self.type}')
301-
302301
raise NotImplementedError
302+
303+
def to_curve(self) -> Curve:
304+
"""Convert the edge geometry to a NURBS curve.
305+
306+
Returns
307+
-------
308+
:class:`compas_occ.geometry.Curve`
309+
310+
"""
311+
return self.curve

src/compas_occ/brep/brepvertex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class BRepVertex:
1212
1313
Parameters
1414
----------
15-
vertex : :class:`TopoDS_Vertex`
15+
vertex : ``TopoDS_Vertex``
1616
An OCC topological vertex data structure.
1717
1818
Attributes
1919
----------
20-
vertex : :class:`TopoDS_Vertex`
20+
vertex : ``TopoDS_Vertex``
2121
The underlying OCC vertex.
2222
point : :class:`compas.geometry.Point`, read-only
2323
The geometric point underlying the topological vertex.

0 commit comments

Comments
 (0)