Skip to content

Commit d1136ec

Browse files
committed
update examples to use viewer
1 parent c408dd8 commit d1136ec

File tree

8 files changed

+88
-83
lines changed

8 files changed

+88
-83
lines changed

docs/examples/boundaries.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import math
2-
import compas_libigl as libigl
32

4-
from compas.datastructures import Mesh
5-
from compas.geometry import Polyline, Rotation, Scale
3+
import compas_libigl as libigl
64
from compas.colors import Color
7-
from compas_view2.app import App
5+
from compas.datastructures import Mesh
6+
from compas.geometry import Polyline
7+
from compas.geometry import Rotation
8+
from compas.geometry import Scale
9+
from compas_viewer import Viewer
810

911
# ==============================================================================
1012
# Input geometry
@@ -28,20 +30,21 @@
2830
# Visualize
2931
# ==============================================================================
3032

31-
viewer = App(width=1600, height=900)
32-
viewer.view.camera.position = [8, -7, 1]
33-
viewer.view.camera.look_at([1, 0, 0])
33+
viewer = Viewer(width=1600, height=900)
34+
# viewer.view.camera.position = [8, -7, 1]
35+
# viewer.view.camera.look_at([1, 0, 0])
3436

35-
viewer.add(
37+
viewer.scene.add(
3638
mesh,
3739
facecolor=Color.green(),
3840
linecolor=Color.green().darkened(20),
3941
opacity=0.7,
42+
show_points=False,
4043
)
4144

4245
for vertices in boundaries:
4346
points = mesh.vertices_attributes("xyz", keys=vertices)
4447
polyline = Polyline(points)
45-
viewer.add(polyline, linecolor=Color.red(), linewidth=3)
48+
viewer.scene.add(polyline, linecolor=Color.red(), linewidth=3)
4649

47-
viewer.run()
50+
viewer.show()

docs/examples/curvature.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import compas
22
import compas_libigl as igl
3-
4-
from compas.geometry import Point, Vector, Line
5-
from compas.datastructures import Mesh
63
from compas.colors import Color
7-
8-
from compas_view2.app import App
4+
from compas.datastructures import Mesh
5+
from compas.geometry import Line
6+
from compas.geometry import Point
7+
from compas.geometry import Vector
8+
from compas_viewer import Viewer
99

1010
# ==============================================================================
1111
# Input geometry
@@ -26,11 +26,11 @@
2626
# Visualisation
2727
# ==============================================================================
2828

29-
viewer = App(width=1600, height=900)
30-
viewer.view.camera.position = [1, -6, 2]
31-
viewer.view.camera.look_at([1, 1, 1])
29+
viewer = Viewer(width=1600, height=900)
30+
# viewer.view.camera.position = [1, -6, 2]
31+
# viewer.view.camera.look_at([1, 1, 1])
3232

33-
viewer.add(mesh, opacity=0.7)
33+
viewer.scene.add(mesh, opacity=0.7, show_points=False)
3434

3535
for vertex in mesh.vertices():
3636
if mesh.is_vertex_on_boundary(vertex):
@@ -41,10 +41,10 @@
4141
c = curvature[vertex]
4242
normal.scale(10 * c)
4343

44-
viewer.add(
44+
viewer.scene.add(
4545
Line(point, point + normal),
4646
linecolor=(Color.red() if c > 0 else Color.blue()),
4747
linewidth=2,
4848
)
4949

50-
viewer.run()
50+
viewer.show()

docs/examples/geodistance.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import compas
22
import compas_libigl as igl
3-
from compas.geometry import Point
3+
from compas.colors import Color
4+
from compas.colors import ColorMap
45
from compas.datastructures import Mesh
5-
from compas.colors import Color, ColorMap
6-
from compas_view2.app import App
6+
from compas.geometry import Point
7+
from compas_viewer import Viewer
78

89
# ==============================================================================
910
# Input
@@ -19,24 +20,22 @@
1920
# ==============================================================================
2021

2122
source = trimesh.vertex_sample(size=1)[0]
22-
distance = igl.trimesh_geodistance(
23-
trimesh.to_vertices_and_faces(), source, method="heat"
24-
)
23+
distance = igl.trimesh_geodistance(trimesh.to_vertices_and_faces(), source, method="heat")
2524

2625
# ==============================================================================
2726
# Visualize
2827
# ==============================================================================
2928

3029
cmap = ColorMap.from_color(Color.red())
3130

32-
viewer = App(width=1600, height=900)
33-
viewer.view.camera.position = [1, -6, 2]
34-
viewer.view.camera.look_at([1, 1, 1])
31+
viewer = Viewer(width=1600, height=900)
32+
# viewer.view.camera.position = [1, -6, 2]
33+
# viewer.view.camera.look_at([1, 1, 1])
3534

36-
viewer.add(mesh)
35+
viewer.scene.add(mesh, show_points=False)
3736

3837
for d, vertex in zip(distance, mesh.vertices()):
3938
point = Point(*mesh.vertex_attributes(vertex, "xyz"))
40-
viewer.add(point, pointsize=30, pointcolor=cmap(d, min(distance), max(distance)))
39+
viewer.scene.add(point, pointsize=30, pointcolor=cmap(d, min(distance), max(distance)))
4140

42-
viewer.run()
41+
viewer.show()

docs/examples/intersections.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import numpy as np
21
import compas
32
import compas_libigl as igl
4-
5-
from compas.geometry import Point, Line
6-
from compas.datastructures import Mesh
3+
import numpy as np
74
from compas.colors import Color
8-
9-
from compas_view2.app import App
5+
from compas.datastructures import Mesh
6+
from compas.geometry import Line
7+
from compas.geometry import Point
8+
from compas_viewer import Viewer
109

1110
# ==============================================================================
1211
# Input geometry
@@ -67,13 +66,13 @@
6766
# Visualisation
6867
# ==============================================================================
6968

70-
viewer = App(width=1600, height=900)
71-
viewer.view.camera.position = [1, -6, 2]
72-
viewer.view.camera.look_at([1, 1, 1])
69+
viewer = Viewer(width=1600, height=900)
70+
# viewer.view.camera.position = [1, -6, 2]
71+
# viewer.view.camera.look_at([1, 1, 1])
7372

74-
viewer.add(mesh, opacity=0.7)
73+
viewer.scene.add(mesh, opacity=0.7, show_points=False)
7574

7675
for intersection in intersections:
77-
viewer.add(Line(base, intersection), linecolor=Color.blue(), linewidth=3)
76+
viewer.scene.add(Line(base, intersection), linecolor=Color.blue(), linewidth=3)
7877

79-
viewer.run()
78+
viewer.show()

docs/examples/isolines.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import math
2+
23
import compas_libigl as igl
3-
from compas.datastructures import Mesh
44
from compas.colors import ColorMap
5-
from compas.geometry import Polyline, Rotation, Scale
6-
from compas_view2.app import App
7-
from compas_view2.objects import Collection
5+
from compas.datastructures import Mesh
6+
from compas.geometry import Polyline
7+
from compas.geometry import Rotation
8+
from compas.geometry import Scale
9+
10+
# from compas_view2.objects import Collection
11+
from compas_viewer import Viewer
812

913
# ==============================================================================
1014
# Input geometry
@@ -30,11 +34,11 @@
3034
# Visualisation
3135
# ==============================================================================
3236

33-
viewer = App(width=1600, height=900)
34-
viewer.view.camera.position = [8, -7, 1]
35-
viewer.view.camera.look_at([1, 0, 0])
37+
viewer = Viewer(width=1600, height=900)
38+
# viewer.view.camera.position = [8, -7, 1]
39+
# viewer.view.camera.look_at([1, 0, 0])
3640

37-
viewer.add(mesh, opacity=0.7, show_lines=False)
41+
viewer.scene.add(mesh, opacity=0.7, show_lines=False, show_points=False)
3842

3943
minval = min(scalars) - 0.01
4044
maxval = max(scalars) + 0.01
@@ -49,10 +53,10 @@
4953
points.append(vertices[j])
5054
polylines.append(Polyline(points))
5155

52-
viewer.add(
53-
Collection(polylines),
54-
linecolor=cmap(value, minval=minval, maxval=maxval),
55-
linewidth=3,
56-
)
56+
# viewer.scene.add(
57+
# Collection(polylines),
58+
# linecolor=cmap(value, minval=minval, maxval=maxval),
59+
# linewidth=3,
60+
# )
5761

5862
viewer.show()

docs/examples/massmatrix.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import compas
22
import compas_libigl as igl
3-
from compas.datastructures import Mesh
43
from compas.colors import ColorMap
5-
from compas_view2.app import App
4+
from compas.datastructures import Mesh
5+
from compas_viewer import Viewer
66

77
# ==============================================================================
88
# Input geometry
@@ -28,14 +28,14 @@
2828
minval = min(mass)
2929
maxval = max(mass)
3030

31-
viewer = App(width=1600, height=900)
32-
viewer.view.camera.position = [1, -6, 2]
33-
viewer.view.camera.look_at([1, 1, 1])
31+
viewer = Viewer(width=1600, height=900)
32+
# viewer.view.camera.position = [1, -6, 2]
33+
# viewer.view.camera.look_at([1, 1, 1])
3434

35-
viewer.add(mesh)
35+
viewer.scene.add(mesh, show_points=False)
3636

3737
for m, vertex in zip(mass, mesh.vertices()):
3838
point = mesh.vertex_point(vertex)
39-
viewer.add(point, pointsize=30, pointcolor=cmap(m, minval, maxval))
39+
viewer.scene.add(point, pointsize=30, pointcolor=cmap(m, minval, maxval))
4040

41-
viewer.run()
41+
viewer.show()

docs/examples/parametrisation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import compas_libigl as igl
22
from compas.datastructures import Mesh
3-
from compas.geometry import Scale, Translation
4-
from compas_view2.app import App
3+
from compas.geometry import Scale
4+
from compas.geometry import Translation
5+
from compas_viewer import Viewer
56

67
# ==============================================================================
78
# Input geometry
@@ -31,7 +32,7 @@
3132

3233
mesh.transform(X)
3334

34-
viewer = App()
35-
viewer.add(mesh)
36-
viewer.add(mesh_lscm)
37-
viewer.run()
35+
viewer = Viewer()
36+
viewer.scene.add(mesh, show_points=False)
37+
viewer.scene.add(mesh_lscm, show_points=False)
38+
viewer.show()

docs/examples/planarize.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import compas
22
import compas_libigl as igl
3+
from compas.colors import Color
4+
from compas.colors import ColorMap
35
from compas.datastructures import Mesh
46
from compas.datastructures import mesh_flatness
5-
from compas.colors import Color, ColorMap
6-
from compas_view2.app import App
7+
from compas_viewer import Viewer
78

89
# ==============================================================================
910
# Input
@@ -31,15 +32,13 @@
3132

3233
cmap = ColorMap.from_two_colors(Color.white(), Color.blue())
3334

34-
viewer = App(width=1600, height=900)
35-
viewer.view.camera.position = [1, -6, 2]
36-
viewer.view.camera.look_at([1, 1, 1])
35+
viewer = Viewer(width=1600, height=900)
36+
# viewer.view.camera.position = [1, -6, 2]
37+
# viewer.view.camera.look_at([1, 1, 1])
3738

38-
viewer.add(
39+
viewer.scene.add(
3940
mesh,
40-
facecolor={
41-
face: (cmap(dev[face]) if dev[face] <= 1.0 else Color.red())
42-
for face in mesh.faces()
43-
},
41+
facecolor={face: (cmap(dev[face]) if dev[face] <= 1.0 else Color.red()) for face in mesh.faces()},
42+
show_points=False,
4443
)
45-
viewer.run()
44+
viewer.show()

0 commit comments

Comments
 (0)