pmneila / PyMCubes

Marching cubes (and related tools) for Python
BSD 3-Clause "New" or "Revised" License
692 stars 87 forks source link

marching cube smooth #40

Closed charlieguo0610 closed 1 year ago

charlieguo0610 commented 1 year ago

Hi, Thank you for your great work! I have one question regarding the mcube smooth operation: is there a degree to which I can control the call on mcubes.smooth(), such as setting a parameter for smoothness?

pmneila commented 1 year ago

Hi,

Yes, you can control the amount of smoothing.

There are two smoothing methods available in mcubes.smooth: gaussian and constrained. By default, the function chooses the method based on the size of the input array, as defined here, but you can force a specific method using the method parameter.

  1. For the gaussian method, you can control the amount of smoothing by passing the argument sigma (default value is 3). You can increase the smoothness by increasing the value of sigma. For example:
mcubes.smooth(array, method='gaussian', sigma=5)

Keep in mind that a high value of sigma can lead to loss of fine details in your surface.

  1. For the constrained method, you can reduce the amount of smoothing by either decreasing the number of iterations max_iters (default 500) or increasing the tolerance rel_tol (default 1e-6). For example:
    mcubes.smooth(array, method='constrained', max_iters=50, rel_tol=1e-4)

    The constrained method is designed to converge to an optimal solution, meaning it will preserve the details of the surface even with high values of max_iters, which is desirable in some cases. However, in many other cases this is not a requirement and it might seem that the constrained method doesn't provide enough smoothing. In that case, just use the gaussian method.

Hope that clarifies your question.

charlieguo0610 commented 1 year ago

Yes, I appreciate your explanation!