-
Notifications
You must be signed in to change notification settings - Fork 105
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
Simplify the CsgOpNodes as we build them, rather than in GetChildren #368
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a43e337
Flatten the CsgOpNodes as we build them, rather than in GetChildren
ochafik f091479
Don't inline reused nodes in CsgNode::Boolean
ochafik 210bb0e
Reinstate difference -> union rewrite
ochafik 7b488a5
No need for opportunistic flattening anymore
ochafik 166c603
Fix typo
ochafik 5f91aa9
Remove CsgOpNode::Impl::simplified_
ochafik 17a13d6
Don't overskip referenced nodes in simplification
ochafik 3bf059c
Avoid needless copy of shared pointers
ochafik ce85a44
Disambiguate CsgOpNode::Impl::flatten_ -> forcedToLeafNodes_ and alig…
ochafik 147017f
Simplified CsgOpNode::GetChildren
ochafik 2ef7d4e
Simpler (a-(b+c)) -> (a-b-c) transform in CsgOpNode::Boolean to work …
ochafik 7cb439c
Simpler build hints for large_scene_test.cpp
ochafik 409dd3f
[flatten] Refine rules about tree flattening + added test case
ochafik 1adafe8
[manifold] Propagate transforms when flattening op trees
ochafik 6fcf61b
[flatten] move tests from manifold_test to boolean_test
ochafik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 The Manifold Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
|
||
#include "manifold.h" | ||
|
||
using namespace manifold; | ||
|
||
/* | ||
Build & execute with the following command: | ||
|
||
( mkdir -p build && cd build && \ | ||
cmake -DCMAKE_BUILD_TYPE=Release -DMANIFOLD_PAR=TBB .. && \ | ||
make -j && \ | ||
time ./extras/largeSceneTest 50 ) | ||
*/ | ||
int main(int argc, char **argv) { | ||
int n = 20; | ||
if (argc == 2) n = atoi(argv[1]); | ||
|
||
std::cout << "n = " << n << std::endl; | ||
|
||
auto start = std::chrono::high_resolution_clock::now(); | ||
Manifold scene; | ||
|
||
for (int i = 0; i < n; ++i) { | ||
for (int j = 0; j < n; ++j) { | ||
for (int k = 0; k < n; ++k) { | ||
if (i == 0 && j == 0 && k == 0) continue; | ||
|
||
Manifold sphere = Manifold::Sphere(1).Translate(glm::vec3(i, j, k)); | ||
scene = scene.Boolean(sphere, OpType::Add); | ||
} | ||
} | ||
} | ||
scene.NumTri(); | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> elapsed = end - start; | ||
std::cout << "nTri = " << scene.NumTri() << ", time = " << elapsed.count() | ||
<< " sec" << std::endl; | ||
} |
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 |
---|---|---|
|
@@ -22,13 +22,16 @@ enum class CsgNodeType { Union, Intersection, Difference, Leaf }; | |
|
||
class CsgLeafNode; | ||
|
||
class CsgNode { | ||
class CsgNode : public std::enable_shared_from_this<CsgNode> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I never know such a thing exists, I wanted to do something similar and have to do it the dumb way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's a nice get out of jail free card 🤣 |
||
public: | ||
virtual std::shared_ptr<CsgLeafNode> ToLeafNode() const = 0; | ||
virtual std::shared_ptr<CsgNode> Transform(const glm::mat4x3 &m) const = 0; | ||
virtual CsgNodeType GetNodeType() const = 0; | ||
virtual glm::mat4x3 GetTransform() const = 0; | ||
|
||
virtual std::shared_ptr<CsgNode> Boolean( | ||
const std::shared_ptr<CsgNode> &second, OpType op); | ||
|
||
std::shared_ptr<CsgNode> Translate(const glm::vec3 &t) const; | ||
std::shared_ptr<CsgNode> Scale(const glm::vec3 &s) const; | ||
std::shared_ptr<CsgNode> Rotate(float xDegrees = 0, float yDegrees = 0, | ||
|
@@ -68,6 +71,9 @@ class CsgOpNode final : public CsgNode { | |
|
||
CsgOpNode(std::vector<std::shared_ptr<CsgNode>> &&children, OpType op); | ||
|
||
std::shared_ptr<CsgNode> Boolean(const std::shared_ptr<CsgNode> &second, | ||
OpType op) override; | ||
|
||
std::shared_ptr<CsgNode> Transform(const glm::mat4x3 &m) const override; | ||
|
||
std::shared_ptr<CsgLeafNode> ToLeafNode() const override; | ||
|
@@ -79,8 +85,7 @@ class CsgOpNode final : public CsgNode { | |
private: | ||
struct Impl { | ||
std::vector<std::shared_ptr<CsgNode>> children_; | ||
bool simplified_ = false; | ||
bool flattened_ = false; | ||
bool forcedToLeafNodes_ = false; | ||
}; | ||
mutable ConcurrentSharedPtr<Impl> impl_ = ConcurrentSharedPtr<Impl>(Impl{}); | ||
CsgNodeType op_; | ||
|
@@ -89,6 +94,7 @@ class CsgOpNode final : public CsgNode { | |
mutable std::shared_ptr<CsgLeafNode> cache_ = nullptr; | ||
|
||
void SetOp(OpType); | ||
bool IsOp(OpType op); | ||
|
||
static std::shared_ptr<Manifold::Impl> BatchBoolean( | ||
OpType operation, | ||
|
@@ -97,7 +103,7 @@ class CsgOpNode final : public CsgNode { | |
void BatchUnion() const; | ||
|
||
std::vector<std::shared_ptr<CsgNode>> &GetChildren( | ||
bool finalize = true) const; | ||
bool forceToLeafNodes = true) const; | ||
}; | ||
|
||
} // namespace manifold |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to see this simplification, but what was the difference between
simplified
andflattened
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simplified
did not perform flattening if the nodes are shared, iirc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flattening (also aliased here to finalization) was forcing leaf nodes, while simplification was flattening 1 level of op nodes nesting (adopting the children of same op children, and in the case of difference, of union op children past the first child).
Have now renamed finalize & flattened_ to force[d]ToLeafNodes[_] to disambiguate, and simplified this method further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thank you!