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

use compose for disjoint union #217

Merged
merged 3 commits into from
Sep 25, 2022
Merged

Conversation

pca006132
Copy link
Collaborator

Last mystery in #114. It turns out that the problem is due to misunderstanding of the bounding box API: Box::Transform is not a safe over-approximation of the bounding box of the manifold after the transform. In fact it might be smaller than that if the transform is not axis aligned (I should have just RTFM at that time). The simple fix is to apply the transform first and then compute the bounding box, this will also make sure that the bounding box is tight.

In the disjointness check, I enlarged the bounding box by the tolerance of the object, which can hopefully overapproximate the behavior of a perturbation of the vertices by at most the tolerance. However, I did not really add tests that can check this, so I am not sure if this is useful.

Note: This patch is not very important right now, maybe we can merge this after the next release, if we are not certain about this. I think the most important part of this patch is the potential performance improvement it brings and shows that our compose implementation should probably be fine.

src/manifold/src/csg_tree.cpp Outdated Show resolved Hide resolved
src/manifold/src/csg_tree.cpp Show resolved Hide resolved
// this kMaxUnionSize is a heuristic to avoid the pairwise disjoint check
// with O(n^2) complexity to take too long.
// If the number of children exceeded this limit, we will operate on chunks
// with size kMaxUnionSize.
Copy link
Owner

Choose a reason for hiding this comment

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

If performance becomes an issue here, this is exactly what collider is for. It does bounding box overlap checks in nlogn, in parallel.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think we talked about it in the previous PR: #131 (comment)

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, right. Is there a reason you need to append boxes? Generally the purpose of the collider is to take your everything vector and find all the collisions at once (hence the parallelism).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is that we need to partition the set of boxes into sets of boxes such that each set contains disjoint boxes. The target is to minimize the number of boxes. Boxes that collided means that they have to be in different sets. Maybe I can think about how to do it efficiently later.

@elalish
Copy link
Owner

elalish commented Sep 25, 2022

If the tests pass, I'll be happy to merge this. If we get some complicated failures, agreed that we shouldn't hold the release for it.

If you're now recomputing the bounding box, is there any source of rounding error? I wouldn't expect this to be a place where tolerance would be required.

@pca006132
Copy link
Collaborator Author

If you're now recomputing the bounding box, is there any source of rounding error? I wouldn't expect this to be a place where tolerance would be required.

Say we have ε = 0.1, one cube with two corners in (0, 0, 0) and (1, 1, 1), another cube in (1.05, 1, 1), (2.05, 2, 2). If we don't consider tolerance, the bounding box are not overlapping, but I guess we still need union to merge them into one cube?

@elalish
Copy link
Owner

elalish commented Sep 25, 2022

Say we have ε = 0.1, one cube with two corners in (0, 0, 0) and (1, 1, 1), another cube in (1.05, 1, 1), (2.05, 2, 2). If we don't consider tolerance, the bounding box are not overlapping, but I guess we still need union to merge them into one cube?

Actually, no. There is no tolerance in the Boolean ops (they only use symbolic perturbation), so those would remain disjoint regardless. Only in the triangulation and degenerate removal does the tolerance play a role. I think you're safer to do compose without tolerance.

@pca006132
Copy link
Collaborator Author

OK, I will remove that tolerance check.

Last mystery in elalish#114. It turns out that the problem is due to
misunderstanding of the bounding box API: Box::Transform is *not* a safe
over-approximation of the bounding box of the manifold after the
transform. In fact it might be smaller than that if the transform is not
axis aligned. The simple fix is to apply the transform first and then
compute the bounding box, this will also make sure that the bounding box
is tight.
@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2022

Codecov Report

Base: 92.31% // Head: 92.36% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (8c7995f) compared to base (975a6e6).
Patch coverage: 96.77% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #217      +/-   ##
==========================================
+ Coverage   92.31%   92.36%   +0.05%     
==========================================
  Files          32       32              
  Lines        3395     3419      +24     
==========================================
+ Hits         3134     3158      +24     
  Misses        261      261              
Impacted Files Coverage Δ
src/manifold/src/csg_tree.h 100.00% <ø> (ø)
src/manifold/src/csg_tree.cpp 93.89% <96.66%> (+1.22%) ⬆️
src/manifold/src/manifold.cpp 88.19% <100.00%> (ø)
src/manifold/src/boolean_result.cpp 97.93% <0.00%> (-0.35%) ⬇️
src/utilities/include/vec_dh.h 82.09% <0.00%> (+0.11%) ⬆️
src/utilities/include/par.h 93.75% <0.00%> (+0.20%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner

@elalish elalish left a comment

Choose a reason for hiding this comment

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

Good catch on the bounding boxes!

@elalish elalish merged commit 8538cf5 into elalish:master Sep 25, 2022
@pca006132 pca006132 deleted the union-compose branch August 15, 2023 12:54
cartesian-theatrics pushed a commit to SovereignShop/manifold that referenced this pull request Mar 11, 2024
* use compose for disjoint union

Last mystery in elalish#114. It turns out that the problem is due to
misunderstanding of the bounding box API: Box::Transform is *not* a safe
over-approximation of the bounding box of the manifold after the
transform. In fact it might be smaller than that if the transform is not
axis aligned. The simple fix is to apply the transform first and then
compute the bounding box, this will also make sure that the bounding box
is tight.

* fix batch union

Co-authored-by: Emmett Lalish <elalish@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants