Skip to content

Commit

Permalink
fixed precision bug for compose/decompose
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Jun 5, 2022
1 parent b31baa6 commit 19dc9de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions manifold/src/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ std::vector<Manifold> Manifold::Decompose() const {
std::vector<Manifold> meshes;
for (int i = 0; i < numLabel; ++i) {
auto impl = std::make_shared<Impl>();
// inherit original object's precision
impl->precision_ = pImpl_->precision_;
impl->vertPos_.resize(NumVert());
VecDH<int> vertNew2Old(NumVert());
auto policy = autoPolicy(NumVert());
Expand Down
13 changes: 13 additions & 0 deletions manifold/src/csg_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,29 @@ CsgNodeType CsgLeafNode::GetNodeType() const { return CsgNodeType::LEAF; }
*/
Manifold::Impl CsgLeafNode::Compose(
const std::vector<std::shared_ptr<CsgLeafNode>> &nodes) {
float precision = -1;
int numVert = 0;
int numEdge = 0;
int numTri = 0;
int numBary = 0;
for (auto &node : nodes) {
float nodeOldScale = node->pImpl_->bBox_.Scale();
float nodeNewScale = node->GetBoundingBox().Scale();
float nodePrecision = node->pImpl_->precision_;
nodePrecision *= glm::max(1.0f, nodeNewScale / nodeOldScale);
nodePrecision = glm::max(nodePrecision, kTolerance * nodeNewScale);
if (!glm::isfinite(nodePrecision))
nodePrecision = -1;
precision = glm::max(precision, nodePrecision);

numVert += node->pImpl_->NumVert();
numEdge += node->pImpl_->NumEdge();
numTri += node->pImpl_->NumTri();
numBary += node->pImpl_->meshRelation_.barycentric.size();
}

Manifold::Impl combined;
combined.precision_ = precision;
combined.vertPos_.resize(numVert);
combined.halfedge_.resize(2 * numEdge);
combined.faceNormal_.resize(numTri);
Expand Down Expand Up @@ -194,6 +205,8 @@ Manifold::Impl CsgLeafNode::Compose(
nextTri += node->pImpl_->NumTri();
nextBary += node->pImpl_->meshRelation_.barycentric.size();
}
// required to remove parts that are smaller than the precision
combined.SimplifyTopology();
combined.Finish();
return combined;
}
Expand Down
2 changes: 1 addition & 1 deletion manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ Manifold::Impl Manifold::Impl::Transform(const glm::mat4x3 &transform_) const {
result.precision_ *= glm::max(1.0f, newScale / oldScale);

// Maximum of inherited precision loss and translational precision loss.
result.SetPrecision(precision_);
result.SetPrecision(result.precision_);
return result;
}

Expand Down

0 comments on commit 19dc9de

Please sign in to comment.