Skip to content

Commit 96abc81

Browse files
DOCS cleanup examples.
1 parent e786e77 commit 96abc81

12 files changed

+26
-120
lines changed

docs/examples/example_meshing.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from compas.datastructures import Mesh
22

3-
# from compas_cgal import remesh
43
from compas.geometry import scale_vector
54
from compas.geometry import Translation
65
from compas.geometry import Rotation
76
from compas.geometry import Scale
87
from compas.geometry import Vector
8+
from compas.geometry import transform_points_numpy
99
from pathlib import Path
1010
import math
1111
from line_profiler import profile
@@ -18,19 +18,9 @@ def main():
1818
"""Remesh a bunny mesh that is loaded from .ply file."""
1919

2020
FILE = Path(__file__).parent.parent.parent / "data" / "Bunny.ply"
21-
22-
# ==============================================================================
23-
# Get the bunny and construct a mesh
24-
# ==============================================================================
25-
2621
bunny = Mesh.from_ply(FILE)
27-
2822
bunny.remove_unused_vertices()
2923

30-
# ==============================================================================
31-
# Move the bunny to the origin and rotate it upright.
32-
# ==============================================================================
33-
3424
centroid = bunny.vertex_point(0)
3525

3626
vector = scale_vector(centroid, -1)
@@ -40,13 +30,12 @@ def main():
4030
R = Rotation.from_axis_and_angle(Vector(1, 0, 0), math.radians(90))
4131

4232
bunny.transform(R * S * T)
33+
V0, F0 = bunny.to_vertices_and_faces()
34+
V1 = transform_points_numpy(V0, R * S * T)
4335

44-
# ==============================================================================
45-
# Remesh
46-
# ==============================================================================
47-
48-
V, F = mesh_remesh(bunny.to_vertices_and_faces(), 0.3, 10)
49-
mesh = Mesh.from_vertices_and_faces(V, F)
36+
V1, F1 = mesh_remesh((V0, F0), 0.3, 10)
37+
V1 = transform_points_numpy(V1, Translation.from_vector([20, 0, 0]))
38+
mesh = Mesh.from_vertices_and_faces(V1, F1)
5039

5140
return bunny, mesh
5241

@@ -63,7 +52,7 @@ def main():
6352
viewer.renderer.camera.target = [0, 0, 0]
6453
viewer.renderer.camera.position = [0, -25, 10]
6554

66-
viewer.scene.add(bunny.transformed(Translation.from_vector([-10, 0, 0])), show_points=False)
67-
viewer.scene.add(mesh.transformed(Translation.from_vector([+10, 0, 0])), show_points=False)
55+
viewer.scene.add(bunny, show_points=False)
56+
viewer.scene.add(mesh, show_points=False)
6857

6958
viewer.show()

docs/examples/example_reconstruction_pointset_outlier_removal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def reconstruction_pointset_outlier_removal():
2525
points = pointset_outlier_removal(c1, 30, 2.0)
2626
c2 = Pointcloud(points)
2727
c3 = c1.difference(c2)
28-
c2.name = "pointset_outlier_removal"
29-
c3.name = "pointset_outlier_removal"
3028

3129
return c2, c3
3230

docs/examples/example_reconstruction_pointset_reduction.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from compas.geometry import Pointcloud
44
from compas.geometry import Translation
5+
from compas.geometry import transform_points_numpy
56
from compas_cgal.reconstruction import pointset_reduction
67
from compas_viewer import Viewer
78
from compas_viewer.config import Config
@@ -12,29 +13,19 @@
1213
def reconstruction_pointset_reduction():
1314
"""Reduce the number of points in a point set."""
1415

15-
# ==============================================================================
16-
# Input geometry
17-
# ==============================================================================
18-
1916
FILE = Path(__file__).parent.parent.parent / "data" / "forked_branch_1.ply"
2017
c = Pointcloud.from_ply(FILE)
2118

