Skip to content

Commit

Permalink
rework (some of) the examples to use new viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Apr 25, 2024
1 parent 6836cfd commit e7318df
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 146 deletions.
20 changes: 11 additions & 9 deletions docs/examples/breps/brep_explorer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from compas.colors import Color
from compas.geometry import Box
from compas.geometry import Brep
from compas_viewer import Viewer

box = Box(1).to_brep()
Expand All @@ -17,18 +19,18 @@
# viewer.view.camera.position = [2, -4, 1]
# viewer.view.camera.look_at([0, 0, 0])

# viewer.scene.add(vertex.point, pointcolor=Color.red(), pointsize=20)
viewer.scene.add(vertex.point, pointcolor=Color.red(), pointsize=20)

# for vertex in vertices:
# viewer.scene.add(vertex.point, pointsize=20)
for vertex in vertices: # type: ignore
viewer.scene.add(vertex.point, pointsize=20)

# for edge in edges:
# viewer.scene.add(edge.to_line(), linewidth=5, linecolor=Color(0.2, 0.2, 0.2))
for edge in edges: # type: ignore
viewer.scene.add(edge.to_line(), linewidth=5, linecolor=Color(0.2, 0.2, 0.2))

# for face in faces:
# brep = Brep.from_brepfaces([face])
# viewer.scene.add(brep, opacity=0.5)
for face in faces: # type: ignore
brep = Brep.from_brepfaces([face])
viewer.scene.add(brep, opacity=0.5)

# viewer.scene.add(box, linewidth=2, linecolor=Color(0.2, 0.2, 0.2), show_faces=False)
viewer.scene.add(box, linewidth=2, linecolor=Color(0.2, 0.2, 0.2), show_faces=False, show_points=False)

viewer.show()
4 changes: 2 additions & 2 deletions docs/examples/breps/brep_fillet.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# viewer.view.camera.position = [5, -1, 10]
# viewer.view.camera.look_at([5, 2, 0])

# for letter in letters:
# viewer.scene.add(letter, linewidth=2, opacity=0.7)
for letter in letters:
viewer.scene.add(letter, linewidth=2, opacity=0.7, show_points=False)

viewer.show()
2 changes: 1 addition & 1 deletion docs/examples/breps/brep_from_booleans.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
# viewer.view.camera.rx = -75
# viewer.view.camera.distance = 7

# viewer.scene.add(result, linewidth=2)
viewer.scene.add(result, linewidth=2, show_points=False)

viewer.show()
2 changes: 1 addition & 1 deletion docs/examples/breps/brep_from_iges.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
# viewer.view.camera.rx = -75
# viewer.view.camera.distance = 7

# viewer.scene.add(brep, linewidth=2)
viewer.scene.add(brep, linewidth=2, show_points=False)

viewer.show()
2 changes: 1 addition & 1 deletion docs/examples/breps/brep_from_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
# viewer.view.camera.position = [1, -6, 2]
# viewer.view.camera.look_at([1, 1, 1])

# viewer.scene.add(brep, linewidth=2)
viewer.scene.add(brep, linewidth=2, show_points=False)

viewer.show()
2 changes: 1 addition & 1 deletion docs/examples/breps/brep_from_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# viewer.view.camera.position = [2, -4, 1]
# viewer.view.camera.look_at([0, 0, 0])

# viewer.scene.add(cylinder, opacity=0.9)
viewer.scene.add(cylinder, opacity=0.9, show_points=False)

viewer.show()
43 changes: 22 additions & 21 deletions docs/examples/breps/brep_overlap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from compas.colors import Color
from compas.geometry import Box
from compas.geometry import Brep
from compas_viewer import Viewer
Expand All @@ -8,7 +9,7 @@
box.translate([1, 0.3, 0.5])
B = Brep.from_box(box)

FA, FB = A.overlap(B)
FA, FB = A.overlap(B) # type: ignore

# =============================================================================
# Visualization
Expand All @@ -19,25 +20,25 @@
# viewer.view.camera.position = [3, -3, 1]
# viewer.view.camera.look_at([-1, 2, 0])

