Skip to content

Commit 1138911

Browse files
committed
update examples
1 parent 8828509 commit 1138911

29 files changed

+150
-230
lines changed

docs/examples/brep_from_booleans.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from compas.geometry import Point, Vector, Plane
2-
from compas.geometry import Box
3-
from compas.geometry import Cylinder
2+
from compas.geometry import Polyline
3+
from compas.geometry import Box, Cylinder
44
from compas_occ.brep import BRep
5-
65
from compas_view2.app import App
76

7+
88
R = 1.4
99
P = Point(0, 0, 0)
1010
X = Vector(1, 0, 0)
@@ -25,6 +25,15 @@
2525
B3 = BRep.from_cylinder(cz)
2626
C = BRep.from_boolean_difference(A, BRep.from_boolean_union(BRep.from_boolean_union(B1, B2), B3))
2727

28+
# ==============================================================================
29+
# Visualisation
30+
# ==============================================================================
31+
32+
# Currently, the viewer does not suppport BRep shapes.
33+
# Therefore we have to convert the components of the BRep to something the viewer does understand.
34+
35+
mesh = C.to_tesselation()
36+
2837
lines = []
2938
circles = []
3039
ellipses = []
@@ -33,27 +42,26 @@
3342
if edge.is_line:
3443
lines.append(edge.to_line())
3544
elif edge.is_circle:
36-
circles.append(edge.to_circle())
45+
circles.append(Polyline(edge.curve.locus()))
3746
elif edge.is_ellipse:
38-
ellipses.append(edge.to_ellipse())
47+
ellipses.append(Polyline(edge.curve.locus()))
3948
else:
4049
raise NotImplementedError
4150

42-
# ==============================================================================
43-
# Visualisation
44-
# ==============================================================================
45-
46-
viewer = App()
51+
viewer = App(viewmode='ghosted', width=1600, height=900)
52+
viewer.view.camera.rz = -30
53+
viewer.view.camera.rx = -75
54+
viewer.view.camera.distance = 7
4755

48-
viewer.add(C.to_tesselation(), show_edges=False)
56+
viewer.add(mesh, show_edges=False)
4957

5058
for line in lines:
5159
viewer.add(line, linewidth=2)
5260

5361
for circle in circles:
54-
viewer.add(circle, linewidth=2, u=64)
62+
viewer.add(circle, linewidth=2)
5563

5664
for ellipse in ellipses:
57-
viewer.add(ellipse, linewidth=2, u=64)
65+
viewer.add(ellipse, linewidth=2)
5866

5967
viewer.run()

docs/examples/brep_from_corners.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from compas_occ.brep import BRep
33
from compas_view2.app import App
44

5+
56
brep3 = BRep.from_corners(Point(0, 0, 0), Point(1, 1, 1), Point(0, 1, 0))
67
brep4 = BRep.from_corners(Point(0, 2, 0), Point(1, 2, 0), Point(1, 3, 1), Point(0, 3, 0))
78

docs/examples/brep_from_mesh.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import compas
22
from compas.geometry import Vector, Translation, Scale
3+
from compas.geometry import Polyline
34
from compas.datastructures import Mesh
45
from compas_occ.brep import BRep
56
from compas_view2.app import App
67

8+
79
mesh = Mesh.from_obj(compas.get('tubemesh.obj'))
810

911
centroid = mesh.centroid()
@@ -18,8 +20,20 @@
1820
mesh.transform(S * T)
1921

2022
brep = BRep.from_mesh(mesh)
21-
tess = brep.to_tesselation()
2223

23-
viewer = App()
24-
viewer.add(tess)
24+
lines = []
25+
curves = []
26+
27+
for edge in brep.edges:
28+
if edge.is_line:
29+
lines.append(edge.to_line())
30+
elif edge.is_bspline:
31+
curves.append(Polyline(edge.curve.locus()))
32+
33+
viewer = App(viewmode='ghosted')
34+
viewer.add(brep.to_tesselation(), show_edges=False)
35+
36+
for curve in curves:
37+
viewer.add(curve, linewidth=2)
38+
2539
viewer.run()

docs/examples/curve_closest_parameters_curve.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from compas.geometry import Point, Polyline
2-
from compas.geometry import NurbsCurve
3-
1+
from compas.geometry import Point
2+
from compas.geometry import Polyline
3+
from compas_occ.geometry import NurbsCurve
44
from compas_view2.app import App
55

6+
67
points0 = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)]
78
curve0 = NurbsCurve.from_points(points0)
89

