From d6d80e721a094318a4db62af1ab896ddcc1e69b4 Mon Sep 17 00:00:00 2001 From: qbp758 Date: Mon, 2 Oct 2023 10:00:16 +0200 Subject: [PATCH 1/3] remove local test flag and update docstring --- .../prox_soft_bodies/collision_detection.py | 47 ++----------------- .../simulators/prox_soft_bodies/types.py | 1 - 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/python/rainbow/simulators/prox_soft_bodies/collision_detection.py b/python/rainbow/simulators/prox_soft_bodies/collision_detection.py index b40c62e..5491424 100644 --- a/python/rainbow/simulators/prox_soft_bodies/collision_detection.py +++ b/python/rainbow/simulators/prox_soft_bodies/collision_detection.py @@ -283,8 +283,9 @@ def _contact_determination(overlaps, engine, stats, debug_on): stats["contact_determination"] = contact_determination_timer.elapsed return stats + def _cp_unique_id(cp) -> tuple: - """ This function returns a unique id for a contact point. + """ This function returns a unique id for a ContactPoint instance. Args: cp (ContactPoint): A instance of the ContactPoint @@ -293,7 +294,8 @@ def _cp_unique_id(cp) -> tuple: """ return (cp.bodyA, cp.bodyB, tuple(cp.p)) -def _optimize_contact_reduction(engine, stats, debug_on): + +def _contact_reduction(engine, stats, debug_on): """ During contact point computation it may happen that different colliding triangles of one body results in the same contact point locations wrt to the other signed distance field of the other body. Imagine a spiky polygonal cone pointing into a spherical shape. Here all triangles of the spike will result in the same @@ -311,6 +313,7 @@ def _optimize_contact_reduction(engine, stats, debug_on): Returns: dict: A dictionary with profiling and timing measurements. """ + reduction_timer = None if debug_on: reduction_timer = Timer("contact_point_reduction", 8) reduction_timer.start() @@ -332,46 +335,6 @@ def _optimize_contact_reduction(engine, stats, debug_on): return stats -def _contact_reduction(engine, stats, debug_on): - """ - During contact point computation it may happen that different colliding triangles of one body results - in the same contact point locations wrt to the other signed distance field of the other body. Imagine a spiky - polygonal cone pointing into a spherical shape. Here all triangles of the spike will result in the same - contact point at the spiky tip. If the spiky polygonal cone has N triangle faces on the spike then we - will have N redundant contact points. This redundancy is usually bad for other numerical sub-routines for - computing impacts or contact forces. Hence, the purpose of this step is to eliminate redundant - contact point information. One may think of this as a kind of post-filtering process to clean up the - contact point information. - - :param engine: The current engine instance we are working with. - :param stats: A dictionary where to add more profiling and timing measurements. - :param debug_on: Boolean flag for toggling debug (aka profiling) info on and off. - :return: A dictionary with profiling and timing measurements. - """ - if engine.params.speedup: - return _optimize_contact_reduction(engine, stats, debug_on) - - reduction_timer = None - if debug_on: - reduction_timer = Timer("contact_point_reduction", 8) - reduction_timer.start() - # TODO 2020-09-07 Kristian: This brute force implementation can be implemented better - reduced_list = [] - for cp1 in engine.contact_points: - unique = True - for cp2 in reduced_list: - if {cp1.bodyA, cp1.bodyB} == {cp2.bodyA, cp2.bodyB} and ( - cp1.p == cp2.p - ).all(): - unique = False - if unique: - reduced_list.append(cp1) - engine.contact_points = reduced_list - if debug_on: - reduction_timer.end() - stats["contact_point_reduction"] = reduction_timer.elapsed - return stats - def run_collision_detection(engine, stats, debug_on): """ diff --git a/python/rainbow/simulators/prox_soft_bodies/types.py b/python/rainbow/simulators/prox_soft_bodies/types.py index b7aa30f..b3cf91d 100644 --- a/python/rainbow/simulators/prox_soft_bodies/types.py +++ b/python/rainbow/simulators/prox_soft_bodies/types.py @@ -252,7 +252,6 @@ def __init__(self): 0.1 # Any geometry within this distance generates a contact point. ) self.resolution = 64 # The number of grid cells along each axis in the signed distance fields. - self.speedup = True class Engine: From 6c7ebcc8821566fdfbe572d655077a739ed7672b Mon Sep 17 00:00:00 2001 From: qbp758 Date: Mon, 2 Oct 2023 10:56:39 +0200 Subject: [PATCH 2/3] PEP style --- python/rainbow/util/USD.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/rainbow/util/USD.py b/python/rainbow/util/USD.py index 1d200b7..3a95618 100644 --- a/python/rainbow/util/USD.py +++ b/python/rainbow/util/USD.py @@ -94,7 +94,7 @@ def set_animation_time(self, duration: float) -> None: """ Set the total animation time of the scene Args: - duration (_type_): The total animation time of the scene + duration (float): The total animation time of the scene """ self.stage.SetStartTimeCode(0) self.stage.SetEndTimeCode(duration) From 4c2a36dddefcb59f2d393bf6cf3cbd33cb0b0d6e Mon Sep 17 00:00:00 2001 From: qbp758 Date: Fri, 6 Oct 2023 21:19:01 +0200 Subject: [PATCH 3/3] fix assert array equal --- python/rainbow/util/test_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/rainbow/util/test_tools.py b/python/rainbow/util/test_tools.py index d4caf88..a0212de 100644 --- a/python/rainbow/util/test_tools.py +++ b/python/rainbow/util/test_tools.py @@ -6,7 +6,7 @@ """ -def is_array_equal(arr1, arr2, dec=8): +def is_array_equal(arr1, arr2): """ 2022-04-06 Kenny TODO: Write proper documentation. @@ -15,7 +15,7 @@ def is_array_equal(arr1, arr2, dec=8): :param dec: :return: """ - return None == np.testing.assert_array_almost_equal(arr1, arr2, dec) + return None == np.testing.assert_allclose(arr1, arr2, rtol=1e-5, atol=1e-8) def is_array_not_equal(arr1, arr2):