There are several smoothing algorithm. Laplacian smoothing is one of the best solutions.
Applying your own laplacian smoothing algorithme can be laborious. Instead you can use MeshlabServer to apply a perfect laplacian smoothing.
You should have necessary meshlab dlls. For that, you can install the Meshlab on the PC.
When you install the Meshlab on a PC, you have all necessary dlls in the installation folder. But if you want to take only the dlls that you need for the filtering method that you want to use, you can put them in your installation folder. In this case, you should install visual C++ redistribuables (Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.26.2872) on the pc that you want to call MeshlabServer's fonctions.
Finally, you should define your .mlx file to tell to the Meshlab server which filter to apply.
Here is the content of the .mlx file for a laplacian smoothing of 6 steps :
<FilterScript>
<filter name="Laplacian Smooth">
<Param name="stepSmoothNum" tooltip="" description="" isxmlparam="0" value="6"
type="RichInt"/>
<Param name="selection" tooltip="" description="" isxmlparam="0" value="false"
type="RichBool"/>
<Param name="boundarySmooth" tooltip="" description="" isxmlparam="0" value="true"
type="RichBool"/>
<Param name="cotangentWeight" tooltip="" description="" isxmlparam="0" value="true"
type="RichBool"/>
</filter>
</FilterScript>
And the C# method to call the filtering function :
/// <summary>
/// Applies a laplacian smoothing filter to the given 3D object.
/// </summary>
/// <param name="input">The path of the source 3D object</param>
/// <param name="output">The path to save the smoothed result.</param>
/// <param name="meshlabRoot">The path of the Meshlab dlls folder</param>
/// <returns></returns>
public static bool LaplacianSmoothing(string input, string output, string meshlabRoot)
{
bool retVal = true;
try
{
string strCmdText;
string mlxPath = meshlabRoot + "LaplacianFilter.mlx";
strCmdText = "/C " + meshlabRoot +
@"meshlabserver " +
@"-i " + input + " " +
@"-o " + output + " -s " +
mlxPath;
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = strCmdText;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
catch (Exception ex)
{
UserMethods.ParseError(ex, "SmoothFile");
retVal = false;
}
return retVal;