# viewer.scene.add(A, opacity=0.5, linewidth=3)
# viewer.scene.add(B, opacity=0.5, linewidth=3)

# for face in FA[:1]:
# brep = Brep.from_brepfaces([face])
# viewer.scene.add(
# brep,
# facecolor=Color.red().lightened(50),
# linewidth=3,
# linecolor=Color.red(),
# )

# for face in FB[:1]:
# brep = Brep.from_brepfaces([face])
# viewer.scene.add(
# brep,
# facecolor=Color.blue().lightened(50),
# linewidth=3,
# linecolor=Color.blue(),
# )
viewer.scene.add(A, opacity=0.5, linewidth=3)
viewer.scene.add(B, opacity=0.5, linewidth=3)

for face in FA[:1]:
brep = Brep.from_brepfaces([face])
viewer.scene.add(
brep,
surfacecolor=Color.red().lightened(50),
linewidth=3,
linecolor=Color.red(),
)

for face in FB[:1]:
brep = Brep.from_brepfaces([face])
viewer.scene.add(
brep,
surfacecolor=Color.blue().lightened(50),
linewidth=3,
linecolor=Color.blue(),
)

viewer.show()
6 changes: 2 additions & 4 deletions docs/examples/breps/brep_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
# Visualization
# =============================================================================

# TODO: this is currently not working properly, because of the new tessellation imlpementation.

viewer = Viewer()

# viewer.view.camera.position = [2, -4, 1]
# viewer.view.camera.look_at([0, 0, 0])

# viewer.scene.add(box, opacity=0.5)
# viewer.scene.add(slice, linewidth=2)
viewer.scene.add(box, opacity=0.5, show_points=False)
viewer.scene.add(slice, linewidth=2)

viewer.show()
43 changes: 24 additions & 19 deletions docs/examples/breps/brep_split.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from math import radians

from compas.colors import Color
from compas.geometry import Box
from compas.geometry import Brep
from compas.geometry import Plane
from compas.geometry import Rotation
from compas_occ.brep import OCCBrep as Brep
from compas.geometry import is_point_infrontof_plane
from compas_viewer import Viewer

box = Box(1).to_brep()

R = Rotation.from_axis_and_angle([0, 1, 0], radians(30))
plane = Plane.worldXY()
plane.transform(R)
splitter = Brep.from_plane(plane, domain_u=(-2, +2), domain_v=(-2, +2))

result = box.split(Brep.from_planes([plane]))
result = box.split(splitter)

# =============================================================================
# Visualization
Expand All @@ -23,22 +26,24 @@
# viewer.view.camera.position = [2, -4, 1]
# viewer.view.camera.look_at([0, 0, 0])

# viewer.scene.add(plane, linewidth=2, opacity=0.3) # there is a debug print statement in the viewer that needs to be removed

# for brep in result:
# if is_point_infrontof_plane(brep.centroid, plane):
# viewer.scene.add(
# brep,
# facecolor=Color.red().lightened(50),
# linecolor=Color.red(),
# linewidth=2,
# )
# else:
# viewer.scene.add(
# brep,
# facecolor=Color.blue().lightened(50),
# linecolor=Color.blue(),
# linewidth=2,
# )
viewer.scene.add(splitter, linewidth=2, opacity=0.3)

for brep in result: # type: ignore
if is_point_infrontof_plane(brep.centroid, plane):
viewer.scene.add(
brep,
surfacecolor=Color.red().lightened(50),
linecolor=Color.red(),
linewidth=2,
show_points=False,
)
else:
viewer.scene.add(
brep,
surfacecolor=Color.blue().lightened(50),
linecolor=Color.blue(),
linewidth=2,
show_points=False,
)

viewer.show()
6 changes: 3 additions & 3 deletions docs/examples/breps/brep_trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
# viewer.view.camera.position = [2, -4, 1]
# viewer.view.camera.look_at([0, 0, 0])

# viewer.scene.add(plane, opacity=0.5)
# viewer.scene.add(trimmed, linewidth=2)
# viewer.scene.add(box, linewidth=1, show_faces=False)
viewer.scene.add(plane, opacity=0.5)
viewer.scene.add(trimmed, linewidth=2, show_points=False)
viewer.scene.add(box, linewidth=1, show_points=False, show_faces=False)

