Skip to content

Commit 55c75ee

Browse files
committed
update for review
1 parent f27e9b1 commit 55c75ee

22 files changed

+180
-258
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
### Changed
13+
* Changed and update the `compas_view2` examples into `compas_viewer`.
1314

1415
### Removed
1516

@@ -24,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2425
* Added `compas.datastructures.Tree.to_graph()`.
2526

2627
### Changed
27-
2828
* Changed `compas.datastructures.TreeNode` to skip serialising `attributes`, `name` and `children` if being empty.
2929
* Changed `compas.datastructures.TreeNode.__repr__` to omit `name` if `None`.
3030
* Fix bug in `compas_rhino.geometry.NurbsCurve.from_parameters` and `compas_rhino.geometry.NurbsCurve.from_points` related to the value of the parameter `degree`.

docs/userguide/_plotter.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@
44
from compas.datastructures import Mesh
55
from compas.colors import Color
66
from compas.geometry import Circle, Polygon, Line, Point, Vector
7-
from compas_view2.objects import Text, Collection
7+
from compas_viewer.scene import Tag
88

99

10-
def viewer_add_vertex(viewer, mesh, vertex, facecolor=None, linecolor=None, size=None):
10+
def viewer_add_vertex(viewer, mesh, vertex, facecolor=None, edgecolor=None, size=None):
1111
facecolor = facecolor or Color.white()
12-
linecolor = linecolor or Color.black()
12+
edgecolor = edgecolor or Color.black()
1313
size = size or 0.1
1414
point: Point = mesh.vertex_point(vertex) + [0, 0, 0.5]
15-
viewer.add(
16-
Circle.from_point_and_radius(point, size).to_polygon(100),
15+
viewer.scene.add(
16+
Circle.from_point_and_radius(point, size),
1717
facecolor=facecolor,
18-
linecolor=linecolor,
18+
edgecolor=edgecolor,
1919
linewidth=2,
20+
n =100,
2021
)
2122

2223

2324
def viewer_add_vertex_label(viewer, mesh, vertex, text, height=None):
2425
height = height or 50
2526
point: Point = mesh.vertex_point(vertex) + [0.09, -0.075, 0.6]
26-
viewer.add(Text(text, point, height=height))
27+
viewer.scene.add(Tag(text, point, height=height, absolute_height=True))
2728

2829

2930
def viewer_add_edge(viewer, mesh, edge, color=None, width=None):
3031
color = color or Color.black()
3132
width = width or 10
32-
viewer.add(
33+
viewer.scene.add(
3334
mesh.edge_line(edge).translated([0, 0, 0.1]),
3435
linecolor=color,
3536
linewidth=width,
@@ -57,9 +58,9 @@ def viewer_add_halfvector(viewer, mesh: Mesh, halfedge, color=None, basewidth=0.
5758
arrowbase = Polygon([a, b, c, d])
5859
arrowhead = Polygon([b, b + direction * basewidth * arrowsize, b + normal * basewidth * arrowsize])
5960

60-
viewer.add(
61-
Collection([arrowbase.translated([0, 0, 0.6]), arrowhead.translated([0, 0, 0.6])]),
62-
facecolor=color,
61+
viewer.scene.add(
62+
[arrowbase.translated([0, 0, 0.6]), arrowhead.translated([0, 0, 0.6])],
63+
surfacecolor=color,
6364
linecolor=color,
6465
show_lines=False,
6566
)

docs/userguide/basics.colors.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ However, using the following template we can compare various examples.
132132
>>> from compas.utilities import linspace, pairwise
133133
>>> from compas.datastructures import Mesh
134134
>>> from compas.colors import Color, ColorMap
135-
>>> from compas_view2.app import App
135+
>>> from compas_viewer import Viewer
136136

137137
>>> n = 1000
138138
>>> t = 0.3
@@ -151,11 +151,10 @@ However, using the following template we can compare various examples.
151151
>>> mesh = Mesh.from_polygons(polygons)
152152

153153
>>> cmap = ... # define color map here
154-
>>> facecolors = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)}
154+
>>> facecolor = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)}
155155

156-
>>> viewer = App()
157-
>>> viewer.view.show_grid = False
158-
>>> viewer.add(mesh, facecolor=facecolors, show_lines=False)
156+
>>> viewer = Viewer(show_grid = False)
157+
>>> viewer.scene.add(mesh, facecolor=facecolor, show_lines=False)
159158
>>> viewer.show()
160159

161160

Lines changed: 8 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,20 @@
11
# type: ignore
22

3-
# import compas
4-
from compas.datastructures import Mesh
5-
from compas_view2.app import App
6-
from compas.colors import Color
7-
from compas.geometry import Circle
8-
from compas_view2.objects import Text
9-
10-
# mesh = Mesh.from_obj(compas.get("tubemesh.obj"))
11-
12-
# viewer = App(width=1600, height=900)
13-
# viewer.add(mesh)
14-
# viewer.view.camera.position = [1, -6, 1.5]
15-
# viewer.view.camera.look_at([1, 0, 1])
16-
# viewer.run()
17-
18-
# mesh = Mesh.from_meshgrid(dx=9, nx=9)
19-
20-
# viewer = App(viewport="top", width=1600, height=900)
21-
22-
# viewer.add(mesh)
23-
# for vertex in range(30, 40):
24-
# color = (1.0, 0.0, 0.0) if mesh.is_vertex_on_boundary(vertex) else (0.0, 0.0, 0.0)
25-
# viewer.add(mesh.vertex_point(vertex), pointsize=20, pointcolor=color)
26-
27-
# viewer.view.camera.zoom_extents()
28-
# viewer.view.camera.distance = 11
29-
# viewer.run()
30-
31-
# mesh = Mesh.from_meshgrid(dx=9, nx=9)
32-
33-
# viewer = App(viewport="top", width=1600, height=900)
34-
35-
# red = Color.red()
36-
37-
# viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
38-
# viewer.add(
39-
# Circle.from_point_and_radius(mesh.vertex_point(23) + [0, 0, 0.1], 0.1).to_polygon(100),
40-
# facecolor=(1.0, 1.0, 1.0),
41-
# linecolor=(0.0, 0.0, 0.0),
42-
# linewidth=2,
43-
# )
44-
45-
# for i, nbr in enumerate(mesh.vertex_neighbors(23, True)):
46-
# print(nbr)
47-
# viewer.add(
48-
# Circle.from_point_and_radius(mesh.vertex_point(nbr) + [0, 0, 0.1], 0.2).to_polygon(100),
49-
# facecolor=red.lightened(50),
50-
# linecolor=red,
51-
# )
52-
# viewer.add(
53-
# Text(
54-
# str(i),
55-
# mesh.vertex_point(nbr) + [0.09, -0.075, 0.1],
56-
# height=50,
57-
# )
58-
# )
59-
60-
# viewer.view.camera.zoom_extents()
61-
# viewer.view.camera.distance = 11
62-
# viewer.run()
3+
from compas_viewer import Viewer
634

64-
# mesh = Mesh.from_meshgrid(dx=9, nx=9)
65-
66-
# viewer = App(viewport="top", width=1600, height=900)
67-
68-
# red = Color.red()
69-
70-
# viewer.add(
71-
# Circle.from_point_and_radius(mesh.vertex_point(23) + [0, 0, 0.1], 0.1).to_polygon(100),
72-
# facecolor=(1.0, 1.0, 1.0),
73-
# linecolor=(0.0, 0.0, 0.0),
74-
# linewidth=2,
75-
# )
76-
77-
# facecolors = {face: (0.95, 0.95, 0.95) for face in mesh.faces()}
78-
# for i, face in enumerate(mesh.vertex_faces(23)):
79-
# print(face)
80-
# viewer.add(
81-
# Text(
82-
# str(i),
83-
# mesh.face_centroid(face) + [0.09, -0.075, 0.1],
84-
# height=50,
85-
# )
86-
# )
87-
# facecolors[face] = red.lightened(50)
88-
89-
# viewer.add(mesh, facecolor=facecolors, linewidth=2)
90-
91-
# viewer.view.camera.zoom_extents()
92-
# viewer.view.camera.distance = 11
93-
# viewer.run()
94-
95-
# mesh = Mesh.from_meshgrid(dx=9, nx=9)
96-
97-
# viewer = App(viewport="top", width=1600, height=900)
98-
99-
# red = Color.red()
100-
101-
# viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
102-
# viewer.add(mesh.edge_line((20, 30)).translated([0, 0, 0.1]), linecolor=red, linewidth=10)
103-
104-
# for edge in mesh.edge_strip((20, 30)):
105-
# viewer.add(mesh.edge_line(edge).translated([0, 0, 0.1]), linewidth=10)
106-
107-
# viewer.view.camera.zoom_extents()
108-
# viewer.view.camera.distance = 11
109-
# viewer.run()
5+
from compas.colors import Color
6+
from compas.datastructures import Mesh
1107

1118
mesh = Mesh.from_meshgrid(dx=9, nx=9)
1129

113-
viewer = App(viewport="top", width=1600, height=900)
10+
viewer = Viewer(viewmode="top", width=1600, height=900)
11411

11512
red = Color.red()
11613

117-
viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
118-
viewer.add(mesh.edge_line((30, 31)).translated([0, 0, 0.1]), linecolor=red, linewidth=10)
14+
viewer.scene.add(mesh, facecolor=(0.95, 0.95, 0.95), lineswidth=2)
15+
viewer.scene.add(mesh.edge_line((30, 31)).translated([0, 0, 0.1]), linecolor=red, lineswidth=10)
11916

12017
for edge in mesh.edge_loop((30, 31)):
121-
viewer.add(mesh.edge_line(edge).translated([0, 0, 0.1]), linewidth=10)
18+
viewer.scene.add(mesh.edge_line(edge).translated([0, 0, 0.1]), lineswidth=10)
12219

123-
viewer.view.camera.zoom_extents()
124-
viewer.view.camera.distance = 11
125-
viewer.run()
20+
viewer.show()

docs/userguide/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The Framework
1717
.. The framework consists of a collection of loosely coupled Python packages that can be used alone or in combination with other packages.
1818
1919
The framework consists of a core library (:mod:`compas`), core extensions (:mod:`compas_cgal`, :mod:`compas_libigl`, :mod:`compas_occ`, :mod:`compas_gmsh`),
20-
a standalone viewer (:mod:`compas_view2`),
20+
a standalone viewer (:mod:`compas_viewer`),
2121
dedicated integrations for Rhino (:mod:`compas_rhino`), Grasshopper (:mod:`compas_ghpython`), and Blender (:mod:`compas_blender`),
2222
and a growing number of packages for specific tasks in the AEC domain, such as:
2323

docs/userguide/samples/colors.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# type: ignore
22

3-
from compas.geometry import Box, Circle, Frame
4-
from compas.colors import Color, ColorMap
5-
from compas_view2.app import App
3+
from compas_viewer import Viewer
64

7-
viewer = App()
8-
viewer.view.show_grid = False
5+
from compas.colors import Color
6+
from compas.geometry import Circle
7+
from compas.geometry import Frame
98

10-
viewer.add(Circle(0.4, Frame([0, 0, 0])).to_polygon(n=100), facecolor=Color.red())
11-
viewer.add(Circle(0.4, Frame([1, 0, 0])).to_polygon(n=100), facecolor=Color.orange())
12-
viewer.add(Circle(0.4, Frame([2, 0, 0])).to_polygon(n=100), facecolor=Color.yellow())
13-
viewer.add(Circle(0.4, Frame([3, 0, 0])).to_polygon(n=100), facecolor=Color.lime())
14-
viewer.add(Circle(0.4, Frame([4, 0, 0])).to_polygon(n=100), facecolor=Color.green())
15-
viewer.add(Circle(0.4, Frame([5, 0, 0])).to_polygon(n=100), facecolor=Color.mint())
16-
viewer.add(Circle(0.4, Frame([6, 0, 0])).to_polygon(n=100), facecolor=Color.cyan())
17-
viewer.add(Circle(0.4, Frame([7, 0, 0])).to_polygon(n=100), facecolor=Color.azure())
18-
viewer.add(Circle(0.4, Frame([8, 0, 0])).to_polygon(n=100), facecolor=Color.blue())
19-
viewer.add(Circle(0.4, Frame([9, 0, 0])).to_polygon(n=100), facecolor=Color.violet())
20-
viewer.add(Circle(0.4, Frame([10, 0, 0])).to_polygon(n=100), facecolor=Color.magenta())
21-
viewer.add(Circle(0.4, Frame([11, 0, 0])).to_polygon(n=100), facecolor=Color.pink())
22-
viewer.add(Circle(0.4, Frame([12, 0, 0])).to_polygon(n=100), facecolor=Color.red())
9+
viewer = Viewer(show_grid=False)
2310

24-
viewer.run()
11+
viewer.scene.add(Circle(0.4, Frame([0, 0, 0])), linecolor=Color.red(), n=100)
12+
viewer.scene.add(Circle(0.4, Frame([1, 0, 0])), linecolor=Color.orange(), n=100)
13+
viewer.scene.add(Circle(0.4, Frame([2, 0, 0])), linecolor=Color.yellow(), n=100)
14+
viewer.scene.add(Circle(0.4, Frame([3, 0, 0])), linecolor=Color.lime(), n=100)
15+
viewer.scene.add(Circle(0.4, Frame([4, 0, 0])), linecolor=Color.green(), n=100)
16+
viewer.scene.add(Circle(0.4, Frame([5, 0, 0])), linecolor=Color.mint(), n=100)
17+
viewer.scene.add(Circle(0.4, Frame([6, 0, 0])), linecolor=Color.cyan(), n=100)
18+
viewer.scene.add(Circle(0.4, Frame([7, 0, 0])), linecolor=Color.azure(), n=100)
19+
viewer.scene.add(Circle(0.4, Frame([8, 0, 0])), linecolor=Color.blue(), n=100)
20+
viewer.scene.add(Circle(0.4, Frame([9, 0, 0])), linecolor=Color.violet(), n=100)
21+
viewer.scene.add(Circle(0.4, Frame([10, 0, 0])), linecolor=Color.magenta(), n=100)
22+
viewer.scene.add(Circle(0.4, Frame([11, 0, 0])), linecolor=Color.pink(), n=100)
23+
viewer.scene.add(Circle(0.4, Frame([12, 0, 0])), linecolor=Color.red(), n=100)
24+
25+
viewer.show()

docs/userguide/samples/colors_lightness.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# type: ignore
22

3-
from compas.geometry import Box, Circle, Frame
4-
from compas.colors import Color, ColorMap
5-
from compas_view2.app import App
3+
from compas_viewer import Viewer
64

7-
viewer = App()
8-
viewer.view.show_grid = False
5+
from compas.colors import Color
6+
from compas.geometry import Circle
7+
from compas.geometry import Frame
8+
9+
viewer = Viewer(show_grid=False)
910

1011
colors = [
1112
Color.red(),
@@ -24,10 +25,10 @@
2425

2526
for up in range(5):
2627
for right, color in enumerate(colors):
27-
viewer.add(Circle(0.4, Frame([right, up, 0])).to_polygon(n=100), facecolor=color.darkened(up * 25))
28+
viewer.scene.add(Circle(0.4, Frame([right, up, 0])), linecolor=color.darkened(up * 25), n=100)
2829

2930
for down in range(1, 5):
3031
for right, color in enumerate(colors):
31-
viewer.add(Circle(0.4, Frame([right, -down, 0])).to_polygon(n=100), facecolor=color.lightened(down * 25))
32+
viewer.scene.add(Circle(0.4, Frame([right, -down, 0])), linecolor=color.lightened(down * 25), n=100)
3233

33-
viewer.run()
34+
viewer.show()

docs/userguide/samples/colors_maps.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# type: ignore
22

3-
from compas.geometry import Pointcloud, Circle, Frame, Polygon
3+
from compas_viewer import Viewer
4+
5+
from compas.colors import Color
6+
from compas.colors import ColorMap
47
from compas.datastructures import Mesh
5-
from compas.colors import Color, ColorMap
6-
from compas_view2.app import App
8+
from compas.geometry import Circle
9+
from compas.geometry import Frame
10+
from compas.geometry import Pointcloud
11+
from compas.geometry import Polygon
712

8-
viewer = App()
9-
viewer.view.show_grid = False
13+
viewer = Viewer(show_grid=False)
1014

1115
cmap = ColorMap.from_mpl("viridis")
1216
w = 16
@@ -31,6 +35,6 @@
3135
facecolors[i] = color
3236
# viewer.add(c.to_polygon(100), facecolor=color)
3337

34-
viewer.add(Mesh.from_polygons(polygons), facecolor=facecolors, show_lines=False)
38+
viewer.scene.add(Mesh.from_polygons(polygons), facecolor=facecolors, show_lines=False, show_points=False)
3539

36-
viewer.run()
40+
viewer.show()
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# type: ignore
22

3-
from compas.geometry import Point, Polygon, Translation
4-
from compas.utilities import linspace, pairwise
3+
from compas_viewer import Viewer
4+
5+
from compas.colors import Color
6+
from compas.colors import ColorMap
57
from compas.datastructures import Mesh
6-
from compas.colors import Color, ColorMap
7-
from compas_view2.app import App
8+
from compas.geometry import Point
9+
from compas.geometry import Polygon
10+
from compas.geometry import Translation
11+
from compas.utilities import linspace
12+
from compas.utilities import pairwise
813

914
n = 1000
1015
t = 0.3
@@ -22,24 +27,23 @@
2227

2328
mesh = Mesh.from_polygons(polygons)
2429

25-
viewer = App()
26-
viewer.view.show_grid = False
30+
viewer = Viewer(show_grid=False)
2731

2832
cmap = ColorMap.from_color(Color.red())
29-
facecolors = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)}
33+
facecolor = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)}
3034

31-
viewer.add(mesh, facecolor=facecolors, show_lines=False)
35+
viewer.scene.add(mesh, facecolor=facecolor, show_lines=False, show_points=False)
3236

3337
cmap = ColorMap.from_color(Color.red(), rangetype="light")
3438
facecolors = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)}
3539

3640
translation = Translation.from_vector([0, -3 * t, 0])
37-
viewer.add(mesh.transformed(translation), facecolor=facecolors, show_lines=False)
41+
viewer.scene.add(mesh.transformed(translation), facecolor=facecolors, show_lines=False, show_points=False)
3842

3943
cmap = ColorMap.from_color(Color.red(), rangetype="dark")
4044
facecolors = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)}
4145

4246
translation = Translation.from_vector([0, -6 * t, 0])
43-
viewer.add(mesh.transformed(translation), facecolor=facecolors, show_lines=False)
47+
viewer.scene.add(mesh.transformed(translation), facecolor=facecolors, show_lines=False, show_points=False)
4448

4549
viewer.show()

0 commit comments

Comments
 (0)