diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index 5944b0a96..726d02e78 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -24,6 +24,13 @@ target_link_libraries(largeSceneTest manifold) target_compile_options(largeSceneTest PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(largeSceneTest PUBLIC cxx_std_17) +if(MANIFOLD_EXPORT) + add_executable(convertFile convert_file.cpp) + target_link_libraries(convertFile manifold meshIO) + target_compile_options(convertFile PRIVATE ${MANIFOLD_FLAGS}) + target_compile_features(convertFile PUBLIC cxx_std_17) +endif() + if(BUILD_TEST_CGAL) add_executable(perfTestCGAL perf_test_cgal.cpp) find_package(CGAL REQUIRED COMPONENTS Core) diff --git a/extras/convert_file.cpp b/extras/convert_file.cpp new file mode 100644 index 000000000..b9e7ca0e7 --- /dev/null +++ b/extras/convert_file.cpp @@ -0,0 +1,67 @@ +// 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 +// +// 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 + +#include "manifold.h" +#include "meshIO.h" + +using namespace manifold; + +/* + */ +int main(int argc, char** argv) { + if (argc < 2) { + std::cout << "Specify an input filename." << std::endl; + return 1; + } + + manifold::ManifoldParams().verbose = true; + + const std::string filename(argv[1]); + + MeshGL input = ImportMesh(filename); + std::cout << input.NumVert() << " vertices, " << input.NumTri() + << " triangles" << std::endl; + + if (input.Merge()) + std::cout << filename << " is not manifold, attempting to fix." + << std::endl; + + const Manifold manifold(input); + if (manifold.Status() != Manifold::Error::NoError) { + std::cout << "Could not make a valid manifold, error: " + << (int)manifold.Status() << std::endl; + return 2; + } + + const std::vector parts = manifold.Decompose(); + std::cout << parts.size() << " objects:" << std::endl; + for (const Manifold& part : parts) { + auto prop = part.GetProperties(); + std::cout << part.NumVert() << " vertices, " << part.NumTri() + << " triangles, volume = " << prop.volume + << ", surface area = " << prop.surfaceArea << std::endl; + } + + if (argc == 3) { + std::string outName = argv[2]; + + std::cout << "Writing " << outName << std::endl; + + ExportMesh(outName, manifold.GetMeshGL(), {}); + } + + return 0; +} \ No newline at end of file diff --git a/meshIO/include/meshIO.h b/meshIO/include/meshIO.h index e7a7ddef6..c11309949 100644 --- a/meshIO/include/meshIO.h +++ b/meshIO/include/meshIO.h @@ -19,10 +19,6 @@ namespace manifold { -/** @addtogroup Debug - * @{ - */ - /** @defgroup MeshIO * @brief 3D model file I/O based on Assimp * @{ @@ -70,5 +66,4 @@ void ExportMesh(const std::string& filename, const Mesh& mesh, void ExportMesh(const std::string& filename, const MeshGL& mesh, const ExportOptions& options); /** @} */ -/** @} */ } // namespace manifold \ No newline at end of file diff --git a/src/manifold/src/edge_op.cpp b/src/manifold/src/edge_op.cpp index 222c53a3d..c7378e3a7 100644 --- a/src/manifold/src/edge_op.cpp +++ b/src/manifold/src/edge_op.cpp @@ -152,6 +152,13 @@ void Manifold::Impl::SimplifyTopology() { flaggedEdges.begin(); flaggedEdges.resize(numFlagged); +#ifdef MANIFOLD_DEBUG + if (ManifoldParams().verbose && numFlagged > 0) { + std::cout << "found " << numFlagged << " duplicate edges to split" + << std::endl; + } +#endif + for (const int edge : flaggedEdges) DedupeEdge(edge); flaggedEdges.resize(halfedge_.size()); @@ -162,6 +169,13 @@ void Manifold::Impl::SimplifyTopology() { flaggedEdges.begin(); flaggedEdges.resize(numFlagged); +#ifdef MANIFOLD_DEBUG + if (ManifoldParams().verbose && numFlagged > 0) { + std::cout << "found " << numFlagged << " short edges to collapse" + << std::endl; + } +#endif + for (const int edge : flaggedEdges) CollapseEdge(edge); flaggedEdges.resize(halfedge_.size()); @@ -172,6 +186,13 @@ void Manifold::Impl::SimplifyTopology() { flaggedEdges.begin(); flaggedEdges.resize(numFlagged); +#ifdef MANIFOLD_DEBUG + if (ManifoldParams().verbose && numFlagged > 0) { + std::cout << "found " << numFlagged << " colinear edges to collapse" + << std::endl; + } +#endif + for (const int edge : flaggedEdges) CollapseEdge(edge); flaggedEdges.resize(halfedge_.size()); @@ -183,6 +204,12 @@ void Manifold::Impl::SimplifyTopology() { flaggedEdges.begin(); flaggedEdges.resize(numFlagged); +#ifdef MANIFOLD_DEBUG + if (ManifoldParams().verbose && numFlagged > 0) { + std::cout << "found " << numFlagged << " edges to swap" << std::endl; + } +#endif + for (const int edge : flaggedEdges) { RecursiveEdgeSwap(edge); }