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

update unify cycles #1413

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Fixed `PluginNotInstalledError` when using `Brep.from_boolean_*` in Rhino.
* Expose the parameters `radius` and `nmax` from `compas.topology._face_adjacency` to `compas.topology.face_adjacency` and further propagate them to `unify_cycles` and `Mesh.unify_cycles`.
* Modify `face_adjacency` to avoid using `compas.topology._face_adjacency` by default when there are more than 100 faces, unless one of the parameters `radius`, `nmax` is passed
* Added support for `Polyline` as input for `compas_rhino.Brep.from_extrusion`.

### Removed
Expand Down
13 changes: 11 additions & 2 deletions src/compas/datastructures/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2932,9 +2932,18 @@ def quads_to_triangles(self, check_angles=False):
del self.facedata[face]

# only reason this is here and not on the halfedge is because of the spatial tree
def unify_cycles(self, root=None):
def unify_cycles(self, root=None, nmax=None, radius=None):
"""Unify the cycles of the mesh.

Parameters
----------
root : str, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type of root is int

The key of the root face.
nmax : int, optional
The maximum number of neighboring faces to consider. If neither nmax nor radius is specified, all faces will be considered.
radius : float, optional
The radius of the search sphere for neighboring faces. If neither nmax nor radius is specified, all faces will be considered.

Returns
-------
None
Expand All @@ -2951,7 +2960,7 @@ def unify_cycles(self, root=None):
vertices = self.vertices_attributes("xyz")
faces = [[vertex_index[vertex] for vertex in self.face_vertices(face)] for face in self.faces()]

unify_cycles(vertices, faces)
unify_cycles(vertices, faces, root=root, nmax=nmax, radius=radius)

self.halfedge = {key: {} for key in self.vertices()}
for index, vertices in enumerate(faces):
Expand Down
24 changes: 17 additions & 7 deletions src/compas/topology/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
return adjacency


def face_adjacency(points, faces):
def face_adjacency(points, faces, nmax=None, radius=None):
"""Build a face adjacency dict.

Parameters
Expand All @@ -103,6 +103,10 @@
The vertex locations of the faces.
faces : list[list[int]]
The faces defined as list of indices in the points list.
nmax : int, optional
The maximum number of neighboring faces to consider. If neither nmax nor radius is specified, all faces will be considered.
radius : float, optional
The radius of the search sphere for neighboring faces. If neither nmax nor radius is specified, all faces will be considered.

Returns
-------
Expand All @@ -117,10 +121,12 @@
purely geometrical, but uses a spatial indexing tree to speed up the search.

"""
f = len(faces)

if f > 100:
return _face_adjacency(points, faces)
if nmax is not None:
if radius is not None:
return _face_adjacency(points, faces, nmax=nmax, radius=radius)
return _face_adjacency(points, faces, nmax=nmax)

Check warning on line 127 in src/compas/topology/orientation.py

View check run for this annotation

Codecov / codecov/patch

src/compas/topology/orientation.py#L127

Added line #L127 was not covered by tests
if radius is not None:
return _face_adjacency(points, faces, radius=radius)

Check warning on line 129 in src/compas/topology/orientation.py

View check run for this annotation

Codecov / codecov/patch

src/compas/topology/orientation.py#L129

Added line #L129 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it would make sense to refactor _face_adjacency such that you can write here

if nmax or radius:
    return _face_adjacency(points, faces, nmax=nmax, radius=radius)


adjacency = {}

Expand Down Expand Up @@ -152,7 +158,7 @@
return adjacency


def unify_cycles(vertices, faces, root=None):
def unify_cycles(vertices, faces, root=None, nmax=None, radius=None):
"""Unify the cycle directions of all faces.

Unified cycle directions is a necessary condition for the data structure to
Expand All @@ -166,6 +172,10 @@
The faces of the mesh defined as lists of vertex indices.
root : str, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

The key of the root face.
nmax : int, optional
The maximum number of neighboring faces to consider. If neither nmax nor radius is specified, all faces will be considered.
radius : float, optional
The radius of the search sphere for neighboring faces. If neither nmax nor radius is specified, all faces will be considered.

Returns
-------
Expand Down Expand Up @@ -196,7 +206,7 @@
if root is None:
root = random.choice(list(range(len(faces))))

adj = face_adjacency(vertices, faces) # this is the only place where the vertex coordinates are used
adj = face_adjacency(vertices, faces, nmax=nmax, radius=radius) # this is the only place where the vertex coordinates are used

visited = breadth_first_traverse(adj, root, unify)

Expand Down
Loading
Loading