-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clip Voronoi regions in cvt_archive_heatmap (#356)
## Description <!-- Provide a brief description of the PR's purpose here. --> The current cvt_archive_heatmap relies on faraway points to draw the polygons at the edges of the Voronoi diagram. Thus, if a user zooms out, they will see that the heatmap actually has polygons going beyond it, like below. In practice, we rarely notice this because the cvt_archive_heatmap sets the axis limits to be the bounds of the archive, so the outer regions are hidden. ![cvt heatmap](https://github.com/icaros-usc/pyribs/assets/38124174/3b3486e0-cf55-4667-ae74-14f3b8a98d63) However, there may be times when this behavior is undesirable, e.g., drawing two cvt archives next to each other. Thus, this PR makes it possible to clip the bounds of the Voronoi diagram, like so: ![cvt heatmap](https://github.com/icaros-usc/pyribs/assets/38124174/217ca661-87eb-43d0-b3f9-3b0ffbae9403) We accomplish this by taking each polygon and computing its intersection with the archive’s bounding box. Intersections are computed via the shapely library: https://shapely.readthedocs.io/ Furthermore, by using shapely, it is possible to clip to arbitrary shapes: ![cvt heatmap](https://github.com/icaros-usc/pyribs/assets/38124174/1b316db7-8ad1-4943-8db4-8dbc8d6949be) There are some tradeoffs to turning this feature on by default, namely: 1. It may be more “intuitive” to have infinite regions at the edge of the archive, as that is how the archive works in practice — namely, points outside the archive bounds are inserted into cells at the edges. 2. Computing the intersection of all the polygons with the bounding box (or bounding shape) can be somewhat time-consuming. However, after running the script in #355 with `clip=True`, I found that the runtime for 10,000 cells was still ~2.3 sec (much slower than the 0.6 sec in that PR, but still very fast). For these reasons, we will keep this feature turned off by default via the `clip` parameter to `cvt_archive_heatmap` . Note that this PR introduces a dependency on shapely, and yet the feature we use shapely for will be turned off by default since `clip=False`. However, I believe this is acceptable because shapely is a well-supported library that is also lightweight (~2MB), so it will not be a burden to users. ## TODO <!-- Notable points that this PR has either accomplished or will accomplish. --> - [x] Add shapely to deps - [x] Add shapely to pinned reqs - [x] Add shapely to intersphinx - [x] Implement clipping - [x] Add flag to turn clipping on and off - [x] Add test for heatmap with and without clipping - [x] Enable clipping to an arbitrary polygon - [x] Add test for clipping to arbitrary polygon, with and without holes ## Questions <!-- Any concerns or points of confusion? --> ## Status - [x] I have read the guidelines in [CONTRIBUTING.md](https://github.com/icaros-usc/pyribs/blob/master/CONTRIBUTING.md) - [x] I have formatted my code using `yapf` - [x] I have tested my code by running `pytest` - [x] I have linted my code with `pylint` - [x] I have added a one-line description of my change to the changelog in `HISTORY.md` - [x] This PR is ready to go
- Loading branch information
Showing
10 changed files
with
149 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ scikit-learn==1.3.0 | |
scipy==1.10.1 | ||
threadpoolctl==3.0.0 | ||
matplotlib==3.7.2 | ||
shapely==2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+73 KB
tests/visualize/baseline_images/visualize_test/cvt_archive_heatmap_clip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+51.9 KB
...s/visualize/baseline_images/visualize_test/cvt_archive_heatmap_clip_polygon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+51 KB
...e/baseline_images/visualize_test/cvt_archive_heatmap_clip_polygon_with_hole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+89.5 KB
tests/visualize/baseline_images/visualize_test/cvt_archive_heatmap_noclip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters