Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scene Object implementation consistency and Scene serialisation #1367

Merged
merged 29 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2310d59
make colordict serialisable
tomvanmele Jun 1, 2024
19efd1f
remove deprecated
tomvanmele Jun 1, 2024
17d49cd
minor stuff
tomvanmele Jun 1, 2024
877eb85
type
tomvanmele Jun 1, 2024
48167e1
comment about faces and surfaces
tomvanmele Jun 1, 2024
702c31d
move stuff to class attributes
tomvanmele Jun 1, 2024
7a57aa7
make drawing of subsets available
tomvanmele Jun 1, 2024
e35a64c
use class attributes
tomvanmele Jun 1, 2024
373a930
clean up data structure bases
tomvanmele Jun 1, 2024
4a138a5
remove implementation of clear scene for gh because its conflicts wit…
tomvanmele Jun 1, 2024
c5b8b73
remove default black because it is problematic for GH
tomvanmele Jun 5, 2024
182d979
add color info to settings
tomvanmele Jun 5, 2024
72fb0e1
add all info to settings
tomvanmele Jun 5, 2024
632f2e5
add all options as attributes
tomvanmele Jun 5, 2024
e6ae78d
move + deprecation
tomvanmele Jun 5, 2024
3bcb4b1
use shape object as base
tomvanmele Jun 5, 2024
1a6c8bc
move and deprecation
tomvanmele Jun 5, 2024
dfc4ce6
hints
tomvanmele Jun 5, 2024
b286327
fix graph mesh volmesh blender
tomvanmele Jun 5, 2024
6b6fc6a
fix graph mesh volmesh gh
tomvanmele Jun 5, 2024
b027ad8
fix graph mesh volmesh rhino
tomvanmele Jun 5, 2024
3bb0c5a
log
tomvanmele Jun 5, 2024
6ec69d7
remove unused
tomvanmele Jun 5, 2024
895e8af
remove abstract decorator
tomvanmele Jun 5, 2024
dd02218
remove unnecessary overwrites
tomvanmele Jun 5, 2024
59c8a55
remove unused
tomvanmele Jun 5, 2024
58e2a0f
ipy can't deal with trailing commas in function signatures
tomvanmele Jun 5, 2024
781f5a8
log
tomvanmele Jun 5, 2024
d4ad97e
Merge branch 'main' into fix-scene-consistency-and-serialisation
tomvanmele Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added implementation of `compute_vertices`, `compute_edges`, `compute_faces` to `compas.geometry.Cylinder`.
* Added implementation of `compute_vertices`, `compute_edges`, `compute_faces` to `compas.geometry.Sphere`.
* Added implementation of `compute_vertices`, `compute_edges`, `compute_faces` to `compas.geometry.Torus`.
* Added `compas_blender.scene.ShapeObject`.

### Changed

Expand All @@ -28,10 +29,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed check for empty vertices and faces to use `is None` to add support for `numpy` arrays.
* Changed order of `u` and `v` of `compas.geometry.SphericalSurface` to the match the excpected parametrisation.
* Changed `compas.geometry.Shape.to_vertices_and_faces` to use `Shape.vertices` and `Shape.faces` or `Shape.triangles`.
* Changed default of `compas.scene.descriptors.color.ColorAttribute` to `None` to support native coloring in CAD contexts.
* Changed `compas.colors.ColorDict.__data__` and `compas.colors.ColorDict.__from_data__` to properly support serialisation.
* Moved `compas_blender.utilities.drawing` to `compas_blender.drawing` with backward compatible imports and deprecation warning.
* Moved `compas_ghpython.utilities.drawing` to `compas_ghpython.drawing` with backward compatible imports and deprecation warning.
* Moved `compas_rhino.utilities.drawing` to `compas_rhino.drawing` with backward compatible imports and deprecation warning.
* Changed `draw_nodes` and `draw_edges` of `compas_blender.scene.GraphObject`, `compas_ghpython.scene.GraphObject`, and `compas_rhino.scene.GraphObject` to use only attributes instead of parameters.
* Changed `draw_vertices`, `draw_edges` and `draw_faces` of `compas_blender.scene.MeshObject`, `compas_ghpython.scene.MeshObject`, and `compas_rhino.scene.MeshObject` to use only attributes instead of parameters.
* Changed `draw_vertices`, `draw_edges` and `draw_faces` of `compas_blender.scene.VolMeshObject`, `compas_ghpython.scene.VolMeshObject`, and `compas_rhino.scene.VolMeshObject` to use only attributes instead of parameters.
* Changed registration of `Capsule`, `Cone`, `Cylinder`, `Sphere`, `Torus` to `ShapeObject` in `compas_blender.scene`.