22-
# ==============================================================================
23-
# Compute
24-
# ==============================================================================
25-
2619
points = Pointcloud(pointset_reduction(c, 50))
20+
transform_points_numpy(points, Translation.from_vector([-1000, 0, 0]))
21+
2722
c.transform(Translation.from_vector([-1000, 0, 0]))
2823

2924
return c, points
3025

3126

3227
c_reduction_0, c_reduction_1 = reconstruction_pointset_reduction()
3328

34-
# ==============================================================================
35-
# Visualize
36-
# ==============================================================================
37-
3829
config = Config()
3930
config.camera.target = [100, 500, 200]
4031
config.camera.position = [100, -1500, 2000]

docs/examples/example_reconstruction_pointset_smoothing.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from compas.geometry import Pointcloud
44
from compas.geometry import Translation
55
from compas_cgal.reconstruction import pointset_smoothing
6+
from compas.geometry import transform_points_numpy
67
from compas_viewer import Viewer
78
from compas_viewer.config import Config
89
from line_profiler import profile
@@ -12,29 +13,12 @@
1213
def reconstruction_pointset_smoothing():
1314
"""Smooth a point set."""
1415

15-
# ==============================================================================
16-
# Input geometry
17-
# ==============================================================================
18-
1916
ply_file_path = Path(__file__).parent.parent.parent / "data" / "box.ply"
2017
original_points = Pointcloud.from_ply(ply_file_path)
21-
original_points.transform(Translation.from_vector([-10000, 0, 0]))
22-
transformed_points = Pointcloud.from_ply(ply_file_path)
23-
transformed_points.transform(Translation.from_vector([10000, 0, 0]))
24-
25-
# ==============================================================================
26-
# Compute
27-
# ==============================================================================
28-
29-
smoothed_points = pointset_smoothing(transformed_points, 1000, 3)
3018

31-
# ==============================================================================
32-
# Visualize
33-
# ==============================================================================
19+
smoothed_points = pointset_smoothing(original_points, 1000, 3)
3420

35-
c_original = Pointcloud(original_points)
36-
c_transformed = Pointcloud(smoothed_points)
37-
return c_original, c_transformed
21+
return Pointcloud(original_points), Pointcloud(smoothed_points)
3822

3923

4024
c_smoothing_0, c_smoothing_1 = reconstruction_pointset_smoothing()

docs/examples/example_reconstruction_poisson_surface_reconstruction.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
@profile
1414
def reconstruction_poisson_surface_reconstruction():
15-
# ==============================================================================
16-
# Input geometry
17-
# ==============================================================================
18-
1915
FILE = Path(__file__).parent.parent.parent / "data" / "oni.xyz"
2016

2117
points = []
@@ -26,23 +22,12 @@ def reconstruction_poisson_surface_reconstruction():
2622
points.append([float(x), float(y), float(z)])
2723
normals.append([float(nx), float(ny), float(nz)])
2824

29-
# ==============================================================================
30-
# Compute
31-
# ==============================================================================
32-
3325
V, F = poisson_surface_reconstruction(points, normals)
3426
mesh = Mesh.from_vertices_and_faces(V, F)
3527

36-
R = Rotation.from_axis_and_angle([1, 0, 0], math.radians(90))
37-
S = Scale.from_factors([10, 10, 10])
38-
T = R * S
39-
4028
c = Pointcloud(V)
41-
c.transform(T)
42-
mesh.transform(T)
43-
points, mesh.name = (c, mesh)
4429

45-
return points, mesh
30+
return c, mesh
4631

4732

4833
points, mesh = reconstruction_poisson_surface_reconstruction()
@@ -52,6 +37,11 @@ def reconstruction_poisson_surface_reconstruction():
5237
# ==============================================================================
5338

5439
viewer = Viewer()
40+
41+
viewer.renderer.camera.target = [0, 0, 0]
42+
viewer.renderer.camera.position = [0, -0.2, 2.0]
43+
5544
viewer.scene.add(points, pointsize=10, pointcolor=(255, 0, 0))
5645
viewer.scene.add(mesh, show_points=False)
46+
5747
viewer.show()

