Skip to content

Commit

Permalink
update surface examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jan 16, 2024
1 parent 49fcf77 commit 7ddad56
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 100 deletions.
4 changes: 2 additions & 2 deletions docs/examples/surfaces/surface_aabb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from math import radians
from compas.geometry import Point, Translation, Rotation
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App


Expand All @@ -14,7 +14,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

T = Translation.from_vector([0, -1.5, 0])
R = Rotation.from_axis_and_angle([0, 0, 1], radians(45))
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/surfaces/surface_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from compas.geometry import Point
from compas.utilities import meshgrid, flatten, linspace
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App
from compas_view2.objects import Collection


points = [
Expand All @@ -13,7 +14,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# Frames
Expand All @@ -29,8 +30,6 @@
view = App()

view.add(surface, show_lines=False)

for frame in frames:
view.add(frame, size=0.3, pointsize=0.25)
view.add(Collection(frames, [{"size": 0.1} for frame in frames]), pointsize=0.25)

view.run()
14 changes: 10 additions & 4 deletions docs/examples/surfaces/surface_from_extrusion-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

from compas.geometry import Vector
from compas.geometry import Circle
from compas_occ.geometry import OCCNurbsCurve
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsCurve
from compas_occ.geometry import (
OCCNurbsSurface as NurbsSurface,
) # this should be added to the pluggable API
from compas_view2.app import App

curve = OCCNurbsCurve.from_circle(Circle(2.0))
curve = NurbsCurve.from_circle(Circle(2.0))

surface = OCCNurbsSurface.from_extrusion(curve, Vector(0, 0, 5))
surface = NurbsSurface.from_extrusion(curve, Vector(0, 0, 5))

# =============================================================================
# Visualisation
# =============================================================================

viewer = App()
viewer.view.camera.position = [-5, -10, 4]
Expand Down
14 changes: 10 additions & 4 deletions docs/examples/surfaces/surface_from_extrusion-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

from compas.geometry import Point
from compas.geometry import Vector
from compas_occ.geometry import OCCNurbsCurve
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsCurve
from compas_occ.geometry import (
OCCNurbsSurface as NurbsSurface,
) # this should be added to the pluggable API
from compas_view2.app import App

points = [Point(0, 0, 0), Point(0, -6, 3), Point(0, 2, 6), Point(0, -2, 9)]
curve = OCCNurbsCurve.from_points(points)
curve = NurbsCurve.from_points(points)
vector = Vector(5, 0, 0)

surface = OCCNurbsSurface.from_extrusion(curve, vector)
surface = NurbsSurface.from_extrusion(curve, vector)

# =============================================================================
# Visualisation
# =============================================================================

viewer = App()
viewer.view.camera.position = [-7, -10, 6]
Expand Down
1 change: 0 additions & 1 deletion docs/examples/surfaces/surface_from_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
style="curved",
)


# ==============================================================================
# Visualisation
# ==============================================================================
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/surfaces/surface_from_meshgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from compas.geometry import Point
from compas.geometry import Polyline
from compas.utilities import meshgrid, linspace
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App


Expand All @@ -27,7 +27,7 @@
row.append(Point(u, v, z))
points.append(row)

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# Visualisation
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/surfaces/surface_from_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from compas.geometry import Point
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App

points = [
Expand Down Expand Up @@ -65,7 +65,7 @@
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
]