viewer.show()
2 changes: 1 addition & 1 deletion docs/examples/breps/brep_with_hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
# =============================================================================

viewer = Viewer()
# viewer.scene.add(brep, linewidth=2)
viewer.scene.add(brep, linewidth=2, show_points=False)
viewer.show()
2 changes: 1 addition & 1 deletion docs/examples/breps/brep_with_holes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
# =============================================================================

viewer = Viewer()
# viewer.scene.add(brep, linewidth=2)
viewer.scene.add(brep, linewidth=2, show_point=False)
viewer.show()
11 changes: 6 additions & 5 deletions docs/examples/curves/curve_closest_parameters_curve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from compas.colors import Color
from compas.geometry import NurbsCurve
from compas.geometry import Point
from compas_viewer import Viewer
Expand All @@ -8,7 +9,7 @@
points1 = [Point(6, -3, 0), Point(3, 1, 0), Point(6, 6, 3), Point(3, 12, 0)]
curve1 = NurbsCurve.from_points(points1)

parameters, distance = curve0.closest_parameters_curve(curve1, return_distance=True)
parameters, distance = curve0.closest_parameters_curve(curve1, return_distance=True) # type: ignore
points = curve0.closest_points_curve(curve1, return_distance=False)

# =============================================================================
Expand All @@ -17,10 +18,10 @@

viewer = Viewer()

viewer.scene.add(curve0.to_polyline(), linewidth=3)
viewer.scene.add(curve1.to_polyline(), linewidth=3)
viewer.scene.add(curve0.to_polyline(), lineswidth=3, show_points=False)
viewer.scene.add(curve1.to_polyline(), lineswidth=3, show_points=False)

viewer.scene.add(points[0], pointcolor=(1, 0, 0))
viewer.scene.add(points[1], pointcolor=(1, 0, 0))
viewer.scene.add(points[0], pointcolor=Color(1, 0, 0))
viewer.scene.add(points[1], pointcolor=Color(1, 0, 0))

viewer.show()
9 changes: 5 additions & 4 deletions docs/examples/curves/curve_closest_point.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from compas.colors import Color
from compas.geometry import NurbsCurve
from compas.geometry import Point
from compas_viewer import Viewer
Expand All @@ -6,16 +7,16 @@
curve = NurbsCurve.from_interpolation(points)

point = Point(2, -1, 0)
closest, t = curve.closest_point(point, return_parameter=True)
closest, t = curve.closest_point(point, return_parameter=True) # type: ignore

# =============================================================================
# Visualization
# =============================================================================

viewer = Viewer()

viewer.scene.add(curve.to_polyline(), linewidth=3)
viewer.scene.add(point, pointcolor=(0, 0, 1))
viewer.scene.add(closest, pointcolor=(1, 0, 0))
viewer.scene.add(curve.to_polyline(), lineswidth=3, show_points=False)
viewer.scene.add(point, pointcolor=Color(0, 0, 1))
viewer.scene.add(closest, pointcolor=Color(1, 0, 0))

viewer.show()
19 changes: 10 additions & 9 deletions docs/examples/curves/curve_comparison1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from compas.colors import Color
from compas.geometry import Bezier
from compas.geometry import NurbsCurve
from compas.geometry import Point
Expand Down Expand Up @@ -43,22 +44,22 @@
Polyline(bezier.points),
show_points=True,
pointsize=20,
pointcolor=(1, 0, 0),
pointcolor=Color.red(),
linewidth=1,
linecolor=(0.3, 0.3, 0.3),
linecolor=Color(0.3, 0.3, 0.3),
)
viewer.scene.add(bezier.to_polyline(), linewidth=5, linecolor=(0, 0, 0))
viewer.scene.add(bezier.to_polyline(), lineswidth=5, linecolor=Color(0, 0, 0), show_points=False)

