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

New decimator #1175

Merged
merged 16 commits into from
Mar 6, 2025
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"program": "${workspaceFolder}/build/test/manifold_test",
"args": [
"--gtest_catch_exceptions=0",
"--gtest_filter=Manifold.MergeRefine"
"--gtest_filter=Properties.ToleranceSphere"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/test",
Expand Down
22 changes: 11 additions & 11 deletions bindings/python/examples/bricks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Copyright 2022 The Manifold Authors.
Copyright 2022 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
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

https://www.apache.org/licenses/LICENSE-2.0
https://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.
"""
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.
"""

from manifold3d import Manifold

Expand Down
22 changes: 11 additions & 11 deletions bindings/python/examples/cube_with_dents.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Copyright 2022 The Manifold Authors.
Copyright 2022 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
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

https://www.apache.org/licenses/LICENSE-2.0
https://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.
"""
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.
"""

from manifold3d import Manifold
from functools import reduce
Expand Down
22 changes: 11 additions & 11 deletions bindings/python/examples/gyroid_module.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Copyright 2023 The Manifold Authors.
Copyright 2023 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
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

https://www.apache.org/licenses/LICENSE-2.0
https://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.
"""
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.
"""

import math
import numpy as np
Expand Down
22 changes: 11 additions & 11 deletions bindings/python/examples/run_all.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Copyright 2022 The Manifold Authors.
Copyright 2022 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
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

https://www.apache.org/licenses/LICENSE-2.0
https://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.
"""
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.
"""

import pathlib
import sys
Expand Down
22 changes: 11 additions & 11 deletions bindings/python/examples/scallop.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Copyright 2023 The Manifold Authors.
Copyright 2023 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
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

https://www.apache.org/licenses/LICENSE-2.0
https://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.
"""
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.
"""

from manifold3d import Manifold, Mesh
import numpy as np
Expand Down
22 changes: 11 additions & 11 deletions bindings/python/examples/split_cube.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Copyright 2022 The Manifold Authors.
Copyright 2022 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
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

https://www.apache.org/licenses/LICENSE-2.0
https://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.
"""
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.
"""

from manifold3d import Manifold

Expand Down
3 changes: 2 additions & 1 deletion bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ NB_MODULE(manifold3d, m) {
nb::arg("radius"), get_circular_segments__radius);

m.def("triangulate", &Triangulate, nb::arg("polygons"),
nb::arg("epsilon") = -1, triangulate__polygons__epsilon);
nb::arg("epsilon") = -1, nb::arg("allow_convex") = true,
triangulate__polygons__epsilon__allow_convex);

nb::class_<Manifold>(m, "Manifold")
.def(nb::init<>(), manifold__manifold)
Expand Down
7 changes: 4 additions & 3 deletions include/manifold/polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ using PolygonsIdx = std::vector<SimplePolygonIdx>;
* @brief Polygon triangulation
* @{
*/
std::vector<ivec3> TriangulateIdx(const PolygonsIdx &polys,
double epsilon = -1);
std::vector<ivec3> TriangulateIdx(const PolygonsIdx &polys, double epsilon = -1,
bool allowConvex = true);

std::vector<ivec3> Triangulate(const Polygons &polygons, double epsilon = -1);
std::vector<ivec3> Triangulate(const Polygons &polygons, double epsilon = -1,
bool allowConvex = true);
/** @} */
} // namespace manifold
12 changes: 12 additions & 0 deletions src/edge_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ void Manifold::Impl::CleanupTopology() {
* meshes, thus decreasing the Genus(). It only increases when meshes that have
* collapsed to just a pair of triangles are removed entirely.
*
* Verts with index less than firstNewVert will be left uncollapsed. This is
* zero by default so that everything can be collapsed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

When do we use this zero default? We should probably explain this mesh simplification behavior in the public documentation as well.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Everywhere except the Boolean - mesh ingestion, AsOriginal, etc. Hmm, come to think of it, the issue of decimating input planar geometry that doesn't intersect anything isn't really fixed, since we're still doing it on mesh import and other places. Perhaps those should all be restricted to short edge collapse? I think I'll do this in a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good.

*
* Rather than actually removing the edges, this step merely marks them for
* removal, by setting vertPos to NaN and halfedge to {-1, -1, -1, -1}.
*/
Expand All @@ -258,6 +261,10 @@ void Manifold::Impl::SimplifyTopology(int firstNewVert) {
{
ZoneScopedN("CollapseShortEdge");
numFlagged = 0;
// Short edges get to skip several checks and hence remove more classes of
// degenerate triangles than flagged edges do, but this could in theory lead
// to error stacking where a vertex moves too far. For this reason this is
// restricted to epsilon, rather than tolerance.
ShortEdge se{halfedge_, vertPos_, epsilon_, firstNewVert};
s.run(nbEdges, se, [&](size_t i) {
const bool didCollapse = CollapseEdge(i, scratchBuffer);
Expand All @@ -275,6 +282,11 @@ void Manifold::Impl::SimplifyTopology(int firstNewVert) {
while (1) {
ZoneScopedN("CollapseFlaggedEdge");
numFlagged = 0;
// Collapse colinear edges, but only remove new verts, i.e. verts with index
// >= firstNewVert. This is used to keep the Boolean from changing the
// non-intersecting parts of the input meshes. Colinear is defined not by a
// local check, but by the global CreateFaces function, which keeps this
// from being vulnerable to error stacking.
FlagEdge se{halfedge_, meshRelation_.triRef, firstNewVert};
s.run(nbEdges, se, [&](size_t i) {
const bool didCollapse = CollapseEdge(i, scratchBuffer);
Expand Down
Loading