Skip to content

Commit c7b05e4

Browse files
committed
Add unit test for each function.
1 parent c141ab2 commit c7b05e4

File tree

22 files changed

+613
-311
lines changed

22 files changed

+613
-311
lines changed

.github/workflows/macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ jobs:
110110
111111
- name: Python Module Test
112112
run: |
113-
poetry run nose2
113+
poetry run nose2 -s tests/python
114114

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ jobs:
110110
111111
- name: Python Module Test
112112
run: |
113-
poetry run nose2
113+
poetry run nose2 -s tests/python
114114

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ jobs:
6161
6262
- name: Python Module Test
6363
run: |
64-
poetry run nose2
64+
poetry run nose2 -s tests/python

data/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
!models/bunny.ply
2+
!models/bunny_mini.ply
23
!models/fandisk.ply
34
!models/box.obj
45
!models/plane.obj

data/models/bunny_mini.ply

186 KB
Binary file not shown.

examples/example_simplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ int main(int argc, char **argv) {
1616
tinymesh::Mesh mesh(argv[1]);
1717

1818
// Simplify
19-
const int target = (int)(ratio * mesh.numVertices());
19+
const int target = (int)(ratio * mesh.numFaces());
2020
tinymesh::holeFill(mesh);
21-
tinymesh::simplifyQEM(mesh, target);
22-
tinymesh::remeshTriangular(mesh);
21+
tinymesh::simplifyQEM(mesh, target, 10, true);
22+
tinymesh::remeshTriangular(mesh, 0.0, 1e6); // remesh by keeping #faces
2323

2424
// Save
2525
const fs::path filepath = fs::canonical(fs::path(argv[1]));

src/pybind11.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ PYBIND11_MODULE(tinymesh, m) {
6363
.def("num_vertices", &Mesh::numVertices)
6464
.def("num_edges", &Mesh::numEdges)
6565
.def("num_halfedges", &Mesh::numHalfedges)
66-
.def("num_faces", &Mesh::numFaces);
66+
.def("num_faces", &Mesh::numFaces)
67+
.def("verify", &Mesh::verify);
6768

6869
py::class_<Vertex, std::shared_ptr<Vertex>>(m, "Vertex")
6970
.def(py::init<>())
@@ -129,14 +130,17 @@ PYBIND11_MODULE(tinymesh, m) {
129130
py::arg("short_length") = 0.8,
130131
py::arg("long_length") = 1.333,
131132
py::arg("angle_keep_less_than") = 0.0,
132-
py::arg("iterations") = 5);
133+
py::arg("iterations") = 5,
134+
py::arg("verbose") = false);
133135

134136
/*** Simplification ***/
135137

136138
m.def("simplify_qem", &simplifyQEM,
137139
"QEM-based simplification",
138140
py::arg("mesh"),
139-
py::arg("n_triangles"));
141+
py::arg("n_triangles"),
142+
py::arg("n_trials") = 10,
143+
py::arg("verbose") = false);
140144

141145
/*** Hole filling ***/
142146

src/tinymesh/core/progress.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class ProgressBar {
2020
}
2121
virtual ~ProgressBar() {}
2222

