Skip to content

Commit

Permalink
update for review
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacZhangzhuo committed Mar 17, 2024
1 parent f27e9b1 commit 55c75ee
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 258 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
* Changed and update the `compas_view2` examples into `compas_viewer`.

### Removed

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

### Changed

* Changed `compas.datastructures.TreeNode` to skip serialising `attributes`, `name` and `children` if being empty.
* Changed `compas.datastructures.TreeNode.__repr__` to omit `name` if `None`.
* Fix bug in `compas_rhino.geometry.NurbsCurve.from_parameters` and `compas_rhino.geometry.NurbsCurve.from_points` related to the value of the parameter `degree`.
Expand Down
23 changes: 12 additions & 11 deletions docs/userguide/_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
from compas.datastructures import Mesh
from compas.colors import Color
from compas.geometry import Circle, Polygon, Line, Point, Vector
from compas_view2.objects import Text, Collection
from compas_viewer.scene import Tag


def viewer_add_vertex(viewer, mesh, vertex, facecolor=None, linecolor=None, size=None):
def viewer_add_vertex(viewer, mesh, vertex, facecolor=None, edgecolor=None, size=None):
facecolor = facecolor or Color.white()
linecolor = linecolor or Color.black()
edgecolor = edgecolor or Color.black()
size = size or 0.1
point: Point = mesh.vertex_point(vertex) + [0, 0, 0.5]
viewer.add(
Circle.from_point_and_radius(point, size).to_polygon(100),
viewer.scene.add(
Circle.from_point_and_radius(point, size),
facecolor=facecolor,
linecolor=linecolor,
edgecolor=edgecolor,
linewidth=2,
n =100,
)


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


def viewer_add_edge(viewer, mesh, edge, color=None, width=None):
color = color or Color.black()
width = width or 10
viewer.add(
viewer.scene.add(
mesh.edge_line(edge).translated([0, 0, 0.1]),
linecolor=color,
linewidth=width,
Expand Down Expand Up @@ -57,9 +58,9 @@ def viewer_add_halfvector(viewer, mesh: Mesh, halfedge, color=None, basewidth=0.
arrowbase = Polygon([a, b, c, d])
arrowhead = Polygon([b, b + direction * basewidth * arrowsize, b + normal * basewidth * arrowsize])

viewer.add(
Collection([arrowbase.translated([0, 0, 0.6]), arrowhead.translated([0, 0, 0.6])]),
facecolor=color,
viewer.scene.add(
[arrowbase.translated([0, 0, 0.6]), arrowhead.translated([0, 0, 0.6])],
surfacecolor=color,
linecolor=color,
show_lines=False,
)
9 changes: 4 additions & 5 deletions docs/userguide/basics.colors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ However, using the following template we can compare various examples.
>>> from compas.utilities import linspace, pairwise
>>> from compas.datastructures import Mesh
>>> from compas.colors import Color, ColorMap
>>> from compas_view2.app import App
>>> from compas_viewer import Viewer

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

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

>>> viewer = App()
>>> viewer.view.show_grid = False
>>> viewer.add(mesh, facecolor=facecolors, show_lines=False)
>>> viewer = Viewer(show_grid = False)
>>> viewer.scene.add(mesh, facecolor=facecolor, show_lines=False)
>>> viewer.show()


Expand Down
121 changes: 8 additions & 113 deletions docs/userguide/basics.datastructures.meshes.py
Original file line number Diff line number Diff line change
@@ -1,125 +1,20 @@
# type: ignore

# import compas
from compas.datastructures import Mesh
from compas_view2.app import App
from compas.colors import Color
from compas.geometry import Circle
from compas_view2.objects import Text

# mesh = Mesh.from_obj(compas.get("tubemesh.obj"))

# viewer = App(width=1600, height=900)
# viewer.add(mesh)
# viewer.view.camera.position = [1, -6, 1.5]
# viewer.view.camera.look_at([1, 0, 1])
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# viewer.add(mesh)
# for vertex in range(30, 40):
# color = (1.0, 0.0, 0.0) if mesh.is_vertex_on_boundary(vertex) else (0.0, 0.0, 0.0)
# viewer.add(mesh.vertex_point(vertex), pointsize=20, pointcolor=color)

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# red = Color.red()

# viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
# viewer.add(
# Circle.from_point_and_radius(mesh.vertex_point(23) + [0, 0, 0.1], 0.1).to_polygon(100),
# facecolor=(1.0, 1.0, 1.0),
# linecolor=(0.0, 0.0, 0.0),
# linewidth=2,
# )

# for i, nbr in enumerate(mesh.vertex_neighbors(23, True)):
# print(nbr)
# viewer.add(
# Circle.from_point_and_radius(mesh.vertex_point(nbr) + [0, 0, 0.1], 0.2).to_polygon(100),
# facecolor=red.lightened(50),
# linecolor=red,
# )
# viewer.add(
# Text(
# str(i),
# mesh.vertex_point(nbr) + [0.09, -0.075, 0.1],
# height=50,
# )
# )

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()
from compas_viewer import Viewer

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# red = Color.red()

# viewer.add(
# Circle.from_point_and_radius(mesh.vertex_point(23) + [0, 0, 0.1], 0.1).to_polygon(100),
# facecolor=(1.0, 1.0, 1.0),
# linecolor=(0.0, 0.0, 0.0),
# linewidth=2,
# )

# facecolors = {face: (0.95, 0.95, 0.95) for face in mesh.faces()}
# for i, face in enumerate(mesh.vertex_faces(23)):
# print(face)
# viewer.add(
# Text(
# str(i),
# mesh.face_centroid(face) + [0.09, -0.075, 0.1],
# height=50,
# )
# )
# facecolors[face] = red.lightened(50)

# viewer.add(mesh, facecolor=facecolors, linewidth=2)

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# red = Color.red()

# viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
# viewer.add(mesh.edge_line((20, 30)).translated([0, 0, 0.1]), linecolor=red, linewidth=10)

# for edge in mesh.edge_strip((20, 30)):
# viewer.add(mesh.edge_line(edge).translated([0, 0, 0.1]), linewidth=10)

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()
from compas.colors import Color
from compas.datastructures import Mesh

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

viewer = App(viewport="top", width=1600, height=900)
viewer = Viewer(viewmode="top", width=1600, height=900)

red = Color.red()

viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
viewer.add(mesh.edge_line((30, 31)).translated([0, 0, 0.1]), linecolor=red, linewidth=10)
viewer.scene.add(mesh, facecolor=(0.95, 0.95, 0.95), lineswidth=2)
viewer.scene.add(mesh.edge_line((30, 31)).translated([0, 0, 0.1]), linecolor=red, lineswidth=10)

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

viewer.view.camera.zoom_extents()
viewer.view.camera.distance = 11
viewer.run()
viewer.show()
2 changes: 1 addition & 1 deletion docs/userguide/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Framework
.. The framework consists of a collection of loosely coupled Python packages that can be used alone or in combination with other packages.
The framework consists of a core library (:mod:`compas`), core extensions (:mod:`compas_cgal`, :mod:`compas_libigl`, :mod:`compas_occ`, :mod:`compas_gmsh`),
a standalone viewer (:mod:`compas_view2`),
a standalone viewer (:mod:`compas_viewer`),
dedicated integrations for Rhino (:mod:`compas_rhino`), Grasshopper (:mod:`compas_ghpython`), and Blender (:mod:`compas_blender`),
and a growing number of packages for specific tasks in the AEC domain, such as:

Expand Down
39 changes: 20 additions & 19 deletions docs/userguide/samples/colors.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# type: ignore

from compas.geometry import Box, Circle, Frame
from compas.colors import Color, ColorMap
from compas_view2.app import App
from compas_viewer import Viewer

viewer = App()
viewer.view.show_grid = False
from compas.colors import Color
from compas.geometry import Circle
from compas.geometry import Frame

viewer.add(Circle(0.4, Frame([0, 0, 0])).to_polygon(n=100), facecolor=Color.red())
viewer.add(Circle(0.4, Frame([1, 0, 0])).to_polygon(n=100), facecolor=Color.orange())
viewer.add(Circle(0.4, Frame([2, 0, 0])).to_polygon(n=100), facecolor=Color.yellow())
viewer.add(Circle(0.4, Frame([3, 0, 0])).to_polygon(n=100), facecolor=Color.lime())
viewer.add(Circle(0.4, Frame([4, 0, 0])).to_polygon(n=100), facecolor=Color.green())
viewer.add(Circle(0.4, Frame([5, 0, 0])).to_polygon(n=100), facecolor=Color.mint())
viewer.add(Circle(0.4, Frame([6, 0, 0])).to_polygon(n=100), facecolor=Color.cyan())
viewer.add(Circle(0.4, Frame([7, 0, 0])).to_polygon(n=100), facecolor=Color.azure())
viewer.add(Circle(0.4, Frame([8, 0, 0])).to_polygon(n=100), facecolor=Color.blue())
viewer.add(Circle(0.4, Frame([9, 0, 0])).to_polygon(n=100), facecolor=Color.violet())
viewer.add(Circle(0.4, Frame([10, 0, 0])).to_polygon(n=100), facecolor=Color.magenta())
viewer.add(Circle(0.4, Frame([11, 0, 0])).to_polygon(n=100), facecolor=Color.pink())
viewer.add(Circle(0.4, Frame([12, 0, 0])).to_polygon(n=100), facecolor=Color.red())
viewer = Viewer(show_grid=False)

viewer.run()
viewer.scene.add(Circle(0.4, Frame([0, 0, 0])), linecolor=Color.red(), n=100)
viewer.scene.add(Circle(0.4, Frame([1, 0, 0])), linecolor=Color.orange(), n=100)
viewer.scene.add(Circle(0.4, Frame([2, 0, 0])), linecolor=Color.yellow(), n=100)
viewer.scene.add(Circle(0.4, Frame([3, 0, 0])), linecolor=Color.lime(), n=100)
viewer.scene.add(Circle(0.4, Frame([4, 0, 0])), linecolor=Color.green(), n=100)
viewer.scene.add(Circle(0.4, Frame([5, 0, 0])), linecolor=Color.mint(), n=100)
viewer.scene.add(Circle(0.4, Frame([6, 0, 0])), linecolor=Color.cyan(), n=100)
viewer.scene.add(Circle(0.4, Frame([7, 0, 0])), linecolor=Color.azure(), n=100)
viewer.scene.add(Circle(0.4, Frame([8, 0, 0])), linecolor=Color.blue(), n=100)
viewer.scene.add(Circle(0.4, Frame([9, 0, 0])), linecolor=Color.violet(), n=100)
viewer.scene.add(Circle(0.4, Frame([10, 0, 0])), linecolor=Color.magenta(), n=100)
viewer.scene.add(Circle(0.4, Frame([11, 0, 0])), linecolor=Color.pink(), n=100)
viewer.scene.add(Circle(0.4, Frame([12, 0, 0])), linecolor=Color.red(), n=100)

viewer.show()
17 changes: 9 additions & 8 deletions docs/userguide/samples/colors_lightness.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# type: ignore

from compas.geometry import Box, Circle, Frame
from compas.colors import Color, ColorMap
from compas_view2.app import App
from compas_viewer import Viewer

viewer = App()
viewer.view.show_grid = False
from compas.colors import Color
from compas.geometry import Circle
from compas.geometry import Frame

viewer = Viewer(show_grid=False)

colors = [
Color.red(),
Expand All @@ -24,10 +25,10 @@

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

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

viewer.run()
viewer.show()
18 changes: 11 additions & 7 deletions docs/userguide/samples/colors_maps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# type: ignore

from compas.geometry import Pointcloud, Circle, Frame, Polygon
from compas_viewer import Viewer

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 Circle
from compas.geometry import Frame
from compas.geometry import Pointcloud
from compas.geometry import Polygon

viewer = App()
viewer.view.show_grid = False
viewer = Viewer(show_grid=False)

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

viewer.add(Mesh.from_polygons(polygons), facecolor=facecolors, show_lines=False)
viewer.scene.add(Mesh.from_polygons(polygons), facecolor=facecolors, show_lines=False, show_points=False)

viewer.run()
viewer.show()
24 changes: 14 additions & 10 deletions docs/userguide/samples/colors_maps_from-one-color.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# type: ignore

from compas.geometry import Point, Polygon, Translation
from compas.utilities import linspace, pairwise
from compas_viewer import Viewer

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.geometry import Polygon
from compas.geometry import Translation
from compas.utilities import linspace
from compas.utilities import pairwise

n = 1000
t = 0.3
Expand All @@ -22,24 +27,23 @@

mesh = Mesh.from_polygons(polygons)

viewer = App()
viewer.view.show_grid = False
viewer = Viewer(show_grid=False)

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

viewer.add(mesh, facecolor=facecolors, show_lines=False)
viewer.scene.add(mesh, facecolor=facecolor, show_lines=False, show_points=False)

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

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

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

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

viewer.show()
Loading

0 comments on commit 55c75ee

Please sign in to comment.