-
Notifications
You must be signed in to change notification settings - Fork 97
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
Cache intermediate results automatically #199
Comments
Yes, we are already using ref-counter so maybe we can do use use_count. |
Sounds good; do you want to give it a try? |
diff --git a/src/manifold/src/csg_tree.cpp b/src/manifold/src/csg_tree.cpp
index 9e31137..d11fb5f 100644
--- a/src/manifold/src/csg_tree.cpp
+++ b/src/manifold/src/csg_tree.cpp
@@ -366,7 +366,7 @@ std::vector<std::shared_ptr<CsgNode>> &CsgOpNode::GetChildren(
CsgNodeType op = op_;
for (auto &child : children_) {
- if (child->GetNodeType() == op) {
+ if (child->GetNodeType() == op && child.use_count() == 1) {
auto grandchildren =
std::dynamic_pointer_cast<CsgOpNode>(child)->GetChildren(finalize);
int start = children_.size(); Indeed it works, but there is still 2 additional boolean operations, not sure what they are, will check later. |
Excellent, I love a simple fix! Looking forward to the PR. 👍 |
Any more progress on this, or would you like me to take a look? |
Sorry I am a bit busy recently, maybe you can take a look at it first. |
OK I understand what is going on for that 2 additional boolean operations now. The problem is that we are cloning all children when we do |
Regarding this comment @pca006132, I did a little test with
./manifold_test --gtest_filter=Samples.Frame -v
before and after removing the two cache-forcing lines. I'm seeing at least double the number of Boolean operations when I remove those lines. Is there a way to make theCsgNode
aware of when it's being used more than once so it can skip flattening and allow reuse instead? Maybe some kind of ref-counter?The text was updated successfully, but these errors were encountered: