Skip to content

Commit 8f9bbe7

Browse files
authored
Merge pull request #60 from petrasvestartas/compute_contacts_bvh
FIX compute_contacts with bvh and kdtree.
2 parents b8d7a99 + 20dc5fd commit 8f9bbe7

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
### Changed
2222

2323
* Fixed bug in `compas_model.models.Model.transformation`.
24+
* BVH and KDTree search combination in `compas_model.models.Model.compute_contacts`.
25+
* Clean-up of mesh boolean triangulation in `compas_model.interactions.modifiers.boolean_modifier`.
26+
2427

2528
### Removed
2629

src/compas_model/interactions/modifiers/boolean_modifier.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@ def apply(self, target: Union[Brep, Mesh]):
6161

6262
V, F = boolean_difference_mesh_mesh(A, B)
6363
mesh: Mesh = Mesh.from_vertices_and_faces(V, F) if len(V) > 0 and len(F) > 0 else mesh0
64+
65+
# WIP: merge coplanar mesh faces, in the future use mesh corefinement from CGAL to avoid Brep to Mesh conversion.
66+
from compas.tolerance import TOL
67+
68+
name = mesh.name
69+
brep = Brep.from_mesh(mesh)
70+
brep.simplify(lineardeflection=TOL.lineardeflection, angulardeflection=TOL.angulardeflection)
71+
mesh = Mesh.from_polygons(brep.to_polygons())
72+
mesh.unify_cycles()
73+
mesh.name = name
6474
return mesh

src/compas_model/models/model.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def compute_kdtree(self) -> KDTree:
626626
def compute_collisions(self):
627627
pass
628628

629-
def compute_contacts(self, tolerance=1e-6, minimum_area=1e-2, k=2) -> None:
629+
def compute_contacts(self, tolerance=1e-6, minimum_area=1e-2, k=2, search_type="bvh") -> None:
630630
"""Compute the contacts between the block elements of this model.
631631
632632
Parameters
@@ -637,6 +637,8 @@ def compute_contacts(self, tolerance=1e-6, minimum_area=1e-2, k=2) -> None:
637637
The minimum contact size.
638638
k : int, optional
639639
The number of element neighbours to consider.
640+
search_type : str, optional
641+
Nearest neighbour algorithm type, possible options: 'bvh' or 'kdtree'.
640642
641643
Returns
642644
-------
@@ -645,8 +647,18 @@ def compute_contacts(self, tolerance=1e-6, minimum_area=1e-2, k=2) -> None:
645647
"""
646648
for element in self.elements():
647649
u = element.graphnode
648-
nnbrs = self.element_nnbrs(element, k=k)
649-
for nbr, _ in nnbrs:
650+
651+
nnbrs = []
652+
if search_type == "bvh":
653+
nnbrs = self.bvh.nearest_neighbors(element)
654+
elif search_type == "kdtree":
655+
nnbrs_and_distances = self.element_nnbrs(element, k=k)
656+
for id, _ in nnbrs_and_distances:
657+
nnbrs.append(id)
658+
else:
659+
raise ValueError("Unknown search type, possible options: 'bvh' or 'kdtree'")
660+
661+
for nbr in nnbrs:
650662
v = nbr.graphnode
651663
if not self.graph.has_edge((u, v), directed=False):
652664
contacts = element.contacts(nbr, tolerance=tolerance, minimum_area=minimum_area)

0 commit comments

Comments
 (0)