23-
void step() {
24-
m_step += 1;
23+
void step(int n = 1) {
24+
m_step += n;
2525
auto now = std::chrono::system_clock::now();
2626

2727
const double percent = 100.0 * m_step / m_total;
@@ -54,6 +54,10 @@ class ProgressBar {
5454
}
5555
}
5656

57+
void finish() {
58+
printf("\n");
59+
}
60+
5761
private:
5862
const int m_width = 40;
5963
int m_step, m_total;

src/tinymesh/remesh/remesh.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <atomic>
77

88
#include "core/vec.h"
9+
#include "core/debug.h"
910
#include "core/openmp.h"
1011
#include "core/mesh.h"
1112
#include "core/vertex.h"
@@ -15,7 +16,7 @@
1516

1617
namespace tinymesh {
1718

18-
void remeshTriangular(Mesh &mesh, double shortLength, double longLength, double keepAngleLessThan, int iterations) {
19+
void remeshTriangular(Mesh &mesh, double shortLength, double longLength, double keepAngleLessThan, int iterations, bool verbose) {
1920
Assertion(mesh.verify(), "Invalid mesh!");
2021

2122
// Compute average edge length
@@ -70,9 +71,11 @@ void remeshTriangular(Mesh &mesh, double shortLength, double longLength, double
7071

7172
// Remesh loop
7273
for (int k = 0; k < iterations; k++) {
73-
printf("*** Original #%d ***\n", k + 1);
74-
printf("#vert: %d\n", (int)mesh.numVertices());
75-
printf("#face: %d\n", (int)mesh.numFaces());
74+
if (verbose) {
75+
Info("*** Original #%d ***\n", k + 1);
76+
Info("#vert: %d\n", (int)mesh.numVertices());
77+
Info("#face: %d\n", (int)mesh.numFaces());
78+
}
7679

7780
// Split long edges
7881
indices.clear();
@@ -95,9 +98,11 @@ void remeshTriangular(Mesh &mesh, double shortLength, double longLength, double
9598
}
9699
}
97100

98-
printf("*** After split ***\n");
99-
printf("#vert: %d\n", (int)mesh.numVertices());
100-
printf("#face: %d\n", (int)mesh.numFaces());
101+
if (verbose) {
102+
Info("*** After split ***\n");
103+
Info("#vert: %d\n", (int)mesh.numVertices());
104+
Info("#face: %d\n", (int)mesh.numFaces());
105+
}
101106

102107
mesh.verify();
103108

@@ -146,9 +151,11 @@ void remeshTriangular(Mesh &mesh, double shortLength, double longLength, double
146151
}
147152
}
148153

149-
printf("*** After collapse ***\n");
150-
printf("#vert: %d\n", (int)mesh.numVertices());
151-
printf("#face: %d\n", (int)mesh.numFaces());
154+
if (verbose) {
155+
Info("*** After collapse ***\n");
156+
Info("#vert: %d\n", (int)mesh.numVertices());
157+
Info("#face: %d\n", (int)mesh.numFaces());
158+
}
152159

153160
// Flip edges
154161
for (int i = 0; i < (int)mesh.numHalfedges(); i++) {

src/tinymesh/remesh/remesh.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
namespace tinymesh {
1111

1212
/**
13-
* Triangular remeshing [Hoppe 1996]
13+
* Minimum direhdral hole filling [Leipa 2003]
1414
*/
15-
TINYMESH_API void remeshTriangular(Mesh &mesh, double shortLength = 0.8, double longLength = 1.333, double keepAngleLessThan = 0.0, int maxiter = 5);
15+
TINYMESH_API void holeFill(Mesh &mesh, double dihedralBound = Pi);
1616

1717
/**
18-
* QEM-based simplification [Garland and Heckbert 1997]
18+
* Triangular remeshing [Hoppe 1996]
1919
*/
20-
TINYMESH_API void simplifyQEM(Mesh &mesh, int numTarget);
20+
TINYMESH_API void remeshTriangular(Mesh &mesh, double shortLength = 0.8, double longLength = 1.333,
21+
double keepAngleLessThan = 0.0, int maxiter = 5, bool verbose = false);
2122

2223
/**
23-
* Minimum direhdral hole filling [Leipa 2003]
24+
* QEM-based simplification [Garland and Heckbert 1997]
2425
*/
25-
TINYMESH_API void holeFill(Mesh &mesh, double dihedralBound = Pi);
26+
TINYMESH_API void simplifyQEM(Mesh &mesh, int numTarget, int maxTrials = 10, bool verbose = false);
2627

2728
} // namespace tinymesh
2829

0 commit comments

Comments
 (0)