### Removed

* Removed `System`dependency in `compas_ghpython/utilities/drawing.py`.
* Removed `System` dependency in `compas_ghpython/utilities/drawing.py`.
* Removed GH plugin for `compas.scene.clear` since it clashed with the Rhino version.

## [2.1.1] 2024-05-14

Expand Down
10 changes: 9 additions & 1 deletion src/compas/colors/colordict.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ class ColorDict(Data):

@property
def __data__(self):
return {"default": self.default.__data__, "dict": self._dict}
return {"default": self.default, "dict": self._dict}

@classmethod
def __from_data__(cls, data):
colordict = cls(data["default"])
# note: this is specific to color dicts for vertices of meshes
# perhaps the color dict needs to be subclassed per scene object type
colordict.update({int(key): value for key, value in data["dict"].items()})
return colordict

def __init__(self, default, name=None):
super(ColorDict, self).__init__(name=name)
Expand Down
3 changes: 0 additions & 3 deletions src/compas/scene/assemblyobject.py

This file was deleted.

1 change: 0 additions & 1 deletion src/compas/scene/descriptors/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ColorAttribute(object):

def __init__(self, default=None, **kwargs):
super(ColorAttribute, self).__init__(**kwargs)
default = default or Color.black()
self.default = Color.coerce(default)

def __set_name__(self, owner, name):
Expand Down
6 changes: 2 additions & 4 deletions src/compas/scene/geometryobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@ def __init__(self, geometry, **kwargs):
self.show_points = kwargs.get("show_points", False)
self.show_lines = kwargs.get("show_lines", True)
self.show_surfaces = kwargs.get("show_surfaces", True)

def draw(self):
"""Draw the geometry. Implemented by child classes."""
raise NotImplementedError
# note: either lines should be renamed to curves
# or surfaces should be renamed to faces?
84 changes: 44 additions & 40 deletions src/compas/scene/graphobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from __future__ import division
from __future__ import print_function

import compas.colors # noqa: F401
import compas.datastructures # noqa: F401
import compas.geometry # noqa: F401
from compas.geometry import transform_points

from .descriptors.colordict import ColorDictAttribute
Expand Down Expand Up @@ -31,7 +34,7 @@ class GraphObject(SceneObject):
The size of the nodes. Default is ``1.0``.
edgewidth : float
The width of the edges. Default is ``1.0``.
show_nodes : Union[bool, sequence[float]]
show_nodes : Union[bool, sequence[hashable]]
Flag for showing or hiding the nodes. Default is ``True``.
show_edges : Union[bool, sequence[tuple[hashable, hashable]]]
Flag for showing or hiding the edges. Default is ``True``.
Expand All @@ -46,64 +49,76 @@ class GraphObject(SceneObject):
nodecolor = ColorDictAttribute()
edgecolor = ColorDictAttribute()

