From 37f08c0e1e509a213c3474db10ab8cda552e9153 Mon Sep 17 00:00:00 2001 From: Romana Rust Date: Sun, 26 May 2024 19:03:57 +0200 Subject: [PATCH] updates --- CHANGELOG.md | 8 ++ .../basics.datastructures.cellnetworks.py | 5 ++ .../cell_network/cell_network.py | 77 ++++++++++++------- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd4235fe8c..f66c6a80dc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `compas.geometry.Brep.from_plane`. * Added `compas.tolerance.Tolerance.angulardeflection`. * Added `compas.scene.SceneObject.scene` attribute. +* Added `compas.datastructures.CellNetwork.do_faces_form_a_closed_cell` +* Added `compas.datastructures.CellNetwork.delete_edge` +* Added `compas.datastructures.CellNetwork.delete_cell` +* Added `compas.datastructures.CellNetwork.delete_face` +* Added `compas.datastructures.CellNetwork.cells_to_graph` +* Added `compas.datastructures.CellNetwork.face_plane` +* Added `compas.datastructures.CellNetwork.cell_volume` +* Added `compas.datastructures.CellNetwork.cell_neighbors` ### Changed diff --git a/docs/userguide/basics.datastructures.cellnetworks.py b/docs/userguide/basics.datastructures.cellnetworks.py index a4729ae41b2..97ae63272a4 100644 --- a/docs/userguide/basics.datastructures.cellnetworks.py +++ b/docs/userguide/basics.datastructures.cellnetworks.py @@ -9,6 +9,7 @@ cell_network = CellNetwork.from_json(compas.get("cellnetwork_example.json")) + viewer = Viewer(show_grid=False) no_cell = cell_network.faces_without_cell() for face in cell_network.faces(): @@ -22,4 +23,8 @@ for edge in cell_network.edges_without_face(): line = Line(*cell_network.edge_coordinates(edge)) viewer.scene.add(line, linewidth=3) + +graph = cell_network.cells_to_graph() +viewer.scene.add(graph) + viewer.show() \ No newline at end of file diff --git a/src/compas/datastructures/cell_network/cell_network.py b/src/compas/datastructures/cell_network/cell_network.py index 8aa1d6a957a..ef03d218fe7 100644 --- a/src/compas/datastructures/cell_network/cell_network.py +++ b/src/compas/datastructures/cell_network/cell_network.py @@ -1,15 +1,39 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function from ast import literal_eval from random import sample -from compas.datastructures import Graph, Mesh -from compas.datastructures.attributes import CellAttributeView, EdgeAttributeView, FaceAttributeView, VertexAttributeView +from compas.datastructures import Graph +from compas.datastructures import Mesh +from compas.datastructures.attributes import CellAttributeView +from compas.datastructures.attributes import EdgeAttributeView +from compas.datastructures.attributes import FaceAttributeView +from compas.datastructures.attributes import VertexAttributeView from compas.datastructures.datastructure import Datastructure from compas.files import OBJ -from compas.geometry import (Line, Plane, Point, Polygon, Polyhedron, Vector, add_vectors, bestfit_plane, bounding_box, centroid_points, centroid_polygon, centroid_polyhedron, - distance_point_point, length_vector, normal_polygon, normalize_vector, project_point_plane, scale_vector, subtract_vectors, volume_polyhedron) +from compas.geometry import Line +from compas.geometry import Plane +from compas.geometry import Point +from compas.geometry import Polygon +from compas.geometry import Polyhedron +from compas.geometry import Vector +from compas.geometry import add_vectors +from compas.geometry import bestfit_plane +from compas.geometry import bounding_box +from compas.geometry import centroid_points +from compas.geometry import centroid_polygon +from compas.geometry import centroid_polyhedron +from compas.geometry import distance_point_point +from compas.geometry import length_vector +from compas.geometry import normal_polygon +from compas.geometry import normalize_vector +from compas.geometry import project_point_plane +from compas.geometry import scale_vector +from compas.geometry import subtract_vectors +from compas.geometry import volume_polyhedron from compas.itertools import pairwise from compas.tolerance import TOL @@ -1058,7 +1082,7 @@ def cells_to_graph(self): graph.add_node(key=cell, x=x, y=y, z=z, attr_dict=attr) for cell in self.cells(): for nbr in self.cell_neighbors(cell): - graph.add_edge(sorted(*[cell, nbr])) + graph.add_edge(*sorted([cell, nbr])) return graph def cell_to_vertices_and_faces(self, cell): @@ -3998,30 +4022,29 @@ def cell_face_neighbors(self, cell, face): nbrs.append(nbr) return nbrs - # def cell_neighbors(self, cell): - # """Find the neighbors of a given cell. + def cell_neighbors(self, cell): + """Find the neighbors of a given cell. - # Parameters - # ---------- - # cell : int - # The identifier of the cell. - - # Returns - # ------- - # list[int] - # The identifiers of the adjacent cells. + Parameters + ---------- + cell : int + The identifier of the cell. - # See Also - # -------- - # :meth:`cell_face_neighbors` + Returns + ------- + list[int] + The identifiers of the adjacent cells. - # """ - # nbrs = [] - # for face in self.cell_faces(cell): - # nbr = self.halfface_opposite_cell(face) - # if nbr is not None: - # nbrs.append(nbr) - # return nbrs + See Also + -------- + :meth:`cell_face_neighbors` + """ + nbrs = [] + for face in self.cell_faces(cell): + for nbr in self.face_cells(face): + if nbr != cell: + nbrs.append(nbr) + return list(set(nbrs)) def is_cell_on_boundary(self, cell): """Verify that a cell is on the boundary.