Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
romanarust committed May 26, 2024
1 parent 1109a0d commit 37f08c0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/userguide/basics.datastructures.cellnetworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
77 changes: 50 additions & 27 deletions src/compas/datastructures/cell_network/cell_network.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 37f08c0

Please sign in to comment.