Skip to content

Commit

Permalink
Added file conversion and debug utility (elalish#407)
Browse files Browse the repository at this point in the history
* added file conversion utility

* added verbose output

* fix build
  • Loading branch information
elalish authored Apr 11, 2023
1 parent 5430b50 commit b30ca18
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 5 deletions.
7 changes: 7 additions & 0 deletions extras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
67 changes: 67 additions & 0 deletions extras/convert_file.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

#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<Manifold> 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;
}
5 changes: 0 additions & 5 deletions meshIO/include/meshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@

namespace manifold {

/** @addtogroup Debug
* @{
*/

/** @defgroup MeshIO
* @brief 3D model file I/O based on Assimp
* @{
Expand Down Expand Up @@ -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
27 changes: 27 additions & 0 deletions src/manifold/src/edge_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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);
}
Expand Down

0 comments on commit b30ca18

Please sign in to comment.