docs/examples/example_skeletonization.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,23 @@
1414

1515
@profile
1616
def main():
17-
# ==============================================================================
18-
# Load and transform mesh
19-
# ==============================================================================
17+
"""Skeletonize a mesh."""
2018

2119
input_file = Path(__file__).parent.parent.parent / "data" / "elephant.off"
2220

23-
# Create transformation sequence
2421
rotation_x = Rotation.from_axis_and_angle([1, 0, 0], math.radians(60))
2522
rotation_y = Rotation.from_axis_and_angle([0, 1, 0], math.radians(5))
2623
rotation = rotation_y * rotation_x
2724
scale = Scale.from_factors([5, 5, 5])
2825
translation = Translation.from_vector([0, 0, 2])
2926

30-
# Apply transformations to mesh
3127
mesh = Mesh.from_off(input_file).transformed(translation * rotation * scale)
3228
mesh = mesh.subdivided("loop")
3329

34-
# ==============================================================================
35-
# Convert mesh to vertices and faces
36-
# ==============================================================================
37-
3830
vertices, faces = mesh.to_vertices_and_faces()
3931

40-
# ==============================================================================
41-
# Generate skeleton edges
42-
# ==============================================================================
43-
4432
skeleton_edges = mesh_skeleton((vertices, faces))
4533

46-
# ==============================================================================
47-
# Convert skeleton edges to polylines
48-
# ==============================================================================
49-
5034
polylines = []
5135
for start_point, end_point in skeleton_edges:
5236
polyline = Polyline([start_point, end_point])

docs/examples/example_slicer.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,12 @@
1313

1414
@profile
1515
def main():
16-
# ==============================================================================
17-
# Input geometry
18-
# ==============================================================================
19-
2016
# Get Mesh from STL
2117
FILE = Path(__file__).parent.parent.parent / "data" / "3DBenchy.stl"
2218
benchy = Mesh.from_stl(FILE)
2319

2420
V, F = benchy.to_vertices_and_faces()
2521

26-
# ==============================================================================
27-
# Create slicing planes
28-
# ==============================================================================
29-
3022
# Get Slice planes from the bounding box
3123
bbox = benchy.aabb()
3224
normal = Vector(0, 0, 1)
@@ -35,10 +27,6 @@ def main():
3527
plane = Plane(Point(0, 0, i), normal)
3628
planes.append(plane)
3729

38-
# ==============================================================================
39-
# Compute
40-
# ==============================================================================
41-
4230
# Slice
4331
slicer_polylines = slice_mesh((V, F), planes)
4432

docs/examples/example_straight_skeleton_2_interior_straight_skeleton.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
def main():
1010
"""Compute the interior straight skeleton of a polygon."""
1111

12-
# ==============================================================================
13-
# Input geometry
14-
# ==============================================================================
15-
1612
points = [
1713
Point(-1.91, 3.59, 0.0),
1814
Point(-5.53, -5.22, 0.0),
@@ -27,10 +23,6 @@ def main():
2723
]
2824
polygon = Polygon(points)
2925

30-
# ==============================================================================
31-
# Compute
32-
# ==============================================================================
33-
3426
graph = interior_straight_skeleton(polygon)
3527

3628
return graph

docs/examples/example_straight_skeleton_2_interior_straight_skeleton_offset_polygon.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
@profile
99
def main():
10+
"""Create offset polygons."""
11+
1012
points = [
1113
(-1.91, 3.59, 0.0),
1214
(-5.53, -5.22, 0.0),

docs/examples/example_straight_skeleton_2_interior_straight_skeleton_weighted_offset_polygon.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
@profile
99
def main():
10+
"""Create weighted offset polygons."""
11+
1012
points = [
1113
(-1.91, 3.59, 0.0),
1214
(-5.53, -5.22, 0.0),

0 commit comments

Comments
 (0)