diff --git a/pyfqmr/Simplify.h b/pyfqmr/Simplify.h index 6e6fcbc..d5540d2 100644 --- a/pyfqmr/Simplify.h +++ b/pyfqmr/Simplify.h @@ -342,7 +342,7 @@ namespace Simplify // void simplify_mesh(int target_count, int update_rate=5, double agressiveness=7, - bool verbose=false, int max_iterations=100, double alpha = 0.000000001, + void (*log)(char*, int)=NULL, int max_iterations=100, double alpha = 0.000000001, int K = 3, bool lossless=false, double threshold_lossless = 0.0001, bool preserve_border = false) { @@ -381,8 +381,10 @@ namespace Simplify if(lossless) threshold = threshold_lossless ; // target number of triangles reached ? Then break - if ((verbose) && (iteration%5==0)) { - printf("iteration %d - triangles %d threshold %g\n",iteration,triangle_count-deleted_triangles, threshold); + if ((log) && (iteration%5==0)) { + char message[128]; + snprintf(message, 127, "iteration %d - triangles %d threshold %g",iteration,triangle_count-deleted_triangles, threshold); + log(message, 128); } // remove vertices & mark deleted triangles diff --git a/pyfqmr/Simplify.pyx b/pyfqmr/Simplify.pyx index 188262b..3a4c310 100644 --- a/pyfqmr/Simplify.pyx +++ b/pyfqmr/Simplify.pyx @@ -21,13 +21,19 @@ _REF = _hidden_ref() cdef extern from "Simplify.h" namespace "Simplify" : void simplify_mesh( int target_count, int update_rate, double aggressiveness, - bool verbose, int max_iterations,double alpha, int K, + void (*log)(char*, int), 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) vector[vector[int]] getFaces() vector[vector[double]] getVertices() vector[vector[double]] getNormals() +cdef void log_message(char* message, int length) noexcept: + if message is not NULL: + from logging import getLogger + + getLogger("pyfqmr").debug(message.decode("utf-8")) + cdef class Simplify : cdef int[:,:] faces_mv @@ -143,15 +149,24 @@ cdef class Simplify : ---- threshold = alpha*pow( iteration + K, agressiveness) """ + + cdef void (*log)(char*, int) noexcept + + log = NULL + if verbose: + log = log_message + N_start = self.faces_mv.shape[0] t_start = _time() - simplify_mesh(target_count, update_rate, aggressiveness, verbose, max_iterations, alpha, K, + simplify_mesh(target_count, update_rate, aggressiveness, log, max_iterations, alpha, K, lossless, threshold_lossless, preserve_border) t_end = _time() N_end = getFaces().size() if verbose: - print('simplified mesh in {} seconds from {} to {} triangles'.format( + from logging import getLogger + + getLogger("pyfqmr").debug('simplified mesh in {} seconds from {} to {} triangles'.format( round(t_end-t_start,4), N_start, N_end) ) diff --git a/tests/test_simplify.py b/tests/test_simplify.py index 32421d0..5dd506b 100644 --- a/tests/test_simplify.py +++ b/tests/test_simplify.py @@ -1,3 +1,4 @@ +from logging import root as root_logger, DEBUG from pathlib import Path import pytest @@ -5,6 +6,8 @@ import numpy as np +root_logger.setLevel(DEBUG) + # Get the /example folder at the root of this repo EXAMPLES_DIR = Path(__file__, "..", "..", "example").resolve()