Skip to content

Commit

Permalink
update examples to use viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Apr 24, 2024
1 parent c408dd8 commit d1136ec
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 83 deletions.
23 changes: 13 additions & 10 deletions docs/examples/boundaries.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import math
import compas_libigl as libigl

from compas.datastructures import Mesh
from compas.geometry import Polyline, Rotation, Scale
import compas_libigl as libigl
from compas.colors import Color
from compas_view2.app import App
from compas.datastructures import Mesh
from compas.geometry import Polyline
from compas.geometry import Rotation
from compas.geometry import Scale
from compas_viewer import Viewer

# ==============================================================================
# Input geometry
Expand All @@ -28,20 +30,21 @@
# Visualize
# ==============================================================================

viewer = App(width=1600, height=900)
viewer.view.camera.position = [8, -7, 1]
viewer.view.camera.look_at([1, 0, 0])
viewer = Viewer(width=1600, height=900)
# viewer.view.camera.position = [8, -7, 1]
# viewer.view.camera.look_at([1, 0, 0])

viewer.add(
viewer.scene.add(
mesh,
facecolor=Color.green(),
linecolor=Color.green().darkened(20),
opacity=0.7,
show_points=False,
)

for vertices in boundaries:
points = mesh.vertices_attributes("xyz", keys=vertices)
polyline = Polyline(points)
viewer.add(polyline, linecolor=Color.red(), linewidth=3)
viewer.scene.add(polyline, linecolor=Color.red(), linewidth=3)

viewer.run()
viewer.show()
22 changes: 11 additions & 11 deletions docs/examples/curvature.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import compas
import compas_libigl as igl

from compas.geometry import Point, Vector, Line
from compas.datastructures import Mesh
from compas.colors import Color

from compas_view2.app import App
from compas.datastructures import Mesh
from compas.geometry import Line
from compas.geometry import Point
from compas.geometry import Vector
from compas_viewer import Viewer

# ==============================================================================
# Input geometry
Expand All @@ -26,11 +26,11 @@
# Visualisation
# ==============================================================================

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

viewer.add(mesh, opacity=0.7)
viewer.scene.add(mesh, opacity=0.7, show_points=False)

for vertex in mesh.vertices():
if mesh.is_vertex_on_boundary(vertex):
Expand All @@ -41,10 +41,10 @@
c = curvature[vertex]
normal.scale(10 * c)

viewer.add(
viewer.scene.add(
Line(point, point + normal),
linecolor=(Color.red() if c > 0 else Color.blue()),
linewidth=2,
)

viewer.run()
viewer.show()
23 changes: 11 additions & 12 deletions docs/examples/geodistance.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import compas
import compas_libigl as igl
from compas.geometry import Point
from compas.colors import Color
from compas.colors import ColorMap
from compas.datastructures import Mesh
from compas.colors import Color, ColorMap
from compas_view2.app import App
from compas.geometry import Point
from compas_viewer import Viewer

# ==============================================================================
# Input
Expand All @@ -19,24 +20,22 @@
# ==============================================================================

source = trimesh.vertex_sample(size=1)[0]
distance = igl.trimesh_geodistance(
trimesh.to_vertices_and_faces(), source, method="heat"
)
distance = igl.trimesh_geodistance(trimesh.to_vertices_and_faces(), source, method="heat")

# ==============================================================================
# Visualize
# ==============================================================================

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

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

viewer.add(mesh)
viewer.scene.add(mesh, show_points=False)

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

viewer.run()
viewer.show()
23 changes: 11 additions & 12 deletions docs/examples/intersections.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import numpy as np
import compas
import compas_libigl as igl

from compas.geometry import Point, Line
from compas.datastructures import Mesh
import numpy as np
from compas.colors import Color

from compas_view2.app import App
from compas.datastructures import Mesh
from compas.geometry import Line
from compas.geometry import Point
from compas_viewer import Viewer

# ==============================================================================
# Input geometry
Expand Down Expand Up @@ -67,13 +66,13 @@
# Visualisation
# ==============================================================================

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

viewer.add(mesh, opacity=0.7)
viewer.scene.add(mesh, opacity=0.7, show_points=False)

for intersection in intersections:
viewer.add(Line(base, intersection), linecolor=Color.blue(), linewidth=3)
viewer.scene.add(Line(base, intersection), linecolor=Color.blue(), linewidth=3)

viewer.run()
viewer.show()
30 changes: 17 additions & 13 deletions docs/examples/isolines.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import math

import compas_libigl as igl
from compas.datastructures import Mesh
from compas.colors import ColorMap
from compas.geometry import Polyline, Rotation, Scale
from compas_view2.app import App
from compas_view2.objects import Collection
from compas.datastructures import Mesh
from compas.geometry import Polyline
from compas.geometry import Rotation
from compas.geometry import Scale

# from compas_view2.objects import Collection
from compas_viewer import Viewer

# ==============================================================================
# Input geometry
Expand All @@ -30,11 +34,11 @@
# Visualisation
# ==============================================================================

viewer = App(width=1600, height=900)
viewer.view.camera.position = [8, -7, 1]
viewer.view.camera.look_at([1, 0, 0])
viewer = Viewer(width=1600, height=900)
# viewer.view.camera.position = [8, -7, 1]
# viewer.view.camera.look_at([1, 0, 0])

viewer.add(mesh, opacity=0.7, show_lines=False)
viewer.scene.add(mesh, opacity=0.7, show_lines=False, show_points=False)

minval = min(scalars) - 0.01
maxval = max(scalars) + 0.01
Expand All @@ -49,10 +53,10 @@
points.append(vertices[j])
polylines.append(Polyline(points))

viewer.add(
Collection(polylines),
linecolor=cmap(value, minval=minval, maxval=maxval),
linewidth=3,
)
# viewer.scene.add(
# Collection(polylines),
# linecolor=cmap(value, minval=minval, maxval=maxval),
# linewidth=3,
# )

viewer.show()
16 changes: 8 additions & 8 deletions docs/examples/massmatrix.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import compas
import compas_libigl as igl
from compas.datastructures import Mesh
from compas.colors import ColorMap
from compas_view2.app import App
from compas.datastructures import Mesh
from compas_viewer import Viewer

# ==============================================================================
# Input geometry
Expand All @@ -28,14 +28,14 @@
minval = min(mass)
maxval = max(mass)

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

viewer.add(mesh)
viewer.scene.add(mesh, show_points=False)

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

viewer.run()
viewer.show()
13 changes: 7 additions & 6 deletions docs/examples/parametrisation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import compas_libigl as igl
from compas.datastructures import Mesh
from compas.geometry import Scale, Translation
from compas_view2.app import App
from compas.geometry import Scale
from compas.geometry import Translation
from compas_viewer import Viewer

# ==============================================================================
# Input geometry
Expand Down Expand Up @@ -31,7 +32,7 @@

mesh.transform(X)

viewer = App()
viewer.add(mesh)
viewer.add(mesh_lscm)
viewer.run()
viewer = Viewer()
viewer.scene.add(mesh, show_points=False)
viewer.scene.add(mesh_lscm, show_points=False)
viewer.show()
21 changes: 10 additions & 11 deletions docs/examples/planarize.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import compas
import compas_libigl as igl
from compas.colors import Color
from compas.colors import ColorMap
from compas.datastructures import Mesh
from compas.datastructures import mesh_flatness
from compas.colors import Color, ColorMap
from compas_view2.app import App
from compas_viewer import Viewer

# ==============================================================================
# Input
Expand Down Expand Up @@ -31,15 +32,13 @@

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

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

viewer.add(
viewer.scene.add(
mesh,
facecolor={
face: (cmap(dev[face]) if dev[face] <= 1.0 else Color.red())
for face in mesh.faces()
},
facecolor={face: (cmap(dev[face]) if dev[face] <= 1.0 else Color.red()) for face in mesh.faces()},
show_points=False,
)
viewer.run()
viewer.show()

0 comments on commit d1136ec

Please sign in to comment.