surface = OCCNurbsSurface.from_parameters(
surface = NurbsSurface.from_parameters(
points=points,
weights=weights,
knots_u=[
Expand Down Expand Up @@ -114,5 +114,4 @@
)

view.add(surface.to_mesh())

view.run()
7 changes: 3 additions & 4 deletions docs/examples/surfaces/surface_from_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from compas.geometry import Point
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App

points = [
Expand All @@ -12,7 +12,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# Visualisation
Expand Down Expand Up @@ -40,6 +40,5 @@
linecolor=(0.3, 0.3, 0.3),
)

view.add(surface.to_mesh(nu=100))

view.add(surface)
view.run()
7 changes: 3 additions & 4 deletions docs/examples/surfaces/surface_intersections_with_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from compas.geometry import Rotation
from compas.geometry import centroid_points_xy
from compas.utilities import flatten
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface

from compas_view2.app import App
from compas_view2.objects import Collection
Expand All @@ -17,7 +17,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# Intersections
Expand Down Expand Up @@ -66,13 +66,12 @@
linecolor=(0.3, 0.3, 0.3),
)

view.add(Collection(intersections), pointsize=30, pointcolor=(0, 0, 1))
view.add(Collection(intersections), pointsize=20, pointcolor=(0, 0, 1))

for x in intersections:
view.add(
Line(base, base + (x - base).scaled(1.2)), linewidth=1, linecolor=(0, 0, 1)
)

view.add(surface)

view.run()
4 changes: 2 additions & 2 deletions docs/examples/surfaces/surface_isocurves.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# type: ignore

from compas.geometry import Point
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App


Expand All @@ -12,7 +12,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# Isocurves
Expand Down
20 changes: 10 additions & 10 deletions docs/examples/surfaces/surface_jsondata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# type: ignore

from compas.geometry import Point
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App


Expand All @@ -11,7 +12,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# JSON Data
Expand All @@ -21,7 +22,7 @@

print(string)

other = OCCNurbsSurface.from_jsonstring(string)
other = NurbsSurface.from_jsonstring(string)

print(surface == other)

Expand All @@ -31,15 +32,14 @@

view = App()

u = surface.u_isocurve(0.5 * sum(surface.u_domain))
v = surface.v_isocurve(0.5 * sum(surface.v_domain))
u = surface.isocurve_u(0.5 * sum(surface.domain_u))
v = surface.isocurve_v(0.5 * sum(surface.domain_v))

view.add(Polyline(u.locus()), linewidth=1, linecolor=(0.3, 0.3, 0.3))
view.add(Polyline(v.locus()), linewidth=1, linecolor=(0.3, 0.3, 0.3))
view.add(u.to_polyline(), linewidth=1, linecolor=(0.3, 0.3, 0.3))
view.add(v.to_polyline(), linewidth=1, linecolor=(0.3, 0.3, 0.3))

for curve in surface.boundary():
view.add(curve.to_polyline(), linewidth=2, linecolor=(0, 0, 0))

view.add(other.to_mesh(), show_lines=False)

view.add(other)
view.run()
7 changes: 3 additions & 4 deletions docs/examples/surfaces/surface_obb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from math import radians
from compas.geometry import Point, Translation, Rotation
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App


Expand All @@ -14,7 +14,7 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

T = Translation.from_vector([0, -1.5, 0])
R = Rotation.from_axis_and_angle([0, 0, 1], radians(45))
Expand Down Expand Up @@ -46,7 +46,6 @@
for col in zip(*surface.points):
view.add(Polyline(col), linewidth=2, linecolor=(0, 1.0, 0))

view.add(surface.to_mesh())
view.add(surface)
view.add(box, show_faces=False)

view.run()
11 changes: 9 additions & 2 deletions docs/examples/surfaces/surface_of_revolution.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# type: ignore

from compas.geometry import Point
from compas.geometry import Vector
from compas_occ.geometry import OCCNurbsCurve
from compas.geometry import NurbsCurve
from compas_occ.geometry import OCCRevolutionSurface
from compas_view2.app import App

points = [Point(0, 0, 0), Point(0, -6, 3), Point(0, 2, 6), Point(0, -2, 9)]
curve = OCCNurbsCurve.from_points(points)
curve = NurbsCurve.from_points(points)
point = Point(0, 0, 0)
vector = Vector(0, 0, 1)

# TODO: TypeError: __init__() missing 1 required positional argument: 'occ_surface'
surface = OCCRevolutionSurface(curve, point=point, vector=vector)

# =============================================================================
# Visualisation
# =============================================================================

viewer = App()
viewer.view.camera.position = [-5, -10, 7]
viewer.view.camera.target = [0, 0, 5]
Expand Down
10 changes: 0 additions & 10 deletions docs/examples/surfaces/surface_of_revolution.rst

This file was deleted.

4 changes: 2 additions & 2 deletions docs/examples/surfaces/surface_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import random
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas_view2.app import App

U = 10
V = 20

surface = OCCNurbsSurface.from_meshgrid(nu=U, nv=V)
surface = NurbsSurface.from_meshgrid(nu=U, nv=V)

# ==============================================================================
# Update
Expand Down
14 changes: 8 additions & 6 deletions docs/examples/surfaces/surface_spacepoints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# type: ignore

from compas.geometry import Point
from compas.geometry import Polyline
from compas_occ.geometry import OCCNurbsSurface
from compas.geometry import NurbsSurface
from compas.utilities import linspace, meshgrid, flatten
from compas_view2.app import App
from compas_view2.objects import Collection

Expand All @@ -12,13 +15,14 @@
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)],
]

surface = OCCNurbsSurface.from_points(points=points)
surface = NurbsSurface.from_points(points=points)

# ==============================================================================
# Points over UV space
# ==============================================================================

spacepoints = surface.xyz(nu=50, nv=10)
U, V = meshgrid(linspace(*surface.domain_u), linspace(*surface.domain_v), "ij")
spacepoints = [surface.point_at(u, v) for u, v in zip(flatten(U), flatten(V))]

# ==============================================================================
# Visualisation
Expand Down Expand Up @@ -46,8 +50,6 @@
linecolor=(0.5, 1.0, 0.5),
)

view.add(surface.to_mesh(), show_lines=False)

view.add(surface)
view.add(Collection(spacepoints))

view.run()
Loading

0 comments on commit 7ddad56

Please sign in to comment.