def __init__(self, graph, **kwargs):
def __init__(self, graph, show_nodes=True, show_edges=True, nodecolor=None, edgecolor=None, nodesize=1.0, edgewidth=1.0, **kwargs):
# type: (compas.datastructures.Graph, bool | list, bool | list, compas.colors.Color | dict | None, compas.colors.Color | dict | None, float | dict, float | dict, dict) -> None
super(GraphObject, self).__init__(item=graph, **kwargs)
self._graph = None
self._node_xyz = None
self.graph = graph
self.nodecolor = kwargs.get("nodecolor", self.color)
self.edgecolor = kwargs.get("edgecolor", self.color)
self.nodesize = kwargs.get("nodesize", 1.0)
self.edgewidth = kwargs.get("edgewidth", 1.0)
self.show_nodes = kwargs.get("show_nodes", True)
self.show_edges = kwargs.get("show_edges", True)
self.show_nodes = show_nodes
self.show_edges = show_edges
self.nodecolor = nodecolor or self.color
self.edgecolor = edgecolor or self.color
self.nodesize = nodesize
self.edgewidth = edgewidth

@property
def settings(self):
# type: () -> dict
settings = super(GraphObject, self).settings
settings["show_nodes"] = self.show_nodes
settings["show_edges"] = self.show_edges
settings["nodecolor"] = self.nodecolor
settings["edgecolor"] = self.edgecolor
settings["nodesize"] = self.nodesize
settings["edgewidth"] = self.edgewidth
return settings

@property
def graph(self):
# type: () -> compas.datastructures.Graph
return self._graph

@graph.setter
def graph(self, graph):
# type: (compas.datastructures.Graph) -> None
self._graph = graph
self._transformation = None
self._node_xyz = None

@property
def transformation(self):
# type: () -> compas.geometry.Transformation | None
return self._transformation

@transformation.setter
def transformation(self, transformation):
# type: (compas.geometry.Transformation) -> None
self._node_xyz = None
self._transformation = transformation

@property
def node_xyz(self):
# type: () -> dict[int | str | tuple, list[float]]
if self._node_xyz is None:
points = self.graph.nodes_attributes("xyz") # type: ignore
points = self.graph.nodes_attributes("xyz")
points = transform_points(points, self.worldtransformation)
self._node_xyz = dict(zip(self.graph.nodes(), points)) # type: ignore
self._node_xyz = dict(zip(self.graph.nodes(), points))
return self._node_xyz

@node_xyz.setter
def node_xyz(self, node_xyz):
# type: (dict[int | str | tuple, list[float]]) -> None
self._node_xyz = node_xyz

def draw_nodes(self, nodes=None, color=None, text=None):
def draw_nodes(self):
"""Draw the nodes of the graph.

Parameters
----------
nodes : list[int], optional
The nodes to include in the drawing.
Default is all nodes.
color : tuple[float, float, float] | :class:`compas.colors.Color` | dict[int, tuple[float, float, float] | :class:`compas.colors.Color`], optional
The color of the nodes,
as either a single color to be applied to all nodes,
or a color dict, mapping specific nodes to specific colors.
text : dict[int, str], optional
The text labels for the nodes
as a text dict, mapping specific nodes to specific text labels.
Nodes are drawn based on the values of

* `self.show_nodes`
* `self.nodecolor`
* `self.nodesize`

Returns
-------
Expand All @@ -113,21 +128,14 @@ def draw_nodes(self, nodes=None, color=None, text=None):
"""
raise NotImplementedError

def draw_edges(self, edges=None, color=None, text=None):
def draw_edges(self):
"""Draw the edges of the graph.

Parameters
----------
edges : list[tuple[int, int]], optional
The edges to include in the drawing.
Default is all edges.
color : tuple[float, float, float] | :class:`compas.colors.Color` | dict[tuple[int, int], tuple[float, float, float] | :class:`compas.colors.Color`], optional
The color of the edges,
as either a single color to be applied to all edges,
or a color dict, mapping specific edges to specific colors.
text : dict[tuple[int, int]], optional
The text labels for the edges
as a text dict, mapping specific edges to specific text labels.
Edges are drawn based on the values of

* `self.show_edges`
* `self.edgecolor`
* `self.edgewidth`

Returns
-------
Expand All @@ -137,10 +145,6 @@ def draw_edges(self, edges=None, color=None, text=None):
"""
raise NotImplementedError

def draw(self):
"""Draw the network."""
raise NotImplementedError

def clear_nodes(self):
"""Clear the nodes of the graph.

Expand Down
Loading
Loading