Skip to content

Commit

Permalink
Return number of iterations after simplifying mesh
Browse files Browse the repository at this point in the history
We can use the number to resume simplification from a simplified mesh
  • Loading branch information
ranlu committed Apr 27, 2024
1 parent 12f3c35 commit 927c71c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 9 additions & 7 deletions pyfqmr/Simplify.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ namespace Simplify
// more iterations yield higher quality
//

void simplify_mesh(int target_count, int update_rate=5, double agressiveness=7,
bool verbose=false, int max_iterations=100, double alpha = 0.000000001,
int simplify_mesh(int target_count, int update_rate=5, double agressiveness=7,
bool verbose=false, int max_iterations=100, double alpha = 0.000000001,
int K = 3, bool lossless=false, double threshold_lossless = 0.0001,
bool preserve_border = false)
{
Expand All @@ -356,9 +356,9 @@ namespace Simplify
int deleted_triangles=0;
std::vector<int> deleted0,deleted1;
int triangle_count=triangles.size();
//int iteration = 0;
int iteration = 0;
//loop(iteration,0,100)
for (int iteration = 0; iteration < max_iterations; iteration ++)
for (iteration = 0; iteration < max_iterations; iteration ++)
{
if(triangle_count-deleted_triangles<=target_count)break;

Expand Down Expand Up @@ -450,9 +450,10 @@ namespace Simplify
}
// clean up mesh
compact_mesh();
return iteration;
} //simplify_mesh()

void simplify_mesh_lossless(bool verbose=false, double epsilon=1e-3, int max_iterations = 9999)
int simplify_mesh_lossless(bool verbose=false, double epsilon=1e-3, int max_iterations = 9999)
{
// init
loopi(0,triangles.size())
Expand All @@ -463,9 +464,9 @@ namespace Simplify
int deleted_triangles=0;
std::vector<int> deleted0,deleted1;
int triangle_count=triangles.size();
//int iteration = 0;
int iteration = 0;
//loop(iteration,0,100)
for (int iteration = 0; iteration < max_iterations; iteration ++)
for (iteration = 0; iteration < max_iterations; iteration ++)
{
// update mesh constantly
update_mesh(iteration);
Expand Down Expand Up @@ -543,6 +544,7 @@ namespace Simplify
} //for each iteration
// clean up mesh
compact_mesh();
return iteration;
} //simplify_mesh_lossless()


Expand Down
8 changes: 5 additions & 3 deletions pyfqmr/Simplify.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cdef extern from "Simplify.h":
double z

cdef extern from "Simplify.h" namespace "Simplify" :
void simplify_mesh( int target_count, int update_rate, double aggressiveness,
int simplify_mesh( int target_count, int update_rate, double aggressiveness,
bool verbose, int max_iterations,double alpha, int K,
bool lossless, double threshold_lossless, bool preserve_border)
void setMeshFromExt(vector[vector[double]] vertices, vector[vector[int]] faces)
Expand Down Expand Up @@ -119,7 +119,7 @@ cdef class Simplify :
else:
setFacesNogil_int(faces_np.astype(dtype="int32", subok=False, copy=False), triangles)

cpdef void simplify_mesh(self, int target_count = 100, int update_rate = 5,
cpdef int simplify_mesh(self, int target_count = 100, int update_rate = 5,
double aggressiveness=7., max_iterations = 100, bool verbose=True,
bool lossless = False, double threshold_lossless=1e-3, double alpha = 1e-9,
int K = 3, bool preserve_border = True):
Expand Down Expand Up @@ -156,11 +156,13 @@ cdef class Simplify :
threshold = alpha*pow( iteration + K, agressiveness)
"""
t_start = _time()
simplify_mesh(target_count, update_rate, aggressiveness, verbose, max_iterations, alpha, K,
iteration = simplify_mesh(target_count, update_rate, aggressiveness, verbose, max_iterations, alpha, K,
lossless, threshold_lossless, preserve_border)
t_end = _time()
N_end = getFaces().size()

return iteration


@cython.boundscheck(False)
@cython.wraparound(False) # turn off negative index wrapping for entire function
Expand Down

0 comments on commit 927c71c

Please sign in to comment.