@@ -11,13 +12,8 @@
1112

1213
parameters, distance = curve0.closest_parameters_curve(curve1, return_distance=True)
1314

14-
print(parameters)
15-
print(distance)
16-
1715
points = curve0.closest_points_curve(curve1, return_distance=False)
1816

19-
print(points)
20-
2117
# ==============================================================================
2218
# Visualisation
2319
# ==============================================================================

docs/examples/curve_closest_point.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from compas.geometry import Point, Polyline
2-
from compas_occ.geometry import OCCNurbsCurve as NurbsCurve
3-
1+
from compas.geometry import Point
2+
from compas.geometry import Polyline
3+
from compas_occ.geometry import NurbsCurve
44
from compas_view2.app import App
55

6+
67
points = [Point(0, 0, 0), Point(3, 0, 2), Point(6, 0, -3), Point(8, 0, 0)]
78
curve = NurbsCurve.from_interpolation(points)
89

docs/examples/curve_comparison1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from compas.geometry import Point, Polyline
2-
from compas.geometry import Bezier
3-
from compas_occ.geometry import OCCNurbsCurve as NurbsCurve
4-
1+
from compas.geometry import Point
2+
from compas.geometry import Polyline, Bezier
3+
from compas_occ.geometry import NurbsCurve
54
from compas_view2.app import App
65

6+
77
points = [Point(0, 0, 0), Point(1, 3, 0), Point(2, 0, 0)]
88
bezier = Bezier(points)
99

docs/examples/curve_comparison2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from compas.geometry import Point, Polyline
2-
from compas.geometry import Bezier
3-
from compas_occ.geometry import OCCNurbsCurve as NurbsCurve
4-
1+
from compas.geometry import Point
2+
from compas.geometry import Polyline, Bezier
3+
from compas_occ.geometry import NurbsCurve
54
from compas_view2.app import App
65

6+
77
points = [Point(0, 0, 0), Point(1, 2, 0), Point(2, -2, 0), Point(3, 0, 0)]
88
bezier = Bezier(points)
99

docs/examples/curve_from_circle.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from compas.geometry import Vector, Point, Polyline, Circle, Plane
2-
from compas_occ.geometry import OCCNurbsCurve as NurbsCurve
3-
1+
from compas.geometry import Vector, Point, Plane
2+
from compas.geometry import Polyline
3+
from compas.geometry import Circle
4+
from compas_occ.geometry import NurbsCurve
45
from compas_view2.app import App
56

7+
68
circle = Circle(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 1.0)
79
curve = NurbsCurve.from_circle(circle)
810

9-
print(curve)
10-
1111
# ==============================================================================
1212
# Visualisation
1313
# ==============================================================================

docs/examples/curve_from_ellipse.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from compas.geometry import Vector, Point, Line, Polyline, Ellipse, Plane
1+
from compas.geometry import Vector, Point, Plane
2+
from compas.geometry import Line, Polyline
3+
from compas.geometry import Ellipse
24
from compas.utilities import pairwise
3-
from compas_occ.geometry import OCCNurbsCurve as NurbsCurve
4-
5+
from compas_occ.geometry import NurbsCurve
56
from compas_view2.app import App
67
from compas_view2.objects import Collection
78

9+
810
ellipse = Ellipse(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 2.0, 1.0)
911
curve = NurbsCurve.from_ellipse(ellipse)
1012

11-
print(curve)
12-
1313
# ==============================================================================
1414
# Visualisation
1515
# ==============================================================================
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from compas.geometry import Point, Polyline, Bezier
2-
from compas_occ.geometry import OCCNurbsCurve as NurbsCurve
3-
1+
from compas.geometry import Point
2+
from compas.geometry import Polyline, Bezier
3+
from compas_occ.geometry import NurbsCurve
44
from compas_view2.app import App
55
from compas_view2.objects import Collection
66

7+
78
points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)]
89
bezier = Bezier(points)
910
points = bezier.locus(10)
1011

1112
curve = NurbsCurve.from_interpolation(points)
1213

13-
print(curve)
14-
1514
# ==============================================================================
1615
# Visualisation
1716
# ==============================================================================
@@ -21,6 +20,4 @@
2120
view.add(Polyline(curve.locus()), linewidth=3)
2221
view.add(Collection(points))
2322

24-
# view.add(Polyline(curve.points), show_points=True, pointsize=20, pointcolor=(1, 0, 0), linewidth=1, linecolor=(0.3, 0.3, 0.3))
25-
2623
view.run()

0 commit comments

Comments
 (0)