viewer.scene.add(
Polyline(curve1.points),
show_points=True,
pointsize=20,
pointcolor=(1, 0, 0),
linewidth=1,
linecolor=(0.3, 0.3, 0.3),
pointcolor=Color.red(),
lineswidth=1,
linecolor=Color(0.3, 0.3, 0.3),
)
viewer.scene.add(curve1.to_polyline(), linewidth=5, linecolor=(0, 0, 0))
viewer.scene.add(curve2.to_polyline(), linewidth=5, linecolor=(0, 1, 1))
viewer.scene.add(curve3.to_polyline(), linewidth=5, linecolor=(0, 0, 1))
viewer.scene.add(curve1.to_polyline(), lineswidth=5, linecolor=Color(0.0, 0.0, 0.0), show_points=False)
viewer.scene.add(curve2.to_polyline(), lineswidth=5, linecolor=Color(0.0, 1.0, 1.0), show_points=False)
viewer.scene.add(curve3.to_polyline(), lineswidth=5, linecolor=Color(0.0, 0.0, 1.0), show_points=False)

viewer.show()
23 changes: 12 additions & 11 deletions docs/examples/curves/curve_comparison2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from compas.colors import Color
from compas.geometry import Bezier
from compas.geometry import Point
from compas.geometry import Polyline
Expand Down Expand Up @@ -67,25 +68,25 @@
Polyline(bezier.points),
show_points=True,
pointsize=20,
pointcolor=(1, 0, 0),
pointcolor=Color.red(),
linewidth=1,
linecolor=(0.3, 0.3, 0.3),
linecolor=Color(0.3, 0.3, 0.3),
)
viewer.scene.add(bezier.to_polyline(), linewidth=5, linecolor=(0, 0, 0))
viewer.scene.add(bezier.to_polyline(), lineswidth=5, linecolor=Color(0, 0, 0), show_points=False)

viewer.scene.add(
Polyline(curve1.points),
show_points=True,
pointsize=20,
pointcolor=(1, 0, 0),
pointcolor=Color.red(),
linewidth=1,
linecolor=(0.3, 0.3, 0.3),
linecolor=Color(0.3, 0.3, 0.3),
)
viewer.scene.add(curve1.to_polyline(), linewidth=5, linecolor=(0, 0, 0))
viewer.scene.add(curve2.to_polyline(), linewidth=3, linecolor=(0, 0, 1))
viewer.scene.add(curve3.to_polyline(), linewidth=3, linecolor=(0.2, 0.2, 1))
viewer.scene.add(curve4.to_polyline(), linewidth=3, linecolor=(0.4, 0.4, 1))
viewer.scene.add(curve5.to_polyline(), linewidth=3, linecolor=(0.6, 0.6, 1))
viewer.scene.add(curve6.to_polyline(), linewidth=3, linecolor=(0.8, 0.8, 1))
viewer.scene.add(curve1.to_polyline(), lineswidth=5, linecolor=Color(0, 0, 0), show_points=False)
viewer.scene.add(curve2.to_polyline(), lineswidth=3, linecolor=Color.blue(), show_points=False)
viewer.scene.add(curve3.to_polyline(), lineswidth=3, linecolor=Color(0.2, 0.2, 1.0), show_points=False)
viewer.scene.add(curve4.to_polyline(), lineswidth=3, linecolor=Color(0.4, 0.4, 1.0), show_points=False)
viewer.scene.add(curve5.to_polyline(), lineswidth=3, linecolor=Color(0.6, 0.6, 1.0), show_points=False)
viewer.scene.add(curve6.to_polyline(), lineswidth=3, linecolor=Color(0.8, 0.8, 1.0), show_points=False)

viewer.show()
4 changes: 2 additions & 2 deletions docs/examples/curves/curve_divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
curve = NurbsCurve.from_points(points)

N = 10
params, points = curve.divide(N, return_points=True)
params, points = curve.divide(N, return_points=True) # type: ignore

for u, v in pairwise(params):
segment = curve.segmented(u, v)
Expand All @@ -19,7 +19,7 @@

viewer = Viewer()

viewer.scene.add(curve.to_polyline())
viewer.scene.add(curve.to_polyline(), show_points=False)
for point in points:
viewer.scene.add(point)
viewer.show()
Loading

0 comments on commit e7318df

Please sign in to comment.